feat: make InvalidBlockHook generic over NodePrimitives (#13105)

This commit is contained in:
Arsenii Kulikov
2024-12-03 19:38:10 +04:00
committed by GitHub
parent 7008ac22df
commit 9d5e159968
21 changed files with 133 additions and 115 deletions

1
Cargo.lock generated
View File

@ -7998,7 +7998,6 @@ dependencies = [
name = "reth-node-api" name = "reth-node-api"
version = "1.1.2" version = "1.1.2"
dependencies = [ dependencies = [
"alloy-consensus",
"alloy-rpc-types-engine", "alloy-rpc-types-engine",
"eyre", "eyre",
"reth-beacon-consensus", "reth-beacon-consensus",

View File

@ -1,4 +1,4 @@
use alloy_consensus::Header; use alloy_consensus::BlockHeader;
use alloy_primitives::{keccak256, B256, U256}; use alloy_primitives::{keccak256, B256, U256};
use alloy_rpc_types_debug::ExecutionWitness; use alloy_rpc_types_debug::ExecutionWitness;
use eyre::OptionExt; use eyre::OptionExt;
@ -8,8 +8,8 @@ use reth_engine_primitives::InvalidBlockHook;
use reth_evm::{ use reth_evm::{
state_change::post_block_balance_increments, system_calls::SystemCaller, ConfigureEvm, state_change::post_block_balance_increments, system_calls::SystemCaller, ConfigureEvm,
}; };
use reth_primitives::{Receipt, SealedBlockWithSenders, SealedHeader}; use reth_primitives::{NodePrimitives, SealedBlockWithSenders, SealedHeader, TransactionSigned};
use reth_primitives_traits::SignedTransaction; use reth_primitives_traits::{HeaderTy, SignedTransaction};
use reth_provider::{BlockExecutionOutput, ChainSpecProvider, StateProviderFactory}; use reth_provider::{BlockExecutionOutput, ChainSpecProvider, StateProviderFactory};
use reth_revm::{ use reth_revm::{
database::StateProviderDatabase, db::states::bundle_state::BundleRetention, database::StateProviderDatabase, db::states::bundle_state::BundleRetention,
@ -54,15 +54,18 @@ where
+ Send + Send
+ Sync + Sync
+ 'static, + 'static,
EvmConfig: ConfigureEvm<Header = Header>,
{ {
fn on_invalid_block( fn on_invalid_block<N>(
&self, &self,
parent_header: &SealedHeader, parent_header: &SealedHeader<N::BlockHeader>,
block: &SealedBlockWithSenders, block: &SealedBlockWithSenders<N::Block>,
output: &BlockExecutionOutput<Receipt>, output: &BlockExecutionOutput<N::Receipt>,
trie_updates: Option<(&TrieUpdates, B256)>, trie_updates: Option<(&TrieUpdates, B256)>,
) -> eyre::Result<()> { ) -> eyre::Result<()>
where
N: NodePrimitives<SignedTx = TransactionSigned>,
EvmConfig: ConfigureEvm<Header = N::BlockHeader>,
{
// TODO(alexey): unify with `DebugApi::debug_execution_witness` // TODO(alexey): unify with `DebugApi::debug_execution_witness`
// Setup database. // Setup database.
@ -86,7 +89,7 @@ where
SystemCaller::new(self.evm_config.clone(), self.provider.chain_spec()); SystemCaller::new(self.evm_config.clone(), self.provider.chain_spec());
// Apply pre-block system contract calls. // Apply pre-block system contract calls.
system_caller.apply_pre_execution_changes(&block.clone().unseal(), &mut evm)?; system_caller.apply_pre_execution_changes(&block.clone().unseal().block, &mut evm)?;
// Re-execute all of the transactions in the block to load all touched accounts into // Re-execute all of the transactions in the block to load all touched accounts into
// the cache DB. // the cache DB.
@ -106,7 +109,7 @@ where
// NOTE: This is not mut because we are not doing the DAO irregular state change here // NOTE: This is not mut because we are not doing the DAO irregular state change here
let balance_increments = post_block_balance_increments( let balance_increments = post_block_balance_increments(
self.provider.chain_spec().as_ref(), self.provider.chain_spec().as_ref(),
&block.block.clone().unseal(), &block.clone().unseal().block,
U256::MAX, U256::MAX,
); );
@ -163,24 +166,24 @@ where
keys: state_preimages, keys: state_preimages,
}; };
let re_executed_witness_path = self.save_file( let re_executed_witness_path = self.save_file(
format!("{}_{}.witness.re_executed.json", block.number, block.hash()), format!("{}_{}.witness.re_executed.json", block.number(), block.hash()),
&response, &response,
)?; )?;
if let Some(healthy_node_client) = &self.healthy_node_client { if let Some(healthy_node_client) = &self.healthy_node_client {
// Compare the witness against the healthy node. // Compare the witness against the healthy node.
let healthy_node_witness = futures::executor::block_on(async move { let healthy_node_witness = futures::executor::block_on(async move {
DebugApiClient::debug_execution_witness(healthy_node_client, block.number.into()) DebugApiClient::debug_execution_witness(healthy_node_client, block.number().into())
.await .await
})?; })?;
let healthy_path = self.save_file( let healthy_path = self.save_file(
format!("{}_{}.witness.healthy.json", block.number, block.hash()), format!("{}_{}.witness.healthy.json", block.number(), block.hash()),
&healthy_node_witness, &healthy_node_witness,
)?; )?;
// If the witnesses are different, write the diff to the output directory. // If the witnesses are different, write the diff to the output directory.
if response != healthy_node_witness { if response != healthy_node_witness {
let filename = format!("{}_{}.witness.diff", block.number, block.hash()); let filename = format!("{}_{}.witness.diff", block.number(), block.hash());
let diff_path = self.save_diff(filename, &response, &healthy_node_witness)?; let diff_path = self.save_diff(filename, &response, &healthy_node_witness)?;
warn!( warn!(
target: "engine::invalid_block_hooks::witness", target: "engine::invalid_block_hooks::witness",
@ -210,15 +213,15 @@ where
if bundle_state != output.state { if bundle_state != output.state {
let original_path = self.save_file( let original_path = self.save_file(
format!("{}_{}.bundle_state.original.json", block.number, block.hash()), format!("{}_{}.bundle_state.original.json", block.number(), block.hash()),
&output.state, &output.state,
)?; )?;
let re_executed_path = self.save_file( let re_executed_path = self.save_file(
format!("{}_{}.bundle_state.re_executed.json", block.number, block.hash()), format!("{}_{}.bundle_state.re_executed.json", block.number(), block.hash()),
&bundle_state, &bundle_state,
)?; )?;
let filename = format!("{}_{}.bundle_state.diff", block.number, block.hash()); let filename = format!("{}_{}.bundle_state.diff", block.number(), block.hash());
let diff_path = self.save_diff(filename, &bundle_state, &output.state)?; let diff_path = self.save_diff(filename, &bundle_state, &output.state)?;
warn!( warn!(
@ -236,26 +239,27 @@ where
state_provider.state_root_with_updates(hashed_state)?; state_provider.state_root_with_updates(hashed_state)?;
if let Some((original_updates, original_root)) = trie_updates { if let Some((original_updates, original_root)) = trie_updates {
if re_executed_root != original_root { if re_executed_root != original_root {
let filename = format!("{}_{}.state_root.diff", block.number, block.hash()); let filename = format!("{}_{}.state_root.diff", block.number(), block.hash());
let diff_path = self.save_diff(filename, &re_executed_root, &original_root)?; let diff_path = self.save_diff(filename, &re_executed_root, &original_root)?;
warn!(target: "engine::invalid_block_hooks::witness", ?original_root, ?re_executed_root, diff_path = %diff_path.display(), "State root mismatch after re-execution"); warn!(target: "engine::invalid_block_hooks::witness", ?original_root, ?re_executed_root, diff_path = %diff_path.display(), "State root mismatch after re-execution");
} }
// If the re-executed state root does not match the _header_ state root, also log that. // If the re-executed state root does not match the _header_ state root, also log that.
if re_executed_root != block.state_root { if re_executed_root != block.state_root() {
let filename = format!("{}_{}.header_state_root.diff", block.number, block.hash()); let filename =
let diff_path = self.save_diff(filename, &re_executed_root, &block.state_root)?; format!("{}_{}.header_state_root.diff", block.number(), block.hash());
warn!(target: "engine::invalid_block_hooks::witness", header_state_root=?block.state_root, ?re_executed_root, diff_path = %diff_path.display(), "Re-executed state root does not match block state root"); let diff_path = self.save_diff(filename, &re_executed_root, &block.state_root())?;
warn!(target: "engine::invalid_block_hooks::witness", header_state_root=?block.state_root(), ?re_executed_root, diff_path = %diff_path.display(), "Re-executed state root does not match block state root");
} }
if &trie_output != original_updates { if &trie_output != original_updates {
// Trie updates are too big to diff, so we just save the original and re-executed // Trie updates are too big to diff, so we just save the original and re-executed
let original_path = self.save_file( let original_path = self.save_file(
format!("{}_{}.trie_updates.original.json", block.number, block.hash()), format!("{}_{}.trie_updates.original.json", block.number(), block.hash()),
original_updates, original_updates,
)?; )?;
let re_executed_path = self.save_file( let re_executed_path = self.save_file(
format!("{}_{}.trie_updates.re_executed.json", block.number, block.hash()), format!("{}_{}.trie_updates.re_executed.json", block.number(), block.hash()),
&trie_output, &trie_output,
)?; )?;
warn!( warn!(
@ -292,23 +296,24 @@ where
} }
} }
impl<P, EvmConfig> InvalidBlockHook for InvalidBlockWitnessHook<P, EvmConfig> impl<P, EvmConfig, N> InvalidBlockHook<N> for InvalidBlockWitnessHook<P, EvmConfig>
where where
N: NodePrimitives<SignedTx = TransactionSigned>,
P: StateProviderFactory P: StateProviderFactory
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks> + ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ Send + Send
+ Sync + Sync
+ 'static, + 'static,
EvmConfig: ConfigureEvm<Header = Header>, EvmConfig: ConfigureEvm<Header = HeaderTy<N>>,
{ {
fn on_invalid_block( fn on_invalid_block(
&self, &self,
parent_header: &SealedHeader, parent_header: &SealedHeader<N::BlockHeader>,
block: &SealedBlockWithSenders, block: &SealedBlockWithSenders<N::Block>,
output: &BlockExecutionOutput<Receipt>, output: &BlockExecutionOutput<N::Receipt>,
trie_updates: Option<(&TrieUpdates, B256)>, trie_updates: Option<(&TrieUpdates, B256)>,
) { ) {
if let Err(err) = self.on_invalid_block(parent_header, block, output, trie_updates) { if let Err(err) = self.on_invalid_block::<N>(parent_header, block, output, trie_updates) {
warn!(target: "engine::invalid_block_hooks::witness", %err, "Failed to invoke hook"); warn!(target: "engine::invalid_block_hooks::witness", %err, "Failed to invoke hook");
} }
} }

View File

@ -72,7 +72,7 @@ where
payload_builder: PayloadBuilderHandle<N::Engine>, payload_builder: PayloadBuilderHandle<N::Engine>,
payload_validator: V, payload_validator: V,
tree_config: TreeConfig, tree_config: TreeConfig,
invalid_block_hook: Box<dyn InvalidBlockHook>, invalid_block_hook: Box<dyn InvalidBlockHook<N::Primitives>>,
sync_metrics_tx: MetricEventsSender, sync_metrics_tx: MetricEventsSender,
to_engine: UnboundedSender<BeaconEngineMessage<N::Engine>>, to_engine: UnboundedSender<BeaconEngineMessage<N::Engine>>,
from_engine: EngineMessageStream<N::Engine>, from_engine: EngineMessageStream<N::Engine>,

View File

@ -1,35 +1,36 @@
use alloy_primitives::B256; use alloy_primitives::B256;
use reth_execution_types::BlockExecutionOutput; use reth_execution_types::BlockExecutionOutput;
use reth_primitives::{Receipt, SealedBlockWithSenders, SealedHeader}; use reth_primitives::{NodePrimitives, SealedBlockWithSenders, SealedHeader};
use reth_trie::updates::TrieUpdates; use reth_trie::updates::TrieUpdates;
/// An invalid block hook. /// An invalid block hook.
pub trait InvalidBlockHook: Send + Sync { pub trait InvalidBlockHook<N: NodePrimitives>: Send + Sync {
/// Invoked when an invalid block is encountered. /// Invoked when an invalid block is encountered.
fn on_invalid_block( fn on_invalid_block(
&self, &self,
parent_header: &SealedHeader, parent_header: &SealedHeader<N::BlockHeader>,
block: &SealedBlockWithSenders, block: &SealedBlockWithSenders<N::Block>,
output: &BlockExecutionOutput<Receipt>, output: &BlockExecutionOutput<N::Receipt>,
trie_updates: Option<(&TrieUpdates, B256)>, trie_updates: Option<(&TrieUpdates, B256)>,
); );
} }
impl<F> InvalidBlockHook for F impl<F, N> InvalidBlockHook<N> for F
where where
N: NodePrimitives,
F: Fn( F: Fn(
&SealedHeader, &SealedHeader<N::BlockHeader>,
&SealedBlockWithSenders, &SealedBlockWithSenders<N::Block>,
&BlockExecutionOutput<Receipt>, &BlockExecutionOutput<N::Receipt>,
Option<(&TrieUpdates, B256)>, Option<(&TrieUpdates, B256)>,
) + Send ) + Send
+ Sync, + Sync,
{ {
fn on_invalid_block( fn on_invalid_block(
&self, &self,
parent_header: &SealedHeader, parent_header: &SealedHeader<N::BlockHeader>,
block: &SealedBlockWithSenders, block: &SealedBlockWithSenders<N::Block>,
output: &BlockExecutionOutput<Receipt>, output: &BlockExecutionOutput<N::Receipt>,
trie_updates: Option<(&TrieUpdates, B256)>, trie_updates: Option<(&TrieUpdates, B256)>,
) { ) {
self(parent_header, block, output, trie_updates) self(parent_header, block, output, trie_updates)

View File

@ -78,7 +78,7 @@ where
payload_builder: PayloadBuilderHandle<N::Engine>, payload_builder: PayloadBuilderHandle<N::Engine>,
payload_validator: V, payload_validator: V,
tree_config: TreeConfig, tree_config: TreeConfig,
invalid_block_hook: Box<dyn InvalidBlockHook>, invalid_block_hook: Box<dyn InvalidBlockHook<N::Primitives>>,
sync_metrics_tx: MetricEventsSender, sync_metrics_tx: MetricEventsSender,
) -> Self ) -> Self
where where

View File

@ -1,6 +1,6 @@
use alloy_primitives::B256; use alloy_primitives::B256;
use reth_engine_primitives::InvalidBlockHook; use reth_engine_primitives::InvalidBlockHook;
use reth_primitives::{Receipt, SealedBlockWithSenders, SealedHeader}; use reth_primitives::{NodePrimitives, SealedBlockWithSenders, SealedHeader};
use reth_provider::BlockExecutionOutput; use reth_provider::BlockExecutionOutput;
use reth_trie::updates::TrieUpdates; use reth_trie::updates::TrieUpdates;
@ -9,32 +9,32 @@ use reth_trie::updates::TrieUpdates;
#[non_exhaustive] #[non_exhaustive]
pub struct NoopInvalidBlockHook; pub struct NoopInvalidBlockHook;
impl InvalidBlockHook for NoopInvalidBlockHook { impl<N: NodePrimitives> InvalidBlockHook<N> for NoopInvalidBlockHook {
fn on_invalid_block( fn on_invalid_block(
&self, &self,
_parent_header: &SealedHeader, _parent_header: &SealedHeader<N::BlockHeader>,
_block: &SealedBlockWithSenders, _block: &SealedBlockWithSenders<N::Block>,
_output: &BlockExecutionOutput<Receipt>, _output: &BlockExecutionOutput<N::Receipt>,
_trie_updates: Option<(&TrieUpdates, B256)>, _trie_updates: Option<(&TrieUpdates, B256)>,
) { ) {
} }
} }
/// Multiple [`InvalidBlockHook`]s that are executed in order. /// Multiple [`InvalidBlockHook`]s that are executed in order.
pub struct InvalidBlockHooks(pub Vec<Box<dyn InvalidBlockHook>>); pub struct InvalidBlockHooks<N: NodePrimitives>(pub Vec<Box<dyn InvalidBlockHook<N>>>);
impl std::fmt::Debug for InvalidBlockHooks { impl<N: NodePrimitives> std::fmt::Debug for InvalidBlockHooks<N> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("InvalidBlockHooks").field("len", &self.0.len()).finish() f.debug_struct("InvalidBlockHooks").field("len", &self.0.len()).finish()
} }
} }
impl InvalidBlockHook for InvalidBlockHooks { impl<N: NodePrimitives> InvalidBlockHook<N> for InvalidBlockHooks<N> {
fn on_invalid_block( fn on_invalid_block(
&self, &self,
parent_header: &SealedHeader, parent_header: &SealedHeader<N::BlockHeader>,
block: &SealedBlockWithSenders, block: &SealedBlockWithSenders<N::Block>,
output: &BlockExecutionOutput<Receipt>, output: &BlockExecutionOutput<N::Receipt>,
trie_updates: Option<(&TrieUpdates, B256)>, trie_updates: Option<(&TrieUpdates, B256)>,
) { ) {
for hook in &self.0 { for hook in &self.0 {

View File

@ -469,6 +469,7 @@ pub enum TreeAction {
/// emitting events. /// emitting events.
pub struct EngineApiTreeHandler<N, P, E, T, V> pub struct EngineApiTreeHandler<N, P, E, T, V>
where where
N: NodePrimitives,
T: EngineTypes, T: EngineTypes,
{ {
provider: P, provider: P,
@ -507,7 +508,7 @@ where
/// Metrics for the engine api. /// Metrics for the engine api.
metrics: EngineApiMetrics, metrics: EngineApiMetrics,
/// An invalid block hook. /// An invalid block hook.
invalid_block_hook: Box<dyn InvalidBlockHook>, invalid_block_hook: Box<dyn InvalidBlockHook<N>>,
/// The engine API variant of this handler /// The engine API variant of this handler
engine_kind: EngineApiKind, engine_kind: EngineApiKind,
/// Captures the types the engine operates on /// Captures the types the engine operates on
@ -516,6 +517,8 @@ where
impl<N, P: Debug, E: Debug, T: EngineTypes + Debug, V: Debug> std::fmt::Debug impl<N, P: Debug, E: Debug, T: EngineTypes + Debug, V: Debug> std::fmt::Debug
for EngineApiTreeHandler<N, P, E, T, V> for EngineApiTreeHandler<N, P, E, T, V>
where
N: NodePrimitives,
{ {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EngineApiTreeHandler") f.debug_struct("EngineApiTreeHandler")
@ -597,7 +600,7 @@ where
} }
/// Sets the invalid block hook. /// Sets the invalid block hook.
fn set_invalid_block_hook(&mut self, invalid_block_hook: Box<dyn InvalidBlockHook>) { fn set_invalid_block_hook(&mut self, invalid_block_hook: Box<dyn InvalidBlockHook<N>>) {
self.invalid_block_hook = invalid_block_hook; self.invalid_block_hook = invalid_block_hook;
} }
@ -616,7 +619,7 @@ where
payload_builder: PayloadBuilderHandle<T>, payload_builder: PayloadBuilderHandle<T>,
canonical_in_memory_state: CanonicalInMemoryState, canonical_in_memory_state: CanonicalInMemoryState,
config: TreeConfig, config: TreeConfig,
invalid_block_hook: Box<dyn InvalidBlockHook>, invalid_block_hook: Box<dyn InvalidBlockHook<N>>,
kind: EngineApiKind, kind: EngineApiKind,
) -> (Sender<FromEngine<EngineApiRequest<T>>>, UnboundedReceiver<EngineApiEvent>) { ) -> (Sender<FromEngine<EngineApiRequest<T>>>, UnboundedReceiver<EngineApiEvent>) {
let best_block_number = provider.best_block_number().unwrap_or(0); let best_block_number = provider.best_block_number().unwrap_or(0);

View File

@ -152,7 +152,7 @@ where
let env = self.evm_env_for_block(&block.header, total_difficulty); let env = self.evm_env_for_block(&block.header, total_difficulty);
let mut evm = self.evm_config.evm_with_env(&mut self.state, env); let mut evm = self.evm_config.evm_with_env(&mut self.state, env);
self.system_caller.apply_pre_execution_changes(block, &mut evm)?; self.system_caller.apply_pre_execution_changes(&block.block, &mut evm)?;
Ok(()) Ok(())
} }
@ -247,7 +247,7 @@ where
drop(evm); drop(evm);
let mut balance_increments = let mut balance_increments =
post_block_balance_increments(&self.chain_spec, block, total_difficulty); post_block_balance_increments(&self.chain_spec, &block.block, total_difficulty);
// Irregular state change at Ethereum DAO hardfork // Irregular state change at Ethereum DAO hardfork
if self.chain_spec.fork(EthereumHardfork::Dao).transitions_at_block(block.number) { if self.chain_spec.fork(EthereumHardfork::Dao).transitions_at_block(block.number) {

View File

@ -1,43 +1,55 @@
//! State changes that are not related to transactions. //! State changes that are not related to transactions.
use alloy_consensus::BlockHeader;
use alloy_eips::eip4895::Withdrawal; use alloy_eips::eip4895::Withdrawal;
use alloy_primitives::{map::HashMap, Address, U256}; use alloy_primitives::{map::HashMap, Address, U256};
use reth_chainspec::EthereumHardforks; use reth_chainspec::EthereumHardforks;
use reth_consensus_common::calc; use reth_consensus_common::calc;
use reth_primitives::Block; use reth_primitives_traits::BlockBody;
/// Collect all balance changes at the end of the block. /// Collect all balance changes at the end of the block.
/// ///
/// Balance changes might include the block reward, uncle rewards, withdrawals, or irregular /// Balance changes might include the block reward, uncle rewards, withdrawals, or irregular
/// state changes (DAO fork). /// state changes (DAO fork).
#[inline] #[inline]
pub fn post_block_balance_increments<ChainSpec: EthereumHardforks>( pub fn post_block_balance_increments<ChainSpec, Block>(
chain_spec: &ChainSpec, chain_spec: &ChainSpec,
block: &Block, block: &Block,
total_difficulty: U256, total_difficulty: U256,
) -> HashMap<Address, u128> { ) -> HashMap<Address, u128>
where
ChainSpec: EthereumHardforks,
Block: reth_primitives_traits::Block,
{
let mut balance_increments = HashMap::default(); let mut balance_increments = HashMap::default();
// Add block rewards if they are enabled. // Add block rewards if they are enabled.
if let Some(base_block_reward) = if let Some(base_block_reward) = calc::base_block_reward(
calc::base_block_reward(chain_spec, block.number, block.difficulty, total_difficulty) chain_spec,
{ block.header().number(),
block.header().difficulty(),
total_difficulty,
) {
// Ommer rewards // Ommer rewards
for ommer in &block.body.ommers { if let Some(ommers) = block.body().ommers() {
*balance_increments.entry(ommer.beneficiary).or_default() += for ommer in ommers {
calc::ommer_reward(base_block_reward, block.number, ommer.number); *balance_increments.entry(ommer.beneficiary()).or_default() +=
calc::ommer_reward(base_block_reward, block.header().number(), ommer.number());
}
} }
// Full block reward // Full block reward
*balance_increments.entry(block.beneficiary).or_default() += *balance_increments.entry(block.header().beneficiary()).or_default() += calc::block_reward(
calc::block_reward(base_block_reward, block.body.ommers.len()); base_block_reward,
block.body().ommers().map(|s| s.len()).unwrap_or(0),
);
} }
// process withdrawals // process withdrawals
insert_post_block_withdrawals_balance_increments( insert_post_block_withdrawals_balance_increments(
chain_spec, chain_spec,
block.timestamp, block.header().timestamp(),
block.body.withdrawals.as_ref().map(|w| w.as_slice()), block.body().withdrawals().as_ref().map(|w| w.as_slice()),
&mut balance_increments, &mut balance_increments,
); );

View File

@ -4,7 +4,6 @@ use alloc::{boxed::Box, string::ToString};
use alloy_eips::eip2935::HISTORY_STORAGE_ADDRESS; use alloy_eips::eip2935::HISTORY_STORAGE_ADDRESS;
use crate::ConfigureEvm; use crate::ConfigureEvm;
use alloy_consensus::Header;
use alloy_primitives::B256; use alloy_primitives::B256;
use reth_chainspec::EthereumHardforks; use reth_chainspec::EthereumHardforks;
use reth_execution_errors::{BlockExecutionError, BlockValidationError}; use reth_execution_errors::{BlockExecutionError, BlockValidationError};
@ -35,7 +34,7 @@ pub(crate) fn transact_blockhashes_contract_call<EvmConfig, EXT, DB>(
where where
DB: Database, DB: Database,
DB::Error: core::fmt::Display, DB::Error: core::fmt::Display,
EvmConfig: ConfigureEvm<Header = Header>, EvmConfig: ConfigureEvm,
{ {
if !chain_spec.is_prague_active_at_timestamp(block_timestamp) { if !chain_spec.is_prague_active_at_timestamp(block_timestamp) {
return Ok(None) return Ok(None)

View File

@ -2,7 +2,6 @@
use alloc::{boxed::Box, string::ToString}; use alloc::{boxed::Box, string::ToString};
use crate::ConfigureEvm; use crate::ConfigureEvm;
use alloy_consensus::Header;
use alloy_eips::eip4788::BEACON_ROOTS_ADDRESS; use alloy_eips::eip4788::BEACON_ROOTS_ADDRESS;
use alloy_primitives::B256; use alloy_primitives::B256;
use reth_chainspec::EthereumHardforks; use reth_chainspec::EthereumHardforks;
@ -31,7 +30,7 @@ pub(crate) fn transact_beacon_root_contract_call<EvmConfig, EXT, DB, Spec>(
where where
DB: Database, DB: Database,
DB::Error: core::fmt::Display, DB::Error: core::fmt::Display,
EvmConfig: ConfigureEvm<Header = Header>, EvmConfig: ConfigureEvm,
Spec: EthereumHardforks, Spec: EthereumHardforks,
{ {
if !chain_spec.is_cancun_active_at_timestamp(block_timestamp) { if !chain_spec.is_cancun_active_at_timestamp(block_timestamp) {

View File

@ -1,7 +1,6 @@
//! [EIP-7002](https://eips.ethereum.org/EIPS/eip-7002) system call implementation. //! [EIP-7002](https://eips.ethereum.org/EIPS/eip-7002) system call implementation.
use crate::ConfigureEvm; use crate::ConfigureEvm;
use alloc::{boxed::Box, format}; use alloc::{boxed::Box, format};
use alloy_consensus::Header;
use alloy_eips::eip7002::WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS; use alloy_eips::eip7002::WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS;
use alloy_primitives::Bytes; use alloy_primitives::Bytes;
use reth_execution_errors::{BlockExecutionError, BlockValidationError}; use reth_execution_errors::{BlockExecutionError, BlockValidationError};
@ -21,7 +20,7 @@ pub(crate) fn transact_withdrawal_requests_contract_call<EvmConfig, EXT, DB>(
where where
DB: Database, DB: Database,
DB::Error: core::fmt::Display, DB::Error: core::fmt::Display,
EvmConfig: ConfigureEvm<Header = Header>, EvmConfig: ConfigureEvm,
{ {
// get previous env // get previous env
let previous_env = Box::new(evm.context.env().clone()); let previous_env = Box::new(evm.context.env().clone());

View File

@ -1,7 +1,6 @@
//! [EIP-7251](https://eips.ethereum.org/EIPS/eip-7251) system call implementation. //! [EIP-7251](https://eips.ethereum.org/EIPS/eip-7251) system call implementation.
use crate::ConfigureEvm; use crate::ConfigureEvm;
use alloc::{boxed::Box, format}; use alloc::{boxed::Box, format};
use alloy_consensus::Header;
use alloy_eips::eip7251::CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS; use alloy_eips::eip7251::CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS;
use alloy_primitives::Bytes; use alloy_primitives::Bytes;
use reth_execution_errors::{BlockExecutionError, BlockValidationError}; use reth_execution_errors::{BlockExecutionError, BlockValidationError};
@ -22,7 +21,7 @@ pub(crate) fn transact_consolidation_requests_contract_call<EvmConfig, EXT, DB>(
where where
DB: Database, DB: Database,
DB::Error: core::fmt::Display, DB::Error: core::fmt::Display,
EvmConfig: ConfigureEvm<Header = Header>, EvmConfig: ConfigureEvm,
{ {
// get previous env // get previous env
let previous_env = Box::new(evm.context.env().clone()); let previous_env = Box::new(evm.context.env().clone());

View File

@ -2,7 +2,7 @@
use crate::ConfigureEvm; use crate::ConfigureEvm;
use alloc::{boxed::Box, sync::Arc}; use alloc::{boxed::Box, sync::Arc};
use alloy_consensus::Header; use alloy_consensus::BlockHeader;
use alloy_eips::{ use alloy_eips::{
eip7002::WITHDRAWAL_REQUEST_TYPE, eip7251::CONSOLIDATION_REQUEST_TYPE, eip7685::Requests, eip7002::WITHDRAWAL_REQUEST_TYPE, eip7251::CONSOLIDATION_REQUEST_TYPE, eip7685::Requests,
}; };
@ -10,7 +10,6 @@ use alloy_primitives::Bytes;
use core::fmt::Display; use core::fmt::Display;
use reth_chainspec::EthereumHardforks; use reth_chainspec::EthereumHardforks;
use reth_execution_errors::BlockExecutionError; use reth_execution_errors::BlockExecutionError;
use reth_primitives::Block;
use revm::{Database, DatabaseCommit, Evm}; use revm::{Database, DatabaseCommit, Evm};
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, EvmState, B256}; use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, EvmState, B256};
@ -91,11 +90,11 @@ where
impl<EvmConfig, Chainspec> SystemCaller<EvmConfig, Chainspec> impl<EvmConfig, Chainspec> SystemCaller<EvmConfig, Chainspec>
where where
EvmConfig: ConfigureEvm<Header = Header>, EvmConfig: ConfigureEvm,
Chainspec: EthereumHardforks, Chainspec: EthereumHardforks,
{ {
/// Apply pre execution changes. /// Apply pre execution changes.
pub fn apply_pre_execution_changes<DB, Ext>( pub fn apply_pre_execution_changes<DB, Ext, Block>(
&mut self, &mut self,
block: &Block, block: &Block,
evm: &mut Evm<'_, Ext, DB>, evm: &mut Evm<'_, Ext, DB>,
@ -103,17 +102,18 @@ where
where where
DB: Database + DatabaseCommit, DB: Database + DatabaseCommit,
DB::Error: Display, DB::Error: Display,
Block: reth_primitives_traits::Block<Header = EvmConfig::Header>,
{ {
self.apply_blockhashes_contract_call( self.apply_blockhashes_contract_call(
block.timestamp, block.header().timestamp(),
block.number, block.header().number(),
block.parent_hash, block.header().parent_hash(),
evm, evm,
)?; )?;
self.apply_beacon_root_contract_call( self.apply_beacon_root_contract_call(
block.timestamp, block.header().timestamp(),
block.number, block.header().number(),
block.parent_beacon_block_root, block.header().parent_beacon_block_root(),
evm, evm,
)?; )?;

View File

@ -26,6 +26,5 @@ reth-node-types.workspace = true
reth-node-core.workspace = true reth-node-core.workspace = true
alloy-rpc-types-engine.workspace = true alloy-rpc-types-engine.workspace = true
alloy-consensus.workspace = true
eyre.workspace = true eyre.workspace = true

View File

@ -1,14 +1,13 @@
//! Traits for configuring a node. //! Traits for configuring a node.
use crate::ConfigureEvm; use crate::ConfigureEvm;
use alloy_consensus::Header;
use alloy_rpc_types_engine::JwtSecret; use alloy_rpc_types_engine::JwtSecret;
use reth_beacon_consensus::BeaconConsensusEngineHandle; use reth_beacon_consensus::BeaconConsensusEngineHandle;
use reth_consensus::FullConsensus; use reth_consensus::FullConsensus;
use reth_evm::execute::BlockExecutorProvider; use reth_evm::execute::BlockExecutorProvider;
use reth_network_api::FullNetwork; use reth_network_api::FullNetwork;
use reth_node_core::node_config::NodeConfig; use reth_node_core::node_config::NodeConfig;
use reth_node_types::{NodeTypes, NodeTypesWithDB, NodeTypesWithEngine, TxTy}; use reth_node_types::{HeaderTy, NodeTypes, NodeTypesWithDB, NodeTypesWithEngine, TxTy};
use reth_payload_builder_primitives::PayloadBuilder; use reth_payload_builder_primitives::PayloadBuilder;
use reth_provider::FullProvider; use reth_provider::FullProvider;
use reth_tasks::TaskExecutor; use reth_tasks::TaskExecutor;
@ -50,7 +49,7 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Self::Types>>> + Unpin; type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Self::Types>>> + Unpin;
/// The node's EVM configuration, defining settings for the Ethereum Virtual Machine. /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
type Evm: ConfigureEvm<Header = Header>; type Evm: ConfigureEvm<Header = HeaderTy<Self::Types>>;
/// The type that knows how to execute blocks. /// The type that knows how to execute blocks.
type Executor: BlockExecutorProvider<Primitives = <Self::Types as NodeTypes>::Primitives>; type Executor: BlockExecutorProvider<Primitives = <Self::Types as NodeTypes>::Primitives>;

View File

@ -7,10 +7,9 @@ use crate::{
}, },
BuilderContext, ConfigureEvm, FullNodeTypes, BuilderContext, ConfigureEvm, FullNodeTypes,
}; };
use alloy_consensus::Header;
use reth_consensus::FullConsensus; use reth_consensus::FullConsensus;
use reth_evm::execute::BlockExecutorProvider; use reth_evm::execute::BlockExecutorProvider;
use reth_node_api::{NodeTypes, NodeTypesWithEngine, TxTy}; use reth_node_api::{HeaderTy, NodeTypes, NodeTypesWithEngine, TxTy};
use reth_payload_builder::PayloadBuilderHandle; use reth_payload_builder::PayloadBuilderHandle;
use reth_transaction_pool::{PoolTransaction, TransactionPool}; use reth_transaction_pool::{PoolTransaction, TransactionPool};
use std::{future::Future, marker::PhantomData}; use std::{future::Future, marker::PhantomData};
@ -378,7 +377,7 @@ where
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>> Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
+ Unpin + Unpin
+ 'static, + 'static,
EVM: ConfigureEvm<Header = Header>, EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>,
Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>, Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>,
Cons: FullConsensus<<Node::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static, Cons: FullConsensus<<Node::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static,
{ {

View File

@ -1,8 +1,7 @@
//! EVM component for the node builder. //! EVM component for the node builder.
use crate::{BuilderContext, FullNodeTypes}; use crate::{BuilderContext, FullNodeTypes};
use alloy_consensus::Header;
use reth_evm::execute::BlockExecutorProvider; use reth_evm::execute::BlockExecutorProvider;
use reth_node_api::ConfigureEvm; use reth_node_api::{ConfigureEvm, HeaderTy};
use std::future::Future; use std::future::Future;
/// A type that knows how to build the executor types. /// A type that knows how to build the executor types.
@ -10,7 +9,7 @@ pub trait ExecutorBuilder<Node: FullNodeTypes>: Send {
/// The EVM config to use. /// The EVM config to use.
/// ///
/// This provides the node with the necessary configuration to configure an EVM. /// This provides the node with the necessary configuration to configure an EVM.
type EVM: ConfigureEvm<Header = Header>; type EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>;
/// The type that knows how to execute blocks. /// The type that knows how to execute blocks.
type Executor: BlockExecutorProvider< type Executor: BlockExecutorProvider<
@ -27,7 +26,7 @@ pub trait ExecutorBuilder<Node: FullNodeTypes>: Send {
impl<Node, F, Fut, EVM, Executor> ExecutorBuilder<Node> for F impl<Node, F, Fut, EVM, Executor> ExecutorBuilder<Node> for F
where where
Node: FullNodeTypes, Node: FullNodeTypes,
EVM: ConfigureEvm<Header = Header>, EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>,
Executor: Executor:
BlockExecutorProvider<Primitives = <Node::Types as reth_node_api::NodeTypes>::Primitives>, BlockExecutorProvider<Primitives = <Node::Types as reth_node_api::NodeTypes>::Primitives>,
F: FnOnce(&BuilderContext<Node>) -> Fut + Send, F: FnOnce(&BuilderContext<Node>) -> Fut + Send,

View File

@ -22,12 +22,11 @@ pub use payload::*;
pub use pool::*; pub use pool::*;
use crate::{ConfigureEvm, FullNodeTypes}; use crate::{ConfigureEvm, FullNodeTypes};
use alloy_consensus::Header;
use reth_consensus::FullConsensus; use reth_consensus::FullConsensus;
use reth_evm::execute::BlockExecutorProvider; use reth_evm::execute::BlockExecutorProvider;
use reth_network::NetworkHandle; use reth_network::NetworkHandle;
use reth_network_api::FullNetwork; use reth_network_api::FullNetwork;
use reth_node_api::{NodeTypes, NodeTypesWithEngine, TxTy}; use reth_node_api::{HeaderTy, NodeTypes, NodeTypesWithEngine, TxTy};
use reth_payload_builder::PayloadBuilderHandle; use reth_payload_builder::PayloadBuilderHandle;
use reth_transaction_pool::{PoolTransaction, TransactionPool}; use reth_transaction_pool::{PoolTransaction, TransactionPool};
@ -41,7 +40,7 @@ pub trait NodeComponents<T: FullNodeTypes>: Clone + Unpin + Send + Sync + 'stati
type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<T::Types>>> + Unpin; type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<T::Types>>> + Unpin;
/// The node's EVM configuration, defining settings for the Ethereum Virtual Machine. /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
type Evm: ConfigureEvm<Header = Header>; type Evm: ConfigureEvm<Header = HeaderTy<T::Types>>;
/// The type that knows how to execute blocks. /// The type that knows how to execute blocks.
type Executor: BlockExecutorProvider<Primitives = <T::Types as NodeTypes>::Primitives>; type Executor: BlockExecutorProvider<Primitives = <T::Types as NodeTypes>::Primitives>;
@ -100,7 +99,7 @@ where
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>> Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
+ Unpin + Unpin
+ 'static, + 'static,
EVM: ConfigureEvm<Header = Header>, EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>,
Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>, Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>,
Cons: FullConsensus<<Node::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static, Cons: FullConsensus<<Node::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static,
{ {
@ -140,7 +139,7 @@ impl<Node, Pool, EVM, Executor, Cons> Clone for Components<Node, Pool, EVM, Exec
where where
Node: FullNodeTypes, Node: FullNodeTypes,
Pool: TransactionPool, Pool: TransactionPool,
EVM: ConfigureEvm<Header = Header>, EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>,
Executor: BlockExecutorProvider, Executor: BlockExecutorProvider,
Cons: Clone, Cons: Clone,
{ {

View File

@ -22,7 +22,9 @@ use reth_evm::noop::NoopBlockExecutorProvider;
use reth_fs_util as fs; use reth_fs_util as fs;
use reth_invalid_block_hooks::InvalidBlockWitnessHook; use reth_invalid_block_hooks::InvalidBlockWitnessHook;
use reth_network_p2p::headers::client::HeadersClient; use reth_network_p2p::headers::client::HeadersClient;
use reth_node_api::{FullNodePrimitives, FullNodeTypes, NodeTypes, NodeTypesWithDB}; use reth_node_api::{
FullNodePrimitives, FullNodeTypes, NodePrimitives, NodeTypes, NodeTypesWithDB,
};
use reth_node_core::{ use reth_node_core::{
args::InvalidBlockHookType, args::InvalidBlockHookType,
dirs::{ChainPath, DataDirPath}, dirs::{ChainPath, DataDirPath},
@ -39,7 +41,7 @@ use reth_node_metrics::{
server::{MetricServer, MetricServerConfig}, server::{MetricServer, MetricServerConfig},
version::VersionInfo, version::VersionInfo,
}; };
use reth_primitives::Head; use reth_primitives::{Head, TransactionSigned};
use reth_provider::{ use reth_provider::{
providers::{ProviderNodeTypes, StaticFileProvider}, providers::{ProviderNodeTypes, StaticFileProvider},
BlockHashReader, BlockNumReader, ChainSpecProvider, ProviderError, ProviderFactory, BlockHashReader, BlockNumReader, ChainSpecProvider, ProviderError, ProviderFactory,
@ -870,11 +872,16 @@ impl<T, CB>
Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithComponents<T, CB>>, Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithComponents<T, CB>>,
> >
where where
T: FullNodeTypes<Provider: StateProviderFactory + ChainSpecProvider, Types: ProviderNodeTypes>, T: FullNodeTypes<
Provider: StateProviderFactory + ChainSpecProvider,
Types: ProviderNodeTypes<Primitives: NodePrimitives<SignedTx = TransactionSigned>>,
>,
CB: NodeComponentsBuilder<T>, CB: NodeComponentsBuilder<T>,
{ {
/// Returns the [`InvalidBlockHook`] to use for the node. /// Returns the [`InvalidBlockHook`] to use for the node.
pub fn invalid_block_hook(&self) -> eyre::Result<Box<dyn InvalidBlockHook>> { pub fn invalid_block_hook(
&self,
) -> eyre::Result<Box<dyn InvalidBlockHook<<T::Types as NodeTypes>::Primitives>>> {
let Some(ref hook) = self.node_config().debug.invalid_block_hook else { let Some(ref hook) = self.node_config().debug.invalid_block_hook else {
return Ok(Box::new(NoopInvalidBlockHook::default())) return Ok(Box::new(NoopInvalidBlockHook::default()))
}; };
@ -898,7 +905,7 @@ where
InvalidBlockHookType::PreState | InvalidBlockHookType::Opcode => { InvalidBlockHookType::PreState | InvalidBlockHookType::Opcode => {
eyre::bail!("invalid block hook {hook:?} is not implemented yet") eyre::bail!("invalid block hook {hook:?} is not implemented yet")
} }
} as Box<dyn InvalidBlockHook>) } as Box<dyn InvalidBlockHook<_>>)
}) })
.collect::<Result<_, _>>()?; .collect::<Result<_, _>>()?;

View File

@ -258,7 +258,7 @@ where
_receipts: &[Receipt], _receipts: &[Receipt],
) -> Result<Requests, Self::Error> { ) -> Result<Requests, Self::Error> {
let balance_increments = let balance_increments =
post_block_balance_increments(&self.chain_spec.clone(), block, total_difficulty); post_block_balance_increments(&self.chain_spec.clone(), &block.block, total_difficulty);
// increment balances // increment balances
self.state self.state
.increment_balances(balance_increments.clone()) .increment_balances(balance_increments.clone())