Skip to content

Commit

Permalink
Fix TooExpensiveTxFilter (#3497)
Browse files Browse the repository at this point in the history
* do not count stale txs when calculating cumulative cost

* regression test

* cosmetic

* simplified test

* break is back
  • Loading branch information
marcindsobczak authored Oct 8, 2021
1 parent 0f8c927 commit 33ff7cd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,41 @@ public void should_not_add_tx_if_already_pending_lower_nonces_are_exhausting_bal

_txPool.GetPendingTransactionsCount().Should().Be(numberOfTxsPossibleToExecuteBeforeGasExhaustion);
}

[TestCase(1, 0)]
[TestCase(2, 1)]
[TestCase(5, 5)]
[TestCase(10, 3)]
public void should_not_count_txs_with_stale_nonces_when_calculating_cumulative_cost(int numberOfTxsPossibleToExecuteBeforeGasExhaustion, int numberOfStaleTxsInBucket)
{
const int gasPrice = 10;
const int value = 1;
int oneTxPrice = _txGasLimit * gasPrice + value;
_txPool = CreatePool();

EnsureSenderBalance(TestItem.AddressA, (UInt256)(oneTxPrice * numberOfTxsPossibleToExecuteBeforeGasExhaustion));

for (int i = 0; i < numberOfTxsPossibleToExecuteBeforeGasExhaustion * 2; i++)
{
Transaction tx = Build.A.Transaction
.WithSenderAddress(TestItem.AddressA)
.WithNonce((UInt256)i)
.WithGasPrice((UInt256)gasPrice)
.WithGasLimit(_txGasLimit)
.WithValue(value)
.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA).TestObject;
_txPool.SubmitTx(tx, TxHandlingOptions.PersistentBroadcast);

if (i < numberOfStaleTxsInBucket)
{
_stateProvider.IncrementNonce(TestItem.AddressA);
}
}

int numberOfTxsInTxPool = _txPool.GetPendingTransactionsCount();
numberOfTxsInTxPool.Should().Be(numberOfTxsPossibleToExecuteBeforeGasExhaustion + numberOfStaleTxsInBucket);
_txPool.GetPendingTransactions()[numberOfTxsInTxPool - 1].Nonce.Should().Be((UInt256)(numberOfTxsInTxPool - 1));
}

[Test]
public void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public TooExpensiveTxFilter(IChainHeadInfoProvider headInfo, IAccountStateProvid

for (int i = 0; i < transactions.Length; i++)
{
if (transactions[i].Nonce < account.Nonce)
{
continue;
}

if (transactions[i].Nonce < tx.Nonce)
{
overflow |= UInt256.MultiplyOverflow(
Expand Down

0 comments on commit 33ff7cd

Please sign in to comment.