From 4535b15548073edf2b3d75cd002b64c51baaad69 Mon Sep 17 00:00:00 2001 From: Tanishq Jasoria Date: Tue, 2 Aug 2022 09:35:49 +0530 Subject: [PATCH] add all nonces to the _nonce --- .../Modules/Eth/EthRpcModuleTests.cs | 2 +- src/Nethermind/Nethermind.TxPool/TxPool.cs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs index 9cc430f6163..f688572bb6d 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs @@ -211,7 +211,7 @@ public async Task Eth_get_tx_count(string blockParameter, string expectedResult) { using Context ctx = await Context.Create(); Transaction tx = Build.A.Transaction.To(TestItem.AddressB).SignedAndResolved(TestItem.PrivateKeyA).WithValue(0.Ether()).WithNonce(4).TestObject; - ValueTask<(Keccak? Hash, AcceptTxResult? AddTxResult)> result = ctx._test.TxSender.SendTransaction(tx, TxHandlingOptions.ManagedNonce); + ValueTask<(Keccak? Hash, AcceptTxResult? AddTxResult)> result = ctx._test.TxSender.SendTransaction(tx, TxHandlingOptions.None); Assert.AreEqual(result.Result.AddTxResult, AcceptTxResult.Accepted); string serialized = ctx._test.TestEthRpc("eth_getTransactionCount", TestItem.AddressA.Bytes.ToHexString(true), blockParameter); Assert.AreEqual($"{{\"jsonrpc\":\"2.0\",\"result\":\"{expectedResult}\",\"id\":67}}", serialized); diff --git a/src/Nethermind/Nethermind.TxPool/TxPool.cs b/src/Nethermind/Nethermind.TxPool/TxPool.cs index 1a09161a955..06bb996cc8b 100644 --- a/src/Nethermind/Nethermind.TxPool/TxPool.cs +++ b/src/Nethermind/Nethermind.TxPool/TxPool.cs @@ -300,6 +300,19 @@ private AcceptTxResult AddCore(Transaction tx, bool isPersistentBroadcast) bool inserted = _transactions.TryInsert(tx.Hash, tx, out Transaction? removed); if (inserted) { + Address address = tx.SenderAddress; + if (!_nonces.TryGetValue(address, out AddressNonces? addressNonces)) + { + addressNonces = new AddressNonces(tx.Nonce); + _nonces.TryAdd(address, addressNonces); + } + + if (!addressNonces.Nonces.TryGetValue(tx.Nonce, out NonceInfo? nonce)) + { + nonce = new NonceInfo(tx.Nonce); + addressNonces.Nonces.TryAdd(tx.Nonce, nonce); + } + _transactions.UpdateGroup(tx.SenderAddress!, UpdateBucketWithAddedTransaction); Metrics.PendingTransactionsAdded++; if (tx.IsEip1559) { Metrics.Pending1559TransactionsAdded++; }