Skip to content

Commit a5be407

Browse files
committed
move creation of componenets to node for easier testing
1 parent f176ff1 commit a5be407

11 files changed

Lines changed: 238 additions & 191 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/ev-reth/src/main.rs

Lines changed: 2 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,16 @@
55
66
#![allow(missing_docs, rustdoc::missing_crate_level_docs)]
77

8-
pub mod attributes;
9-
pub mod builder;
10-
pub mod error;
11-
pub mod executor;
12-
pub mod validator;
13-
14-
use alloy_rpc_types::engine::{
15-
ExecutionData, ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3,
16-
ExecutionPayloadEnvelopeV4, ExecutionPayloadEnvelopeV5, ExecutionPayloadV1,
17-
};
188
use clap::Parser;
199
use evolve_ev_reth::{
2010
config::EvolveConfig,
21-
consensus::EvolveConsensusBuilder,
2211
rpc::txpool::{EvolveTxpoolApiImpl, EvolveTxpoolApiServer},
2312
};
24-
use reth_ethereum::{
25-
chainspec::ChainSpec,
26-
node::{
27-
api::{EngineTypes, FullNodeTypes, NodeTypes, PayloadTypes},
28-
builder::{
29-
components::{BasicPayloadServiceBuilder, ComponentsBuilder},
30-
rpc::RpcAddOns,
31-
Node, NodeAdapter,
32-
},
33-
node::{EthereumNetworkBuilder, EthereumPoolBuilder},
34-
EthereumEthApiBuilder,
35-
},
36-
primitives::SealedBlock,
37-
};
3813
use reth_ethereum_cli::{chainspec::EthereumChainSpecParser, Cli};
39-
use reth_payload_builder::EthBuiltPayload;
40-
use serde::{Deserialize, Serialize};
4114
use tracing::info;
4215
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
4316

44-
use crate::{
45-
attributes::{EvolveEnginePayloadAttributes, EvolveEnginePayloadBuilderAttributes},
46-
builder::{EvolveArgs, EvolvePayloadBuilderBuilder},
47-
executor::EvolveExecutorBuilder,
48-
validator::EvolveEngineValidatorBuilder,
49-
};
17+
use ev_node::{log_startup, EvolveArgs, EvolveNode};
5018

5119
#[global_allocator]
5220
static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::new_allocator();
@@ -64,95 +32,6 @@ fn init_otlp_tracing() -> eyre::Result<()> {
6432
Ok(())
6533
}
6634

67-
/// Evolve engine types - uses custom payload attributes that support transactions
68-
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
69-
#[non_exhaustive]
70-
pub struct EvolveEngineTypes;
71-
72-
impl PayloadTypes for EvolveEngineTypes {
73-
type ExecutionData = ExecutionData;
74-
type BuiltPayload = EthBuiltPayload;
75-
type PayloadAttributes = EvolveEnginePayloadAttributes;
76-
type PayloadBuilderAttributes = EvolveEnginePayloadBuilderAttributes;
77-
78-
fn block_to_payload(
79-
block: SealedBlock<
80-
<<Self::BuiltPayload as reth_ethereum::node::api::BuiltPayload>::Primitives as reth_ethereum::node::api::NodePrimitives>::Block,
81-
>,
82-
) -> ExecutionData {
83-
let (payload, sidecar) =
84-
reth_ethereum::rpc::types::engine::ExecutionPayload::from_block_unchecked(
85-
block.hash(),
86-
&block.into_block(),
87-
);
88-
ExecutionData { payload, sidecar }
89-
}
90-
}
91-
92-
impl EngineTypes for EvolveEngineTypes {
93-
type ExecutionPayloadEnvelopeV1 = ExecutionPayloadV1;
94-
type ExecutionPayloadEnvelopeV2 = ExecutionPayloadEnvelopeV2;
95-
type ExecutionPayloadEnvelopeV3 = ExecutionPayloadEnvelopeV3;
96-
type ExecutionPayloadEnvelopeV4 = ExecutionPayloadEnvelopeV4;
97-
type ExecutionPayloadEnvelopeV5 = ExecutionPayloadEnvelopeV5;
98-
}
99-
100-
/// Evolve node type
101-
#[derive(Debug, Clone, Default)]
102-
#[non_exhaustive]
103-
pub struct EvolveNode {
104-
/// Evolve-specific arguments
105-
pub args: EvolveArgs,
106-
}
107-
108-
impl EvolveNode {
109-
/// Create a new evolve node with the given arguments
110-
pub const fn new(args: EvolveArgs) -> Self {
111-
Self { args }
112-
}
113-
}
114-
115-
impl NodeTypes for EvolveNode {
116-
type Primitives = reth_ethereum::EthPrimitives;
117-
type ChainSpec = ChainSpec;
118-
type Storage = reth_ethereum::provider::EthStorage;
119-
type Payload = EvolveEngineTypes;
120-
}
121-
122-
/// Evolve node addons configuring RPC types with custom engine validator
123-
pub type EvolveNodeAddOns<N> = RpcAddOns<N, EthereumEthApiBuilder, EvolveEngineValidatorBuilder>;
124-
125-
impl<N> Node<N> for EvolveNode
126-
where
127-
N: FullNodeTypes<Types = Self>,
128-
{
129-
type ComponentsBuilder = ComponentsBuilder<
130-
N,
131-
EthereumPoolBuilder,
132-
BasicPayloadServiceBuilder<EvolvePayloadBuilderBuilder>,
133-
EthereumNetworkBuilder,
134-
EvolveExecutorBuilder,
135-
EvolveConsensusBuilder,
136-
>;
137-
type AddOns = EvolveNodeAddOns<NodeAdapter<N>>;
138-
139-
fn components_builder(&self) -> Self::ComponentsBuilder {
140-
ComponentsBuilder::default()
141-
.node_types::<N>()
142-
.pool(EthereumPoolBuilder::default())
143-
.executor(EvolveExecutorBuilder::default())
144-
.payload(BasicPayloadServiceBuilder::new(
145-
EvolvePayloadBuilderBuilder::new(&self.args),
146-
))
147-
.network(EthereumNetworkBuilder::default())
148-
.consensus(EvolveConsensusBuilder::default())
149-
}
150-
151-
fn add_ons(&self) -> Self::AddOns {
152-
EvolveNodeAddOns::default()
153-
}
154-
}
155-
15635
fn main() {
15736
info!("=== EV-RETH NODE STARTING ===");
15837

@@ -173,9 +52,7 @@ fn main() {
17352

17453
if let Err(err) = Cli::<EthereumChainSpecParser, EvolveArgs>::parse().run(
17554
async move |builder, evolve_args| {
176-
info!("=== EV-RETH: Starting with args: {:?} ===", evolve_args);
177-
info!("=== EV-RETH: Evolve node mode enabled ===");
178-
info!("=== EV-RETH: Using custom payload builder with transaction support ===");
55+
log_startup(&evolve_args);
17956
let handle = builder
18057
.node(EvolveNode::new(evolve_args))
18158
.extend_rpc_modules(move |ctx| {

crates/node/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ ev-revm = { path = "../ev-revm" }
1717
# Reth dependencies
1818
reth-node-builder.workspace = true
1919
reth-chainspec.workspace = true
20+
reth-ethereum = { workspace = true, features = ["node", "cli", "pool"] }
21+
reth-ethereum-forks.workspace = true
2022
reth-ethereum-payload-builder.workspace = true
2123
reth-payload-primitives.workspace = true
2224
reth-primitives.workspace = true
@@ -60,6 +62,7 @@ serde_json.workspace = true
6062
thiserror.workspace = true
6163
async-trait.workspace = true
6264
futures.workspace = true
65+
clap.workspace = true
6366

6467
[dev-dependencies]
6568
# Test dependencies

crates/node/src/args.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use clap::Parser;
2+
use serde::{Deserialize, Serialize};
3+
4+
/// Evolve-specific command line arguments.
5+
#[derive(Debug, Clone, Parser, PartialEq, Eq, Serialize, Deserialize, Default)]
6+
pub struct EvolveArgs {
7+
/// Enable Evolve mode for the node (enabled by default).
8+
#[arg(
9+
long = "ev-reth.enable",
10+
default_value = "true",
11+
help = "Enable Evolve integration for transaction processing via Engine API"
12+
)]
13+
pub enable_evolve: bool,
14+
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ use serde::{Deserialize, Serialize};
1313

1414
use crate::error::EvolveEngineError;
1515

16-
/// Evolve payload attributes that support passing transactions via Engine API
16+
/// Evolve payload attributes that support passing transactions via Engine API.
1717
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1818
pub struct EvolveEnginePayloadAttributes {
19-
/// Standard Ethereum payload attributes
19+
/// Standard Ethereum payload attributes.
2020
#[serde(flatten)]
2121
pub inner: EthPayloadAttributes,
22-
/// Transactions to be included in the payload (passed via Engine API)
22+
/// Transactions to be included in the payload (passed via Engine API).
2323
pub transactions: Option<Vec<Bytes>>,
24-
/// Optional gas limit for the payload
24+
/// Optional gas limit for the payload.
2525
#[serde(rename = "gasLimit")]
2626
pub gas_limit: Option<u64>,
2727
}
@@ -40,14 +40,14 @@ impl PayloadAttributes for EvolveEnginePayloadAttributes {
4040
}
4141
}
4242

43-
/// Evolve payload builder attributes
43+
/// Evolve payload builder attributes.
4444
#[derive(Clone, Debug, PartialEq, Eq)]
4545
pub struct EvolveEnginePayloadBuilderAttributes {
46-
/// Ethereum payload builder attributes
46+
/// Ethereum payload builder attributes.
4747
pub ethereum_attributes: EthPayloadBuilderAttributes,
48-
/// Decoded transactions from the Engine API
48+
/// Decoded transactions from the Engine API.
4949
pub transactions: Vec<TransactionSigned>,
50-
/// Gas limit for the payload
50+
/// Gas limit for the payload.
5151
pub gas_limit: Option<u64>,
5252
}
5353

@@ -62,7 +62,7 @@ impl PayloadBuilderAttributes for EvolveEnginePayloadBuilderAttributes {
6262
) -> Result<Self, Self::Error> {
6363
let ethereum_attributes = EthPayloadBuilderAttributes::new(parent, attributes.inner);
6464

65-
// Decode transactions from bytes if provided
65+
// Decode transactions from bytes if provided.
6666
let transactions = attributes
6767
.transactions
6868
.unwrap_or_default()
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use evolve_ev_reth::PayloadAttributesError;
22
use thiserror::Error;
33

4-
/// Custom error type used in payload attributes validation
4+
/// Custom error type used in payload attributes validation.
55
#[derive(Debug, Error)]
66
pub enum EvolveEngineError {
7+
/// Provided transaction bytes failed to decode.
78
#[error("Invalid transaction data: {0}")]
89
InvalidTransactionData(String),
10+
/// Requested payload exceeded allowed gas limit.
911
#[error("Gas limit exceeded")]
1012
GasLimitExceeded,
13+
/// Underlying evolve payload attribute validation failed.
1114
#[error("Evolve payload attributes error: {0}")]
1215
PayloadAttributes(#[from] PayloadAttributesError),
1316
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Helpers to build the ev-reth executor with EV-specific hooks applied.
22
33
use alloy_evm::eth::{spec::EthExecutorSpec, EthEvmFactory};
4-
use ev_node::EvolvePayloadBuilderConfig;
54
use ev_revm::{with_ev_handler, BaseFeeRedirect, EvEvmFactory};
65
use reth_chainspec::ChainSpec;
76
use reth_ethereum::{
@@ -16,13 +15,15 @@ use reth_ethereum_forks::Hardforks;
1615
use reth_node_builder::PayloadBuilderConfig;
1716
use tracing::info;
1817

18+
use crate::{config::EvolvePayloadBuilderConfig, EvolveNode};
19+
1920
/// Type alias for the EV-aware EVM config we install into the node.
2021
pub type EvolveEvmConfig = EthEvmConfig<ChainSpec, EvEvmFactory<EthEvmFactory>>;
2122

2223
/// Builds the EV-aware EVM configuration by wrapping the default config with the EV handler.
2324
pub fn build_evm_config<Node>(ctx: &BuilderContext<Node>) -> eyre::Result<EvolveEvmConfig>
2425
where
25-
Node: FullNodeTypes<Types = crate::EvolveNode>,
26+
Node: FullNodeTypes<Types = EvolveNode>,
2627
ChainSpec: Hardforks + EthExecutorSpec + EthereumHardforks,
2728
{
2829
let chain_spec = ctx.chain_spec();
@@ -51,7 +52,7 @@ pub struct EvolveExecutorBuilder;
5152

5253
impl<Node> RethExecutorBuilder<Node> for EvolveExecutorBuilder
5354
where
54-
Node: FullNodeTypes<Types = crate::EvolveNode>,
55+
Node: FullNodeTypes<Types = EvolveNode>,
5556
ChainSpec: Hardforks + EthExecutorSpec + EthereumHardforks,
5657
{
5758
type EVM = EvolveEvmConfig;

crates/node/src/lib.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,32 @@
55
//! - Node configuration
66
//! - RPC interfaces
77
8+
/// CLI argument handling for evolve-specific options.
9+
pub mod args;
10+
/// Evolve-specific payload attribute wiring.
11+
pub mod attributes;
812
/// Builder module for payload construction and related utilities.
913
pub mod builder;
10-
/// Configuration types and validation for the Evolve payload builder
14+
/// Configuration types and validation for the Evolve payload builder.
1115
pub mod config;
16+
/// Shared error types for evolve node wiring.
17+
pub mod error;
18+
/// Executor wiring for EV aware execution.
19+
pub mod executor;
20+
/// Node composition and payload types.
21+
pub mod node;
22+
/// Payload service integration.
23+
pub mod payload_service;
24+
/// Payload validator integration.
25+
pub mod validator;
1226

13-
// Re-export public types
27+
// Re-export public types for convenience.
28+
pub use args::EvolveArgs;
29+
pub use attributes::{EvolveEnginePayloadAttributes, EvolveEnginePayloadBuilderAttributes};
1430
pub use builder::{create_payload_builder_service, EvolvePayloadBuilder};
1531
pub use config::{ConfigError, EvolvePayloadBuilderConfig};
32+
pub use error::EvolveEngineError;
33+
pub use executor::{build_evm_config, EvolveEvmConfig, EvolveExecutorBuilder};
34+
pub use node::{log_startup, parse_args, EvolveEngineTypes, EvolveNode, EvolveNodeAddOns};
35+
pub use payload_service::{EvolveEnginePayloadBuilder, EvolvePayloadBuilderBuilder};
36+
pub use validator::{EvolveEngineValidator, EvolveEngineValidatorBuilder};

0 commit comments

Comments
 (0)