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): Add NodePrimitives::BlockHeader and NodePrimitives::BlockBody #12647

Merged
merged 39 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b5a88b5
Make Chain generic over data primitives
emhane Nov 17, 2024
01ec336
Merge branch 'main' into emhane/chain-generic-prims
emhane Nov 18, 2024
72d4b4c
Remove redundant AnyPrimitives
emhane Nov 18, 2024
f305a13
Add NodePrimitives::BlockHeader and NodePrimitives::BlockBody
emhane Nov 19, 2024
680765e
Merge branch 'emhane/chain-generic-prims' into emhane/node-prims-bloc…
emhane Nov 19, 2024
3ca1964
Merge branch 'main' into emhane/chain-generic-prims
emhane Nov 19, 2024
076aeb2
Merge branch 'emhane/chain-generic-prims' into emhane/node-prims-bloc…
emhane Nov 19, 2024
c93fb43
Move OpPrimitives to reth-optimism-primitives
emhane Nov 19, 2024
0fe0050
Use OpPrimitives in test
emhane Nov 19, 2024
660e4c6
Fix lint
emhane Nov 19, 2024
9c44d16
Merge branch 'main' into emhane/node-prims-block-parts
emhane Nov 19, 2024
13c3463
Merge branch 'main' into emhane/op-prims
emhane Nov 19, 2024
85f7ee1
Merge branch 'emhane/op-prims' into emhane/node-prims-block-parts
emhane Nov 19, 2024
424c270
Merge branch 'main' into emhane/node-prims-block-parts
emhane Nov 19, 2024
48b1ab3
Link FullNodePrimitives::BlockBody and FullNodePrimitives::BlockHeader
emhane Nov 19, 2024
a1458ef
Merge branch 'main' into emhane/node-prims-block-parts
emhane Nov 19, 2024
bac2f0b
Fix merge conflicts
emhane Nov 19, 2024
47badb2
Fix merge conflicts op
emhane Nov 19, 2024
faa86ae
Remove Compact trait bound on FullSignedTx in accordance with Transac…
emhane Nov 19, 2024
f65fb6d
Fix merge conflicts by introducing helper triat MaybeCompact
emhane Nov 19, 2024
16b2caa
Define helper triat MaybeCompact
emhane Nov 19, 2024
f1689e5
Fix docs
emhane Nov 19, 2024
dfd285f
Merge branch 'emhane/maybe-compact' into emhane/node-prims-block-parts
emhane Nov 19, 2024
a35d1bb
Fix docs
emhane Nov 19, 2024
f6ccb05
Merge branch 'emhane/maybe-compact' into emhane/node-prims-block-parts
emhane Nov 19, 2024
bb6c040
Add no_std support for reth-optimism-primitives
emhane Nov 19, 2024
abd6bdc
Fix deps
emhane Nov 19, 2024
55c6f3c
Fix deps
emhane Nov 19, 2024
350974f
Fix deps
emhane Nov 19, 2024
1dd5939
Fix deps
emhane Nov 19, 2024
9c63528
Merge branch 'main' into emhane/maybe-compact
emhane Nov 20, 2024
8a46085
Shrink scope
emhane Nov 20, 2024
164c694
Merge branch 'emhane/maybe-compact' into emhane/node-prims-block-parts
emhane Nov 20, 2024
10adffa
Fix conflicts
emhane Nov 20, 2024
e813460
Skip reth-optimism-primitives in wasm check
emhane Nov 20, 2024
a0b8960
Add super trait MaybeCompact to FullSignedTx
emhane Nov 20, 2024
ba55822
Fix docs
emhane Nov 20, 2024
9c3dbe4
Merge branch 'emhane/maybe-compact' into emhane/node-prims-block-parts
emhane Nov 20, 2024
44c765f
Merge branch 'main' into emhane/node-prims-block-parts
emhane Nov 21, 2024
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/optimism/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ reth-optimism-rpc.workspace = true
reth-optimism-chainspec.workspace = true
reth-optimism-consensus.workspace = true
reth-optimism-forks.workspace = true
reth-optimism-primitives.workspace = true

# revm with required optimism features
revm = { workspace = true, features = ["secp256k1", "blst", "c-kzg"] }
Expand Down Expand Up @@ -119,3 +120,7 @@ test-utils = [
"revm/test-utils",
"reth-optimism-node/test-utils",
]
reth-codec = [
"reth-primitives/reth-codec",
"reth-optimism-primitives/reth-codec",
]
16 changes: 3 additions & 13 deletions crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use reth_db::transaction::{DbTx, DbTxMut};
use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm};
use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, PeersInfo};
use reth_node_api::{
AddOnsContext, EngineValidator, FullNodeComponents, FullNodePrimitives, NodeAddOns,
PayloadBuilder,
AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, PayloadBuilder,
};
use reth_node_builder::{
components::{
Expand All @@ -25,12 +24,13 @@ use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_consensus::OpBeaconConsensus;
use reth_optimism_evm::{OpEvmConfig, OpExecutionStrategyFactory};
use reth_optimism_payload_builder::builder::OpPayloadTransactions;
use reth_optimism_primitives::OpPrimitives;
use reth_optimism_rpc::{
witness::{DebugExecutionWitnessApiServer, OpDebugWitnessApi},
OpEthApi,
};
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
use reth_primitives::{Block, BlockBody, Receipt, TransactionSigned, TxType};
use reth_primitives::BlockBody;
use reth_provider::{
providers::ChainStorage, BlockBodyWriter, CanonStateSubscriptions, DBProvider, EthStorage,
ProviderResult,
Expand All @@ -49,16 +49,6 @@ use crate::{
txpool::{OpTransactionPool, OpTransactionValidator},
OpEngineTypes,
};
/// Optimism primitive types.
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct OpPrimitives;

impl FullNodePrimitives for OpPrimitives {
type Block = Block;
type SignedTx = TransactionSigned;
type TxType = TxType;
type Receipt = Receipt;
}

/// Storage implementation for Optimism.
#[derive(Debug, Default, Clone)]
Expand Down
15 changes: 13 additions & 2 deletions crates/optimism/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,21 @@ reth-codecs = { workspace = true, features = ["test-utils"] }
rstest.workspace = true

[features]
default = ["reth-codec"]
default = ["std", "reth-codec"]
std = [
"reth-primitives-traits/std",
"reth-primitives/std",
"reth-node-types/std",
"reth-codecs/std",
"alloy-consensus/std",
"alloy-eips/std",
"alloy-primitives/std",
"serde/std",
]
reth-codec = [
"dep:reth-codecs",
"reth-primitives/reth-codec"
"reth-primitives/reth-codec",
"reth-primitives-traits/reth-codec",
]
serde = [
"dep:serde",
Expand Down
10 changes: 7 additions & 3 deletions crates/optimism/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]

pub mod bedrock;
pub mod tx_type;

pub use tx_type::OpTxType;

use reth_node_types::NodePrimitives;
use reth_primitives::{Block, Receipt, TransactionSigned};
use alloy_consensus::Header;
use reth_node_types::FullNodePrimitives;
use reth_primitives::{Block, BlockBody, Receipt, TransactionSigned};

/// Optimism primitive types.
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct OpPrimitives;

impl NodePrimitives for OpPrimitives {
impl FullNodePrimitives for OpPrimitives {
type Block = Block;
type BlockHeader = Header;
type BlockBody = BlockBody;
type SignedTx = TransactionSigned;
type TxType = OpTxType;
type Receipt = Receipt;
Expand Down
3 changes: 2 additions & 1 deletion crates/primitives-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@ serde = [
"revm-primitives/serde",
"roaring/serde",
"revm-primitives/serde",
]
]
reth-codec = []
1 change: 0 additions & 1 deletion crates/primitives-traits/src/block/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub trait BlockBody:
+ MaybeSerde
{
/// Ordered list of signed transactions as committed in block.
// todo: requires trait for signed transaction
type Transaction: Transaction;

/// Returns reference to transactions in block.
Expand Down
7 changes: 3 additions & 4 deletions crates/primitives-traits/src/block/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
use core::fmt;

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

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

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

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

/// Abstraction of a block header.
pub trait BlockHeader:
Expand Down
8 changes: 4 additions & 4 deletions crates/primitives-traits/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ pub mod header;

use alloc::fmt;

use alloy_rlp::{Decodable, Encodable};

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

/// Helper trait that unifies all behaviour required by block to support full node operations.
pub trait FullBlock:
Block<Header: FullBlockHeader, Body: FullBlockBody> + Encodable + Decodable
Block<Header: FullBlockHeader, Body: FullBlockBody> + alloy_rlp::Encodable + alloy_rlp::Decodable
{
}

impl<T> FullBlock for T where
T: Block<Header: FullBlockHeader, Body: FullBlockBody> + Encodable + Decodable
T: Block<Header: FullBlockHeader, Body: FullBlockBody>
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
{
}

Expand Down
14 changes: 14 additions & 0 deletions crates/primitives-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,17 @@ pub trait MaybeSerde {}
impl<T> MaybeSerde for T where T: serde::Serialize + for<'de> serde::Deserialize<'de> {}
#[cfg(not(feature = "serde"))]
impl<T> MaybeSerde for T {}

/// Helper trait that requires database encoding implementation since `reth-codec` feature is
/// enabled.
#[cfg(feature = "reth-codec")]
pub trait MaybeCompact: reth_codecs::Compact {}
/// Noop. Helper trait that would require database encoding implementation if `reth-codec` feature
/// were enabled.
#[cfg(not(feature = "reth-codec"))]
pub trait MaybeCompact {}

#[cfg(feature = "reth-codec")]
impl<T> MaybeCompact for T where T: reth_codecs::Compact {}
#[cfg(not(feature = "reth-codec"))]
impl<T> MaybeCompact for T {}
38 changes: 35 additions & 3 deletions crates/primitives-traits/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use core::fmt;

use crate::{BlockBody, FullBlock, FullReceipt, FullSignedTx, FullTxType, MaybeSerde};
use crate::{
FullBlock, FullBlockBody, FullBlockHeader, FullReceipt, FullSignedTx, FullTxType, MaybeSerde,
};

/// Configures all the primitive types of the node.
pub trait NodePrimitives:
Expand All @@ -17,6 +19,28 @@ pub trait NodePrimitives:
+ Eq
+ MaybeSerde
+ 'static;
/// Block header primitive.
type BlockHeader: Send
+ Sync
+ Unpin
+ Clone
+ Default
+ fmt::Debug
+ PartialEq
+ Eq
+ MaybeSerde
+ 'static;
/// Block body primitive.
type BlockBody: Send
+ Sync
+ Unpin
+ Clone
+ Default
+ fmt::Debug
+ PartialEq
+ Eq
+ MaybeSerde
+ 'static;
/// Signed version of the transaction type.
type SignedTx: Send
+ Sync
Expand Down Expand Up @@ -45,6 +69,8 @@ pub trait NodePrimitives:

impl NodePrimitives for () {
type Block = ();
type BlockHeader = ();
type BlockBody = ();
type SignedTx = ();
type TxType = ();
type Receipt = ();
Expand All @@ -55,7 +81,11 @@ pub trait FullNodePrimitives:
Send + Sync + Unpin + Clone + Default + fmt::Debug + PartialEq + Eq + 'static
{
/// Block primitive.
type Block: FullBlock<Body: BlockBody<Transaction = Self::SignedTx>>;
type Block: FullBlock<Header = Self::BlockHeader, Body = Self::BlockBody>;
/// Block header primitive.
type BlockHeader: FullBlockHeader + 'static;
/// Block body primitive.
type BlockBody: FullBlockBody<Transaction = Self::SignedTx> + 'static;
/// Signed version of the transaction type.
type SignedTx: FullSignedTx;
/// Transaction envelope type ID.
Expand All @@ -66,9 +96,11 @@ pub trait FullNodePrimitives:

impl<T> NodePrimitives for T
where
T: FullNodePrimitives<Block: 'static, SignedTx: 'static, Receipt: 'static, TxType: 'static>,
T: FullNodePrimitives,
{
type Block = T::Block;
type BlockHeader = T::BlockHeader;
type BlockBody = T::BlockBody;
type SignedTx = T::SignedTx;
type TxType = T::TxType;
type Receipt = T::Receipt;
Expand Down
11 changes: 6 additions & 5 deletions crates/primitives-traits/src/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
//! Receipt abstraction

use crate::{InMemorySize, MaybeSerde};
use core::fmt;

use alloc::vec::Vec;
use alloy_consensus::TxReceipt;
use alloy_primitives::B256;
use core::fmt;
use reth_codecs::Compact;

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

/// Helper trait that unifies all behaviour required by receipt to support full node operations.
pub trait FullReceipt: Receipt + Compact {}
pub trait FullReceipt: Receipt + MaybeCompact {}

impl<T> FullReceipt for T where T: ReceiptExt + Compact {}
impl<T> FullReceipt for T where T: ReceiptExt + MaybeCompact {}

/// Abstraction of a receipt.
#[auto_impl::auto_impl(&, Arc)]
Expand Down
7 changes: 3 additions & 4 deletions crates/primitives-traits/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ pub mod signed;
use core::{fmt, hash::Hash};

use alloy_primitives::B256;
use reth_codecs::Compact;

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

/// Helper trait that unifies all behaviour required by transaction to support full node operations.
pub trait FullTransaction: Transaction<Type: FullTxType> + Compact {}
pub trait FullTransaction: Transaction<Type: FullTxType> + MaybeCompact {}

impl<T> FullTransaction for T where T: Transaction<Type: FullTxType> + Compact {}
impl<T> FullTransaction for T where T: Transaction<Type: FullTxType> + MaybeCompact {}

/// Abstraction of a transaction.
pub trait Transaction:
Expand Down
11 changes: 2 additions & 9 deletions crates/primitives-traits/src/transaction/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@ use core::hash::Hash;

use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{keccak256, Address, PrimitiveSignature, TxHash, B256};
use reth_codecs::Compact;

use crate::{FillTxEnv, FullTransaction, InMemorySize, MaybeArbitrary, MaybeSerde, Transaction};

/// Helper trait that unifies all behaviour required by block to support full node operations.
pub trait FullSignedTx:
SignedTransaction<Transaction: FullTransaction> + FillTxEnv + Compact
{
}
pub trait FullSignedTx: SignedTransaction<Transaction: FullTransaction> + FillTxEnv {}

impl<T> FullSignedTx for T where
T: SignedTransaction<Transaction: FullTransaction> + FillTxEnv + Compact
{
}
impl<T> FullSignedTx for T where T: SignedTransaction<Transaction: FullTransaction> + FillTxEnv {}

/// A signed transaction.
#[auto_impl::auto_impl(&, Arc)]
Expand Down
7 changes: 3 additions & 4 deletions crates/primitives-traits/src/tx_type.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use core::fmt;

use alloy_primitives::{U64, U8};
use reth_codecs::Compact;

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

/// Helper trait that unifies all behaviour required by transaction type ID to support full node
/// operations.
pub trait FullTxType: TxType + Compact {}
pub trait FullTxType: TxType + MaybeCompact {}

impl<T> FullTxType for T where T: TxType + Compact {}
impl<T> FullTxType for T where T: TxType + MaybeCompact {}

/// Trait representing the behavior of a transaction type.
pub trait TxType:
Expand Down
7 changes: 6 additions & 1 deletion crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ std = [
"serde/std",
"alloy-trie/std"
]
reth-codec = ["dep:reth-codecs", "dep:zstd", "dep:modular-bitfield", "std"]
reth-codec = [
"dep:reth-codecs",
"dep:zstd",
"dep:modular-bitfield", "std",
"reth-primitives-traits/reth-codec",
]
asm-keccak = ["alloy-primitives/asm-keccak", "revm-primitives/asm-keccak"]
arbitrary = [
"dep:arbitrary",
Expand Down
11 changes: 2 additions & 9 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,10 @@ pub mod serde_bincode_compat {
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct EthPrimitives;

#[cfg(feature = "reth-codec")]
impl reth_primitives_traits::FullNodePrimitives for EthPrimitives {
type Block = crate::Block;
type SignedTx = crate::TransactionSigned;
type TxType = crate::TxType;
type Receipt = crate::Receipt;
}

#[cfg(not(feature = "reth-codec"))]
impl NodePrimitives for EthPrimitives {
type Block = crate::Block;
type BlockHeader = alloy_consensus::Header;
type BlockBody = crate::BlockBody;
type SignedTx = crate::TransactionSigned;
type TxType = crate::TxType;
type Receipt = crate::Receipt;
Expand Down
Loading