Skip to content

Commit

Permalink
fix: check active hardforks using head block for validator (#4882)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Oct 2, 2023
1 parent f59db31 commit 08c5c43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions bin/reth/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {

// 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),
Expand All @@ -296,11 +296,15 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
.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());
Expand Down Expand Up @@ -333,7 +337,6 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
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),
Expand Down Expand Up @@ -680,6 +683,9 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
Ok(handle)
}

/// Fetches the head block from the database.
///
/// If the database is empty, returns the genesis block.
fn lookup_head(&self, db: Arc<DatabaseEnv>) -> RethResult<Head> {
let factory = ProviderFactory::new(db, self.chain.clone());
let provider = factory.provider()?;
Expand Down
9 changes: 9 additions & 0 deletions crates/transaction-pool/src/validate/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
///
Expand Down

0 comments on commit 08c5c43

Please sign in to comment.