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

chore: update gas limit on new head block #13333

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Changes from 1 commit
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
26 changes: 17 additions & 9 deletions crates/transaction-pool/src/validate/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ use reth_storage_api::{AccountReader, StateProviderFactory};
use reth_tasks::TaskSpawner;
use std::{
marker::PhantomData,
sync::{atomic::AtomicBool, Arc},
sync::{
atomic::{AtomicBool, AtomicU64},
Arc,
},
};
use tokio::sync::Mutex;

Expand Down Expand Up @@ -141,7 +144,7 @@ pub(crate) struct EthTransactionValidatorInner<Client, T> {
/// Fork indicator whether we are using EIP-7702 type transactions.
eip7702: bool,
/// The current max gas limit
block_gas_limit: u64,
block_gas_limit: AtomicU64,
/// Minimum priority fee to enforce for acceptance into the pool.
minimum_priority_fee: Option<u128>,
/// Stores the setup and parameters needed for validating KZG proofs.
Expand Down Expand Up @@ -245,12 +248,12 @@ where

// Checks for gas limit
let transaction_gas_limit = transaction.gas_limit();
if transaction_gas_limit > self.block_gas_limit {
if transaction_gas_limit > self.block_gas_limit.load(std::sync::atomic::Ordering::Relaxed) {
TheDhejavu marked this conversation as resolved.
Show resolved Hide resolved
return TransactionValidationOutcome::Invalid(
transaction,
InvalidPoolTransactionError::ExceedsGasLimit(
transaction_gas_limit,
self.block_gas_limit,
self.block_gas_limit.load(std::sync::atomic::Ordering::Relaxed),
),
)
}
Expand Down Expand Up @@ -484,11 +487,16 @@ where
if self.chain_spec.is_prague_active_at_timestamp(new_tip_block.timestamp()) {
self.fork_tracker.prague.store(true, std::sync::atomic::Ordering::Relaxed);
}

if new_tip_block.gas_limit() > 0 {
TheDhejavu marked this conversation as resolved.
Show resolved Hide resolved
self.block_gas_limit
.store(new_tip_block.gas_limit(), std::sync::atomic::Ordering::Relaxed);
}
}
}

/// A builder for [`TransactionValidationTaskExecutor`]
#[derive(Debug, Clone)]
#[derive(Debug)]
pub struct EthTransactionValidatorBuilder {
chain_spec: Arc<ChainSpec>,
/// Fork indicator whether we are in the Shanghai stage.
Expand All @@ -506,7 +514,7 @@ pub struct EthTransactionValidatorBuilder {
/// Whether using EIP-7702 type transactions is allowed
eip7702: bool,
/// The current max gas limit
block_gas_limit: u64,
block_gas_limit: AtomicU64,
/// Minimum priority fee to enforce for acceptance into the pool.
minimum_priority_fee: Option<u128>,
/// Determines how many additional tasks to spawn
Expand All @@ -533,7 +541,7 @@ impl EthTransactionValidatorBuilder {
/// - EIP-4844
pub fn new(chain_spec: Arc<ChainSpec>) -> Self {
Self {
block_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT,
block_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT.into(),
chain_spec,
minimum_priority_fee: None,
additional_tasks: 1,
Expand Down Expand Up @@ -670,8 +678,8 @@ impl EthTransactionValidatorBuilder {
/// Sets the block gas limit
///
/// Transactions with a gas limit greater than this will be rejected.
pub const fn set_block_gas_limit(mut self, block_gas_limit: u64) -> Self {
self.block_gas_limit = block_gas_limit;
pub fn set_block_gas_limit(self, block_gas_limit: u64) -> Self {
self.block_gas_limit.store(block_gas_limit, std::sync::atomic::Ordering::Relaxed);
self
}

Expand Down
Loading