diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b23830912c1f..e65edb1e0932 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,7 +10,7 @@ env: CARGO_TERM_COLOR: always jobs: - clippy: + clippy-binaries: name: clippy / ${{ matrix.network }} runs-on: ubuntu-latest timeout-minutes: 30 @@ -28,7 +28,22 @@ jobs: with: cache-on-failure: true - run: - cargo clippy --bin "${{ matrix.binary }}" --workspace --features "${{ matrix.network }}" --lib --tests --benches --examples + cargo clippy --bin "${{ matrix.binary }}" --workspace --features "${{ matrix.network }} asm-keccak jemalloc jemalloc-prof min-error-logs min-warn-logs min-info-logs min-debug-logs min-trace-logs" + env: + RUSTFLAGS: -D warnings + + clippy: + name: clippy + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@clippy + - uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + - run: + cargo clippy --workspace --lib --examples --tests --benches --all-features env: RUSTFLAGS: -D warnings @@ -98,7 +113,7 @@ jobs: name: lint success runs-on: ubuntu-latest if: always() - needs: [clippy, docs, fmt, grafana] + needs: [clippy-binaries, clippy, docs, fmt, grafana] timeout-minutes: 30 steps: - name: Decide whether the needed jobs succeeded or failed diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a732d9322f09..53f5c9075bcb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -98,11 +98,7 @@ likelihood of the PR getting merged. Please also make sure that the following commands pass if you have changed the code: ```sh -cargo check --all -cargo test --all --all-features -cargo +nightly fmt -- --check -cargo clippy --bin "reth" --workspace --features "ethereum" --lib --tests --benches --examples -- -D warnings -cargo clippy --bin "op-reth" --workspace --features "optimism" --lib --tests --benches --examples -- -D warnings +make pr ``` If you are working in VSCode, we recommend you install the [rust-analyzer](https://rust-analyzer.github.io/) extension, @@ -111,14 +107,6 @@ and use the following VSCode user settings: ```json "editor.formatOnSave": true, "rust-analyzer.rustfmt.extraArgs": ["+nightly"], -"rust-analyzer.check.overrideCommand": [ -"cargo", -"+nightly", -"clippy", -"--all", -"--all-features", -"--message-format=json" -], "[rust]": { "editor.defaultFormatter": "rust-lang.rust-analyzer" } diff --git a/Makefile b/Makefile index d97fbd414b44..5961654cc65e 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,9 @@ EF_TESTS_DIR := ./testing/ef-tests/ethereum-tests # The docker image name DOCKER_IMAGE_NAME ?= ghcr.io/paradigmxyz/reth +# Features in reth/op-reth binary crate other than "ethereum" and "optimism" +BIN_OTHER_FEATURES := asm-keccak jemalloc jemalloc-prof min-error-logs min-warn-logs min-info-logs min-debug-logs min-trace-logs + ##@ Help .PHONY: help @@ -239,3 +242,44 @@ maxperf: ## Builds `reth` with the most aggressive optimisations. .PHONY: maxperf-no-asm maxperf-no-asm: ## Builds `reth` with the most aggressive optimisations, minus the "asm-keccak" feature. RUSTFLAGS="-C target-cpu=native" cargo build --profile maxperf --features jemalloc + + +fmt: + cargo +nightly fmt + +lint-reth: + cargo +nightly clippy --workspace --bin "reth" --lib --examples --tests --benches --features "ethereum $(BIN_OTHER_FEATURES)" -- -D warnings + +lint-op-reth: + cargo +nightly clippy --workspace --bin "op-reth" --lib --examples --tests --benches --features "optimism $(BIN_OTHER_FEATURES)" -- -D warnings + +lint-other-targets: + cargo +nightly clippy --workspace --lib --examples --tests --benches --all-features -- -D warnings + +lint: + make lint-reth && \ + make lint-op-reth && \ + make lint-other-targets + +docs: + RUSTDOCFLAGS="--cfg docsrs --show-type-layout --generate-link-to-definition --enable-index-page -Zunstable-options -D warnings" cargo +nightly docs --document-private-items + +test-reth: + cargo test --workspace --bin "reth" --lib --examples --tests --benches --features "ethereum $(BIN_OTHER_FEATURES)" + +test-op-reth: + cargo test --workspace --bin "op-reth" --lib --examples --tests --benches --features "optimism $(BIN_OTHER_FEATURES)" + +test-other-targets: + cargo test --workspace --lib --examples --tests --benches --all-features + +test: + make test-reth && \ + make test-op-reth && \ + make test-other-targets + +pr: + make fmt && \ + make lint && \ + make docs && \ + make test diff --git a/crates/net/eth-wire/tests/fuzz_roundtrip.rs b/crates/net/eth-wire/tests/fuzz_roundtrip.rs index cfe2b6a3610c..f829e978817c 100644 --- a/crates/net/eth-wire/tests/fuzz_roundtrip.rs +++ b/crates/net/eth-wire/tests/fuzz_roundtrip.rs @@ -37,6 +37,7 @@ where macro_rules! fuzz_type_and_name { ( $x:ty, $fuzzname:ident ) => { /// Fuzzes the round-trip encoding of the type. + #[allow(non_snake_case)] #[test_fuzz] fn $fuzzname(thing: $x) { crate::roundtrip_fuzz::<$x>(thing) @@ -130,7 +131,7 @@ pub mod fuzz_rlp { RlpEncodableWrapper, RlpDecodableWrapper, )] - struct GetBlockHeadersWrapper(pub GetBlockHeaders); + struct GetBlockHeadersWrapper(GetBlockHeaders); impl Default for GetBlockHeadersWrapper { fn default() -> Self { diff --git a/crates/transaction-pool/benches/priority.rs b/crates/transaction-pool/benches/priority.rs index 65218c4a2f24..073b58b85d3b 100644 --- a/crates/transaction-pool/benches/priority.rs +++ b/crates/transaction-pool/benches/priority.rs @@ -1,3 +1,4 @@ +#![allow(missing_docs)] use criterion::{ black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion, }; @@ -21,7 +22,7 @@ fn generate_test_data_priority() -> (u128, u128, u128, u128) { } fn priority_bench( - group: &mut BenchmarkGroup, + group: &mut BenchmarkGroup<'_, WallTime>, description: &str, input_data: (u128, u128, u128, u128), ) { @@ -40,7 +41,7 @@ fn priority_bench( } fn fee_jump_bench( - group: &mut BenchmarkGroup, + group: &mut BenchmarkGroup<'_, WallTime>, description: &str, input_data: (u128, u128), ) { @@ -53,7 +54,7 @@ fn fee_jump_bench( }); } -pub fn blob_priority_calculation(c: &mut Criterion) { +fn blob_priority_calculation(c: &mut Criterion) { let mut group = c.benchmark_group("Blob priority calculation"); let fee_jump_input = generate_test_data_fee_delta(); diff --git a/crates/transaction-pool/benches/reorder.rs b/crates/transaction-pool/benches/reorder.rs index d2fb5b0b1240..b81f0dafce03 100644 --- a/crates/transaction-pool/benches/reorder.rs +++ b/crates/transaction-pool/benches/reorder.rs @@ -1,3 +1,4 @@ +#![allow(missing_docs)] use criterion::{ criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion, }; @@ -9,12 +10,12 @@ use proptest::{ use reth_transaction_pool::test_utils::MockTransaction; /// Transaction Pool trait for benching. -pub trait BenchTxPool: Default { +trait BenchTxPool: Default { fn add_transaction(&mut self, tx: MockTransaction); fn reorder(&mut self, base_fee: u64); } -pub fn txpool_reordering(c: &mut Criterion) { +fn txpool_reordering(c: &mut Criterion) { let mut group = c.benchmark_group("Transaction Pool Reordering"); for seed_size in [1_000, 10_000, 50_000, 100_000] { @@ -54,7 +55,7 @@ pub fn txpool_reordering(c: &mut Criterion) { } fn txpool_reordering_bench( - group: &mut BenchmarkGroup, + group: &mut BenchmarkGroup<'_, WallTime>, description: &str, seed: Vec, new_txs: Vec, @@ -170,7 +171,7 @@ mod implementations { impl PartialEq for MockTransactionWithPriority { fn eq(&self, other: &Self) -> bool { - self.priority.eq(&other.priority) + self.priority == other.priority } } diff --git a/crates/transaction-pool/benches/truncate.rs b/crates/transaction-pool/benches/truncate.rs index ca25d731d699..8a34c18fbf56 100644 --- a/crates/transaction-pool/benches/truncate.rs +++ b/crates/transaction-pool/benches/truncate.rs @@ -1,3 +1,4 @@ +#![allow(missing_docs)] use criterion::{ criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion, }; @@ -124,7 +125,7 @@ fn txpool_truncate(c: &mut Criterion) { } fn truncate_pending( - group: &mut BenchmarkGroup, + group: &mut BenchmarkGroup<'_, WallTime>, description: &str, seed: Vec, senders: usize, @@ -159,7 +160,7 @@ fn truncate_pending( } fn truncate_parked( - group: &mut BenchmarkGroup, + group: &mut BenchmarkGroup<'_, WallTime>, description: &str, seed: Vec, senders: usize,