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

feat: integrate builder #6611

Merged
merged 45 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a789a5a
Add crate
mattsse Feb 14, 2024
a52ba54
add noargs
mattsse Feb 14, 2024
85197e8
chore: add launch function
mattsse Feb 14, 2024
5f9e70a
chore: work on lauch
mattsse Feb 14, 2024
acd5aa0
chore: add run ethereum
mattsse Feb 14, 2024
0665d74
Merge branch 'main' into matt/integrate-node-builder
mattsse Feb 15, 2024
c695ae1
make it compile
mattsse Feb 15, 2024
1777089
migrate main
mattsse Feb 15, 2024
3fafb61
enable evm config
mattsse Feb 15, 2024
99195c1
migrate binaries
mattsse Feb 15, 2024
abecb65
remove rollup args
mattsse Feb 15, 2024
f405944
fix compile error
mattsse Feb 15, 2024
f6e0c6b
port engine interceptor
mattsse Feb 15, 2024
743691d
chore: use futures block on
mattsse Feb 15, 2024
7a2c392
asyincify component traits
mattsse Feb 15, 2024
dc8ee5e
impl for async closures
mattsse Feb 15, 2024
f291d85
migrate example
mattsse Feb 15, 2024
f5f14e1
migrate more examples
mattsse Feb 15, 2024
5dd8a6c
migrate more
mattsse Feb 15, 2024
d083d73
chore: migrate more
mattsse Feb 15, 2024
1e8d16c
chore: migrate example
mattsse Feb 15, 2024
295337e
fix clippy
mattsse Feb 15, 2024
7b51d98
cleanup
mattsse Feb 15, 2024
a6ebf52
more example
mattsse Feb 15, 2024
f8bd1fc
fixes
mattsse Feb 15, 2024
00db04b
clippy
mattsse Feb 15, 2024
7666cdb
fix: use separate receipt root functions
mattsse Feb 15, 2024
74fbb1b
add node trait
mattsse Feb 16, 2024
16e5a51
add node trait
mattsse Feb 16, 2024
aced888
chore: docs
mattsse Feb 16, 2024
e499012
more docs
mattsse Feb 16, 2024
9d0aaa1
update node example
mattsse Feb 16, 2024
f1a26b1
Merge branch 'main' into matt/integrate-node-builder
mattsse Feb 16, 2024
5854d83
rename
mattsse Feb 16, 2024
162fc6d
fix missing fn
mattsse Feb 16, 2024
97feba2
Merge branch 'main' into matt/integrate-node-builder
mattsse Feb 20, 2024
6254ddb
cleanup
mattsse Feb 20, 2024
cd494ba
fixes
mattsse Feb 20, 2024
e952573
Merge branch 'main' into matt/integrate-node-builder
mattsse Feb 27, 2024
136622e
add evm example
mattsse Feb 27, 2024
c8e915e
feat: add custom precompile example
mattsse Feb 27, 2024
cbc3a3e
Merge branch 'main' into matt/integrate-node-builder
mattsse Feb 29, 2024
f85b24e
resolve conflicts
mattsse Feb 29, 2024
56d74ed
migrate example
mattsse Feb 29, 2024
34b3ea8
Merge branch 'main' into matt/integrate-node-builder
mattsse Feb 29, 2024
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
3 changes: 3 additions & 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 @@ -59,6 +59,7 @@ reth-node-optimism = { workspace = true, optional = true, features = [
"optimism",
] }
reth-node-core.workspace = true
reth-node-builder.workspace = true

# crypto
alloy-rlp.workspace = true
Expand Down
81 changes: 33 additions & 48 deletions bin/reth/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ use crate::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
LogArgs,
},
cli::ext::RethCliExt,
commands::{
config_cmd, db, debug_cmd, import, init_cmd, node, p2p, recover, stage, test_vectors,
config_cmd, db, debug_cmd, import, init_cmd, node, node::NoArgs, p2p, recover, stage,
test_vectors,
},
runner::CliRunner,
version::{LONG_VERSION, SHORT_VERSION},
};
use clap::{value_parser, Parser, Subcommand};
use reth_db::DatabaseEnv;
use reth_node_builder::{InitState, WithLaunchContext};
use reth_primitives::ChainSpec;
use reth_tracing::FileWorkerGuard;
use std::sync::Arc;
use std::{fmt, future::Future, sync::Arc};

/// Re-export of the `reth_node_core` types specifically in the `cli` module.
///
Expand All @@ -29,7 +31,7 @@ pub use crate::core::cli::*;
/// This is the entrypoint to the executable.
#[derive(Debug, Parser)]
#[command(author, version = SHORT_VERSION, long_version = LONG_VERSION, about = "Reth", long_about = None)]
pub struct Cli<Ext: RethCliExt = ()> {
pub struct Cli<Ext: clap::Args + fmt::Debug = NoArgs> {
/// The command to run
#[clap(subcommand)]
command: Commands<Ext>,
Expand Down Expand Up @@ -67,9 +69,16 @@ pub struct Cli<Ext: RethCliExt = ()> {
logs: LogArgs,
}

impl<Ext: RethCliExt> Cli<Ext> {
impl<Ext: clap::Args + fmt::Debug> Cli<Ext> {
/// Execute the configured cli command.
pub fn run(mut self) -> eyre::Result<()> {
///
/// This accepts a closure that is used to launch the node via the
/// [NodeCommand](node::NodeCommand).
pub fn run<L, Fut>(mut self, launcher: L) -> eyre::Result<()>
where
L: FnOnce(WithLaunchContext<Arc<DatabaseEnv>, InitState>, Ext) -> Fut,
Fut: Future<Output = eyre::Result<()>>,
{
// add network name to logs dir
self.logs.log_file_directory =
self.logs.log_file_directory.join(self.chain.chain.to_string());
Expand All @@ -78,7 +87,9 @@ impl<Ext: RethCliExt> Cli<Ext> {

let runner = CliRunner;
match self.command {
Commands::Node(command) => runner.run_command_until_exit(|ctx| command.execute(ctx)),
Commands::Node(command) => {
runner.run_command_until_exit(|ctx| command.execute2(ctx, launcher))
}
Commands::Init(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Import(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Db(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Expand All @@ -99,26 +110,11 @@ impl<Ext: RethCliExt> Cli<Ext> {
let guard = self.logs.init_tracing()?;
Ok(guard)
}

/// Configures the given node extension.
pub fn with_node_extension<C>(mut self, conf: C) -> Self
where
C: Into<Ext::Node>,
{
self.command.set_node_extension(conf.into());
self
}
}

/// Convenience function for parsing CLI options, set up logging and run the chosen command.
#[inline]
pub fn run() -> eyre::Result<()> {
Cli::<()>::parse().run()
}

/// Commands to be executed
#[derive(Debug, Subcommand)]
pub enum Commands<Ext: RethCliExt = ()> {
pub enum Commands<Ext: clap::Args + fmt::Debug = NoArgs> {
/// Start the node
#[command(name = "node")]
Node(node::NodeCommand<Ext>),
Expand Down Expand Up @@ -151,28 +147,15 @@ pub enum Commands<Ext: RethCliExt = ()> {
Recover(recover::Command),
}

impl<Ext: RethCliExt> Commands<Ext> {
/// Sets the node extension if it is the [NodeCommand](node::NodeCommand).
///
/// This is a noop if the command is not the [NodeCommand](node::NodeCommand).
pub fn set_node_extension(&mut self, ext: Ext::Node) {
if let Commands::Node(command) = self {
command.ext = ext
}
}
}

#[cfg(test)]
mod tests {
use clap::CommandFactory;

use crate::args::{utils::SUPPORTED_CHAINS, ColorMode};

use super::*;
use crate::args::{utils::SUPPORTED_CHAINS, ColorMode};
use clap::CommandFactory;

#[test]
fn parse_color_mode() {
let reth = Cli::<()>::try_parse_from(["reth", "node", "--color", "always"]).unwrap();
let reth = Cli::<NoArgs>::try_parse_from(["reth", "node", "--color", "always"]).unwrap();
assert_eq!(reth.logs.color, ColorMode::Always);
}

Expand All @@ -181,9 +164,9 @@ mod tests {
/// runtime
#[test]
fn test_parse_help_all_subcommands() {
let reth = Cli::<()>::command();
let reth = Cli::<NoArgs>::command();
for sub_command in reth.get_subcommands() {
let err = Cli::<()>::try_parse_from(["reth", sub_command.get_name(), "--help"])
let err = Cli::<NoArgs>::try_parse_from(["reth", sub_command.get_name(), "--help"])
.err()
.unwrap_or_else(|| {
panic!("Failed to parse help message {}", sub_command.get_name())
Expand All @@ -199,7 +182,7 @@ mod tests {
/// name
#[test]
fn parse_logs_path() {
let mut reth = Cli::<()>::try_parse_from(["reth", "node"]).unwrap();
let mut reth = Cli::<NoArgs>::try_parse_from(["reth", "node"]).unwrap();
reth.logs.log_file_directory =
reth.logs.log_file_directory.join(reth.chain.chain.to_string());
let log_dir = reth.logs.log_file_directory;
Expand All @@ -209,7 +192,8 @@ mod tests {
let mut iter = SUPPORTED_CHAINS.iter();
iter.next();
for chain in iter {
let mut reth = Cli::<()>::try_parse_from(["reth", "node", "--chain", chain]).unwrap();
let mut reth =
Cli::<NoArgs>::try_parse_from(["reth", "node", "--chain", chain]).unwrap();
reth.logs.log_file_directory =
reth.logs.log_file_directory.join(reth.chain.chain.to_string());
let log_dir = reth.logs.log_file_directory;
Expand All @@ -222,17 +206,18 @@ mod tests {
fn override_trusted_setup_file() {
// We already have a test that asserts that this has been initialized,
// so we cheat a little bit and check that loading a random file errors.
let reth = Cli::<()>::try_parse_from(["reth", "node", "--trusted-setup-file", "README.md"])
.unwrap();
assert!(reth.run().is_err());
let reth =
Cli::<NoArgs>::try_parse_from(["reth", "node", "--trusted-setup-file", "README.md"])
.unwrap();
// assert!(reth.run().is_err());
mattsse marked this conversation as resolved.
Show resolved Hide resolved
}

#[test]
fn parse_env_filter_directives() {
let temp_dir = tempfile::tempdir().unwrap();

std::env::set_var("RUST_LOG", "info,evm=debug");
let reth = Cli::<()>::try_parse_from([
let reth = Cli::<NoArgs>::try_parse_from([
"reth",
"init",
"--datadir",
Expand All @@ -241,6 +226,6 @@ mod tests {
"debug,net=trace",
])
.unwrap();
assert!(reth.run().is_ok());
// assert!(reth.run().is_ok());
}
}
5 changes: 1 addition & 4 deletions bin/reth/src/commands/debug_cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
//! `reth debug` command. Collection of various debugging routines.

use clap::{Parser, Subcommand};

use crate::runner::CliContext;

use clap::{Parser, Subcommand};
mod build_block;
pub mod engine_api_store;
mod execution;
mod in_memory_merkle;
mod merkle;
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/replay_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs, NetworkArgs,
},
commands::debug_cmd::engine_api_store::{EngineApiStore, StoredEngineApiMessage},
dirs::{DataDirPath, MaybePlatformPath},
runner::CliContext,
};
Expand All @@ -20,6 +19,7 @@ use reth_db::{init_db, mdbx::DatabaseArguments, DatabaseEnv};
use reth_interfaces::consensus::Consensus;
use reth_network::NetworkHandle;
use reth_network_api::NetworkInfo;
use reth_node_core::engine_api_store::{EngineApiStore, StoredEngineApiMessage};
#[cfg(not(feature = "optimism"))]
use reth_node_ethereum::{EthEngineTypes, EthEvmConfig};
#[cfg(feature = "optimism")]
Expand Down
Loading
Loading