Skip to content

Commit

Permalink
add all nonces to the _nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishqjasoria committed Aug 3, 2022
1 parent 5881a7c commit 4535b15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions src/Nethermind/Nethermind.TxPool/TxPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++; }
Expand Down

0 comments on commit 4535b15

Please sign in to comment.