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

chore: add and fix more lints, improve docs #4765

Merged
merged 14 commits into from
Sep 25, 2023
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
docs = "doc --workspace --all-features --no-deps"
30 changes: 15 additions & 15 deletions .github/workflows/book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:
run: |
mkdir mdbook
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.14/mdbook-v0.4.14-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
echo `pwd`/mdbook >> $GITHUB_PATH
echo $(pwd)/mdbook >> $GITHUB_PATH

- name: Install mdbook-template
run: |
mkdir mdbook-template
curl -sSL https://github.com/sgoudham/mdbook-template/releases/latest/download/mdbook-template-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook-template
echo `pwd`/mdbook-template >> $GITHUB_PATH
echo $(pwd)/mdbook-template >> $GITHUB_PATH

- name: Run tests
run: mdbook test
Expand All @@ -43,8 +43,8 @@ jobs:
mkdir mdbook-linkcheck
curl -sSL -o mdbook-linkcheck.zip https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/latest/download/mdbook-linkcheck.x86_64-unknown-linux-gnu.zip
unzip mdbook-linkcheck.zip -d ./mdbook-linkcheck
chmod +x `pwd`/mdbook-linkcheck/mdbook-linkcheck
echo `pwd`/mdbook-linkcheck >> $GITHUB_PATH
chmod +x $(pwd)/mdbook-linkcheck/mdbook-linkcheck
echo $(pwd)/mdbook-linkcheck >> $GITHUB_PATH

- name: Run linkcheck
run: mdbook-linkcheck --standalone
Expand All @@ -54,32 +54,32 @@ jobs:
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- uses: dtolnay/rust-toolchain@nightly

- name: Install mdbook
run: |
mkdir mdbook
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.14/mdbook-v0.4.14-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
echo `pwd`/mdbook >> $GITHUB_PATH
echo $(pwd)/mdbook >> $GITHUB_PATH

- name: Install mdbook-template
run: |
mkdir mdbook-template
curl -sSL https://github.com/sgoudham/mdbook-template/releases/latest/download/mdbook-template-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook-template
echo `pwd`/mdbook-template >> $GITHUB_PATH
echo $(pwd)/mdbook-template >> $GITHUB_PATH

- uses: Swatinem/rust-cache@v2

- name: Build book
run: mdbook build

- name: Build docs
run: RUSTDOCFLAGS="--enable-index-page -Zunstable-options" cargo +nightly doc --all --no-deps
run: cargo docs
env:
# Keep in sync with ./ci.yml:jobs.docs
RUSTDOCFLAGS:
--cfg docsrs --show-type-layout --generate-link-to-definition --enable-index-page
-Zunstable-options

- name: Move docs to book folder
run: |
Expand Down
85 changes: 37 additions & 48 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,53 @@ on:
branches: [main]

env:
RUSTFLAGS: -D warnings
CARGO_TERM_COLOR: always

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

name: ci
jobs:
lint:
name: code lint
runs-on: ubuntu-20.04
timeout-minutes: 60
clippy:
name: clippy
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt, clippy
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@clippy
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true

- name: cargo check
uses: actions-rs/cargo@v1
with:
command: check
args: --all --all-features --benches --tests

- name: cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all --check

- name: cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all --all-features --benches --tests
- run: cargo clippy --workspace --all-targets --all-features
env:
RUSTFLAGS: -D warnings

doc-lint:
name: doc lint
runs-on: ubuntu-20.04
timeout-minutes: 60
docs:
name: docs
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
- name: Check if documentation builds
run: RUSTDOCFLAGS="-D warnings" cargo doc --all --no-deps --all-features --document-private-items
- run: cargo docs --document-private-items
env:
# Keep in sync with ./book.yml:jobs.build
# This should only add `-D warnings`
RUSTDOCFLAGS:
--cfg docsrs --show-type-layout --generate-link-to-definition --enable-index-page
-Zunstable-options -D warnings

fmt:
name: fmt
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- run: cargo fmt --all --check

grafana-lint:
name: grafana lint
runs-on: ubuntu-20.04
timeout-minutes: 60
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- name: Check dashboard JSON with jq
Expand All @@ -73,9 +62,9 @@ jobs:
lint-success:
if: always()
name: lint success
runs-on: ubuntu-20.04
needs: [lint, doc-lint, grafana-lint]
timeout-minutes: 60
runs-on: ubuntu-latest
onbjerg marked this conversation as resolved.
Show resolved Hide resolved
needs: [clippy, docs, fmt, grafana-lint]
timeout-minutes: 30
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
Expand Down
1 change: 1 addition & 0 deletions bin/reth/src/cli/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl<T> RethNodeCommandExt for T where T: RethNodeCommandConfig + fmt::Debug + c
///
/// This is a convenience type for [NoArgs<()>].
#[derive(Debug, Clone, Copy, Default, Args)]
#[non_exhaustive]
pub struct DefaultRethNodeCommandConfig;

impl RethNodeCommandConfig for DefaultRethNodeCommandConfig {}
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<Ext: RethCliExt> Cli<Ext> {

let _guard = self.init_tracing()?;

let runner = CliRunner::default();
let runner = CliRunner;
match self.command {
Commands::Node(command) => runner.run_command_until_exit(|ctx| command.execute(ctx)),
Commands::Init(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Expand Down
2 changes: 0 additions & 2 deletions bin/reth/src/db/clear.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use clap::Parser;

use reth_db::{
database::Database,
table::Table,
Expand All @@ -11,7 +10,6 @@ use reth_db::{
#[derive(Parser, Debug)]
pub struct Command {
/// Table name
#[arg()]
onbjerg marked this conversation as resolved.
Show resolved Hide resolved
pub table: Tables,
}

Expand Down
1 change: 0 additions & 1 deletion bin/reth/src/db/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub struct Command {
/// The table name
///
/// NOTE: The dupsort tables are not supported now.
#[arg()]
pub table: Tables,

/// The key to get content for
Expand Down
4 changes: 2 additions & 2 deletions bin/reth/src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn logs_dir() -> Option<PathBuf> {
///
/// The data dir should contain a subdirectory for each chain, and those chain directories will
/// include all information for that chain, such as the p2p secret.
#[derive(Default, Debug, Clone)]
#[derive(Clone, Copy, Debug, Default)]
#[non_exhaustive]
pub struct DataDirPath;

Expand All @@ -73,7 +73,7 @@ impl XdgPath for DataDirPath {
/// Returns the path to the reth logs directory.
///
/// Refer to [dirs_next::cache_dir] for cross-platform behavior.
#[derive(Default, Debug, Clone)]
#[derive(Clone, Copy, Debug, Default)]
#[non_exhaustive]
pub struct LogsDir;

Expand Down
16 changes: 9 additions & 7 deletions bin/reth/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
#![warn(missing_docs, unreachable_pub, unused_crate_dependencies)]
#![deny(unused_must_use, rust_2018_idioms)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]

//! Rust Ethereum (reth) binary executable.
//!
//! ## Feature Flags
Expand All @@ -23,6 +16,15 @@
//! - `min-debug-logs`: Disables all logs below `debug` level.
//! - `min-trace-logs`: Disables all logs below `trace` level.

#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxzy/reth/issues/"
)]
#![warn(missing_docs, unreachable_pub, rustdoc::all)]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

pub mod args;
pub mod chain;
pub mod cli;
Expand Down
9 changes: 8 additions & 1 deletion bin/reth/src/node/cl_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use futures::Stream;
use reth_provider::CanonChainTracker;
use std::{
fmt,
pin::Pin,
task::{ready, Context, Poll},
time::Duration,
Expand All @@ -24,6 +25,12 @@ pub struct ConsensusLayerHealthEvents {
canon_chain: Box<dyn CanonChainTracker>,
}

impl fmt::Debug for ConsensusLayerHealthEvents {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ConsensusLayerHealthEvents").field("interval", &self.interval).finish()
}
}

impl ConsensusLayerHealthEvents {
/// Creates a new [ConsensusLayerHealthEvents] with the given canonical chain tracker.
pub fn new(canon_chain: Box<dyn CanonChainTracker>) -> Self {
Expand Down Expand Up @@ -78,7 +85,7 @@ impl Stream for ConsensusLayerHealthEvents {

/// Event that is triggered when Consensus Layer health is degraded from the
/// Execution Layer point of view.
#[derive(Debug)]
#[derive(Clone, Copy, Debug)]
pub enum ConsensusLayerHealthEvent {
/// Consensus Layer client was never seen.
NeverSeen,
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/p2p/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ pub struct Command {
command: Subcommands,
}

#[derive(Subcommand, Debug)]
/// `reth p2p` subcommands
#[derive(Subcommand, Debug)]
pub enum Subcommands {
/// Download block header
Header {
Expand Down
4 changes: 2 additions & 2 deletions bin/reth/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use reth_tasks::{TaskExecutor, TaskManager};
use std::future::Future;
use tracing::trace;

/// Used to execute cli commands
#[derive(Default, Debug)]
/// Executes CLI commands.
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct CliRunner;

Expand Down
2 changes: 1 addition & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ level = 1
build-dir = "target/book"

[preprocessor.template]
before = [ "links" ]
before = ["links"]

[preprocessor.index]

Expand Down
1 change: 1 addition & 0 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub struct BlockchainTree<DB: Database, C: Consensus, EF: ExecutorFactory> {

/// A container that wraps chains and block indices to allow searching for block hashes across all
/// sidechains.
#[derive(Debug)]
pub struct BlockHashes<'a> {
/// The current tracked chains.
pub chains: &'a mut HashMap<BlockChainId, AppendableChain>,
Expand Down
21 changes: 9 additions & 12 deletions crates/blockchain-tree/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxzy/reth/issues/"
)]
#![warn(missing_docs, unreachable_pub)]
#![deny(unused_must_use, rust_2018_idioms)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]
//! Implementation of a tree-like structure for blockchains.
//!
//! The [BlockchainTree] can validate, execute, and revert blocks in multiple competing sidechains.
Expand All @@ -22,6 +10,15 @@
//!
//! - `test-utils`: Export utilities for testing

#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxzy/reth/issues/"
)]
#![warn(missing_debug_implementations, missing_docs, unreachable_pub, rustdoc::all)]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

pub mod blockchain_tree;
pub use blockchain_tree::{BlockHashes, BlockchainTree};

Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain-tree/src/shareable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::{
use tracing::trace;

/// Shareable blockchain tree that is behind tokio::RwLock
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct ShareableBlockchainTree<DB: Database, C: Consensus, EF: ExecutorFactory> {
/// BlockchainTree
pub tree: Arc<RwLock<BlockchainTree<DB, C, EF>>>,
Expand Down
Loading
Loading