From 9b12f4ff9362f98a6c2142db2ab6ed7de5dc524e Mon Sep 17 00:00:00 2001 From: Siyuan Han <47173566+hsyodyssey@users.noreply.github.com> Date: Tue, 26 Dec 2023 20:22:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(txpool):=20missing=20condition=20that=20tx?= =?UTF-8?q?=20gas=20limit=20equal=20to=20block=20gas=20l=E2=80=A6=20(#5858?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/transaction-pool/src/pool/txpool.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index 617cdaa94c93..1c488fd8cfee 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -1415,6 +1415,9 @@ impl AllTransactions { let mut cumulative_cost = U256::ZERO; let mut updates = Vec::new(); + // Current tx does not exceed block gas limit after ensure_valid check + state.insert(TxState::NOT_TOO_MUCH_GAS); + // identifier of the ancestor transaction, will be None if the transaction is the next tx of // the sender let ancestor = TransactionId::ancestor( @@ -1457,11 +1460,6 @@ impl AllTransactions { state.insert(TxState::ENOUGH_FEE_CAP_BLOCK); } - // Ensure tx does not exceed block gas limit - if transaction.gas_limit() < self.block_gas_limit { - state.insert(TxState::NOT_TOO_MUCH_GAS); - } - // placeholder for the replaced transaction, if any let mut replaced_tx = None; @@ -2491,6 +2489,20 @@ mod tests { )); } + #[test] + fn test_tx_equal_gas_limit() { + let on_chain_balance = U256::from(1_000); + let on_chain_nonce = 0; + let mut f = MockTransactionFactory::default(); + let mut pool = AllTransactions::default(); + + let tx = MockTransaction::eip1559().with_gas_limit(30_000_000); + + let InsertOk { state, .. } = + pool.insert_tx(f.validated(tx), on_chain_balance, on_chain_nonce).unwrap(); + assert!(state.contains(TxState::NOT_TOO_MUCH_GAS)); + } + #[test] fn update_basefee_subpools() { let mut f = MockTransactionFactory::default();