Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sdk): define new BlockHeader trait #12452

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ revm-primitives.workspace = true
# alloy
alloy-primitives.workspace = true
alloy-eips.workspace = true
alloy-consensus.workspace = true

auto_impl.workspace = true
futures-util.workspace = true
Expand Down
19 changes: 10 additions & 9 deletions crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@

extern crate alloc;

use crate::builder::RethEvmBuilder;
use alloy_primitives::{Address, Bytes, B256, U256};
use reth_primitives::TransactionSigned;
use reth_primitives_traits::BlockHeader;
use revm::{Database, Evm, GetInspector};
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, Env, EnvWithHandlerCfg, SpecId, TxEnv};

pub mod builder;
pub mod either;
pub mod execute;
Expand All @@ -33,11 +26,19 @@ pub mod noop;
pub mod provider;
pub mod state_change;
pub mod system_calls;

#[cfg(any(test, feature = "test-utils"))]
/// test helpers for mocking executor
pub mod test_utils;

use alloy_consensus::BlockHeader as _;
use alloy_primitives::{Address, Bytes, B256, U256};
use reth_primitives::TransactionSigned;
use reth_primitives_traits::BlockHeader;
use revm::{Database, Evm, GetInspector};
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, Env, EnvWithHandlerCfg, SpecId, TxEnv};

use crate::builder::RethEvmBuilder;
emhane marked this conversation as resolved.
Show resolved Hide resolved

/// Trait for configuring the EVM for executing full blocks.
#[auto_impl::auto_impl(&, Arc)]
pub trait ConfigureEvm: ConfigureEvmEnv {
Expand Down Expand Up @@ -155,7 +156,7 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
block_env.coinbase = header.beneficiary();
block_env.timestamp = U256::from(header.timestamp());
if after_merge {
block_env.prevrandao = Some(header.mix_hash());
block_env.prevrandao = header.mix_hash();
block_env.difficulty = U256::ZERO;
} else {
block_env.difficulty = header.difficulty();
Expand Down
49 changes: 49 additions & 0 deletions crates/primitives-traits/src/block/header.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! Block header data primitive.

use core::fmt;

use alloy_primitives::Sealable;
use reth_codecs::Compact;

/// Helper trait that unifies all behaviour required by block header to support full node
/// operations.
pub trait FullBlockHeader: BlockHeader + Compact {}

impl<T> FullBlockHeader for T where T: BlockHeader + Compact {}

/// Abstraction of a block header.
pub trait BlockHeader:
Send
+ Sync
+ Unpin
+ Clone
+ Default
+ fmt::Debug
+ PartialEq
+ Eq
+ serde::Serialize
+ for<'de> serde::Deserialize<'de>
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
+ alloy_consensus::BlockHeader
+ Sealable
{
}

impl<T> BlockHeader for T where
T: Send
+ Sync
+ Unpin
+ Clone
+ Default
+ fmt::Debug
+ PartialEq
+ Eq
+ serde::Serialize
+ for<'de> serde::Deserialize<'de>
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
+ alloy_consensus::BlockHeader
+ Sealable
{
}
10 changes: 5 additions & 5 deletions crates/primitives-traits/src/block/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//! Block abstraction.

pub mod body;
pub mod header;

use alloc::{fmt, vec::Vec};

use alloy_consensus::BlockHeader;
use alloy_primitives::{Address, Sealable, B256};
use alloy_primitives::{Address, B256};
use reth_codecs::Compact;

use crate::BlockBody;
use crate::{BlockBody, BlockHeader, FullBlockHeader};

/// Helper trait that unifies all behaviour required by block to support full node operations.
pub trait FullBlock: Block<Header: Compact> + Compact {}

impl<T> FullBlock for T where T: Block<Header: Compact> + Compact {}
impl<T> FullBlock for T where T: Block<Header: FullBlockHeader> + Compact {}

/// Abstraction of block data type.
// todo: make sealable super-trait, depends on <https://github.com/paradigmxyz/reth/issues/11449>
Expand All @@ -34,7 +34,7 @@ pub trait Block:
+ Into<(Self::Header, Self::Body)>
{
/// Header part of the block.
type Header: BlockHeader + Sealable;
type Header: BlockHeader;

/// The block's body contains the transactions in the block.
type Body: BlockBody;
Expand Down
8 changes: 6 additions & 2 deletions crates/primitives-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ mod integer_list;
pub use integer_list::{IntegerList, IntegerListError};

pub mod block;
pub use block::{body::BlockBody, Block, FullBlock};
pub use block::{
body::BlockBody,
header::{BlockHeader, FullBlockHeader},
Block, FullBlock,
};

mod withdrawal;
pub use withdrawal::Withdrawal;
Expand All @@ -56,7 +60,7 @@ pub use tx_type::TxType;
pub mod header;
#[cfg(any(test, feature = "arbitrary", feature = "test-utils"))]
pub use header::test_utils;
pub use header::{BlockHeader, Header, HeaderError, SealedHeader};
pub use header::{Header, HeaderError, SealedHeader};

/// Bincode-compatible serde implementations for common abstracted types in Reth.
///
Expand Down
Loading