Skip to content

Commit

Permalink
Use auto seal consensus for node in --dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianBland committed Jun 5, 2024
1 parent fc8c5ba commit 7ddfc8c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
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.

1 change: 1 addition & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ reth-revm.workspace = true
reth-stages.workspace = true
reth-errors.workspace = true
reth-transaction-pool.workspace = true
reth-auto-seal-consensus.workspace = true
reth-beacon-consensus.workspace = true
reth-cli-runner.workspace = true
reth-consensus-common.workspace = true
Expand Down
39 changes: 36 additions & 3 deletions bin/reth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,36 @@
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

#[cfg(all(feature = "optimism", not(test)))]
compile_error!("Cannot build the `reth` binary with the `optimism` feature flag enabled. Did you mean to build `op-reth`?");
compile_error!(
"Cannot build the `reth` binary with the `optimism` feature flag enabled. Did you
mean to build `op-reth`?"
);

#[cfg(not(feature = "optimism"))]
fn main() {
use reth::cli::Cli;
use reth_node_ethereum::EthereumNode;

use reth_auto_seal_consensus::AutoSealConsensus;
use reth_node_builder::{components::ConsensusBuilder, node::FullNodeTypes, BuilderContext};

#[derive(Debug, Clone, Copy)]
struct DevConsensusBuilder;

impl<Node> ConsensusBuilder<Node> for DevConsensusBuilder
where
Node: FullNodeTypes,
{
type Consensus = AutoSealConsensus;

async fn build_consensus(
self,
ctx: &BuilderContext<Node>,
) -> eyre::Result<Self::Consensus> {
Ok(AutoSealConsensus::new(ctx.chain_spec()))
}
}

reth::sigsegv_handler::install();

// Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.
Expand All @@ -21,8 +44,18 @@ fn main() {
}

if let Err(err) = Cli::parse_args().run(|builder, _| async {
let handle = builder.launch_node(EthereumNode::default()).await?;
handle.node_exit_future.await
let is_dev_mode = builder.config().dev.dev;
if is_dev_mode {
let handle = builder
.with_types::<EthereumNode>()
.with_components(EthereumNode::components().consensus(DevConsensusBuilder))
.launch()
.await?;
handle.node_exit_future.await
} else {
let handle = builder.launch_node(EthereumNode::default()).await?;
handle.node_exit_future.await
}
}) {
eprintln!("Error: {err:?}");
std::process::exit(1);
Expand Down

0 comments on commit 7ddfc8c

Please sign in to comment.