chore: update gas limit on new head block (#13333)

This commit is contained in:
Ayodeji Akinola
2024-12-12 14:27:59 +01:00
committed by GitHub
parent b94a31f6d8
commit f7dc27f026

View File

@ -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;
@ -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.
@ -245,12 +248,13 @@ where
// Checks for gas limit
let transaction_gas_limit = transaction.gas_limit();
if transaction_gas_limit > self.block_gas_limit {
let block_gas_limit = self.max_gas_limit();
if transaction_gas_limit > block_gas_limit {
return TransactionValidationOutcome::Invalid(
transaction,
InvalidPoolTransactionError::ExceedsGasLimit(
transaction_gas_limit,
self.block_gas_limit,
block_gas_limit,
),
)
}
@ -484,11 +488,17 @@ 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);
}
self.block_gas_limit.store(new_tip_block.gas_limit(), std::sync::atomic::Ordering::Relaxed);
}
fn max_gas_limit(&self) -> u64 {
self.block_gas_limit.load(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.
@ -506,7 +516,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
@ -533,7 +543,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,
@ -670,8 +680,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
}