Skip to content

Commit

Permalink
refactor: extract op-reth binary to separate crate (#10641)
Browse files Browse the repository at this point in the history
Co-authored-by: Loocapro <[email protected]>
Co-authored-by: joshieDo <[email protected]>
  • Loading branch information
3 people authored Sep 2, 2024
1 parent 5b97ace commit fcab695
Show file tree
Hide file tree
Showing 24 changed files with 249 additions and 260 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo hack check
- run: cargo hack check --workspace --exclude op-reth
- run: cargo check -p op-reth --features "optimism"

msrv:
name: MSRV / ${{ matrix.network }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/op-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ jobs:
with:
cache-on-failure: true
- name: Build op-reth
run: |
cargo install --features asm-keccak,jemalloc,optimism --bin op-reth --path bin/reth
run: make install-op
- name: Run sync
# https://basescan.org/block/10000
run: |
Expand Down
31 changes: 17 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ members = [
"crates/node/core/",
"crates/node/events/",
"crates/node/metrics",
"crates/optimism/bin",
"crates/optimism/chainspec",
"crates/optimism/cli",
"crates/optimism/consensus",
Expand Down Expand Up @@ -349,6 +350,7 @@ reth-node-ethereum = { path = "crates/ethereum/node" }
reth-node-events = { path = "crates/node/events" }
reth-node-metrics = { path = "crates/node/metrics" }
reth-node-optimism = { path = "crates/optimism/node" }
op-reth = { path = "crates/optimism/bin" }
reth-optimism-chainspec = { path = "crates/optimism/chainspec" }
reth-optimism-cli = { path = "crates/optimism/cli" }
reth-optimism-consensus = { path = "crates/optimism/consensus" }
Expand Down Expand Up @@ -563,3 +565,4 @@ serial_test = "3"
similar-asserts = "1.5.0"
tempfile = "3.8"
test-fuzz = "5"
tikv-jemallocator = { version = "0.5.0" }
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ install: ## Build and install the reth binary under `~/.cargo/bin`.

.PHONY: install-op
install-op: ## Build and install the op-reth binary under `~/.cargo/bin`.
cargo install --path bin/reth --bin op-reth --force --locked \
cargo install --path crates/optimism/bin --bin op-reth --force --locked \
--features "optimism,$(FEATURES)" \
--profile "$(PROFILE)" \
$(CARGO_INSTALL_EXTRA_FLAGS)
Expand All @@ -67,14 +67,14 @@ build-debug: ## Build the reth binary into `target/debug` directory.

.PHONY: build-op
build-op: ## Build the op-reth binary into `target` directory.
cargo build --bin op-reth --features "optimism,$(FEATURES)" --profile "$(PROFILE)"
cargo build --bin op-reth --features "optimism,$(FEATURES)" --profile "$(PROFILE)" --manifest-path crates/optimism/bin/Cargo.toml

# Builds the reth binary natively.
build-native-%:
cargo build --bin reth --target $* --features "$(FEATURES)" --profile "$(PROFILE)"

op-build-native-%:
cargo build --bin op-reth --target $* --features "optimism,$(FEATURES)" --profile "$(PROFILE)"
cargo build --bin op-reth --target $* --features "optimism,$(FEATURES)" --profile "$(PROFILE)" --manifest-path crates/optimism/bin/Cargo.toml

# The following commands use `cross` to build a cross-compile.
#
Expand Down Expand Up @@ -106,7 +106,7 @@ build-%:

op-build-%:
RUSTFLAGS="-C link-arg=-lgcc -Clink-arg=-static-libgcc" \
cross build --bin op-reth --target $* --features "optimism,$(FEATURES)" --profile "$(PROFILE)"
cross build --bin op-reth --target $* --features "optimism,$(FEATURES)" --profile "$(PROFILE)" --manifest-path crates/optimism/bin/Cargo.toml

# Unfortunately we can't easily use cross to build for Darwin because of licensing issues.
# If we wanted to, we would need to build a custom Docker image with the SDK available.
Expand Down Expand Up @@ -314,7 +314,7 @@ maxperf: ## Builds `reth` with the most aggressive optimisations.

.PHONY: maxperf-op
maxperf-op: ## Builds `op-reth` with the most aggressive optimisations.
RUSTFLAGS="-C target-cpu=native" cargo build --profile maxperf --features jemalloc,asm-keccak,optimism --bin op-reth
RUSTFLAGS="-C target-cpu=native" cargo build --profile maxperf --features jemalloc,asm-keccak,optimism --bin op-reth --manifest-path crates/optimism/bin/Cargo.toml

.PHONY: maxperf-no-asm
maxperf-no-asm: ## Builds `reth` with the most aggressive optimisations, minus the "asm-keccak" feature.
Expand Down
2 changes: 1 addition & 1 deletion bin/reth-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ clap = { workspace = true, features = ["derive", "env"] }
csv = "1.3.0"

[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { version = "0.5.0", optional = true }
tikv-jemallocator = { workspace = true, optional = true }
libc = "0.2"

[dev-dependencies]
Expand Down
44 changes: 2 additions & 42 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,18 @@ reth-payload-primitives.workspace = true
reth-payload-validator.workspace = true
reth-basic-payload-builder.workspace = true
reth-static-file.workspace = true
reth-static-file-types = { workspace = true, features = ["clap"] }
reth-trie = { workspace = true, features = ["metrics"] }
reth-trie-db = { workspace = true, features = ["metrics"] }
reth-node-api.workspace = true
reth-node-optimism = { workspace = true, optional = true, features = [
"optimism",
] }
reth-node-core.workspace = true
reth-ethereum-payload-builder.workspace = true
reth-db-common.workspace = true
reth-node-ethereum.workspace = true
reth-node-builder.workspace = true
reth-node-events.workspace = true
reth-node-metrics.workspace = true
reth-consensus.workspace = true
reth-optimism-primitives.workspace = true
reth-engine-util.workspace = true
reth-prune.workspace = true
reth-stages-api.workspace = true
reth-optimism-cli = { workspace = true, optional = true }
reth-optimism-rpc.workspace = true

# crypto
alloy-rlp.workspace = true
Expand All @@ -82,13 +73,7 @@ alloy-rlp.workspace = true
tracing.workspace = true

# io
fdlimit.workspace = true
serde.workspace = true
serde_json.workspace = true
toml = { workspace = true, features = ["display"] }

# metrics
metrics-process.workspace = true

# async
tokio = { workspace = true, features = [
Expand All @@ -103,20 +88,15 @@ futures.workspace = true
aquamarine.workspace = true
eyre.workspace = true
clap = { workspace = true, features = ["derive", "env"] }
tempfile.workspace = true
backon.workspace = true
similar-asserts.workspace = true
itertools.workspace = true

# p2p
discv5.workspace = true

[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { version = "0.5.0", optional = true }
libc = "0.2"
tikv-jemallocator = { workspace = true, optional = true }

[dev-dependencies]
reth-discv4.workspace = true
tempfile.workspace = true

[features]
default = ["jemalloc"]
Expand All @@ -134,26 +114,6 @@ min-info-logs = ["tracing/release_max_level_info"]
min-debug-logs = ["tracing/release_max_level_debug"]
min-trace-logs = ["tracing/release_max_level_trace"]

optimism = [
"dep:reth-node-optimism",
"dep:reth-optimism-cli",
"reth-beacon-consensus/optimism",
"reth-blockchain-tree/optimism",
"reth-node-core/optimism",
"reth-optimism-cli?/optimism",
"reth-primitives/optimism",
"reth-provider/optimism",
"reth-rpc/optimism",
]

# no-op feature flag for switching between the `optimism` and default functionality in CI matrices
ethereum = []

[[bin]]
name = "reth"
path = "src/main.rs"

[[bin]]
name = "op-reth"
path = "src/optimism.rs"
required-features = ["optimism"]
25 changes: 5 additions & 20 deletions bin/reth/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use crate::{
args::{utils::chain_help, LogArgs},
commands::debug_cmd,
macros::block_executor,
version::{LONG_VERSION, SHORT_VERSION},
};
use clap::{value_parser, Parser, Subcommand};
Expand All @@ -18,6 +17,7 @@ use reth_cli_runner::CliRunner;
use reth_db::DatabaseEnv;
use reth_node_builder::{NodeBuilder, WithLaunchContext};
use reth_node_core::args::utils::DefaultChainSpecParser;
use reth_node_ethereum::EthExecutorProvider;
use reth_tracing::FileWorkerGuard;
use std::{ffi::OsString, fmt, future::Future, sync::Arc};
use tracing::info;
Expand Down Expand Up @@ -150,20 +150,13 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>, Ext: clap::Args + fmt::Debug> Cl
}
Commands::Init(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::InitState(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Import(command) => runner.run_blocking_until_ctrl_c(
command.execute(|chain_spec| block_executor!(chain_spec)),
),
#[cfg(feature = "optimism")]
Commands::ImportOp(command) => runner.run_blocking_until_ctrl_c(command.execute()),
#[cfg(feature = "optimism")]
Commands::ImportReceiptsOp(command) => {
runner.run_blocking_until_ctrl_c(command.execute())
Commands::Import(command) => {
runner.run_blocking_until_ctrl_c(command.execute(EthExecutorProvider::ethereum))
}
Commands::DumpGenesis(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Db(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Stage(command) => runner.run_command_until_exit(|ctx| {
command.execute(ctx, |chain_spec| block_executor!(chain_spec))
}),
Commands::Stage(command) => runner
.run_command_until_exit(|ctx| command.execute(ctx, EthExecutorProvider::ethereum)),
Commands::P2P(command) => runner.run_until_ctrl_c(command.execute()),
#[cfg(feature = "dev")]
Commands::TestVectors(command) => runner.run_until_ctrl_c(command.execute()),
Expand Down Expand Up @@ -199,14 +192,6 @@ pub enum Commands<C: ChainSpecParser, Ext: clap::Args + fmt::Debug> {
/// This syncs RLP encoded blocks from a file.
#[command(name = "import")]
Import(import::ImportCommand<C>),
/// This syncs RLP encoded OP blocks below Bedrock from a file, without executing.
#[cfg(feature = "optimism")]
#[command(name = "import-op")]
ImportOp(reth_optimism_cli::ImportOpCommand<C>),
/// This imports RLP encoded receipts from a file.
#[cfg(feature = "optimism")]
#[command(name = "import-receipts-op")]
ImportReceiptsOp(reth_optimism_cli::ImportReceiptsOpCommand<C>),
/// Dumps genesis block JSON configuration to stdout.
DumpGenesis(dump_genesis::DumpGenesisCommand<C>),
/// Database debugging utilities
Expand Down
Loading

0 comments on commit fcab695

Please sign in to comment.