From 4a7eb6e914a621cebaeab1aa25cf3726883bca3f Mon Sep 17 00:00:00 2001 From: greged93 <82421016+greged93@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:18:04 +0200 Subject: [PATCH] fix: update pool gas limit (#11025) --- crates/ethereum/node/tests/e2e/dev.rs | 2 +- crates/transaction-pool/src/lib.rs | 16 ++++++++-------- crates/transaction-pool/src/maintain.rs | 2 ++ crates/transaction-pool/src/noop.rs | 3 ++- crates/transaction-pool/src/pool/txpool.rs | 7 +++++++ crates/transaction-pool/src/traits.rs | 5 ++++- crates/transaction-pool/tests/it/evict.rs | 5 ++++- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/crates/ethereum/node/tests/e2e/dev.rs b/crates/ethereum/node/tests/e2e/dev.rs index 894d76a71..2ef6e08c7 100644 --- a/crates/ethereum/node/tests/e2e/dev.rs +++ b/crates/ethereum/node/tests/e2e/dev.rs @@ -48,7 +48,7 @@ fn custom_chain() -> Arc { "nonce": "0x42", "timestamp": "0x0", "extraData": "0x5343", - "gasLimit": "0x1388", + "gasLimit": "0x13880", "difficulty": "0x400000000", "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "coinbase": "0x0000000000000000000000000000000000000000", diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index 2af1a025c..4aec8ab40 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -505,6 +505,14 @@ where self.pool.get_transactions_by_origin(origin) } + /// Returns all pending transactions filtered by [`TransactionOrigin`] + fn get_pending_transactions_by_origin( + &self, + origin: TransactionOrigin, + ) -> Vec>> { + self.pool.get_pending_transactions_by_origin(origin) + } + fn unique_senders(&self) -> HashSet
{ self.pool.unique_senders() } @@ -533,14 +541,6 @@ where ) -> Result>, BlobStoreError> { self.pool.blob_store().get_by_versioned_hashes(versioned_hashes) } - - /// Returns all pending transactions filtered by [`TransactionOrigin`] - fn get_pending_transactions_by_origin( - &self, - origin: TransactionOrigin, - ) -> Vec>> { - self.pool.get_pending_transactions_by_origin(origin) - } } impl TransactionPoolExt for Pool diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index 255d81251..4865606ac 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -117,6 +117,7 @@ pub async fn maintain_transaction_pool( let latest = latest.seal_slow(); let chain_spec = client.chain_spec(); let info = BlockInfo { + block_gas_limit: latest.gas_limit, last_seen_block_hash: latest.hash(), last_seen_block_number: latest.number, pending_basefee: latest @@ -403,6 +404,7 @@ pub async fn maintain_transaction_pool( maintained_state = MaintainedPoolState::Drifted; debug!(target: "txpool", ?depth, "skipping deep canonical update"); let info = BlockInfo { + block_gas_limit: tip.gas_limit, last_seen_block_hash: tip.hash(), last_seen_block_number: tip.number, pending_basefee: pending_block_base_fee, diff --git a/crates/transaction-pool/src/noop.rs b/crates/transaction-pool/src/noop.rs index 9ca639427..0c4caa573 100644 --- a/crates/transaction-pool/src/noop.rs +++ b/crates/transaction-pool/src/noop.rs @@ -19,7 +19,7 @@ use crate::{ use alloy_eips::eip4844::BlobAndProofV1; use alloy_primitives::{Address, TxHash, B256, U256}; use reth_eth_wire_types::HandleMempoolData; -use reth_primitives::BlobTransactionSidecar; +use reth_primitives::{constants::ETHEREUM_BLOCK_GAS_LIMIT, BlobTransactionSidecar}; use std::{collections::HashSet, marker::PhantomData, sync::Arc}; use tokio::sync::{mpsc, mpsc::Receiver}; @@ -40,6 +40,7 @@ impl TransactionPool for NoopTransactionPool { fn block_info(&self) -> BlockInfo { BlockInfo { + block_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, last_seen_block_hash: Default::default(), last_seen_block_number: 0, pending_basefee: 0, diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index a20ff4699..f3b59e094 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -132,6 +132,7 @@ impl TxPool { /// Returns the currently tracked block values pub const fn block_info(&self) -> BlockInfo { BlockInfo { + block_gas_limit: self.all_transactions.block_gas_limit, last_seen_block_hash: self.all_transactions.last_seen_block_hash, last_seen_block_number: self.all_transactions.last_seen_block_number, pending_basefee: self.all_transactions.pending_fees.base_fee, @@ -236,6 +237,7 @@ impl TxPool { /// This will also apply updates to the pool based on the new base fee pub fn set_block_info(&mut self, info: BlockInfo) { let BlockInfo { + block_gas_limit, last_seen_block_hash, last_seen_block_number, pending_basefee, @@ -245,6 +247,8 @@ impl TxPool { self.all_transactions.last_seen_block_number = last_seen_block_number; let basefee_ordering = self.update_basefee(pending_basefee); + self.all_transactions.block_gas_limit = block_gas_limit; + if let Some(blob_fee) = pending_blob_fee { self.update_blob_fee(blob_fee, basefee_ordering) } @@ -1001,6 +1005,7 @@ impl AllTransactions { /// Updates the block specific info fn set_block_info(&mut self, block_info: BlockInfo) { let BlockInfo { + block_gas_limit, last_seen_block_hash, last_seen_block_number, pending_basefee, @@ -1012,6 +1017,8 @@ impl AllTransactions { self.pending_fees.base_fee = pending_basefee; self.metrics.base_fee.set(pending_basefee as f64); + self.block_gas_limit = block_gas_limit; + if let Some(pending_blob_fee) = pending_blob_fee { self.pending_fees.blob_fee = pending_blob_fee; self.metrics.blob_base_fee.set(pending_blob_fee as f64); diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index 0f4ca5d96..8ebfb0970 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -666,6 +666,7 @@ impl<'a> CanonicalStateUpdate<'a> { /// Returns the block info for the tip block. pub fn block_info(&self) -> BlockInfo { BlockInfo { + block_gas_limit: self.new_tip.gas_limit, last_seen_block_hash: self.hash(), last_seen_block_number: self.number(), pending_basefee: self.pending_block_base_fee, @@ -1302,8 +1303,10 @@ impl PoolSize { pub struct BlockInfo { /// Hash for the currently tracked block. pub last_seen_block_hash: B256, - /// Current the currently tracked block. + /// Currently tracked block. pub last_seen_block_number: u64, + /// Current block gas limit for the latest block. + pub block_gas_limit: u64, /// Currently enforced base fee: the threshold for the basefee sub-pool. /// /// Note: this is the derived base fee of the _next_ block that builds on the block the pool is diff --git a/crates/transaction-pool/tests/it/evict.rs b/crates/transaction-pool/tests/it/evict.rs index c55d52309..c7438c996 100644 --- a/crates/transaction-pool/tests/it/evict.rs +++ b/crates/transaction-pool/tests/it/evict.rs @@ -2,7 +2,7 @@ use alloy_primitives::{Address, B256}; use rand::distributions::Uniform; -use reth_primitives::constants::MIN_PROTOCOL_BASE_FEE; +use reth_primitives::constants::{ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE}; use reth_transaction_pool::{ error::PoolErrorKind, test_utils::{ @@ -27,6 +27,7 @@ async fn only_blobs_eviction() { let pool: TestPool = TestPoolBuilder::default().with_config(pool_config.clone()).into(); let block_info = BlockInfo { + block_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, last_seen_block_hash: B256::ZERO, last_seen_block_number: 0, pending_basefee: 10, @@ -139,6 +140,7 @@ async fn mixed_eviction() { let pool: TestPool = TestPoolBuilder::default().with_config(pool_config.clone()).into(); let block_info = BlockInfo { + block_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, last_seen_block_hash: B256::ZERO, last_seen_block_number: 0, pending_basefee: 10, @@ -240,6 +242,7 @@ async fn nonce_gaps_eviction() { let pool: TestPool = TestPoolBuilder::default().with_config(pool_config.clone()).into(); let block_info = BlockInfo { + block_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, last_seen_block_hash: B256::ZERO, last_seen_block_number: 0, pending_basefee: 10,