Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fast test for balance < tx.Value + gas #5783

Merged
merged 3 commits into from
Jun 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Nethermind/Nethermind.TxPool/Filters/BalanceZeroFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public AcceptTxResult Accept(Transaction tx, TxFilteringState state, TxHandlingO
AcceptTxResult.InsufficientFunds :
AcceptTxResult.InsufficientFunds.WithMessage("Balance is zero, cannot pay gas");
}

if (balance < tx.Value)
{
Metrics.PendingTransactionsBalanceBelowValue++;
Expand All @@ -42,6 +43,23 @@ public AcceptTxResult Accept(Transaction tx, TxFilteringState state, TxHandlingO
AcceptTxResult.InsufficientFunds.WithMessage($"Balance is {balance} less than sending value {tx.Value}");
}

if (UInt256.MultiplyOverflow(tx.MaxFeePerGas, (UInt256)tx.GasLimit, out UInt256 txCostAndValue) ||
UInt256.AddOverflow(txCostAndValue, tx.Value, out txCostAndValue))
{
Metrics.PendingTransactionsBalanceBelowValue++;
if (_logger.IsTrace)
_logger.Trace($"Skipped adding transaction {tx.ToString(" ")}, cost overflow.");
return AcceptTxResult.Int256Overflow;
}

if (balance < txCostAndValue)
{
Metrics.PendingTransactionsBalanceBelowValue++;
return isNotLocal ?
AcceptTxResult.InsufficientFunds :
AcceptTxResult.InsufficientFunds.WithMessage($"Balance is {balance} less than sending value + gas {txCostAndValue}");
}

return AcceptTxResult.Accepted;
}
}
Expand Down