Skip to content

Commit

Permalink
feat: op-reth (#4377)
Browse files Browse the repository at this point in the history
Co-authored-by: Roberto Bayardo <[email protected]>
Co-authored-by: refcell.eth <[email protected]>
Co-authored-by: Roman Krasiuk <[email protected]>
Co-authored-by: refcell <[email protected]>
Co-authored-by: nicolas <[email protected]>
  • Loading branch information
6 people authored and mattsse committed Nov 8, 2023
1 parent 4879cfc commit 7b41998
Show file tree
Hide file tree
Showing 105 changed files with 33,415 additions and 408 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ concurrency:

jobs:
test:
name: test (${{ matrix.partition }}/${{ strategy.job-total }})
name: test (${{ matrix.network }} | ${{ matrix.partition }}/${{ strategy.job-total }})
runs-on:
group: Reth
strategy:
matrix:
partition: [1, 2]
network: ["ethereum", "optimism"]
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
Expand All @@ -34,10 +35,20 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Set binary value
id: binary
run: |
if [[ "${{ matrix.network }}" == "ethereum" ]]; then
echo "binary=reth" >> $GITHUB_OUTPUT
else
echo "binary=op-reth" >> $GITHUB_OUTPUT
fi
- name: Run tests
run: |
cargo nextest run \
--locked --all-features --workspace --exclude examples --exclude ef-tests \
--locked --features "${{ matrix.network }}" \
--bin ${{ steps.binary.outputs.binary }} \
--workspace --exclude examples --exclude ef-tests \
--partition hash:${{ matrix.partition }}/${{ strategy.job-total }} \
-E 'kind(test)'
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ jobs:
name: clippy
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
include:
- binary: "reth"
network: "ethereum"
- binary: "op-reth"
network: "optimism"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@clippy
Expand All @@ -22,7 +29,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo clippy --workspace --all-targets --all-features
- run: cargo clippy --bin "${{ matrix.binary }}" --workspace --features "${{ matrix.network }}"
env:
RUSTFLAGS: -D warnings

Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ env:
jobs:
unused-dependencies:
runs-on: ubuntu-latest
strategy:
matrix:
network: ["ethereum", "optimism"]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: taiki-e/install-action@cargo-udeps
- name: Check for unused dependencies
run: cargo udeps --all-features --all-targets
run: cargo udeps --features "jemalloc,${{ matrix.network }}"
- uses: JasonEtco/create-an-issue@v2
if: ${{ failure() }}
env:
Expand Down
23 changes: 19 additions & 4 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ concurrency:

jobs:
test:
name: tests (${{ matrix.partition }}/${{ strategy.job-total }})
name: tests (${{ matrix.network }} | ${{ matrix.partition }}/${{ strategy.job-total }})
runs-on:
group: Reth
strategy:
matrix:
partition: [1, 2]
network: ["ethereum", "optimism"]
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
Expand All @@ -32,10 +33,20 @@ jobs:
with:
cache-on-failure: true
- uses: taiki-e/install-action@nextest
- name: Set binary value
id: binary
run: |
if [[ "${{ matrix.network }}" == "ethereum" ]]; then
echo "binary=reth" >> $GITHUB_OUTPUT
else
echo "binary=op-reth" >> $GITHUB_OUTPUT
fi
- name: Run tests
run: |
cargo nextest run \
--locked --all-features --workspace --exclude examples --exclude ef-tests \
--locked --features "${{ matrix.network }}" \
--bin ${{ steps.binary.outputs.binary }} \
--workspace --exclude examples --exclude ef-tests \
--partition hash:${{ matrix.partition }}/${{ strategy.job-total }} \
-E "kind(lib) | kind(bin) | kind(proc-macro)"
Expand Down Expand Up @@ -63,17 +74,21 @@ jobs:
- run: cargo nextest run --release -p ef-tests --features ef-tests

doc:
name: doc tests
name: doc tests (${{ matrix.network }})
runs-on:
group: Reth
timeout-minutes: 30
strategy:
matrix:
network: ["ethereum", "optimism"]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo test --doc --workspace --all-features
- name: Run doctests
run: cargo test --doc --workspace --features "${{ matrix.network }}"

unit-success:
name: unit success
Expand Down
5 changes: 4 additions & 1 deletion Cargo.lock

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

27 changes: 26 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,20 @@ install: ## Build and install the reth binary under `~/.cargo/bin`.
--profile "$(PROFILE)" \
$(CARGO_INSTALL_EXTRA_FLAGS)

.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 \
--features "optimism,$(FEATURES)" \
--profile "$(PROFILE)" \
$(CARGO_INSTALL_EXTRA_FLAGS)

# 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)"

# The following commands use `cross` to build a cross-compile.
#
# These commands require that:
Expand All @@ -70,6 +80,10 @@ build-%:
RUSTFLAGS="-C link-arg=-lgcc -Clink-arg=-static-libgcc" \
cross build --bin reth --target $* --features "$(FEATURES)" --profile "$(PROFILE)"

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

# 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 @@ -105,19 +119,30 @@ build-release-tarballs: ## Create a series of `.tar.gz` files in the BIN_DIR dir

##@ Test

UNIT_TEST_ARGS := --locked --workspace --all-features -E 'kind(lib)' -E 'kind(bin)' -E 'kind(proc-macro)'
UNIT_TEST_ARGS := --locked --workspace --features 'jemalloc-prof' -E 'kind(lib)' -E 'kind(bin)' -E 'kind(proc-macro)'
UNIT_TEST_ARGS_OP := --locked --workspace --features 'jemalloc-prof,optimism' -E 'kind(lib)' -E 'kind(bin)' -E 'kind(proc-macro)'
COV_FILE := lcov.info

.PHONY: test-unit
test-unit: ## Run unit tests.
cargo install cargo-nextest --locked
cargo nextest run $(UNIT_TEST_ARGS)

.PHONY: test-unit-op
test-unit-op: ## Run unit tests (with optimism feature flag enabled).
cargo install cargo-nextest --locked
cargo nextest run $(UNIT_TEST_ARGS_OP)

.PHONY: cov-unit
cov-unit: ## Run unit tests with coverage.
rm -f $(COV_FILE)
cargo llvm-cov nextest --lcov --output-path $(COV_FILE) $(UNIT_TEST_ARGS)

.PHONY: cov-unit-op
cov-unit-op: ## Run unit tests with coverage (with optimism feature flag enabled).
rm -f $(COV_FILE)
cargo llvm-cov nextest --lcov --output-path $(COV_FILE) $(UNIT_TEST_ARGS_OP)

.PHONY: cov-report-html
cov-report-html: cov-unit ## Generate a HTML coverage report and open it in the browser.
cargo llvm-cov report --html
Expand Down
24 changes: 24 additions & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,30 @@ min-warn-logs = ["tracing/release_max_level_warn"]
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 = [
"reth-primitives/optimism",
"reth-revm/optimism",
"reth-interfaces/optimism",
"reth-rpc/optimism",
"reth-rpc-engine-api/optimism",
"reth-transaction-pool/optimism",
"reth-provider/optimism",
"reth-beacon-consensus/optimism",
"reth-basic-payload-builder/optimism",
"reth-network/optimism",
"reth-network-api/optimism"
]
# no-op feature flag for switching between the `optimism` and default functionality in CI matrices
ethereum = []

[build-dependencies]
vergen = { version = "8.0.0", features = ["build", "cargo", "git", "gitcl"] }

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

[[bin]]
name = "op-reth"
path = "src/optimism.rs"
required-features = ["optimism"]
6 changes: 6 additions & 0 deletions bin/reth/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ pub use dev_args::DevArgs;
mod pruning_args;
pub use pruning_args::PruningArgs;

/// RollupArgs for configuring the op-reth rollup
#[cfg(feature = "optimism")]
mod rollup_args;
#[cfg(feature = "optimism")]
pub use rollup_args::RollupArgs;

pub mod utils;

pub mod types;
17 changes: 17 additions & 0 deletions bin/reth/src/args/payload_builder_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ pub struct PayloadBuilderArgs {
/// Maximum number of tasks to spawn for building a payload.
#[arg(long = "builder.max-tasks", help_heading = "Builder", default_value = "3", value_parser = RangedU64ValueParser::<usize>::new().range(1..))]
pub max_payload_tasks: usize,

/// By default the pending block equals the latest block
/// to save resources and not leak txs from the tx-pool,
/// this flag enables computing of the pending block
/// from the tx-pool instead.
///
/// If `compute_pending_block` is not enabled, the payload builder
/// will use the payload attributes from the latest block. Note
/// that this flag is not yet functional.
#[cfg(feature = "optimism")]
#[arg(long = "rollup.compute-pending-block")]
pub compute_pending_block: bool,
}

impl PayloadBuilderConfig for PayloadBuilderArgs {
Expand All @@ -58,6 +70,11 @@ impl PayloadBuilderConfig for PayloadBuilderArgs {
fn max_payload_tasks(&self) -> usize {
self.max_payload_tasks
}

#[cfg(feature = "optimism")]
fn compute_pending_block(&self) -> bool {
self.compute_pending_block
}
}

#[derive(Clone, Debug, Default)]
Expand Down
19 changes: 19 additions & 0 deletions bin/reth/src/args/rollup_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! clap [Args](clap::Args) for op-reth rollup configuration

/// Parameters for rollup configuration
#[derive(Debug, clap::Args)]
#[command(next_help_heading = "Rollup")]
pub struct RollupArgs {
/// HTTP endpoint for the sequencer mempool
#[arg(long = "rollup.sequencer-http", value_name = "HTTP_URL")]
pub sequencer_http: Option<String>,

/// Disable transaction pool gossip
#[arg(long = "rollup.disable-tx-pool-gossip")]
pub disable_txpool_gossip: bool,

/// Enable walkback to genesis on startup. This is useful for re-validating the existing DB
/// prior to beginning normal syncing.
#[arg(long = "rollup.enable-genesis-walkback")]
pub enable_genesis_walkback: bool,
}
20 changes: 20 additions & 0 deletions bin/reth/src/args/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use std::{
time::Duration,
};

#[cfg(feature = "optimism")]
use reth_primitives::{BASE_GOERLI, BASE_MAINNET};

/// Helper to parse a [Duration] from seconds
pub fn parse_duration_from_secs(arg: &str) -> eyre::Result<Duration, std::num::ParseIntError> {
let seconds = arg.parse()?;
Expand All @@ -27,6 +30,10 @@ pub fn chain_spec_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Er
"sepolia" => SEPOLIA.clone(),
"holesky" => HOLESKY.clone(),
"dev" => DEV.clone(),
#[cfg(feature = "optimism")]
"base-goerli" => BASE_GOERLI.clone(),
#[cfg(feature = "optimism")]
"base" => BASE_MAINNET.clone(),
_ => {
let raw = fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned()))?;
serde_json::from_str(&raw)?
Expand All @@ -46,6 +53,10 @@ pub fn genesis_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error
"sepolia" => SEPOLIA.clone(),
"holesky" => HOLESKY.clone(),
"dev" => DEV.clone(),
#[cfg(feature = "optimism")]
"base-goerli" => BASE_GOERLI.clone(),
#[cfg(feature = "optimism")]
"base" => BASE_MAINNET.clone(),
_ => {
// try to read json from path first
let mut raw =
Expand Down Expand Up @@ -156,6 +167,15 @@ mod tests {
use secp256k1::rand::thread_rng;
use std::collections::HashMap;

#[cfg(feature = "optimism")]
#[test]
fn parse_optimism_chain_spec() {
for chain in ["base-goerli", "base"] {
chain_spec_value_parser(chain).unwrap();
genesis_value_parser(chain).unwrap();
}
}

#[test]
fn parse_known_chain_spec() {
for chain in ["mainnet", "sepolia", "goerli", "holesky"] {
Expand Down
4 changes: 4 additions & 0 deletions bin/reth/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ pub trait PayloadBuilderConfig {

/// Maximum number of tasks to spawn for building a payload.
fn max_payload_tasks(&self) -> usize;

/// Returns whether or not to construct the pending block.
#[cfg(feature = "optimism")]
fn compute_pending_block(&self) -> bool;
}
Loading

0 comments on commit 7b41998

Please sign in to comment.