Skip to content

Commit

Permalink
feat: support custom payload attributes in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisht13 committed Feb 4, 2025
1 parent 51e9fab commit 1d6355e
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 647 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion bin/reth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() {
if let Err(err) = Cli::<EthereumChainSpecParser>::parse().run(|builder, _| async move {
info!(target: "reth::cli", "Launching node");
let handle = builder.launch_node(EthereumNode::default()).await?;
handle.node_exit_future().await
handle.node_exit_future.await
}) {
eprintln!("Error: {err:?}");
std::process::exit(1);
Expand Down
1 change: 0 additions & 1 deletion crates/engine/local/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ reth-consensus.workspace = true
reth-engine-primitives.workspace = true
reth-engine-service.workspace = true
reth-engine-tree.workspace = true
reth-node-api.workspace = true
reth-node-types.workspace = true
reth-evm.workspace = true
reth-ethereum-engine-primitives.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/local/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![allow(incomplete_features)]
#![feature(specialization)]

// pub mod engine;
pub mod miner;
pub mod payload;
pub mod service;

// pub use engine::LocalEngineNodeLauncher;
pub use miner::MiningMode;
pub use payload::LocalPayloadAttributesBuilder;
pub use service::LocalEngineService;
31 changes: 9 additions & 22 deletions crates/engine/local/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
use alloy_primitives::{Address, B256};
use reth_chainspec::EthereumHardforks;
use reth_ethereum_engine_primitives::EthPayloadAttributes;
use reth_node_api::{AddOnsContext, FullNodeComponents, NodeTypesWithEngine, PayloadTypes};
use reth_payload_primitives::PayloadAttributesBuilder;
use std::{future::Future, sync::Arc};
use std::sync::Arc;

/// The attributes builder for local Ethereum payload.
#[derive(Debug)]
Expand All @@ -20,11 +19,6 @@ impl<ChainSpec> LocalPayloadAttributesBuilder<ChainSpec> {
pub const fn new(chain_spec: Arc<ChainSpec>) -> Self {
Self { chain_spec }
}

/// Returns the chain spec.
pub fn chain_spec(&self) -> &ChainSpec {
&self.chain_spec
}
}

impl<ChainSpec> PayloadAttributesBuilder<EthPayloadAttributes>
Expand Down Expand Up @@ -66,18 +60,11 @@ where
}
}

// / A temporary workaround to support local payload engine launcher for arbitrary payload
// / attributes.
// TODO(mattsse): This should be reworked so that LocalPayloadAttributesBuilder can be implemented
// for any
// pub trait UnsupportedLocalAttributes: Send + Sync + 'static {}

// impl<T, ChainSpec> PayloadAttributesBuilder<T> for LocalPayloadAttributesBuilder<ChainSpec>
// where
// ChainSpec: Send + Sync + 'static,
// T: UnsupportedLocalAttributes,
// {
// fn build(&self, _: u64) -> T {
// panic!("Unsupported payload attributes")
// }
// }
impl<T, ChainSpec> PayloadAttributesBuilder<T> for LocalPayloadAttributesBuilder<ChainSpec>
where
ChainSpec: Send + Sync + 'static,
{
default fn build(&self, _: u64) -> T {
panic!("Unsupported payload attributes")
}
}
77 changes: 12 additions & 65 deletions crates/node/builder/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
components::NodeComponentsBuilder,
node::FullNode,
rpc::{RethRpcAddOns, RethRpcServerHandles, RpcContext},
BlockReaderFor, EngineNodeLauncher, LaunchNode, LocalEngineNodeLauncher, Node, NodeHandle,
BlockReaderFor, EngineNodeLauncher, LaunchNode, Node,
};
use alloy_eips::eip4844::env_settings::EnvKzgSettings;
use futures::Future;
Expand All @@ -21,13 +21,12 @@ use reth_network::{
NetworkHandle, NetworkManager, NetworkPrimitives,
};
use reth_node_api::{
FullNodeComponents, FullNodePrimitives, FullNodeTypes, FullNodeTypesAdapter, NodeAddOns,
NodeTypes, NodeTypesWithDBAdapter, NodeTypesWithEngine,
FullNodePrimitives, FullNodeTypes, FullNodeTypesAdapter, NodeAddOns, NodeTypes,
NodeTypesWithDBAdapter, NodeTypesWithEngine,
};
use reth_node_core::{
cli::config::{PayloadBuilderConfig, RethTransactionPoolConfig},
dirs::{ChainPath, DataDirPath},
exit::NodeExitFuture,
node_config::NodeConfig,
primitives::Head,
};
Expand Down Expand Up @@ -344,14 +343,9 @@ where
self,
node: N,
) -> eyre::Result<
LaunchedNode<
<EngineNodeLauncher as LaunchNode<
NodeBuilderWithComponents<RethFullAdapter<DB, N>, N::ComponentsBuilder, N::AddOns>,
>>::Node,
<LocalEngineNodeLauncher as LaunchNode<
NodeBuilderWithComponents<RethFullAdapter<DB, N>, N::ComponentsBuilder, N::AddOns>,
>>::Node,
>,
<EngineNodeLauncher as LaunchNode<
NodeBuilderWithComponents<RethFullAdapter<DB, N>, N::ComponentsBuilder, N::AddOns>,
>>::Node,
>
where
N: Node<RethFullAdapter<DB, N>, ChainSpec = ChainSpec> + NodeTypesForProvider,
Expand All @@ -365,9 +359,6 @@ where
EngineNodeLauncher: LaunchNode<
NodeBuilderWithComponents<RethFullAdapter<DB, N>, N::ComponentsBuilder, N::AddOns>,
>,
LocalEngineNodeLauncher: LaunchNode<
NodeBuilderWithComponents<RethFullAdapter<DB, N>, N::ComponentsBuilder, N::AddOns>,
>,
{
self.node(node).launch().await
}
Expand Down Expand Up @@ -552,53 +543,21 @@ where
}
}

pub enum LaunchedNode<T1, T2> {
Engine(T1),
Local(T2),
}

impl<T1: HasNodeExitFuture, T2: HasNodeExitFuture> LaunchedNode<T1, T2> {
pub fn node_exit_future(self) -> NodeExitFuture {
match self {
LaunchedNode::Engine(node) => node.node_exit_future(),
LaunchedNode::Local(node) => node.node_exit_future(),
}
}
}

trait HasNodeExitFuture {
// Change to return owned NodeExitFuture instead of reference
fn node_exit_future(self) -> NodeExitFuture;
}

impl<N: FullNodeComponents, AO: RethRpcAddOns<N>> HasNodeExitFuture for NodeHandle<N, AO> {
// Update implementation to return owned NodeExitFuture
fn node_exit_future(self) -> NodeExitFuture {
self.node_exit_future
}
}

impl<T, DB, CB, AO> WithLaunchContext<NodeBuilderWithComponents<RethFullAdapter<DB, T>, CB, AO>>
where
DB: Database + DatabaseMetrics + Clone + Unpin + 'static,
T: NodeTypesWithEngine + NodeTypesForProvider,
CB: NodeComponentsBuilder<RethFullAdapter<DB, T>>,
AO: RethRpcAddOns<NodeAdapter<RethFullAdapter<DB, T>, CB::Components>>,
EngineNodeLauncher: LaunchNode<NodeBuilderWithComponents<RethFullAdapter<DB, T>, CB, AO>>,
LocalEngineNodeLauncher: LaunchNode<NodeBuilderWithComponents<RethFullAdapter<DB, T>, CB, AO>>,
{
/// Launches the node with the [`EngineNodeLauncher`] that sets up engine API consensus and rpc
pub async fn launch(
self,
) -> eyre::Result<
LaunchedNode<
<EngineNodeLauncher as LaunchNode<
NodeBuilderWithComponents<RethFullAdapter<DB, T>, CB, AO>,
>>::Node,
<LocalEngineNodeLauncher as LaunchNode<
NodeBuilderWithComponents<RethFullAdapter<DB, T>, CB, AO>,
>>::Node,
>,
<EngineNodeLauncher as LaunchNode<
NodeBuilderWithComponents<RethFullAdapter<DB, T>, CB, AO>,
>>::Node,
> {
let Self { builder, task_executor } = self;

Expand All @@ -610,21 +569,9 @@ where
builder.config.engine.state_root_task_compare_updates,
);

if builder.config.dev.dev {
let launcher = LocalEngineNodeLauncher::new(
task_executor,
builder.config.datadir(),
engine_tree_config,
);
Ok(LaunchedNode::Local(builder.launch_with(launcher).await?))
} else {
let launcher = EngineNodeLauncher::new(
task_executor,
builder.config.datadir(),
engine_tree_config,
);
Ok(LaunchedNode::Engine(builder.launch_with(launcher).await?))
}
let launcher =
EngineNodeLauncher::new(task_executor, builder.config.datadir(), engine_tree_config);
builder.launch_with(launcher).await
}
}

Expand Down
Loading

0 comments on commit 1d6355e

Please sign in to comment.