Skip to content

Commit

Permalink
fix: update pool gas limit (#11025)
Browse files Browse the repository at this point in the history
  • Loading branch information
greged93 authored Sep 19, 2024
1 parent 2924d88 commit 4a7eb6e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion crates/ethereum/node/tests/e2e/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn custom_chain() -> Arc<ChainSpec> {
"nonce": "0x42",
"timestamp": "0x0",
"extraData": "0x5343",
"gasLimit": "0x1388",
"gasLimit": "0x13880",
"difficulty": "0x400000000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
Expand Down
16 changes: 8 additions & 8 deletions crates/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<ValidPoolTransaction<Self::Transaction>>> {
self.pool.get_pending_transactions_by_origin(origin)
}

fn unique_senders(&self) -> HashSet<Address> {
self.pool.unique_senders()
}
Expand Down Expand Up @@ -533,14 +541,6 @@ where
) -> Result<Vec<Option<BlobAndProofV1>>, 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<Arc<ValidPoolTransaction<Self::Transaction>>> {
self.pool.get_pending_transactions_by_origin(origin)
}
}

impl<V, T, S> TransactionPoolExt for Pool<V, T, S>
Expand Down
2 changes: 2 additions & 0 deletions crates/transaction-pool/src/maintain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub async fn maintain_transaction_pool<Client, P, St, Tasks>(
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
Expand Down Expand Up @@ -403,6 +404,7 @@ pub async fn maintain_transaction_pool<Client, P, St, Tasks>(
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,
Expand Down
3 changes: 2 additions & 1 deletion crates/transaction-pool/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions crates/transaction-pool/src/pool/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl<T: TransactionOrdering> TxPool<T> {
/// 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,
Expand Down Expand Up @@ -236,6 +237,7 @@ impl<T: TransactionOrdering> TxPool<T> {
/// 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,
Expand All @@ -245,6 +247,8 @@ impl<T: TransactionOrdering> TxPool<T> {
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)
}
Expand Down Expand Up @@ -1001,6 +1005,7 @@ impl<T: PoolTransaction> AllTransactions<T> {
/// 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,
Expand All @@ -1012,6 +1017,8 @@ impl<T: PoolTransaction> AllTransactions<T> {
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);
Expand Down
5 changes: 4 additions & 1 deletion crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion crates/transaction-pool/tests/it/evict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4a7eb6e

Please sign in to comment.