chore(sdk): Add NodePrimitives::BlockHeader and NodePrimitives::BlockBody (#12647)

This commit is contained in:
Emilia Hane
2024-11-21 18:03:05 +01:00
committed by GitHub
parent 2c7b404c24
commit 2093d2bd9a
9 changed files with 68 additions and 31 deletions

View File

@ -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

1
Cargo.lock generated
View File

@ -8328,6 +8328,7 @@ dependencies = [
"reth-optimism-forks",
"reth-optimism-node",
"reth-optimism-payload-builder",
"reth-optimism-primitives",
"reth-optimism-rpc",
"reth-payload-builder",
"reth-payload-util",

View File

@ -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"] }
@ -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",
]

View File

@ -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::{
@ -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,
@ -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)]

View File

@ -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",

View File

@ -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;

View File

@ -100,4 +100,4 @@ reth-codec = [
"dep:reth-codecs",
"dep:modular-bitfield",
"dep:byteorder",
]
]

View File

@ -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:
@ -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
@ -45,6 +69,8 @@ pub trait NodePrimitives:
impl NodePrimitives for () {
type Block = ();
type BlockHeader = ();
type BlockBody = ();
type SignedTx = ();
type TxType = ();
type Receipt = ();
@ -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.
@ -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;

View File

@ -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;