Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI with Gnosis arguments (block import and state init) #27

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why pub?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to import the GnosisExecutorProvider in main.rs

mod gnosis;
mod payload_builder;

Expand Down
53 changes: 45 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
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;
use tracing::{error, info};

// We use jemalloc for performance reasons
#[cfg(all(feature = "jemalloc", unix))]
Expand All @@ -20,12 +29,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) => {
info!(target: "reth::cli", "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 {
error!(target: "reth::cli", "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 {
error!(target: "reth::cli", "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
}) {
error!(target: "reth::cli", "Error: {err:?}");
std::process::exit(1);
}
}
}
}
Loading