From f6f13e1b9598d015393ff9c35b07b81bf4bcc5fb Mon Sep 17 00:00:00 2001 From: debjit Date: Sun, 3 Nov 2024 16:50:10 +0530 Subject: [PATCH] custom cli and no-evm state import --- src/execute.rs | 24 +++++++++++++++++++++++ src/lib.rs | 2 +- src/main.rs | 52 ++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 69 insertions(+), 9 deletions(-) diff --git a/src/execute.rs b/src/execute.rs index 14b9305..576b376 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -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::{ @@ -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, + ) -> BasicBlockExecutorProvider { + 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(), + ) + } +} diff --git a/src/lib.rs b/src/lib.rs index c745148..2bf97ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/main.rs b/src/main.rs index d085d54..17668bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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))] @@ -20,12 +28,40 @@ fn main() { std::env::set_var("RUST_BACKTRACE", "1"); } - if let Err(err) = Cli::::parse().run(|builder, _| async move { - let handle = builder.node(GnosisNode::new()).launch().await?; + let cli = Cli::::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::( + |chain_spec| -> BasicBlockExecutorProvider { + 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::()); + 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); + } + } } }