diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaSendRawTransaction.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaSendRawTransaction.java index f3c74fef7b..52db6457a9 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaSendRawTransaction.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaSendRawTransaction.java @@ -17,6 +17,7 @@ import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Transaction; +import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPool; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcMethod; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; @@ -35,6 +36,8 @@ import tech.pegasys.pantheon.ethereum.rlp.RLPException; import tech.pegasys.pantheon.util.bytes.BytesValue; +import java.util.OptionalLong; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -46,6 +49,7 @@ public class EeaSendRawTransaction implements JsonRpcMethod { private final PrivateTransactionHandler privateTransactionHandler; private final TransactionPool transactionPool; private final JsonRpcParameter parameters; + private final PendingTransactions pendingTransactions; public EeaSendRawTransaction( final BlockchainQueries blockchain, @@ -56,6 +60,7 @@ public EeaSendRawTransaction( this.privateTransactionHandler = privateTransactionHandler; this.transactionPool = transactionPool; this.parameters = parameters; + this.pendingTransactions = transactionPool.getPendingTransactions(); } @Override @@ -137,6 +142,8 @@ private PrivateTransaction decodeRawTransaction(final String hash) } protected long getNonce(final Address address) { - return blockchain.getTransactionCount(address, blockchain.headBlockNumber()); + final OptionalLong pendingNonce = pendingTransactions.getNextNonceForSender(address); + return pendingNonce.orElseGet( + () -> blockchain.getTransactionCount(address, blockchain.headBlockNumber())); } } diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaSendRawTransactionTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaSendRawTransactionTest.java index 9cc87fb233..2cbcf6a2dd 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaSendRawTransactionTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaSendRawTransactionTest.java @@ -22,6 +22,7 @@ import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.Wei; +import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPool; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter; @@ -39,6 +40,7 @@ import java.io.IOException; import java.math.BigInteger; import java.util.Optional; +import java.util.OptionalLong; import org.junit.Before; import org.junit.Test; @@ -100,8 +102,12 @@ public class EeaSendRawTransactionTest { @Mock private BlockchainQueries blockchainQueries; + @Mock private PendingTransactions pendingTransactions; + @Before public void before() { + when(transactionPool.getPendingTransactions()).thenReturn(pendingTransactions); + method = new EeaSendRawTransaction(blockchainQueries, privateTxHandler, transactionPool, parameter); } @@ -192,7 +198,6 @@ public void validTransactionIsSentToTransactionPool() throws Exception { .thenReturn(PUBLIC_TRANSACTION); when(transactionPool.addLocalTransaction(any(Transaction.class))) .thenReturn(ValidationResult.valid()); - final JsonRpcRequest request = new JsonRpcRequest( "2.0", "eea_sendRawTransaction", new String[] {VALID_PRIVATE_TRANSACTION_RLP}); @@ -293,7 +298,6 @@ private void verifyErrorForInvalidTransaction( .thenReturn(PUBLIC_TRANSACTION); when(transactionPool.addLocalTransaction(any(Transaction.class))) .thenReturn(ValidationResult.invalid(transactionInvalidReason)); - final JsonRpcRequest request = new JsonRpcRequest( "2.0", "eea_sendRawTransaction", new String[] {VALID_PRIVATE_TRANSACTION_RLP}); @@ -314,6 +318,13 @@ private void verifyErrorForInvalidTransaction( verify(transactionPool).addLocalTransaction(any(Transaction.class)); } + @Test + public void nextNonceUsesTxPool() { + Address address = PUBLIC_TRANSACTION.getSender(); + when(pendingTransactions.getNextNonceForSender(address)).thenReturn(OptionalLong.of(123)); + assertThat(method.getNonce(address)).isEqualTo(123); + } + @Test public void getMethodReturnsExpectedName() { assertThat(method.getName()).matches("eea_sendRawTransaction"); diff --git a/ethereum/referencetests/src/test/resources b/ethereum/referencetests/src/test/resources index 0327d9f76c..420f443477 160000 --- a/ethereum/referencetests/src/test/resources +++ b/ethereum/referencetests/src/test/resources @@ -1 +1 @@ -Subproject commit 0327d9f76ce2a292a99e7a9dfc93627368ce589e +Subproject commit 420f443477caa8516f1f9ee8122fafc3415c0f34