Consensys/gpact

Parallel Execution Engine can cause "Replacement transaction underpriced"

drinkcoffee opened this issue · 1 comments

When the parallel execution engine is used, it sends transactions in parallel. If multiple transactions are executed by Ethereum from the same account with the same nonce at the same gas price, then an error "Replacement transaction underpriced" is returned.

Web3J determines the nonce to use by contacting the Ethereum node and finding out what the current nonce value is for the account, given the current transactions. However, if multiple parallel transactions are sent simultaneously, they will be submitted with the same nonce.

There are two ways of solving this issue:

Send transactions that are for information from separate blockchains using different accounts. This would then mean that each of the accounts would need to be funded on each blockchain.
Keep a track of the nonce value to use, and create the Web3J raw transaction manager. An example of how to do this is here: https://ethereum.stackexchange.com/questions/66277/how-to-change-the-nonce-between-transactions-in-web3j

The nonce management has been improved. Nonces are now managed using https://github.com/ConsenSys/gpact/blob/master/library/common/src/main/java/net/consensys/gpact/common/FastTxManager.java
and
https://github.com/ConsenSys/gpact/blob/master/library/common/src/main/java/net/consensys/gpact/common/TxManagerCache.java
FastTxManager has an incrementing nonce value managed outside of the blockchain.
The TxManagerCache allows multiple uses of a transaction manager for the same credentials and blockchain across an application.
The issues described above no longer occur.