Skip to content

Commit

Permalink
chore(sdk): Add NodePrimitives::BlockHeader and `NodePrimitives::Bl…
Browse files Browse the repository at this point in the history
…ockBody` (#12647)
  • Loading branch information
emhane authored Nov 21, 2024
1 parent 2c7b404 commit 2093d2b
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 31 deletions.
1 change: 1 addition & 0 deletions .github/assets/check_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ exclude_crates=(
reth-optimism-node
reth-optimism-payload-builder
reth-optimism-rpc
reth-optimism-primitives
reth-rpc
reth-rpc-api
reth-rpc-api-testing-util
Expand Down
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
2 changes: 1 addition & 1 deletion crates/primitives-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ reth-codec = [
"dep:reth-codecs",
"dep:modular-bitfield",
"dep:byteorder",
]
]
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: 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

0 comments on commit 2093d2b

Please sign in to comment.