Skip to content

Commit

Permalink
Merge branch 'main' into emhane/block-prims
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Nov 24, 2024
2 parents 7fec99c + 0d6ebec commit 16c938d
Show file tree
Hide file tree
Showing 63 changed files with 790 additions and 768 deletions.
246 changes: 126 additions & 120 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/consensus/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ pub mod test_utils;

/// Post execution input passed to [`Consensus::validate_block_post_execution`].
#[derive(Debug)]
pub struct PostExecutionInput<'a> {
pub struct PostExecutionInput<'a, R = Receipt> {
/// Receipts of the block.
pub receipts: &'a [Receipt],
pub receipts: &'a [R],
/// EIP-7685 requests of the block.
pub requests: &'a Requests,
}

impl<'a> PostExecutionInput<'a> {
impl<'a, R> PostExecutionInput<'a, R> {
/// Creates a new instance of `PostExecutionInput`.
pub const fn new(receipts: &'a [Receipt], requests: &'a Requests) -> Self {
pub const fn new(receipts: &'a [R], requests: &'a Requests) -> Self {
Self { receipts, requests }
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ethereum/payload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ where
};

let sealed_block = Arc::new(block.seal_slow());
debug!(target: "payload_builder", sealed_block_header = ?sealed_block.header, "sealed built block");
debug!(target: "payload_builder", id=%attributes.id, sealed_block_header = ?sealed_block.header, "sealed built block");

// create the executed block data
let executed = ExecutedBlock {
Expand Down
3 changes: 3 additions & 0 deletions crates/node/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,6 @@ pub type HeaderTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::BlockHe

/// Helper adapter type for accessing [`NodePrimitives::BlockBody`] on [`NodeTypes`].
pub type BodyTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::BlockBody;

/// Helper adapter type for accessing [`NodePrimitives::SignedTx`] on [`NodeTypes`].
pub type TxTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::SignedTx;
3 changes: 2 additions & 1 deletion crates/optimism/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ optimism = [
]

dev = [
"reth-optimism-cli/dev"
"reth-optimism-cli/dev",
"reth-optimism-primitives/arbitrary",
]

min-error-logs = ["tracing/release_max_level_error"]
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/cli/src/ovm_file_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ impl Encodable2718 for TransactionSigned {
Transaction::Deposit(deposit_tx) => deposit_tx.eip2718_encoded_length(),
}
}

fn encode_2718(&self, out: &mut dyn alloy_rlp::BufMut) {
self.transaction.eip2718_encode(&self.signature, out)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ reth-primitives = { workspace = true, features = ["test-utils"] }
reth-optimism-chainspec.workspace = true
alloy-genesis.workspace = true
alloy-consensus.workspace = true
reth-optimism-primitives.workspace = true
reth-optimism-primitives = { workspace = true, features = ["arbitrary"] }

[features]
default = ["std"]
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/evm/src/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::OpBlockExecutionError;
use alloc::{string::ToString, sync::Arc};
use alloy_consensus::Transaction;
use alloy_primitives::{address, b256, hex, Address, Bytes, B256, U256};
use reth_chainspec::ChainSpec;
use reth_execution_errors::BlockExecutionError;
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ test-utils = [
"reth-trie-db/test-utils",
"revm/test-utils",
"reth-optimism-node/test-utils",
"reth-optimism-primitives/arbitrary",
]
reth-codec = [
"reth-primitives/reth-codec",
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ where
};

let sealed_block = Arc::new(block.seal_slow());
debug!(target: "payload_builder", sealed_block_header = ?sealed_block.header, "sealed built block");
debug!(target: "payload_builder", id=%ctx.attributes().payload_id(), sealed_block_header = ?sealed_block.header, "sealed built block");

// create the executed block data
let executed = ExecutedBlock {
Expand Down
14 changes: 14 additions & 0 deletions crates/optimism/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ serde = { workspace = true, optional = true }
# misc
derive_more.workspace = true

# test-utils
arbitrary = { workspace = true, features = ["derive"], optional = true }

[dev-dependencies]
reth-codecs = { workspace = true, features = ["test-utils"] }
rstest.workspace = true
arbitrary.workspace = true

[features]
default = ["std", "reth-codec"]
Expand Down Expand Up @@ -65,3 +69,13 @@ serde = [
"reth-codecs/serde",
"op-alloy-consensus/serde",
]
arbitrary = [
"dep:arbitrary",
"reth-primitives-traits/arbitrary",
"reth-primitives/arbitrary",
"reth-codecs?/arbitrary",
"op-alloy-consensus/arbitrary",
"alloy-consensus/arbitrary",
"alloy-eips/arbitrary",
"alloy-primitives/arbitrary",
]
7 changes: 5 additions & 2 deletions crates/optimism/primitives/src/tx_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
//! `OpTxType` implements `reth_primitives_traits::TxType`.
//! This type is required because a `Compact` impl is needed on the deposit tx type.
use core::fmt::Debug;

use alloy_primitives::{U64, U8};
use alloy_rlp::{Decodable, Encodable, Error};
use bytes::BufMut;
use core::fmt::Debug;
use derive_more::{
derive::{From, Into},
Display,
};
use op_alloy_consensus::OpTxType as AlloyOpTxType;
use reth_primitives_traits::{InMemorySize, TxType};

/// Wrapper type for [`op_alloy_consensus::OpTxType`] to implement [`TxType`] trait.
/// Wrapper type for [`op_alloy_consensus::OpTxType`] to implement
/// [`TxType`] trait.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Display, Ord, Hash, From, Into)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[into(u8)]
pub struct OpTxType(AlloyOpTxType);

Expand Down
3 changes: 2 additions & 1 deletion crates/optimism/rpc/src/eth/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_evm::RethL1BlockInfo;
use reth_optimism_forks::OpHardforks;
use reth_primitives::{Receipt, TransactionMeta, TransactionSigned, TxType};
use reth_provider::ChainSpecProvider;
use reth_provider::{ChainSpecProvider, TransactionsProvider};
use reth_rpc_eth_api::{helpers::LoadReceipt, FromEthApiError, RpcReceipt};
use reth_rpc_eth_types::{receipt::build_receipt, EthApiError};

Expand All @@ -21,6 +21,7 @@ impl<N> LoadReceipt for OpEthApi<N>
where
Self: Send + Sync,
N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>,
Self::Provider: TransactionsProvider<Transaction = TransactionSigned>,
{
async fn build_transaction_receipt(
&self,
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl<N> LoadTransaction for OpEthApi<N>
where
Self: SpawnBlocking + FullEthApiTypes,
N: RpcNodeCore<Provider: TransactionsProvider, Pool: TransactionPool>,
Self::Pool: TransactionPool,
{
}

Expand Down
3 changes: 2 additions & 1 deletion crates/primitives-traits/src/block/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use alloc::fmt;

use crate::{FullSignedTx, InMemorySize, MaybeSerde, SignedTransaction};
use crate::{FullSignedTx, InMemorySize, MaybeArbitrary, MaybeSerde, SignedTransaction};

/// Helper trait that unifies all behaviour required by transaction to support full node operations.
pub trait FullBlockBody: BlockBody<Transaction: FullSignedTx> {}
Expand All @@ -24,6 +24,7 @@ pub trait BlockBody:
+ alloy_rlp::Decodable
+ InMemorySize
+ MaybeSerde
+ MaybeArbitrary
{
/// Signed transaction.
type Transaction: SignedTransaction;
Expand Down
4 changes: 3 additions & 1 deletion crates/primitives-traits/src/block/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::fmt;

use alloy_primitives::Sealable;

use crate::{InMemorySize, MaybeCompact, MaybeSerde};
use crate::{InMemorySize, MaybeArbitrary, MaybeCompact, MaybeSerde};

/// Helper trait that unifies all behaviour required by block header to support full node
/// operations.
Expand All @@ -28,6 +28,7 @@ pub trait BlockHeader:
+ Sealable
+ InMemorySize
+ MaybeSerde
+ MaybeArbitrary
{
}

Expand All @@ -46,5 +47,6 @@ impl<T> BlockHeader for T where
+ Sealable
+ InMemorySize
+ MaybeSerde
+ MaybeArbitrary
{
}
16 changes: 14 additions & 2 deletions crates/primitives-traits/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ pub mod header;

use alloc::fmt;

use crate::{BlockHeader, FullBlockBody, FullBlockHeader, InMemorySize, MaybeSerde};
use crate::{
BlockHeader, FullBlockBody, FullBlockHeader, InMemorySize, MaybeArbitrary, MaybeSerde,
};

/// Helper trait that unifies all behaviour required by block to support full node operations.
pub trait FullBlock:
Expand All @@ -26,7 +28,17 @@ impl<T> FullBlock for T where
// senders
#[auto_impl::auto_impl(&, Arc)]
pub trait Block:
Send + Sync + Unpin + Clone + Default + fmt::Debug + PartialEq + Eq + InMemorySize + MaybeSerde
Send
+ Sync
+ Unpin
+ Clone
+ Default
+ fmt::Debug
+ PartialEq
+ Eq
+ InMemorySize
+ MaybeSerde
+ MaybeArbitrary
{
/// Header part of the block.
type Header: BlockHeader + 'static;
Expand Down
7 changes: 5 additions & 2 deletions crates/primitives-traits/src/header/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,12 @@ impl<H> From<SealedHeader<H>> for Sealed<H> {
}

#[cfg(any(test, feature = "arbitrary"))]
impl<'a> arbitrary::Arbitrary<'a> for SealedHeader {
impl<'a, H> arbitrary::Arbitrary<'a> for SealedHeader<H>
where
H: for<'b> arbitrary::Arbitrary<'b> + Sealable,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
let header = Header::arbitrary(u)?;
let header = H::arbitrary(u)?;

Ok(Self::seal(header))
}
Expand Down
5 changes: 3 additions & 2 deletions crates/primitives-traits/src/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Receipt abstraction
use alloc::vec::Vec;
use core::fmt;

use alloc::vec::Vec;
use alloy_consensus::TxReceipt;
use alloy_primitives::B256;

use crate::{InMemorySize, MaybeCompact, MaybeSerde};
use crate::{InMemorySize, MaybeArbitrary, MaybeCompact, MaybeSerde};

/// Helper trait that unifies all behaviour required by receipt to support full node operations.
pub trait FullReceipt: Receipt + MaybeCompact {}
Expand All @@ -27,6 +27,7 @@ pub trait Receipt:
+ alloy_rlp::Decodable
+ MaybeSerde
+ InMemorySize
+ MaybeArbitrary
{
/// Returns transaction type.
fn tx_type(&self) -> u8;
Expand Down
19 changes: 18 additions & 1 deletion crates/primitives-traits/src/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,32 @@ pub trait InMemorySize {

impl<T: InMemorySize> InMemorySize for alloy_consensus::Signed<T> {
fn size(&self) -> usize {
T::size(self.tx()) + core::mem::size_of::<Signature>() + core::mem::size_of::<TxHash>()
T::size(self.tx()) + self.signature().size() + self.hash().size()
}
}

/// Implement `InMemorySize` for a type with `size_of`
macro_rules! impl_in_mem_size_size_of {
($($ty:ty),*) => {
$(
impl InMemorySize for $ty {
#[inline]
fn size(&self) -> usize {
core::mem::size_of::<Self>()
}
}
)*
};
}

impl_in_mem_size_size_of!(Signature, TxHash);

/// Implement `InMemorySize` for a type with a native `size` method.
macro_rules! impl_in_mem_size {
($($ty:ty),*) => {
$(
impl InMemorySize for $ty {
#[inline]
fn size(&self) -> usize {
Self::size(self)
}
Expand Down
3 changes: 2 additions & 1 deletion crates/primitives-traits/src/transaction/tx_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::fmt;

use alloy_primitives::{U64, U8};

use crate::{InMemorySize, MaybeCompact};
use crate::{InMemorySize, MaybeArbitrary, MaybeCompact};

/// Helper trait that unifies all behaviour required by transaction type ID to support full node
/// operations.
Expand Down Expand Up @@ -33,6 +33,7 @@ pub trait TxType:
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
+ InMemorySize
+ MaybeArbitrary
{
/// Returns `true` if this is a legacy transaction.
fn is_legacy(&self) -> bool;
Expand Down
Loading

0 comments on commit 16c938d

Please sign in to comment.