From e45db5fb5a438f34ab8337f505b348b0c0f8f7b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Moraczy=C5=84ski?= Date: Thu, 22 Jul 2021 12:00:01 +0200 Subject: [PATCH] One more balance fix (#3241) * One more balance fix * fix test * fix test --- .../TransactionsExecutorTests.cs | 18 ++++++++++++++++++ ...ocessor.BlockProductionTransactionPicker.cs | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs index 28e285ac7a3..ce1157fe5bc 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs @@ -179,6 +179,23 @@ public static IEnumerable ProperTransactionsSelectedTestCases GasLimit = 10000000 }; yield return new TestCaseData(balanceBelowMaxFeeTimesGasLimit).SetName("EIP1559 transactions: none transactions selected because balance is lower than MaxFeePerGas times GasLimit"); + + ProperTransactionsSelectedTestCase balanceFailingWithMaxFeePerGasCheck = + new ProperTransactionsSelectedTestCase() + { + Eip1559Enabled = true, + BaseFee = 5, + AccountStates = {{TestItem.AddressA, (400, 1)}}, + Transactions = + { + Build.A.Transaction.WithSenderAddress(TestItem.AddressA).WithNonce(1) + .WithMaxFeePerGas(300).WithMaxPriorityFeePerGas(10).WithGasLimit(10) + .WithType(TxType.EIP1559).WithValue(101).SignedAndResolved(TestItem.PrivateKeyA) + .TestObject, + }, + GasLimit = 10000000 + }; + yield return new TestCaseData(balanceFailingWithMaxFeePerGasCheck).SetName("EIP1559 transactions: None transactions selected - sender balance and max fee per gas check"); } } @@ -196,6 +213,7 @@ public void Proper_transactions_selected(ProperTransactionsSelectedTestCase test { IsEip1559Enabled = testCase.Eip1559Enabled }; + specProvider.GetSpec(Arg.Any()).Returns(spec); ITransactionProcessor transactionProcessor = Substitute.For(); transactionProcessor.When(t => t.BuildUp(Arg.Any(), Arg.Any(), Arg.Any())) diff --git a/src/Nethermind/Nethermind.Blockchain/Processing/BlockProcessor.BlockProductionTransactionPicker.cs b/src/Nethermind/Nethermind.Blockchain/Processing/BlockProcessor.BlockProductionTransactionPicker.cs index 4458dd500f8..c7ed5dab683 100644 --- a/src/Nethermind/Nethermind.Blockchain/Processing/BlockProcessor.BlockProductionTransactionPicker.cs +++ b/src/Nethermind/Nethermind.Blockchain/Processing/BlockProcessor.BlockProductionTransactionPicker.cs @@ -95,7 +95,7 @@ private bool HasEnoughFounds(Transaction transaction, UInt256 senderBalance, Add return false; } - if (transaction.IsEip1559 && !transaction.IsServiceTransaction && senderBalance < (UInt256)transaction.GasLimit * transaction.MaxFeePerGas) + if (eip1559Enabled && !transaction.IsServiceTransaction && senderBalance < (UInt256)transaction.GasLimit * transaction.MaxFeePerGas + transaction.Value) { e.Set(TxAction.Skip, $"MaxFeePerGas ({transaction.MaxFeePerGas}) times GasLimit {transaction.GasLimit} is higher than sender balance ({senderBalance})"); return false;