mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: make InvalidBlockHook generic over NodePrimitives (#13105)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -7998,7 +7998,6 @@ dependencies = [
|
||||
name = "reth-node-api"
|
||||
version = "1.1.2"
|
||||
dependencies = [
|
||||
"alloy-consensus",
|
||||
"alloy-rpc-types-engine",
|
||||
"eyre",
|
||||
"reth-beacon-consensus",
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use alloy_consensus::Header;
|
||||
use alloy_consensus::BlockHeader;
|
||||
use alloy_primitives::{keccak256, B256, U256};
|
||||
use alloy_rpc_types_debug::ExecutionWitness;
|
||||
use eyre::OptionExt;
|
||||
@ -8,8 +8,8 @@ use reth_engine_primitives::InvalidBlockHook;
|
||||
use reth_evm::{
|
||||
state_change::post_block_balance_increments, system_calls::SystemCaller, ConfigureEvm,
|
||||
};
|
||||
use reth_primitives::{Receipt, SealedBlockWithSenders, SealedHeader};
|
||||
use reth_primitives_traits::SignedTransaction;
|
||||
use reth_primitives::{NodePrimitives, SealedBlockWithSenders, SealedHeader, TransactionSigned};
|
||||
use reth_primitives_traits::{HeaderTy, SignedTransaction};
|
||||
use reth_provider::{BlockExecutionOutput, ChainSpecProvider, StateProviderFactory};
|
||||
use reth_revm::{
|
||||
database::StateProviderDatabase, db::states::bundle_state::BundleRetention,
|
||||
@ -54,15 +54,18 @@ where
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
{
|
||||
fn on_invalid_block(
|
||||
fn on_invalid_block<N>(
|
||||
&self,
|
||||
parent_header: &SealedHeader,
|
||||
block: &SealedBlockWithSenders,
|
||||
output: &BlockExecutionOutput<Receipt>,
|
||||
parent_header: &SealedHeader<N::BlockHeader>,
|
||||
block: &SealedBlockWithSenders<N::Block>,
|
||||
output: &BlockExecutionOutput<N::Receipt>,
|
||||
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`
|
||||
|
||||
// Setup database.
|
||||
@ -86,7 +89,7 @@ where
|
||||
SystemCaller::new(self.evm_config.clone(), self.provider.chain_spec());
|
||||
|
||||
// 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
|
||||
// the cache DB.
|
||||
@ -106,7 +109,7 @@ where
|
||||
// NOTE: This is not mut because we are not doing the DAO irregular state change here
|
||||
let balance_increments = post_block_balance_increments(
|
||||
self.provider.chain_spec().as_ref(),
|
||||
&block.block.clone().unseal(),
|
||||
&block.clone().unseal().block,
|
||||
U256::MAX,
|
||||
);
|
||||
|
||||
@ -163,24 +166,24 @@ where
|
||||
keys: state_preimages,
|
||||
};
|
||||
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,
|
||||
)?;
|
||||
if let Some(healthy_node_client) = &self.healthy_node_client {
|
||||
// Compare the witness against the healthy node.
|
||||
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
|
||||
})?;
|
||||
|
||||
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,
|
||||
)?;
|
||||
|
||||
// If the witnesses are different, write the diff to the output directory.
|
||||
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)?;
|
||||
warn!(
|
||||
target: "engine::invalid_block_hooks::witness",
|
||||
@ -210,15 +213,15 @@ where
|
||||
|
||||
if bundle_state != output.state {
|
||||
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,
|
||||
)?;
|
||||
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,
|
||||
)?;
|
||||
|
||||
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)?;
|
||||
|
||||
warn!(
|
||||
@ -236,26 +239,27 @@ where
|
||||
state_provider.state_root_with_updates(hashed_state)?;
|
||||
if let Some((original_updates, original_root)) = trie_updates {
|
||||
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)?;
|
||||
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 re_executed_root != block.state_root {
|
||||
let filename = format!("{}_{}.header_state_root.diff", block.number, block.hash());
|
||||
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 re_executed_root != block.state_root() {
|
||||
let filename =
|
||||
format!("{}_{}.header_state_root.diff", block.number(), block.hash());
|
||||
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 {
|
||||
// Trie updates are too big to diff, so we just save the original and re-executed
|
||||
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,
|
||||
)?;
|
||||
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,
|
||||
)?;
|
||||
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
|
||||
N: NodePrimitives<SignedTx = TransactionSigned>,
|
||||
P: StateProviderFactory
|
||||
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
EvmConfig: ConfigureEvm<Header = HeaderTy<N>>,
|
||||
{
|
||||
fn on_invalid_block(
|
||||
&self,
|
||||
parent_header: &SealedHeader,
|
||||
block: &SealedBlockWithSenders,
|
||||
output: &BlockExecutionOutput<Receipt>,
|
||||
parent_header: &SealedHeader<N::BlockHeader>,
|
||||
block: &SealedBlockWithSenders<N::Block>,
|
||||
output: &BlockExecutionOutput<N::Receipt>,
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ where
|
||||
payload_builder: PayloadBuilderHandle<N::Engine>,
|
||||
payload_validator: V,
|
||||
tree_config: TreeConfig,
|
||||
invalid_block_hook: Box<dyn InvalidBlockHook>,
|
||||
invalid_block_hook: Box<dyn InvalidBlockHook<N::Primitives>>,
|
||||
sync_metrics_tx: MetricEventsSender,
|
||||
to_engine: UnboundedSender<BeaconEngineMessage<N::Engine>>,
|
||||
from_engine: EngineMessageStream<N::Engine>,
|
||||
|
||||
@ -1,35 +1,36 @@
|
||||
use alloy_primitives::B256;
|
||||
use reth_execution_types::BlockExecutionOutput;
|
||||
use reth_primitives::{Receipt, SealedBlockWithSenders, SealedHeader};
|
||||
use reth_primitives::{NodePrimitives, SealedBlockWithSenders, SealedHeader};
|
||||
use reth_trie::updates::TrieUpdates;
|
||||
|
||||
/// An invalid block hook.
|
||||
pub trait InvalidBlockHook: Send + Sync {
|
||||
pub trait InvalidBlockHook<N: NodePrimitives>: Send + Sync {
|
||||
/// Invoked when an invalid block is encountered.
|
||||
fn on_invalid_block(
|
||||
&self,
|
||||
parent_header: &SealedHeader,
|
||||
block: &SealedBlockWithSenders,
|
||||
output: &BlockExecutionOutput<Receipt>,
|
||||
parent_header: &SealedHeader<N::BlockHeader>,
|
||||
block: &SealedBlockWithSenders<N::Block>,
|
||||
output: &BlockExecutionOutput<N::Receipt>,
|
||||
trie_updates: Option<(&TrieUpdates, B256)>,
|
||||
);
|
||||
}
|
||||
|
||||
impl<F> InvalidBlockHook for F
|
||||
impl<F, N> InvalidBlockHook<N> for F
|
||||
where
|
||||
N: NodePrimitives,
|
||||
F: Fn(
|
||||
&SealedHeader,
|
||||
&SealedBlockWithSenders,
|
||||
&BlockExecutionOutput<Receipt>,
|
||||
&SealedHeader<N::BlockHeader>,
|
||||
&SealedBlockWithSenders<N::Block>,
|
||||
&BlockExecutionOutput<N::Receipt>,
|
||||
Option<(&TrieUpdates, B256)>,
|
||||
) + Send
|
||||
+ Sync,
|
||||
{
|
||||
fn on_invalid_block(
|
||||
&self,
|
||||
parent_header: &SealedHeader,
|
||||
block: &SealedBlockWithSenders,
|
||||
output: &BlockExecutionOutput<Receipt>,
|
||||
parent_header: &SealedHeader<N::BlockHeader>,
|
||||
block: &SealedBlockWithSenders<N::Block>,
|
||||
output: &BlockExecutionOutput<N::Receipt>,
|
||||
trie_updates: Option<(&TrieUpdates, B256)>,
|
||||
) {
|
||||
self(parent_header, block, output, trie_updates)
|
||||
|
||||
@ -78,7 +78,7 @@ where
|
||||
payload_builder: PayloadBuilderHandle<N::Engine>,
|
||||
payload_validator: V,
|
||||
tree_config: TreeConfig,
|
||||
invalid_block_hook: Box<dyn InvalidBlockHook>,
|
||||
invalid_block_hook: Box<dyn InvalidBlockHook<N::Primitives>>,
|
||||
sync_metrics_tx: MetricEventsSender,
|
||||
) -> Self
|
||||
where
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use alloy_primitives::B256;
|
||||
use reth_engine_primitives::InvalidBlockHook;
|
||||
use reth_primitives::{Receipt, SealedBlockWithSenders, SealedHeader};
|
||||
use reth_primitives::{NodePrimitives, SealedBlockWithSenders, SealedHeader};
|
||||
use reth_provider::BlockExecutionOutput;
|
||||
use reth_trie::updates::TrieUpdates;
|
||||
|
||||
@ -9,32 +9,32 @@ use reth_trie::updates::TrieUpdates;
|
||||
#[non_exhaustive]
|
||||
pub struct NoopInvalidBlockHook;
|
||||
|
||||
impl InvalidBlockHook for NoopInvalidBlockHook {
|
||||
impl<N: NodePrimitives> InvalidBlockHook<N> for NoopInvalidBlockHook {
|
||||
fn on_invalid_block(
|
||||
&self,
|
||||
_parent_header: &SealedHeader,
|
||||
_block: &SealedBlockWithSenders,
|
||||
_output: &BlockExecutionOutput<Receipt>,
|
||||
_parent_header: &SealedHeader<N::BlockHeader>,
|
||||
_block: &SealedBlockWithSenders<N::Block>,
|
||||
_output: &BlockExecutionOutput<N::Receipt>,
|
||||
_trie_updates: Option<(&TrieUpdates, B256)>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
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(
|
||||
&self,
|
||||
parent_header: &SealedHeader,
|
||||
block: &SealedBlockWithSenders,
|
||||
output: &BlockExecutionOutput<Receipt>,
|
||||
parent_header: &SealedHeader<N::BlockHeader>,
|
||||
block: &SealedBlockWithSenders<N::Block>,
|
||||
output: &BlockExecutionOutput<N::Receipt>,
|
||||
trie_updates: Option<(&TrieUpdates, B256)>,
|
||||
) {
|
||||
for hook in &self.0 {
|
||||
|
||||
@ -469,6 +469,7 @@ pub enum TreeAction {
|
||||
/// emitting events.
|
||||
pub struct EngineApiTreeHandler<N, P, E, T, V>
|
||||
where
|
||||
N: NodePrimitives,
|
||||
T: EngineTypes,
|
||||
{
|
||||
provider: P,
|
||||
@ -507,7 +508,7 @@ where
|
||||
/// Metrics for the engine api.
|
||||
metrics: EngineApiMetrics,
|
||||
/// An invalid block hook.
|
||||
invalid_block_hook: Box<dyn InvalidBlockHook>,
|
||||
invalid_block_hook: Box<dyn InvalidBlockHook<N>>,
|
||||
/// The engine API variant of this handler
|
||||
engine_kind: EngineApiKind,
|
||||
/// 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
|
||||
for EngineApiTreeHandler<N, P, E, T, V>
|
||||
where
|
||||
N: NodePrimitives,
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("EngineApiTreeHandler")
|
||||
@ -597,7 +600,7 @@ where
|
||||
}
|
||||
|
||||
/// 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;
|
||||
}
|
||||
|
||||
@ -616,7 +619,7 @@ where
|
||||
payload_builder: PayloadBuilderHandle<T>,
|
||||
canonical_in_memory_state: CanonicalInMemoryState,
|
||||
config: TreeConfig,
|
||||
invalid_block_hook: Box<dyn InvalidBlockHook>,
|
||||
invalid_block_hook: Box<dyn InvalidBlockHook<N>>,
|
||||
kind: EngineApiKind,
|
||||
) -> (Sender<FromEngine<EngineApiRequest<T>>>, UnboundedReceiver<EngineApiEvent>) {
|
||||
let best_block_number = provider.best_block_number().unwrap_or(0);
|
||||
|
||||
@ -152,7 +152,7 @@ where
|
||||
let env = self.evm_env_for_block(&block.header, total_difficulty);
|
||||
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(())
|
||||
}
|
||||
@ -247,7 +247,7 @@ where
|
||||
drop(evm);
|
||||
|
||||
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
|
||||
if self.chain_spec.fork(EthereumHardfork::Dao).transitions_at_block(block.number) {
|
||||
|
||||
@ -1,43 +1,55 @@
|
||||
//! State changes that are not related to transactions.
|
||||
|
||||
use alloy_consensus::BlockHeader;
|
||||
use alloy_eips::eip4895::Withdrawal;
|
||||
use alloy_primitives::{map::HashMap, Address, U256};
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_consensus_common::calc;
|
||||
use reth_primitives::Block;
|
||||
use reth_primitives_traits::BlockBody;
|
||||
|
||||
/// Collect all balance changes at the end of the block.
|
||||
///
|
||||
/// Balance changes might include the block reward, uncle rewards, withdrawals, or irregular
|
||||
/// state changes (DAO fork).
|
||||
#[inline]
|
||||
pub fn post_block_balance_increments<ChainSpec: EthereumHardforks>(
|
||||
pub fn post_block_balance_increments<ChainSpec, Block>(
|
||||
chain_spec: &ChainSpec,
|
||||
block: &Block,
|
||||
total_difficulty: U256,
|
||||
) -> HashMap<Address, u128> {
|
||||
) -> HashMap<Address, u128>
|
||||
where
|
||||
ChainSpec: EthereumHardforks,
|
||||
Block: reth_primitives_traits::Block,
|
||||
{
|
||||
let mut balance_increments = HashMap::default();
|
||||
|
||||
// Add block rewards if they are enabled.
|
||||
if let Some(base_block_reward) =
|
||||
calc::base_block_reward(chain_spec, block.number, block.difficulty, total_difficulty)
|
||||
{
|
||||
if let Some(base_block_reward) = calc::base_block_reward(
|
||||
chain_spec,
|
||||
block.header().number(),
|
||||
block.header().difficulty(),
|
||||
total_difficulty,
|
||||
) {
|
||||
// Ommer rewards
|
||||
for ommer in &block.body.ommers {
|
||||
*balance_increments.entry(ommer.beneficiary).or_default() +=
|
||||
calc::ommer_reward(base_block_reward, block.number, ommer.number);
|
||||
if let Some(ommers) = block.body().ommers() {
|
||||
for ommer in ommers {
|
||||
*balance_increments.entry(ommer.beneficiary()).or_default() +=
|
||||
calc::ommer_reward(base_block_reward, block.header().number(), ommer.number());
|
||||
}
|
||||
}
|
||||
|
||||
// Full block reward
|
||||
*balance_increments.entry(block.beneficiary).or_default() +=
|
||||
calc::block_reward(base_block_reward, block.body.ommers.len());
|
||||
*balance_increments.entry(block.header().beneficiary()).or_default() += calc::block_reward(
|
||||
base_block_reward,
|
||||
block.body().ommers().map(|s| s.len()).unwrap_or(0),
|
||||
);
|
||||
}
|
||||
|
||||
// process withdrawals
|
||||
insert_post_block_withdrawals_balance_increments(
|
||||
chain_spec,
|
||||
block.timestamp,
|
||||
block.body.withdrawals.as_ref().map(|w| w.as_slice()),
|
||||
block.header().timestamp(),
|
||||
block.body().withdrawals().as_ref().map(|w| w.as_slice()),
|
||||
&mut balance_increments,
|
||||
);
|
||||
|
||||
|
||||
@ -4,7 +4,6 @@ use alloc::{boxed::Box, string::ToString};
|
||||
use alloy_eips::eip2935::HISTORY_STORAGE_ADDRESS;
|
||||
|
||||
use crate::ConfigureEvm;
|
||||
use alloy_consensus::Header;
|
||||
use alloy_primitives::B256;
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_execution_errors::{BlockExecutionError, BlockValidationError};
|
||||
@ -35,7 +34,7 @@ pub(crate) fn transact_blockhashes_contract_call<EvmConfig, EXT, DB>(
|
||||
where
|
||||
DB: Database,
|
||||
DB::Error: core::fmt::Display,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
EvmConfig: ConfigureEvm,
|
||||
{
|
||||
if !chain_spec.is_prague_active_at_timestamp(block_timestamp) {
|
||||
return Ok(None)
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
use alloc::{boxed::Box, string::ToString};
|
||||
|
||||
use crate::ConfigureEvm;
|
||||
use alloy_consensus::Header;
|
||||
use alloy_eips::eip4788::BEACON_ROOTS_ADDRESS;
|
||||
use alloy_primitives::B256;
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
@ -31,7 +30,7 @@ pub(crate) fn transact_beacon_root_contract_call<EvmConfig, EXT, DB, Spec>(
|
||||
where
|
||||
DB: Database,
|
||||
DB::Error: core::fmt::Display,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
EvmConfig: ConfigureEvm,
|
||||
Spec: EthereumHardforks,
|
||||
{
|
||||
if !chain_spec.is_cancun_active_at_timestamp(block_timestamp) {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
//! [EIP-7002](https://eips.ethereum.org/EIPS/eip-7002) system call implementation.
|
||||
use crate::ConfigureEvm;
|
||||
use alloc::{boxed::Box, format};
|
||||
use alloy_consensus::Header;
|
||||
use alloy_eips::eip7002::WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS;
|
||||
use alloy_primitives::Bytes;
|
||||
use reth_execution_errors::{BlockExecutionError, BlockValidationError};
|
||||
@ -21,7 +20,7 @@ pub(crate) fn transact_withdrawal_requests_contract_call<EvmConfig, EXT, DB>(
|
||||
where
|
||||
DB: Database,
|
||||
DB::Error: core::fmt::Display,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
EvmConfig: ConfigureEvm,
|
||||
{
|
||||
// get previous env
|
||||
let previous_env = Box::new(evm.context.env().clone());
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
//! [EIP-7251](https://eips.ethereum.org/EIPS/eip-7251) system call implementation.
|
||||
use crate::ConfigureEvm;
|
||||
use alloc::{boxed::Box, format};
|
||||
use alloy_consensus::Header;
|
||||
use alloy_eips::eip7251::CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS;
|
||||
use alloy_primitives::Bytes;
|
||||
use reth_execution_errors::{BlockExecutionError, BlockValidationError};
|
||||
@ -22,7 +21,7 @@ pub(crate) fn transact_consolidation_requests_contract_call<EvmConfig, EXT, DB>(
|
||||
where
|
||||
DB: Database,
|
||||
DB::Error: core::fmt::Display,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
EvmConfig: ConfigureEvm,
|
||||
{
|
||||
// get previous env
|
||||
let previous_env = Box::new(evm.context.env().clone());
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
use crate::ConfigureEvm;
|
||||
use alloc::{boxed::Box, sync::Arc};
|
||||
use alloy_consensus::Header;
|
||||
use alloy_consensus::BlockHeader;
|
||||
use alloy_eips::{
|
||||
eip7002::WITHDRAWAL_REQUEST_TYPE, eip7251::CONSOLIDATION_REQUEST_TYPE, eip7685::Requests,
|
||||
};
|
||||
@ -10,7 +10,6 @@ use alloy_primitives::Bytes;
|
||||
use core::fmt::Display;
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_execution_errors::BlockExecutionError;
|
||||
use reth_primitives::Block;
|
||||
use revm::{Database, DatabaseCommit, Evm};
|
||||
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, EvmState, B256};
|
||||
|
||||
@ -91,11 +90,11 @@ where
|
||||
|
||||
impl<EvmConfig, Chainspec> SystemCaller<EvmConfig, Chainspec>
|
||||
where
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
EvmConfig: ConfigureEvm,
|
||||
Chainspec: EthereumHardforks,
|
||||
{
|
||||
/// Apply pre execution changes.
|
||||
pub fn apply_pre_execution_changes<DB, Ext>(
|
||||
pub fn apply_pre_execution_changes<DB, Ext, Block>(
|
||||
&mut self,
|
||||
block: &Block,
|
||||
evm: &mut Evm<'_, Ext, DB>,
|
||||
@ -103,17 +102,18 @@ where
|
||||
where
|
||||
DB: Database + DatabaseCommit,
|
||||
DB::Error: Display,
|
||||
Block: reth_primitives_traits::Block<Header = EvmConfig::Header>,
|
||||
{
|
||||
self.apply_blockhashes_contract_call(
|
||||
block.timestamp,
|
||||
block.number,
|
||||
block.parent_hash,
|
||||
block.header().timestamp(),
|
||||
block.header().number(),
|
||||
block.header().parent_hash(),
|
||||
evm,
|
||||
)?;
|
||||
self.apply_beacon_root_contract_call(
|
||||
block.timestamp,
|
||||
block.number,
|
||||
block.parent_beacon_block_root,
|
||||
block.header().timestamp(),
|
||||
block.header().number(),
|
||||
block.header().parent_beacon_block_root(),
|
||||
evm,
|
||||
)?;
|
||||
|
||||
|
||||
@ -26,6 +26,5 @@ reth-node-types.workspace = true
|
||||
reth-node-core.workspace = true
|
||||
|
||||
alloy-rpc-types-engine.workspace = true
|
||||
alloy-consensus.workspace = true
|
||||
|
||||
eyre.workspace = true
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
//! Traits for configuring a node.
|
||||
|
||||
use crate::ConfigureEvm;
|
||||
use alloy_consensus::Header;
|
||||
use alloy_rpc_types_engine::JwtSecret;
|
||||
use reth_beacon_consensus::BeaconConsensusEngineHandle;
|
||||
use reth_consensus::FullConsensus;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_network_api::FullNetwork;
|
||||
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_provider::FullProvider;
|
||||
use reth_tasks::TaskExecutor;
|
||||
@ -50,7 +49,7 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
|
||||
type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Self::Types>>> + Unpin;
|
||||
|
||||
/// 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.
|
||||
type Executor: BlockExecutorProvider<Primitives = <Self::Types as NodeTypes>::Primitives>;
|
||||
|
||||
@ -7,10 +7,9 @@ use crate::{
|
||||
},
|
||||
BuilderContext, ConfigureEvm, FullNodeTypes,
|
||||
};
|
||||
use alloy_consensus::Header;
|
||||
use reth_consensus::FullConsensus;
|
||||
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_transaction_pool::{PoolTransaction, TransactionPool};
|
||||
use std::{future::Future, marker::PhantomData};
|
||||
@ -378,7 +377,7 @@ where
|
||||
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
|
||||
+ Unpin
|
||||
+ 'static,
|
||||
EVM: ConfigureEvm<Header = Header>,
|
||||
EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>,
|
||||
Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>,
|
||||
Cons: FullConsensus<<Node::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static,
|
||||
{
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
//! EVM component for the node builder.
|
||||
use crate::{BuilderContext, FullNodeTypes};
|
||||
use alloy_consensus::Header;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_node_api::ConfigureEvm;
|
||||
use reth_node_api::{ConfigureEvm, HeaderTy};
|
||||
use std::future::Future;
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// 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.
|
||||
type Executor: BlockExecutorProvider<
|
||||
@ -27,7 +26,7 @@ pub trait ExecutorBuilder<Node: FullNodeTypes>: Send {
|
||||
impl<Node, F, Fut, EVM, Executor> ExecutorBuilder<Node> for F
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
EVM: ConfigureEvm<Header = Header>,
|
||||
EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>,
|
||||
Executor:
|
||||
BlockExecutorProvider<Primitives = <Node::Types as reth_node_api::NodeTypes>::Primitives>,
|
||||
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
|
||||
|
||||
@ -22,12 +22,11 @@ pub use payload::*;
|
||||
pub use pool::*;
|
||||
|
||||
use crate::{ConfigureEvm, FullNodeTypes};
|
||||
use alloy_consensus::Header;
|
||||
use reth_consensus::FullConsensus;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_network::NetworkHandle;
|
||||
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_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;
|
||||
|
||||
/// 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.
|
||||
type Executor: BlockExecutorProvider<Primitives = <T::Types as NodeTypes>::Primitives>;
|
||||
@ -100,7 +99,7 @@ where
|
||||
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
|
||||
+ Unpin
|
||||
+ 'static,
|
||||
EVM: ConfigureEvm<Header = Header>,
|
||||
EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>,
|
||||
Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>,
|
||||
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
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool,
|
||||
EVM: ConfigureEvm<Header = Header>,
|
||||
EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>,
|
||||
Executor: BlockExecutorProvider,
|
||||
Cons: Clone,
|
||||
{
|
||||
|
||||
@ -22,7 +22,9 @@ use reth_evm::noop::NoopBlockExecutorProvider;
|
||||
use reth_fs_util as fs;
|
||||
use reth_invalid_block_hooks::InvalidBlockWitnessHook;
|
||||
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::{
|
||||
args::InvalidBlockHookType,
|
||||
dirs::{ChainPath, DataDirPath},
|
||||
@ -39,7 +41,7 @@ use reth_node_metrics::{
|
||||
server::{MetricServer, MetricServerConfig},
|
||||
version::VersionInfo,
|
||||
};
|
||||
use reth_primitives::Head;
|
||||
use reth_primitives::{Head, TransactionSigned};
|
||||
use reth_provider::{
|
||||
providers::{ProviderNodeTypes, StaticFileProvider},
|
||||
BlockHashReader, BlockNumReader, ChainSpecProvider, ProviderError, ProviderFactory,
|
||||
@ -870,11 +872,16 @@ impl<T, CB>
|
||||
Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithComponents<T, CB>>,
|
||||
>
|
||||
where
|
||||
T: FullNodeTypes<Provider: StateProviderFactory + ChainSpecProvider, Types: ProviderNodeTypes>,
|
||||
T: FullNodeTypes<
|
||||
Provider: StateProviderFactory + ChainSpecProvider,
|
||||
Types: ProviderNodeTypes<Primitives: NodePrimitives<SignedTx = TransactionSigned>>,
|
||||
>,
|
||||
CB: NodeComponentsBuilder<T>,
|
||||
{
|
||||
/// 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 {
|
||||
return Ok(Box::new(NoopInvalidBlockHook::default()))
|
||||
};
|
||||
@ -898,7 +905,7 @@ where
|
||||
InvalidBlockHookType::PreState | InvalidBlockHookType::Opcode => {
|
||||
eyre::bail!("invalid block hook {hook:?} is not implemented yet")
|
||||
}
|
||||
} as Box<dyn InvalidBlockHook>)
|
||||
} as Box<dyn InvalidBlockHook<_>>)
|
||||
})
|
||||
.collect::<Result<_, _>>()?;
|
||||
|
||||
|
||||
@ -258,7 +258,7 @@ where
|
||||
_receipts: &[Receipt],
|
||||
) -> Result<Requests, Self::Error> {
|
||||
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
|
||||
self.state
|
||||
.increment_balances(balance_increments.clone())
|
||||
|
||||
Reference in New Issue
Block a user