Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web3j only supports 1 transaction per block #43

Closed
tramonex-nate opened this issue Jan 12, 2017 · 13 comments
Closed

Web3j only supports 1 transaction per block #43

tramonex-nate opened this issue Jan 12, 2017 · 13 comments
Labels
enhancement a feature request

Comments

@tramonex-nate
Copy link
Contributor

Due to the behaviour of getNonce in ManagedTransaction.java:

    protected BigInteger getNonce(String address) throws InterruptedException, ExecutionException {
        EthGetTransactionCount ethGetTransactionCount = web3j.ethGetTransactionCount(
                address, DefaultBlockParameterName.LATEST).sendAsync().get();

        return ethGetTransactionCount.getTransactionCount();
    }

If more than 1 transaction is sent per block, the nonce will be incorrect (all transactions sent in the same block will have the same nonce). This will lead to all transaction but one being invalid.

Suggestion:
Maintain a count of how many transactions have been sent from the address for the current block, and return ethGetTransactionCount.getTransactionCount() + sentTransactionCount. This could still lead to problems in various situations, but would be an improvement. Really open to alternate solutions

@conor10 conor10 added the enhancement a feature request label Jan 13, 2017
@conor10
Copy link
Contributor

conor10 commented Jan 13, 2017

@ferOnti would you be willing to share your implementation?

#34 (comment)

@ferOnti
Copy link

ferOnti commented Jan 16, 2017

@conor10 the implementation is not ready yet, because still having the issue "rlp: non-canonical integer (leading zero bytes) for *big.Int, decoding into (types.Transaction)(types.txdata).S”

for this reason I'm losing some transactions from time to time. Since I'm in proof of concept this is enough for this state.

Later this week I will revisit this feature and work in the nonce manager. I will keep you posted on this.

@conor10
Copy link
Contributor

conor10 commented Jan 16, 2017

Was my previous response of help?

Is there a quantity value in your pre-encoded request that is being specified with a leading zero, e.g. 0x0... - as these are not supported in the JSON-RPC API - see https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding.

@ferOnti
Copy link

ferOnti commented Jan 30, 2017 via email

@conor10
Copy link
Contributor

conor10 commented Jan 31, 2017

@ferOnti RLP issue fix has just been checked in, see https://github.com/web3j/web3j/blob/master/src/main/java/org/web3j/rlp/RlpString.java#L25 for details.

Re: web3j-quorum, the API for working with smart contracts in Quorum is going to get a lot simpler when I put out the web3j 1.2.0 release in the next week. All that will be required is a Quorum transaction manager instead of a Quorum specific smart contract code generator as is currently the case.

@fraspadafora
Copy link

Why to mantain a local nonce and increment it?
If with another client I'm creating transactions there can be a problem.

As I suggested here : #54
You can use the method:

web3j.ethGetTransactionCount(address, DefaultBlockParameterName.PENDING)

That returns the number of transactions validated and in pending, so after you create a transaction you can receive the nonce updated.

@tramonex-nate
Copy link
Contributor Author

Have you tested this? According to my knowledge of how the 'pending' block parameter name works, it's actually the block that the target node is mining (which will not be anything if the node is not mining)

@ferOnti
Copy link

ferOnti commented Feb 9, 2017

I had some doubts about use this, but I will test now

@fraspadafora
Copy link

From: https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethdefaultblock

"pending", the currently mined block (including pending transactions)

@ferOnti
Copy link

ferOnti commented Feb 9, 2017

I tested with these two alternatives, but the web3j.ethGetTransactionCount(address, DefaultBlockParameterName.PENDING) is repeating the nonce many times

The first graph is using the PENDING option, and as you can see the log in the line Web3Service:988 is repeating the nonce many times ( 969 three times, 971 five times, etc )

screen shot 2017-02-09 at 4 46 36 pm

This second graph, is getting the nonce from the HQTransactionManager , and the nonce is not repeated

screen shot 2017-02-09 at 4 50 26 pm

when the nonce is repeated, the transactions are overwritten and they are not included in any block.

I will post the HQTransactionManager with the second option

@fraspadafora
Copy link

fraspadafora commented Feb 13, 2017

Can you check using the RawTransactionManager class but making the executeTransaction method synchronized?

I think using the synchronized method solves the problem.

As I said here: #54

In the FastRawTransactionManager If I use another client with the same account and I send a transaction, the nonce in the will be not updated and all transactions will be invalid.

@scalahub
Copy link

scalahub commented Oct 25, 2017

Is this solved? I am getting outdated nonces with DefaultBlockParameterName.LATEST. Right now I have no other option but to maintain a list internally.. kind of writing a client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement a feature request
Projects
None yet
Development

No branches or pull requests

5 participants