Skip to content

Commit

Permalink
feat: integrate OpPrimitives (#13556)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Dec 27, 2024
1 parent c35fe4a commit 4994cdf
Show file tree
Hide file tree
Showing 44 changed files with 527 additions and 509 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

10 changes: 6 additions & 4 deletions crates/e2e-test-utils/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use jsonrpsee::{
http_client::{transport::HttpBackend, HttpClient},
};
use reth_chainspec::EthereumHardforks;
use reth_node_api::EngineTypes;
use reth_node_api::{EngineTypes, NodePrimitives};
use reth_node_builder::BuiltPayload;
use reth_payload_builder::PayloadId;
use reth_payload_primitives::PayloadBuilderAttributes;
Expand All @@ -17,14 +17,16 @@ use std::{marker::PhantomData, sync::Arc};

/// Helper for engine api operations
#[derive(Debug)]
pub struct EngineApiTestContext<E, ChainSpec> {
pub struct EngineApiTestContext<E, ChainSpec, N: NodePrimitives> {
pub chain_spec: Arc<ChainSpec>,
pub canonical_stream: CanonStateNotificationStream,
pub canonical_stream: CanonStateNotificationStream<N>,
pub engine_api_client: HttpClient<AuthClientService<HttpBackend>>,
pub _marker: PhantomData<E>,
}

impl<E: EngineTypes, ChainSpec: EthereumHardforks> EngineApiTestContext<E, ChainSpec> {
impl<E: EngineTypes, ChainSpec: EthereumHardforks, N: NodePrimitives>
EngineApiTestContext<E, ChainSpec, N>
{
/// Retrieves a v3 payload from the engine api
pub async fn get_payload_v3(
&self,
Expand Down
9 changes: 2 additions & 7 deletions crates/e2e-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use reth_chainspec::EthChainSpec;
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
use reth_engine_local::LocalPayloadAttributesBuilder;
use reth_network_api::test_utils::PeersHandleProvider;
use reth_node_api::EngineValidator;
use reth_node_builder::{
components::NodeComponentsBuilder,
rpc::{EngineValidatorAddOn, RethRpcAddOns},
Expand All @@ -14,7 +13,6 @@ use reth_node_builder::{
PayloadTypes,
};
use reth_node_core::args::{DiscoveryArgs, NetworkArgs, RpcServerArgs};
use reth_primitives::EthPrimitives;
use reth_provider::providers::{
BlockchainProvider, BlockchainProvider2, NodeTypesForProvider, NodeTypesForTree,
};
Expand Down Expand Up @@ -122,7 +120,7 @@ pub async fn setup_engine<N>(
where
N: Default
+ Node<TmpNodeAdapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>>
+ NodeTypesWithEngine<Primitives = EthPrimitives>
+ NodeTypesWithEngine
+ NodeTypesForProvider,
N::ComponentsBuilder: NodeComponentsBuilder<
TmpNodeAdapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>,
Expand All @@ -132,10 +130,7 @@ where
>,
>,
N::AddOns: RethRpcAddOns<Adapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>>
+ EngineValidatorAddOn<
Adapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>,
Validator: EngineValidator<N::Engine, Block = reth_primitives::Block>,
>,
+ EngineValidatorAddOn<Adapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>>,
LocalPayloadAttributesBuilder<N::ChainSpec>: PayloadAttributesBuilder<
<<N as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadAttributes,
>,
Expand Down
19 changes: 8 additions & 11 deletions crates/e2e-test-utils/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use crate::{
};
use alloy_consensus::BlockHeader;
use alloy_eips::BlockId;
use alloy_primitives::{BlockHash, BlockNumber, Bytes, B256};
use alloy_primitives::{BlockHash, BlockNumber, Bytes, Sealable, B256};
use alloy_rpc_types_engine::PayloadStatusEnum;
use alloy_rpc_types_eth::BlockNumberOrTag;
use eyre::Ok;
use futures_util::Future;
use reth_chainspec::EthereumHardforks;
use reth_network_api::test_utils::PeersHandleProvider;
use reth_node_api::{Block, EngineTypes, FullNodeComponents};
use reth_node_api::{Block, BlockTy, EngineTypes, FullNodeComponents};
use reth_node_builder::{rpc::RethRpcAddOns, FullNode, NodeTypes, NodeTypesWithEngine};
use reth_node_core::primitives::SignedTransaction;
use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes};
use reth_primitives::EthPrimitives;
use reth_provider::{
BlockReader, BlockReaderIdExt, CanonStateSubscriptions, StageCheckpointReader,
};
Expand All @@ -25,7 +25,7 @@ use tokio_stream::StreamExt;
use url::Url;

/// An helper struct to handle node actions
#[allow(missing_debug_implementations)]
#[expect(missing_debug_implementations, clippy::complexity)]
pub struct NodeTestContext<Node, AddOns>
where
Node: FullNodeComponents,
Expand All @@ -41,6 +41,7 @@ where
pub engine_api: EngineApiTestContext<
<Node::Types as NodeTypesWithEngine>::Engine,
<Node::Types as NodeTypes>::ChainSpec,
<Node::Types as NodeTypes>::Primitives,
>,
/// Context for testing RPC features.
pub rpc: RpcTestContext<Node, AddOns::EthApi>,
Expand All @@ -50,11 +51,7 @@ impl<Node, Engine, AddOns> NodeTestContext<Node, AddOns>
where
Engine: EngineTypes,
Node: FullNodeComponents,
Node::Types: NodeTypesWithEngine<
ChainSpec: EthereumHardforks,
Engine = Engine,
Primitives = EthPrimitives,
>,
Node::Types: NodeTypesWithEngine<ChainSpec: EthereumHardforks, Engine = Engine>,
Node::Network: PeersHandleProvider,
AddOns: RethRpcAddOns<Node>,
{
Expand Down Expand Up @@ -97,7 +94,7 @@ where
where
Engine::ExecutionPayloadEnvelopeV3: From<Engine::BuiltPayload> + PayloadEnvelopeExt,
Engine::ExecutionPayloadEnvelopeV4: From<Engine::BuiltPayload> + PayloadEnvelopeExt,
AddOns::EthApi: EthApiSpec<Provider: BlockReader<Block = reth_primitives::Block>>
AddOns::EthApi: EthApiSpec<Provider: BlockReader<Block = BlockTy<Node::Types>>>
+ EthTransactions
+ TraceExt,
{
Expand Down Expand Up @@ -236,7 +233,7 @@ where
// pool is actually present in the canonical block
let head = self.engine_api.canonical_stream.next().await.unwrap();
let tx = head.tip().transactions().first();
assert_eq!(tx.unwrap().hash().as_slice(), tip_tx_hash.as_slice());
assert_eq!(tx.unwrap().tx_hash().as_slice(), tip_tx_hash.as_slice());

loop {
// wait for the block to commit
Expand Down
14 changes: 3 additions & 11 deletions crates/e2e-test-utils/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloy_consensus::TxEnvelope;
use alloy_network::eip2718::Decodable2718;
use alloy_primitives::{Bytes, B256};
use reth_chainspec::EthereumHardforks;
use reth_node_api::{FullNodeComponents, NodePrimitives};
use reth_node_api::{BlockTy, FullNodeComponents};
use reth_node_builder::{rpc::RpcRegistry, NodeTypes};
use reth_provider::BlockReader;
use reth_rpc_api::DebugApiServer;
Expand All @@ -18,16 +18,8 @@ pub struct RpcTestContext<Node: FullNodeComponents, EthApi: EthApiTypes> {

impl<Node, EthApi> RpcTestContext<Node, EthApi>
where
Node: FullNodeComponents<
Types: NodeTypes<
ChainSpec: EthereumHardforks,
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
>,
>,
>,
EthApi: EthApiSpec<Provider: BlockReader<Block = reth_primitives::Block>>
Node: FullNodeComponents<Types: NodeTypes<ChainSpec: EthereumHardforks>>,
EthApi: EthApiSpec<Provider: BlockReader<Block = BlockTy<Node::Types>>>
+ EthTransactions
+ TraceExt,
{
Expand Down
4 changes: 3 additions & 1 deletion crates/ethereum/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ reth-consensus.workspace = true

# Ethereum
revm-primitives.workspace = true
reth-primitives-traits.workspace = true

# Alloy
alloy-primitives.workspace = true
Expand Down Expand Up @@ -52,5 +53,6 @@ std = [
"revm-primitives/std",
"secp256k1/std",
"reth-ethereum-forks/std",
"serde_json/std"
"serde_json/std",
"reth-primitives-traits/std"
]
3 changes: 2 additions & 1 deletion crates/ethereum/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use alloy_consensus::{BlockHeader, Header};
use alloy_primitives::{Address, Bytes, TxKind, U256};
use reth_chainspec::ChainSpec;
use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes};
use reth_primitives::{transaction::FillTxEnv, TransactionSigned};
use reth_primitives::TransactionSigned;
use reth_primitives_traits::transaction::execute::FillTxEnv;
use revm_primitives::{
AnalysisKind, BlobExcessGasAndPrice, BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, Env, SpecId, TxEnv,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern crate alloc;
use crate::builder::RethEvmBuilder;
use alloy_consensus::BlockHeader as _;
use alloy_primitives::{Address, Bytes, B256, U256};
use reth_primitives_traits::BlockHeader;
use reth_primitives_traits::{BlockHeader, SignedTransaction};
use revm::{Database, Evm, GetInspector};
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, Env, EnvWithHandlerCfg, SpecId, TxEnv};

Expand Down Expand Up @@ -119,7 +119,7 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
type Header: BlockHeader;

/// The transaction type.
type Transaction;
type Transaction: SignedTransaction;

/// The error type that is returned by [`Self::next_cfg_and_block_env`].
type Error: core::error::Error + Send + Sync;
Expand Down
28 changes: 12 additions & 16 deletions crates/node/builder/src/launch/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ use reth_exex::ExExManagerHandle;
use reth_network::{NetworkSyncUpdater, SyncState};
use reth_network_api::BlockDownloaderProvider;
use reth_node_api::{
BlockTy, BuiltPayload, EngineValidator, FullNodeTypes, NodeTypesWithDBAdapter,
NodeTypesWithEngine, PayloadAttributesBuilder, PayloadBuilder, PayloadTypes,
BuiltPayload, FullNodeTypes, NodeTypesWithDBAdapter, NodeTypesWithEngine,
PayloadAttributesBuilder, PayloadBuilder, PayloadTypes,
};
use reth_node_core::{
dirs::{ChainPath, DataDirPath},
exit::NodeExitFuture,
primitives::Head,
};
use reth_node_events::{cl::ConsensusLayerHealthEvents, node};
use reth_primitives::{EthPrimitives, EthereumHardforks};
use reth_primitives::EthereumHardforks;
use reth_provider::providers::{BlockchainProvider2, NodeTypesForProvider};
use reth_tasks::TaskExecutor;
use reth_tokio_util::EventSender;
Expand Down Expand Up @@ -74,7 +74,7 @@ impl EngineNodeLauncher {

impl<Types, DB, T, CB, AO> LaunchNode<NodeBuilderWithComponents<T, CB, AO>> for EngineNodeLauncher
where
Types: NodeTypesForProvider + NodeTypesWithEngine<Primitives = EthPrimitives>,
Types: NodeTypesForProvider + NodeTypesWithEngine,
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
T: FullNodeTypes<
Types = Types,
Expand All @@ -83,11 +83,7 @@ where
>,
CB: NodeComponentsBuilder<T>,
AO: RethRpcAddOns<NodeAdapter<T, CB::Components>>
+ EngineValidatorAddOn<
NodeAdapter<T, CB::Components>,
Validator: EngineValidator<Types::Engine, Block = BlockTy<Types>>,
>,

+ EngineValidatorAddOn<NodeAdapter<T, CB::Components>>,
LocalPayloadAttributesBuilder<Types::ChainSpec>: PayloadAttributesBuilder<
<<Types as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadAttributes,
>,
Expand Down Expand Up @@ -157,13 +153,13 @@ where
let consensus_engine_stream = UnboundedReceiverStream::from(consensus_engine_rx)
.maybe_skip_fcu(node_config.debug.skip_fcu)
.maybe_skip_new_payload(node_config.debug.skip_new_payload)
.maybe_reorg(
ctx.blockchain_db().clone(),
ctx.components().evm_config().clone(),
reth_payload_validator::ExecutionPayloadValidator::new(ctx.chain_spec()),
node_config.debug.reorg_frequency,
node_config.debug.reorg_depth,
)
// .maybe_reorg(
// ctx.blockchain_db().clone(),
// ctx.components().evm_config().clone(),
// reth_payload_validator::ExecutionPayloadValidator::new(ctx.chain_spec()),
// node_config.debug.reorg_frequency,
// node_config.debug.reorg_depth,
// )
// Store messages _after_ skipping so that `replay-engine` command
// would replay only the messages that were observed by the engine
// during this run.
Expand Down
54 changes: 20 additions & 34 deletions crates/optimism/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,26 @@ fn main() {

if let Err(err) =
Cli::<OpChainSpecParser, RollupArgs>::parse().run(|builder, rollup_args| async move {
if rollup_args.experimental {
tracing::warn!(target: "reth::cli", "Experimental engine is default now, and the --engine.experimental flag is deprecated. To enable the legacy functionality, use --engine.legacy.");
}
let use_legacy_engine = rollup_args.legacy;
match use_legacy_engine {
false => {
let engine_tree_config = TreeConfig::default()
.with_persistence_threshold(rollup_args.persistence_threshold)
.with_memory_block_buffer_target(rollup_args.memory_block_buffer_target);

let op_node = OpNode::new(rollup_args.clone());
let handle = builder
.with_types_and_provider::<OpNode, BlockchainProvider2<_>>()
.with_components(op_node.components())
.with_add_ons(op_node.add_ons())
.launch_with_fn(|builder| {
let launcher = EngineNodeLauncher::new(
builder.task_executor().clone(),
builder.config().datadir(),
engine_tree_config,
);
builder.launch_with(launcher)
})
.await?;

handle.node_exit_future.await
}
true => {
let handle =
builder.node(OpNode::new(rollup_args.clone())).launch().await?;

handle.node_exit_future.await
}
}
let engine_tree_config = TreeConfig::default()
.with_persistence_threshold(rollup_args.persistence_threshold)
.with_memory_block_buffer_target(rollup_args.memory_block_buffer_target);

let op_node = OpNode::new(rollup_args.clone());
let handle = builder
.with_types_and_provider::<OpNode, BlockchainProvider2<_>>()
.with_components(op_node.components())
.with_add_ons(op_node.add_ons())
.launch_with_fn(|builder| {
let launcher = EngineNodeLauncher::new(
builder.task_executor().clone(),
builder.config().datadir(),
engine_tree_config,
);
builder.launch_with(launcher)
})
.await?;

handle.node_exit_future.await
})
{
eprintln!("Error: {err:?}");
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ workspace = true
reth-static-file-types = { workspace = true, features = ["clap"] }
reth-cli-commands.workspace = true
reth-consensus.workspace = true
reth-db = { workspace = true, features = ["mdbx"] }
reth-db = { workspace = true, features = ["mdbx", "op"] }
reth-db-api.workspace = true
reth-db-common.workspace = true
reth-downloaders.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/optimism/cli/src/commands/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use reth_db_api::transaction::DbTx;
use reth_downloaders::file_client::{
ChunkedFileReader, FileClient, DEFAULT_BYTE_LEN_CHUNK_CHAIN_FILE,
};
use reth_node_builder::BlockTy;
use reth_node_core::version::SHORT_VERSION;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_evm::OpExecutorProvider;
Expand Down Expand Up @@ -69,7 +70,7 @@ impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> ImportOpCommand<C> {
let mut total_decoded_txns = 0;
let mut total_filtered_out_dup_txns = 0;

while let Some(mut file_client) = reader.next_chunk::<FileClient>().await? {
while let Some(mut file_client) = reader.next_chunk::<FileClient<BlockTy<N>>>().await? {
// create a new FileClient from chunk read from file
info!(target: "reth::cli",
"Importing chain file chunk"
Expand Down
Loading

0 comments on commit 4994cdf

Please sign in to comment.