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 all 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 .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
Loading