From 08c5c43b78fed4405743670ed65a341fa7c41f55 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 3 Oct 2023 00:08:12 +0200 Subject: [PATCH] fix: check active hardforks using head block for validator (#4882) --- bin/reth/src/node/mod.rs | 10 ++++++++-- crates/transaction-pool/src/validate/eth.rs | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index cc6627a07f..5455f02065 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -276,7 +276,7 @@ impl NodeCommand { // configure blockchain tree let tree_externals = TreeExternals::new( - db.clone(), + Arc::clone(&db), Arc::clone(&consensus), Factory::new(self.chain.clone()), Arc::clone(&self.chain), @@ -296,11 +296,15 @@ impl NodeCommand { .with_sync_metrics_tx(metrics_tx.clone()), ); + // fetch the head block from the database + let head = self.lookup_head(Arc::clone(&db)).wrap_err("the head block is missing")?; + // setup the blockchain provider let factory = ProviderFactory::new(Arc::clone(&db), Arc::clone(&self.chain)); let blockchain_db = BlockchainProvider::new(factory, blockchain_tree.clone())?; let blob_store = InMemoryBlobStore::default(); let validator = TransactionValidationTaskExecutor::eth_builder(Arc::clone(&self.chain)) + .with_head_timestamp(head.timestamp) .kzg_settings(self.kzg_settings()?) .with_additional_tasks(1) .build_with_tasks(blockchain_db.clone(), ctx.task_executor.clone(), blob_store.clone()); @@ -333,7 +337,6 @@ impl NodeCommand { debug!(target: "reth::cli", ?network_secret_path, "Loading p2p key file"); let secret_key = get_secret_key(&network_secret_path)?; let default_peers_path = data_dir.known_peers_path(); - let head = self.lookup_head(Arc::clone(&db)).expect("the head block is missing"); let network_config = self.load_network_config( &config, Arc::clone(&db), @@ -680,6 +683,9 @@ impl NodeCommand { Ok(handle) } + /// Fetches the head block from the database. + /// + /// If the database is empty, returns the genesis block. fn lookup_head(&self, db: Arc) -> RethResult { let factory = ProviderFactory::new(db, self.chain.clone()); let provider = factory.provider()?; diff --git a/crates/transaction-pool/src/validate/eth.rs b/crates/transaction-pool/src/validate/eth.rs index f37ba7f214..936793ea80 100644 --- a/crates/transaction-pool/src/validate/eth.rs +++ b/crates/transaction-pool/src/validate/eth.rs @@ -485,6 +485,15 @@ impl EthTransactionValidatorBuilder { self } + /// Configures validation rules based on the head block's timestamp. + /// + /// For example, whether the Shanghai and Cancun hardfork is activated at launch. + pub fn with_head_timestamp(mut self, timestamp: u64) -> Self { + self.cancun = self.chain_spec.is_cancun_active_at_timestamp(timestamp); + self.shanghai = self.chain_spec.is_shanghai_active_at_timestamp(timestamp); + self + } + /// Builds a the [EthTransactionValidator] and spawns validation tasks via the /// [TransactionValidationTaskExecutor] ///