Skip to content

Commit

Permalink
custom cli and no-evm state import
Browse files Browse the repository at this point in the history
  • Loading branch information
debjit-bw committed Nov 3, 2024
1 parent a4374e6 commit f6f13e1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 9 deletions.
24 changes: 24 additions & 0 deletions src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use reth_evm::{
ConfigureEvm,
};
use reth_evm_ethereum::eip6110::parse_deposits_from_receipts;
use reth_node_ethereum::BasicBlockExecutorProvider;
use reth_primitives::{BlockWithSenders, Header, Receipt};
use revm::State;
use revm_primitives::{
Expand Down Expand Up @@ -277,3 +278,26 @@ where
&mut self.state
}
}

/// Helper type with backwards compatible methods to obtain executor providers.
#[derive(Debug, Clone)]
pub struct GnosisExecutorProvider;

impl GnosisExecutorProvider {
/// Creates a new default gnosis executor strategy factory.
pub fn gnosis(
chain_spec: Arc<ChainSpec>,
) -> BasicBlockExecutorProvider<GnosisExecutionStrategyFactory> {
let collector_address = chain_spec
.genesis()
.config
.extra_fields
.get("eip1559collector")
.unwrap();
let collector_address: Address = serde_json::from_value(collector_address.clone()).unwrap();
let evm_config = GnosisEvmConfig::new(collector_address, chain_spec.clone());
BasicBlockExecutorProvider::new(
GnosisExecutionStrategyFactory::new(chain_spec, evm_config).unwrap(),
)
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::sync::Arc;
mod consensus;
mod errors;
mod evm_config;
mod execute;
pub mod execute;
mod gnosis;
mod payload_builder;

Expand Down
52 changes: 44 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
use clap::{Args, Parser};
use reth::{chainspec::EthereumChainSpecParser, cli::Cli};
use reth_gnosis::GnosisNode;
use reth::{
chainspec::EthereumChainSpecParser,
cli::{Cli, Commands},
CliRunner,
};
use reth_gnosis::{
execute::{GnosisExecutionStrategyFactory, GnosisExecutorProvider},
GnosisNode,
};
use reth_node_ethereum::BasicBlockExecutorProvider;

// We use jemalloc for performance reasons
#[cfg(all(feature = "jemalloc", unix))]
Expand All @@ -20,12 +28,40 @@ fn main() {
std::env::set_var("RUST_BACKTRACE", "1");
}

if let Err(err) = Cli::<EthereumChainSpecParser, NoArgs>::parse().run(|builder, _| async move {
let handle = builder.node(GnosisNode::new()).launch().await?;
let cli = Cli::<EthereumChainSpecParser, NoArgs>::parse();
let _ = cli.init_tracing().unwrap();

handle.node_exit_future.await
}) {
eprintln!("Error: {err:?}");
std::process::exit(1);
match cli.command {
Commands::Import(command) => {
dbg!("Importing with custom cli");
let runner = CliRunner::default();
let res = runner.run_blocking_until_ctrl_c(command.execute::<GnosisNode, _, _>(
|chain_spec| -> BasicBlockExecutorProvider<GnosisExecutionStrategyFactory> {
GnosisExecutorProvider::gnosis(chain_spec)
},
));
if let Err(err) = res {
eprintln!("Error: {err:?}");
std::process::exit(1);
}
}
Commands::InitState(command) => {
let runner = CliRunner::default();
let res = runner.run_blocking_until_ctrl_c(command.execute::<GnosisNode>());
if let Err(err) = res {
eprintln!("Error: {err:?}");
std::process::exit(1);
}
}
_ => {
if let Err(err) = cli.run(|builder, _| async move {
let handle = builder.node(GnosisNode::new()).launch().await?;

handle.node_exit_future.await
}) {
eprintln!("Error: {err:?}");
std::process::exit(1);
}
}
}
}

0 comments on commit f6f13e1

Please sign in to comment.