From 8c469e19af2ac6fd8550f604f573b473e706bb76 Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Sun, 24 Dec 2023 14:57:22 +0800 Subject: [PATCH 01/11] feat: add rustfmt imports_granularity --- .circleci/config.yml | 63 +++++++++--------- ethportal-api/src/beacon.rs | 18 ++--- ethportal-api/src/discv5.rs | 6 +- ethportal-api/src/history.rs | 18 ++--- ethportal-api/src/lib.rs | 22 +++---- ethportal-api/src/types/cli.rs | 7 +- .../src/types/consensus/execution_payload.rs | 7 +- ethportal-api/src/types/consensus/fork.rs | 8 ++- .../types/consensus/light_client/bootstrap.rs | 11 ++-- .../consensus/light_client/finality_update.rs | 12 ++-- .../types/consensus/light_client/header.rs | 9 ++- .../light_client/optimistic_update.rs | 8 +-- .../types/consensus/light_client/update.rs | 16 +++-- .../src/types/consensus/sync_committee.rs | 3 +- ethportal-api/src/types/content_key/beacon.rs | 7 +- .../src/types/content_key/history.rs | 7 +- .../src/types/content_key/overlay.rs | 6 +- ethportal-api/src/types/content_key/state.rs | 3 +- .../src/types/content_value/beacon.rs | 52 ++++++++------- .../src/types/content_value/history.rs | 13 ++-- ethportal-api/src/types/distance.rs | 3 +- ethportal-api/src/types/enr.rs | 17 +++-- ethportal-api/src/types/execution/header.rs | 6 +- ethportal-api/src/types/execution/receipts.rs | 6 +- ethportal-api/src/types/jsonrpc/endpoints.rs | 6 +- ethportal-api/src/types/jsonrpc/request.rs | 6 +- ethportal-api/src/types/portal.rs | 4 +- ethportal-api/src/types/portal_wire.rs | 14 ++-- ethportal-api/src/types/query_trace.rs | 9 +-- .../src/utils/serde/hex_fixed_vec.rs | 3 +- ethportal-api/src/utils/serde/hex_var_list.rs | 3 +- ethportal-peertest/src/lib.rs | 20 ++++-- ethportal-peertest/src/scenarios/basic.rs | 8 +-- ethportal-peertest/src/scenarios/bridge.rs | 27 ++++---- ethportal-peertest/src/scenarios/find.rs | 11 ++-- ethportal-peertest/src/scenarios/paginate.rs | 3 +- ethportal-peertest/src/scenarios/utp.rs | 6 +- .../src/scenarios/validation.rs | 8 +-- light-client/src/client.rs | 15 ++--- light-client/src/config/base.rs | 3 +- light-client/src/config/checkpoints.rs | 3 +- light-client/src/config/client_config.rs | 7 +- light-client/src/config/networks.rs | 3 +- .../src/consensus/consensus_client.rs | 65 +++++++++---------- light-client/src/consensus/rpc/nimbus_rpc.rs | 14 ++-- light-client/src/consensus/rpc/portal_rpc.rs | 22 ++++--- light-client/src/consensus/types.rs | 22 ++++--- light-client/src/consensus/utils.rs | 6 +- light-client/src/main.rs | 8 +-- light-client/src/node.rs | 10 +-- light-client/tests/sync.rs | 8 +-- portal-bridge/src/api/execution.rs | 15 +++-- portal-bridge/src/bridge/beacon.rs | 54 ++++++++------- portal-bridge/src/bridge/history.rs | 46 +++++++------ portal-bridge/src/cli.rs | 10 +-- portal-bridge/src/gossip.rs | 4 +- portal-bridge/src/main.rs | 23 ++++--- portal-bridge/src/pandaops.rs | 6 +- portal-bridge/src/stats.rs | 12 ++-- portal-bridge/src/types/full_header.rs | 12 ++-- portal-bridge/src/types/mode.rs | 3 +- portal-bridge/src/types/network.rs | 3 +- portal-bridge/src/utils.rs | 21 +++--- portalnet/src/config.rs | 4 +- portalnet/src/discovery.rs | 27 ++++---- portalnet/src/events.rs | 12 ++-- portalnet/src/find/iterators/findcontent.rs | 12 ++-- portalnet/src/find/iterators/findnodes.rs | 6 +- portalnet/src/find/query_info.rs | 10 ++- portalnet/src/gossip.rs | 21 +++--- portalnet/src/overlay.rs | 28 ++++---- portalnet/src/overlay_service.rs | 28 ++++---- portalnet/src/storage.rs | 15 +++-- portalnet/src/types/node.rs | 3 +- portalnet/src/utils/db.rs | 6 +- portalnet/tests/overlay.rs | 23 ++++--- rpc/src/beacon_rpc.rs | 27 ++++---- rpc/src/builder.rs | 20 +++--- rpc/src/discv5_rpc.rs | 4 +- rpc/src/errors.rs | 12 ++-- rpc/src/eth_rpc.rs | 15 +++-- rpc/src/fetch.rs | 16 +++-- rpc/src/history_rpc.rs | 27 ++++---- rpc/src/lib.rs | 18 ++--- rpc/src/rpc_server.rs | 38 ++++++----- rustfmt.toml | 1 + src/bin/purge_db.rs | 24 ++++--- src/lib.rs | 3 +- tests/rpc_server.rs | 13 ++-- tests/self_peertest.rs | 9 +-- trin-beacon/src/jsonrpc.rs | 22 ++++--- trin-beacon/src/lib.rs | 6 +- trin-beacon/src/network.rs | 11 ++-- trin-beacon/src/sync.rs | 8 +-- trin-history/src/jsonrpc.rs | 18 ++--- trin-history/src/lib.rs | 3 +- trin-history/src/network.rs | 8 +-- trin-history/src/utils.rs | 7 +- trin-history/src/validation.rs | 27 ++++---- trin-metrics/src/portalnet.rs | 3 +- trin-state/src/lib.rs | 3 +- trin-state/src/network.rs | 8 +-- trin-utils/build.rs | 3 +- trin-validation/src/accumulator.rs | 26 ++++---- trin-validation/src/oracle.rs | 12 ++-- utp-testing/src/bin/test_app.rs | 3 +- utp-testing/src/bin/test_suite.rs | 4 +- utp-testing/src/lib.rs | 31 ++++----- 108 files changed, 802 insertions(+), 674 deletions(-) create mode 100644 rustfmt.toml diff --git a/.circleci/config.yml b/.circleci/config.yml index d449e6ab7..deea3bedb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,6 +49,9 @@ executors: IMAGE_NAME: portalnetwork/trin docker: - image: cimg/rust:1.71.1 + docker-nightly: + docker: + - image: rustlang/rust:nightly-slim jobs: docker-build: resource_class: xlarge @@ -119,29 +122,27 @@ jobs: echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin docker push $IMAGE_NAME:latest-bridge lint: - description: | - Check linting with Clippy and rustfmt. - resource_class: xlarge - executor: - name: rust/default - tag: 1.71.1 - environment: - RUSTFLAGS: '-D warnings' - RUST_LOG: 'debug' - steps: - - checkout - - install-depends - - run: - name: Run rustfmt - command: cargo fmt --all -- --check - - run: - name: Install Clippy - command: rustup component add clippy - - setup-and-restore-sccache-cache - - run: - name: Run Clippy - command: cargo clippy --all --all-targets --all-features --no-deps -- --deny warnings - - save-sccache-cache + description: | + Check linting with Clippy and rustfmt. + resource_class: xlarge + executor: docker-nightly + environment: + RUSTFLAGS: "-D warnings" + RUST_LOG: "debug" + steps: + - checkout + - install-depends + - run: + name: Run rustfmt + command: cargo +nightly fmt --all -- --check + - run: + name: Install Clippy + command: rustup component add clippy + - setup-and-restore-sccache-cache + - run: + name: Run Clippy + command: cargo clippy --all --all-targets --all-features --no-deps -- --deny warnings + - save-sccache-cache build: description: | Build the crate. @@ -150,8 +151,8 @@ jobs: name: rust/default tag: 1.71.1 environment: - RUSTFLAGS: '-D warnings' - RUST_LOG: 'debug' + RUSTFLAGS: "-D warnings" + RUST_LOG: "debug" steps: - checkout - install-depends @@ -167,8 +168,8 @@ jobs: name: win/default size: xlarge environment: - RUSTFLAGS: '-D warnings' - RUST_LOG: 'debug' + RUSTFLAGS: "-D warnings" + RUST_LOG: "debug" steps: - checkout - run: @@ -187,8 +188,8 @@ jobs: name: rust/default tag: 1.71.1 environment: - RUSTFLAGS: '-D warnings' - RUST_LOG: 'debug' + RUSTFLAGS: "-D warnings" + RUST_LOG: "debug" steps: - checkout - install-depends @@ -204,8 +205,8 @@ jobs: image: ubuntu-2204:current resource_class: xlarge environment: - RUSTFLAGS: '-D warnings' - RUST_LOG: 'debug' + RUSTFLAGS: "-D warnings" + RUST_LOG: "debug" steps: - checkout - run: diff --git a/ethportal-api/src/beacon.rs b/ethportal-api/src/beacon.rs index 93c487949..edfc8cb4d 100644 --- a/ethportal-api/src/beacon.rs +++ b/ethportal-api/src/beacon.rs @@ -1,12 +1,14 @@ -use crate::types::content_key::beacon::BeaconContentKey; -use crate::types::enr::Enr; -use crate::types::portal::FindNodesInfo; -use crate::types::portal::{ - AcceptInfo, ContentInfo, DataRadius, PaginateLocalContentInfo, PongInfo, TraceContentInfo, - TraceGossipInfo, +use crate::{ + types::{ + content_key::beacon::BeaconContentKey, + enr::Enr, + portal::{ + AcceptInfo, ContentInfo, DataRadius, FindNodesInfo, PaginateLocalContentInfo, PongInfo, + TraceContentInfo, TraceGossipInfo, + }, + }, + BeaconContentValue, PossibleBeaconContentValue, RoutingTableInfo, }; -use crate::RoutingTableInfo; -use crate::{BeaconContentValue, PossibleBeaconContentValue}; use discv5::enr::NodeId; use jsonrpsee::{core::RpcResult, proc_macros::rpc}; diff --git a/ethportal-api/src/discv5.rs b/ethportal-api/src/discv5.rs index 0ed164c34..84e1b9efc 100644 --- a/ethportal-api/src/discv5.rs +++ b/ethportal-api/src/discv5.rs @@ -1,5 +1,7 @@ -use crate::types::discv5::{NodeInfo, RoutingTableInfo}; -use crate::types::enr::Enr; +use crate::types::{ + discv5::{NodeInfo, RoutingTableInfo}, + enr::Enr, +}; use discv5::enr::NodeId; use jsonrpsee::{core::RpcResult, proc_macros::rpc}; diff --git a/ethportal-api/src/history.rs b/ethportal-api/src/history.rs index 0365ee5ee..c0cbbac3a 100644 --- a/ethportal-api/src/history.rs +++ b/ethportal-api/src/history.rs @@ -1,12 +1,14 @@ -use crate::types::content_key::history::HistoryContentKey; -use crate::types::enr::Enr; -use crate::types::portal::FindNodesInfo; -use crate::types::portal::{ - AcceptInfo, ContentInfo, DataRadius, PaginateLocalContentInfo, PongInfo, TraceContentInfo, - TraceGossipInfo, +use crate::{ + types::{ + content_key::history::HistoryContentKey, + enr::Enr, + portal::{ + AcceptInfo, ContentInfo, DataRadius, FindNodesInfo, PaginateLocalContentInfo, PongInfo, + TraceContentInfo, TraceGossipInfo, + }, + }, + HistoryContentValue, PossibleHistoryContentValue, RoutingTableInfo, }; -use crate::RoutingTableInfo; -use crate::{HistoryContentValue, PossibleHistoryContentValue}; use discv5::enr::NodeId; use jsonrpsee::{core::RpcResult, proc_macros::rpc}; diff --git a/ethportal-api/src/lib.rs b/ethportal-api/src/lib.rs index c2b9e74ac..c589dff18 100644 --- a/ethportal-api/src/lib.rs +++ b/ethportal-api/src/lib.rs @@ -33,21 +33,19 @@ pub use types::content_key::{ state::StateContentKey, }; -pub use types::consensus; -pub use types::consensus::light_client; -pub use types::content_value::{ - beacon::{BeaconContentValue, PossibleBeaconContentValue}, - error::ContentValueError, - history::{HistoryContentValue, PossibleHistoryContentValue}, +pub use types::{ + consensus, + consensus::light_client, + content_value::{ + beacon::{BeaconContentValue, PossibleBeaconContentValue}, + error::ContentValueError, + history::{HistoryContentValue, PossibleHistoryContentValue}, + }, + execution::{block_body::*, header::*, receipts::*}, }; -pub use types::execution::block_body::*; -pub use types::execution::header::*; -pub use types::execution::receipts::*; // Re-exports jsonrpsee crate pub use jsonrpsee; pub use types::content_value::ContentValue; -pub use types::discv5::*; -pub use types::enr::*; -pub use types::node_id::*; +pub use types::{discv5::*, enr::*, node_id::*}; diff --git a/ethportal-api/src/types/cli.rs b/ethportal-api/src/types/cli.rs index 92b9827a4..c4f034b98 100644 --- a/ethportal-api/src/types/cli.rs +++ b/ethportal-api/src/types/cli.rs @@ -1,5 +1,8 @@ -use clap::error::{Error, ErrorKind}; -use clap::{arg, Args, Parser, Subcommand}; +use clap::{ + arg, + error::{Error, ErrorKind}, + Args, Parser, Subcommand, +}; use ethereum_types::H256; use std::{env, ffi::OsString, fmt, net::SocketAddr, path::PathBuf, str::FromStr}; use url::Url; diff --git a/ethportal-api/src/types/consensus/execution_payload.rs b/ethportal-api/src/types/consensus/execution_payload.rs index 37c6fa41b..6c851e167 100644 --- a/ethportal-api/src/types/consensus/execution_payload.rs +++ b/ethportal-api/src/types/consensus/execution_payload.rs @@ -1,7 +1,8 @@ use super::serde::{de_hex_to_txs, de_number_to_u256, se_hex_to_number, se_txs_to_hex}; -use crate::types::consensus::body::Transactions; -use crate::types::consensus::fork::ForkName; -use crate::utils::serde::{hex_fixed_vec, hex_var_list}; +use crate::{ + types::consensus::{body::Transactions, fork::ForkName}, + utils::serde::{hex_fixed_vec, hex_var_list}, +}; use ethereum_types::{H160, H256, U256}; use serde::{Deserialize, Serialize}; use serde_this_or_that::as_u64; diff --git a/ethportal-api/src/types/consensus/fork.rs b/ethportal-api/src/types/consensus/fork.rs index f51068307..3f5cc47ee 100644 --- a/ethportal-api/src/types/consensus/fork.rs +++ b/ethportal-api/src/types/consensus/fork.rs @@ -1,7 +1,9 @@ use crate::utils::bytes::hex_encode; -use std::fmt; -use std::fmt::{Display, Formatter}; -use std::str::FromStr; +use std::{ + fmt, + fmt::{Display, Formatter}, + str::FromStr, +}; use thiserror::Error; /// Error thrown when failed to parse a valid [`ForkName`]. diff --git a/ethportal-api/src/types/consensus/light_client/bootstrap.rs b/ethportal-api/src/types/consensus/light_client/bootstrap.rs index b8cafde12..e8fcb9a81 100644 --- a/ethportal-api/src/types/consensus/light_client/bootstrap.rs +++ b/ethportal-api/src/types/consensus/light_client/bootstrap.rs @@ -1,14 +1,13 @@ -use crate::types::consensus::fork::ForkName; -use crate::types::consensus::light_client::header::{ - LightClientHeaderBellatrix, LightClientHeaderCapella, +use crate::types::consensus::{ + fork::ForkName, + light_client::header::{LightClientHeaderBellatrix, LightClientHeaderCapella}, + sync_committee::SyncCommittee, }; -use crate::types::consensus::sync_committee::SyncCommittee; use ethereum_types::H256; use serde::{Deserialize, Serialize}; use ssz::Decode; use ssz_derive::{Decode, Encode}; -use ssz_types::typenum::U5; -use ssz_types::FixedVector; +use ssz_types::{typenum::U5, FixedVector}; use superstruct::superstruct; pub type CurrentSyncCommitteeProofLen = U5; diff --git a/ethportal-api/src/types/consensus/light_client/finality_update.rs b/ethportal-api/src/types/consensus/light_client/finality_update.rs index 84c9f6c66..bef55daf0 100644 --- a/ethportal-api/src/types/consensus/light_client/finality_update.rs +++ b/ethportal-api/src/types/consensus/light_client/finality_update.rs @@ -1,9 +1,11 @@ -use crate::types::consensus::body::SyncAggregate; -use crate::types::consensus::fork::ForkName; -use crate::types::consensus::light_client::header::{ - LightClientHeaderBellatrix, LightClientHeaderCapella, +use crate::types::consensus::{ + body::SyncAggregate, + fork::ForkName, + light_client::{ + header::{LightClientHeaderBellatrix, LightClientHeaderCapella}, + update::FinalizedRootProofLen, + }, }; -use crate::types::consensus::light_client::update::FinalizedRootProofLen; use ethereum_types::H256; use serde::{Deserialize, Serialize}; use serde_this_or_that::as_u64; diff --git a/ethportal-api/src/types/consensus/light_client/header.rs b/ethportal-api/src/types/consensus/light_client/header.rs index f7ae9ee2b..181341234 100644 --- a/ethportal-api/src/types/consensus/light_client/header.rs +++ b/ethportal-api/src/types/consensus/light_client/header.rs @@ -1,12 +1,11 @@ -use crate::types::consensus::execution_payload::ExecutionPayloadHeaderCapella; -use crate::types::consensus::fork::ForkName; -use crate::types::consensus::header::BeaconBlockHeader; +use crate::types::consensus::{ + execution_payload::ExecutionPayloadHeaderCapella, fork::ForkName, header::BeaconBlockHeader, +}; use ethereum_types::H256; use serde::{Deserialize, Serialize}; use ssz::Decode; use ssz_derive::{Decode, Encode}; -use ssz_types::typenum::U4; -use ssz_types::FixedVector; +use ssz_types::{typenum::U4, FixedVector}; use superstruct::superstruct; use tree_hash_derive::TreeHash; diff --git a/ethportal-api/src/types/consensus/light_client/optimistic_update.rs b/ethportal-api/src/types/consensus/light_client/optimistic_update.rs index ec008ba4e..defb7a8eb 100644 --- a/ethportal-api/src/types/consensus/light_client/optimistic_update.rs +++ b/ethportal-api/src/types/consensus/light_client/optimistic_update.rs @@ -1,7 +1,7 @@ -use crate::types::consensus::body::SyncAggregate; -use crate::types::consensus::fork::ForkName; -use crate::types::consensus::light_client::header::{ - LightClientHeaderBellatrix, LightClientHeaderCapella, +use crate::types::consensus::{ + body::SyncAggregate, + fork::ForkName, + light_client::header::{LightClientHeaderBellatrix, LightClientHeaderCapella}, }; use serde::{Deserialize, Serialize}; use serde_this_or_that::as_u64; diff --git a/ethportal-api/src/types/consensus/light_client/update.rs b/ethportal-api/src/types/consensus/light_client/update.rs index 5c6beefcc..e4643308b 100644 --- a/ethportal-api/src/types/consensus/light_client/update.rs +++ b/ethportal-api/src/types/consensus/light_client/update.rs @@ -1,16 +1,18 @@ -use crate::types::consensus::body::SyncAggregate; -use crate::types::consensus::fork::ForkName; -use crate::types::consensus::light_client::header::{ - LightClientHeaderBellatrix, LightClientHeaderCapella, +use crate::types::consensus::{ + body::SyncAggregate, + fork::ForkName, + light_client::header::{LightClientHeaderBellatrix, LightClientHeaderCapella}, + sync_committee::SyncCommittee, }; -use crate::types::consensus::sync_committee::SyncCommittee; use ethereum_types::H256; use serde::{Deserialize, Serialize}; use serde_this_or_that::as_u64; use ssz::Decode; use ssz_derive::{Decode, Encode}; -use ssz_types::typenum::{U5, U6}; -use ssz_types::FixedVector; +use ssz_types::{ + typenum::{U5, U6}, + FixedVector, +}; use superstruct::superstruct; type NextSyncCommitteeProofLen = U5; diff --git a/ethportal-api/src/types/consensus/sync_committee.rs b/ethportal-api/src/types/consensus/sync_committee.rs index b8a430b54..4dd25d149 100644 --- a/ethportal-api/src/types/consensus/sync_committee.rs +++ b/ethportal-api/src/types/consensus/sync_committee.rs @@ -1,8 +1,7 @@ use crate::types::consensus::pubkey::PubKey; use serde::{Deserialize, Serialize}; use ssz_derive::{Decode, Encode}; -use ssz_types::typenum::U512; -use ssz_types::FixedVector; +use ssz_types::{typenum::U512, FixedVector}; use tree_hash_derive::TreeHash; type SyncCommitteeSize = U512; diff --git a/ethportal-api/src/types/content_key/beacon.rs b/ethportal-api/src/types/content_key/beacon.rs index cc8fe9b50..d84807c0b 100644 --- a/ethportal-api/src/types/content_key/beacon.rs +++ b/ethportal-api/src/types/content_key/beacon.rs @@ -1,6 +1,7 @@ -use crate::types::content_key::error::ContentKeyError; -use crate::types::content_key::overlay::OverlayContentKey; -use crate::utils::bytes::{hex_decode, hex_encode, hex_encode_compact}; +use crate::{ + types::content_key::{error::ContentKeyError, overlay::OverlayContentKey}, + utils::bytes::{hex_decode, hex_encode, hex_encode_compact}, +}; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use sha2::{Digest, Sha256}; use ssz::{Decode, DecodeError, Encode}; diff --git a/ethportal-api/src/types/content_key/history.rs b/ethportal-api/src/types/content_key/history.rs index db71baeca..948f15e14 100644 --- a/ethportal-api/src/types/content_key/history.rs +++ b/ethportal-api/src/types/content_key/history.rs @@ -5,9 +5,10 @@ use ssz::{self, Decode, Encode}; use ssz_derive::{Decode, Encode}; use std::fmt; -use crate::types::content_key::error::ContentKeyError; -use crate::types::content_key::overlay::OverlayContentKey; -use crate::utils::bytes::{hex_decode, hex_encode, hex_encode_compact}; +use crate::{ + types::content_key::{error::ContentKeyError, overlay::OverlayContentKey}, + utils::bytes::{hex_decode, hex_encode, hex_encode_compact}, +}; /// SSZ encoded overlay content key as bytes pub type RawContentKey = Vec; diff --git a/ethportal-api/src/types/content_key/overlay.rs b/ethportal-api/src/types/content_key/overlay.rs index 7e5ac23ba..0ca3d9500 100644 --- a/ethportal-api/src/types/content_key/overlay.rs +++ b/ethportal-api/src/types/content_key/overlay.rs @@ -1,5 +1,7 @@ -use crate::types::content_key::error::ContentKeyError; -use crate::utils::bytes::{hex_encode, hex_encode_compact}; +use crate::{ + types::content_key::error::ContentKeyError, + utils::bytes::{hex_encode, hex_encode_compact}, +}; use quickcheck::{Arbitrary, Gen}; use std::fmt; diff --git a/ethportal-api/src/types/content_key/state.rs b/ethportal-api/src/types/content_key/state.rs index 346794dc8..a3b792ee6 100644 --- a/ethportal-api/src/types/content_key/state.rs +++ b/ethportal-api/src/types/content_key/state.rs @@ -1,5 +1,4 @@ -use crate::types::content_key::overlay::OverlayContentKey; -use crate::utils::bytes::hex_encode_compact; +use crate::{types::content_key::overlay::OverlayContentKey, utils::bytes::hex_encode_compact}; use ethereum_types::{U256, U512}; use sha2::{Digest as Sha2Digest, Sha256}; use sha3::{Digest, Keccak256}; diff --git a/ethportal-api/src/types/content_value/beacon.rs b/ethportal-api/src/types/content_value/beacon.rs index f4e650eb1..19ae662b3 100644 --- a/ethportal-api/src/types/content_value/beacon.rs +++ b/ethportal-api/src/types/content_value/beacon.rs @@ -1,26 +1,33 @@ -use crate::types::consensus::fork::{ForkDigest, ForkName}; -use crate::types::consensus::header_proof::HistoricalSummariesWithProof; -use crate::types::consensus::light_client::bootstrap::{ - LightClientBootstrap, LightClientBootstrapBellatrix, LightClientBootstrapCapella, -}; -use crate::types::consensus::light_client::finality_update::{ - LightClientFinalityUpdate, LightClientFinalityUpdateBellatrix, LightClientFinalityUpdateCapella, -}; -use crate::types::consensus::light_client::optimistic_update::{ - LightClientOptimisticUpdate, LightClientOptimisticUpdateBellatrix, - LightClientOptimisticUpdateCapella, -}; -use crate::types::consensus::light_client::update::{ - LightClientUpdate, LightClientUpdateBellatrix, LightClientUpdateCapella, +use crate::{ + types::{ + consensus::{ + fork::{ForkDigest, ForkName}, + header_proof::HistoricalSummariesWithProof, + light_client::{ + bootstrap::{ + LightClientBootstrap, LightClientBootstrapBellatrix, + LightClientBootstrapCapella, + }, + finality_update::{ + LightClientFinalityUpdate, LightClientFinalityUpdateBellatrix, + LightClientFinalityUpdateCapella, + }, + optimistic_update::{ + LightClientOptimisticUpdate, LightClientOptimisticUpdateBellatrix, + LightClientOptimisticUpdateCapella, + }, + update::{LightClientUpdate, LightClientUpdateBellatrix, LightClientUpdateCapella}, + }, + }, + constants::CONTENT_ABSENT, + content_value::ContentValue, + }, + utils::bytes::{hex_decode, hex_encode}, + ContentValueError, }; -use crate::types::constants::CONTENT_ABSENT; -use crate::types::content_value::ContentValue; -use crate::utils::bytes::{hex_decode, hex_encode}; -use crate::ContentValueError; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use ssz::{Decode, DecodeError, Encode}; -use ssz_types::typenum::U128; -use ssz_types::VariableList; +use ssz_types::{typenum::U128, VariableList}; use std::ops::Deref; #[derive(Clone, Debug, PartialEq)] @@ -541,8 +548,9 @@ impl<'de> Deserialize<'de> for BeaconContentValue { #[cfg(test)] mod test { - use crate::utils::bytes::hex_decode; - use crate::{BeaconContentValue, ContentValue, PossibleBeaconContentValue}; + use crate::{ + utils::bytes::hex_decode, BeaconContentValue, ContentValue, PossibleBeaconContentValue, + }; use serde_json::Value; use std::fs; diff --git a/ethportal-api/src/types/content_value/history.rs b/ethportal-api/src/types/content_value/history.rs index c7b89f611..f946a9d9d 100644 --- a/ethportal-api/src/types/content_value/history.rs +++ b/ethportal-api/src/types/content_value/history.rs @@ -1,8 +1,11 @@ -use crate::types::constants::CONTENT_ABSENT; -use crate::types::content_value::ContentValue; -use crate::types::execution::accumulator::EpochAccumulator; -use crate::utils::bytes::{hex_decode, hex_encode}; -use crate::{BlockBody, ContentValueError, HeaderWithProof, Receipts}; +use crate::{ + types::{ + constants::CONTENT_ABSENT, content_value::ContentValue, + execution::accumulator::EpochAccumulator, + }, + utils::bytes::{hex_decode, hex_encode}, + BlockBody, ContentValueError, HeaderWithProof, Receipts, +}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use ssz::{Decode, Encode}; diff --git a/ethportal-api/src/types/distance.rs b/ethportal-api/src/types/distance.rs index 558f0b80a..895bd3c4d 100644 --- a/ethportal-api/src/types/distance.rs +++ b/ethportal-api/src/types/distance.rs @@ -1,5 +1,4 @@ -use std::fmt; -use std::ops::Deref; +use std::{fmt, ops::Deref}; use ethereum_types::U256; diff --git a/ethportal-api/src/types/enr.rs b/ethportal-api/src/types/enr.rs index 75cda39ac..a45cbae52 100644 --- a/ethportal-api/src/types/enr.rs +++ b/ethportal-api/src/types/enr.rs @@ -1,13 +1,14 @@ -use discv5::enr::CombinedKey; -use discv5::enr::Enr as Discv5Enr; +use discv5::enr::{CombinedKey, Enr as Discv5Enr}; use rand::Rng; use rlp::Encodable; use serde::{Deserialize, Serialize}; use serde_json::Value; use ssz::DecodeError; -use std::net::Ipv4Addr; -use std::ops::{Deref, DerefMut}; -use std::str::FromStr; +use std::{ + net::Ipv4Addr, + ops::{Deref, DerefMut}, + str::FromStr, +}; use validator::ValidationError; pub type Enr = Discv5Enr; @@ -99,8 +100,10 @@ pub fn generate_random_remote_enr() -> (CombinedKey, Enr) { #[cfg(test)] mod test { - use crate::generate_random_node_id; - use crate::types::distance::{Metric, XorMetric}; + use crate::{ + generate_random_node_id, + types::distance::{Metric, XorMetric}, + }; use discv5::enr::NodeId; use test_log::test; diff --git a/ethportal-api/src/types/execution/header.rs b/ethportal-api/src/types/execution/header.rs index 8195dd107..eba8136bc 100644 --- a/ethportal-api/src/types/execution/header.rs +++ b/ethportal-api/src/types/execution/header.rs @@ -6,8 +6,10 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use ssz::{Encode, SszDecoderBuilder, SszEncoder}; use ssz_derive::{Decode, Encode}; -use crate::types::bytes::ByteList; -use crate::utils::bytes::{hex_decode, hex_encode}; +use crate::{ + types::bytes::ByteList, + utils::bytes::{hex_decode, hex_encode}, +}; const LONDON_BLOCK_NUMBER: u64 = 12965000; const SHANGHAI_BLOCK_NUMBER: u64 = 17034871; diff --git a/ethportal-api/src/types/execution/receipts.rs b/ethportal-api/src/types/execution/receipts.rs index 9bfadadb6..a92bb43a6 100644 --- a/ethportal-api/src/types/execution/receipts.rs +++ b/ethportal-api/src/types/execution/receipts.rs @@ -1,5 +1,7 @@ -use std::ops::{Deref, DerefMut}; -use std::sync::Arc; +use std::{ + ops::{Deref, DerefMut}, + sync::Arc, +}; use anyhow::anyhow; use bytes::Bytes; diff --git a/ethportal-api/src/types/jsonrpc/endpoints.rs b/ethportal-api/src/types/jsonrpc/endpoints.rs index ac1fc4e4c..691baa46b 100644 --- a/ethportal-api/src/types/jsonrpc/endpoints.rs +++ b/ethportal-api/src/types/jsonrpc/endpoints.rs @@ -1,6 +1,6 @@ -use crate::types::enr::Enr; -use crate::{BeaconContentKey, HistoryContentKey}; -use crate::{BeaconContentValue, HistoryContentValue}; +use crate::{ + types::enr::Enr, BeaconContentKey, BeaconContentValue, HistoryContentKey, HistoryContentValue, +}; use discv5::enr::NodeId; /// Discv5 JSON-RPC endpoints. Start with "discv5_" prefix diff --git a/ethportal-api/src/types/jsonrpc/request.rs b/ethportal-api/src/types/jsonrpc/request.rs index 4f107820b..43b54e3c9 100644 --- a/ethportal-api/src/types/jsonrpc/request.rs +++ b/ethportal-api/src/types/jsonrpc/request.rs @@ -3,8 +3,10 @@ use serde_json::Value; use tokio::sync::mpsc; use validator::{Validate, ValidationError}; -use super::endpoints::{BeaconEndpoint, HistoryEndpoint, StateEndpoint}; -use super::params::Params; +use super::{ + endpoints::{BeaconEndpoint, HistoryEndpoint, StateEndpoint}, + params::Params, +}; type Responder = mpsc::UnboundedSender>; diff --git a/ethportal-api/src/types/portal.rs b/ethportal-api/src/types/portal.rs index 5ac18193e..fc90fce44 100644 --- a/ethportal-api/src/types/portal.rs +++ b/ethportal-api/src/types/portal.rs @@ -2,9 +2,7 @@ use serde::{Deserialize, Serialize}; use ssz_types::{typenum, BitList}; use super::query_trace::QueryTrace; -use crate::types::enr::Enr; -use crate::HistoryContentKey; -use crate::PossibleHistoryContentValue; +use crate::{types::enr::Enr, HistoryContentKey, PossibleHistoryContentValue}; pub type DataRadius = ethereum_types::U256; pub type Distance = ethereum_types::U256; diff --git a/ethportal-api/src/types/portal_wire.rs b/ethportal-api/src/types/portal_wire.rs index 9d5f4351e..f8ec2754f 100644 --- a/ethportal-api/src/types/portal_wire.rs +++ b/ethportal-api/src/types/portal_wire.rs @@ -15,11 +15,15 @@ use ssz_types::{typenum, BitList}; use thiserror::Error; use validator::ValidationError; -use crate::types::bytes::ByteList; -use crate::types::distance::Distance; -use crate::types::enr::{Enr, SszEnr}; -use crate::utils::bytes::{hex_decode, hex_encode, ByteUtilsError}; -use crate::RawContentKey; +use crate::{ + types::{ + bytes::ByteList, + distance::Distance, + enr::{Enr, SszEnr}, + }, + utils::bytes::{hex_decode, hex_encode, ByteUtilsError}, + RawContentKey, +}; /// The maximum size of a Discv5 packet. pub(crate) const MAX_DISCV5_PACKET_SIZE: usize = 1280; diff --git a/ethportal-api/src/types/query_trace.rs b/ethportal-api/src/types/query_trace.rs index a8bccf1fe..403aefc04 100644 --- a/ethportal-api/src/types/query_trace.rs +++ b/ethportal-api/src/types/query_trace.rs @@ -1,12 +1,13 @@ -use std::collections::HashMap; -use std::time::SystemTime; +use std::{collections::HashMap, time::SystemTime}; use discv5::enr::NodeId; use ethereum_types::H256; use serde::{Deserialize, Serialize}; -use super::distance::{Metric, XorMetric}; -use super::enr::Enr; +use super::{ + distance::{Metric, XorMetric}, + enr::Enr, +}; type ContentId = [u8; 32]; diff --git a/ethportal-api/src/utils/serde/hex_fixed_vec.rs b/ethportal-api/src/utils/serde/hex_fixed_vec.rs index 9d12183d4..dd5a085a4 100644 --- a/ethportal-api/src/utils/serde/hex_fixed_vec.rs +++ b/ethportal-api/src/utils/serde/hex_fixed_vec.rs @@ -1,8 +1,7 @@ use crate::utils::bytes::hex_encode; use serde::{Deserializer, Serializer}; use serde_utils::hex::PrefixedHexVisitor; -use ssz_types::typenum::Unsigned; -use ssz_types::FixedVector; +use ssz_types::{typenum::Unsigned, FixedVector}; pub fn serialize(bytes: &FixedVector, serializer: S) -> Result where diff --git a/ethportal-api/src/utils/serde/hex_var_list.rs b/ethportal-api/src/utils/serde/hex_var_list.rs index 5704336d8..300839fe5 100644 --- a/ethportal-api/src/utils/serde/hex_var_list.rs +++ b/ethportal-api/src/utils/serde/hex_var_list.rs @@ -2,8 +2,7 @@ use serde::{Deserializer, Serializer}; use serde_utils::hex::{self, PrefixedHexVisitor}; -use ssz_types::typenum::Unsigned; -use ssz_types::VariableList; +use ssz_types::{typenum::Unsigned, VariableList}; pub fn serialize(bytes: &VariableList, serializer: S) -> Result where diff --git a/ethportal-peertest/src/lib.rs b/ethportal-peertest/src/lib.rs index f5a5021aa..bc25e8f56 100644 --- a/ethportal-peertest/src/lib.rs +++ b/ethportal-peertest/src/lib.rs @@ -4,14 +4,20 @@ pub mod constants; pub mod scenarios; pub mod utils; -use std::net::{IpAddr, Ipv4Addr}; -use std::path::PathBuf; -use std::{thread, time}; +use std::{ + net::{IpAddr, Ipv4Addr}, + path::PathBuf, + thread, time, +}; -use ethportal_api::types::cli::{TrinConfig, DEFAULT_DISCOVERY_PORT}; -use ethportal_api::types::enr::Enr; -use ethportal_api::utils::bytes::hex_encode; -use ethportal_api::Discv5ApiClient; +use ethportal_api::{ + types::{ + cli::{TrinConfig, DEFAULT_DISCOVERY_PORT}, + enr::Enr, + }, + utils::bytes::hex_encode, + Discv5ApiClient, +}; use futures::future; use jsonrpsee::async_client::Client; use rpc::RpcServerHandle; diff --git a/ethportal-peertest/src/scenarios/basic.rs b/ethportal-peertest/src/scenarios/basic.rs index 69dedbf3f..ddcb1e4cf 100644 --- a/ethportal-peertest/src/scenarios/basic.rs +++ b/ethportal-peertest/src/scenarios/basic.rs @@ -1,10 +1,8 @@ -use crate::constants::fixture_header_with_proof; -use crate::Peertest; +use crate::{constants::fixture_header_with_proof, Peertest}; use ethereum_types::{H256, U256}; -use ethportal_api::types::distance::Distance; use ethportal_api::{ - BlockHeaderKey, Discv5ApiClient, HistoryContentKey, HistoryNetworkApiClient, - PossibleHistoryContentValue, Web3ApiClient, + types::distance::Distance, BlockHeaderKey, Discv5ApiClient, HistoryContentKey, + HistoryNetworkApiClient, PossibleHistoryContentValue, Web3ApiClient, }; use jsonrpsee::async_client::Client; use ssz::Encode; diff --git a/ethportal-peertest/src/scenarios/bridge.rs b/ethportal-peertest/src/scenarios/bridge.rs index 14142c9e8..c83ebca9b 100644 --- a/ethportal-peertest/src/scenarios/bridge.rs +++ b/ethportal-peertest/src/scenarios/bridge.rs @@ -1,21 +1,22 @@ -use crate::constants::fixture_header_with_proof_1000010; -use crate::utils::{wait_for_beacon_content, wait_for_history_content}; -use crate::Peertest; -use ethportal_api::jsonrpsee::http_client::HttpClient; +use crate::{ + constants::fixture_header_with_proof_1000010, + utils::{wait_for_beacon_content, wait_for_history_content}, + Peertest, +}; use ethportal_api::{ - BeaconContentKey, BeaconContentValue, PossibleBeaconContentValue, PossibleHistoryContentValue, + jsonrpsee::http_client::HttpClient, BeaconContentKey, BeaconContentValue, + PossibleBeaconContentValue, PossibleHistoryContentValue, +}; +use portal_bridge::{ + api::{consensus::ConsensusApi, execution::ExecutionApi}, + bridge::{beacon::BeaconBridge, history::HistoryBridge}, + pandaops::PandaOpsMiddleware, + types::mode::BridgeMode, }; -use portal_bridge::api::consensus::ConsensusApi; -use portal_bridge::api::execution::ExecutionApi; -use portal_bridge::bridge::beacon::BeaconBridge; -use portal_bridge::bridge::history::HistoryBridge; -use portal_bridge::pandaops::PandaOpsMiddleware; -use portal_bridge::types::mode::BridgeMode; use serde_json::Value; use std::sync::Arc; use tokio::time::{sleep, Duration}; -use trin_validation::accumulator::MasterAccumulator; -use trin_validation::oracle::HeaderOracle; +use trin_validation::{accumulator::MasterAccumulator, oracle::HeaderOracle}; pub async fn test_history_bridge(peertest: &Peertest, target: &HttpClient) { let master_acc = MasterAccumulator::default(); diff --git a/ethportal-peertest/src/scenarios/find.rs b/ethportal-peertest/src/scenarios/find.rs index cc35e55e9..5210c3e6c 100644 --- a/ethportal-peertest/src/scenarios/find.rs +++ b/ethportal-peertest/src/scenarios/find.rs @@ -4,11 +4,12 @@ use discv5::enr::NodeId; use jsonrpsee::async_client::Client; use tracing::info; -use crate::constants::fixture_header_with_proof; -use crate::Peertest; -use ethportal_api::types::portal::{ContentInfo, TraceContentInfo}; -use ethportal_api::utils::bytes::hex_decode; -use ethportal_api::{HistoryNetworkApiClient, OverlayContentKey, PossibleHistoryContentValue}; +use crate::{constants::fixture_header_with_proof, Peertest}; +use ethportal_api::{ + types::portal::{ContentInfo, TraceContentInfo}, + utils::bytes::hex_decode, + HistoryNetworkApiClient, OverlayContentKey, PossibleHistoryContentValue, +}; pub async fn test_find_content_return_enr(target: &Client, peertest: &Peertest) { info!("Testing find content returns enrs properly"); diff --git a/ethportal-peertest/src/scenarios/paginate.rs b/ethportal-peertest/src/scenarios/paginate.rs index 956db8c9a..ec554c071 100644 --- a/ethportal-peertest/src/scenarios/paginate.rs +++ b/ethportal-peertest/src/scenarios/paginate.rs @@ -1,5 +1,4 @@ -use ethportal_api::HistoryNetworkApiClient; -use ethportal_api::{BlockHeaderKey, HistoryContentKey}; +use ethportal_api::{BlockHeaderKey, HistoryContentKey, HistoryNetworkApiClient}; use crate::{constants::fixture_header_with_proof, Peertest}; diff --git a/ethportal-peertest/src/scenarios/utp.rs b/ethportal-peertest/src/scenarios/utp.rs index 8d79c20d1..3b35a3c5c 100644 --- a/ethportal-peertest/src/scenarios/utp.rs +++ b/ethportal-peertest/src/scenarios/utp.rs @@ -3,8 +3,10 @@ use crate::{ Peertest, }; use discv5::enr::NodeId; -use ethportal_api::types::portal::{ContentInfo, TraceContentInfo}; -use ethportal_api::{HistoryNetworkApiClient, PossibleHistoryContentValue}; +use ethportal_api::{ + types::portal::{ContentInfo, TraceContentInfo}, + HistoryNetworkApiClient, PossibleHistoryContentValue, +}; use tracing::info; pub async fn test_recursive_utp(peertest: &Peertest) { diff --git a/ethportal-peertest/src/scenarios/validation.rs b/ethportal-peertest/src/scenarios/validation.rs index 81fed3087..dbd1a0b68 100644 --- a/ethportal-peertest/src/scenarios/validation.rs +++ b/ethportal-peertest/src/scenarios/validation.rs @@ -3,12 +3,10 @@ use crate::{ Peertest, }; use ethereum_types::H256; -use ethportal_api::types::content_key::history::BlockHeaderKey; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::portal::ContentInfo; use ethportal_api::{ - jsonrpsee::async_client::Client, HistoryContentKey, HistoryNetworkApiClient, - PossibleHistoryContentValue, + jsonrpsee::async_client::Client, + types::{content_key::history::BlockHeaderKey, enr::Enr, portal::ContentInfo}, + HistoryContentKey, HistoryNetworkApiClient, PossibleHistoryContentValue, }; use std::str::FromStr; use tracing::info; diff --git a/light-client/src/client.rs b/light-client/src/client.rs index 0298312da..298204018 100644 --- a/light-client/src/client.rs +++ b/light-client/src/client.rs @@ -8,17 +8,14 @@ use tokio::sync::RwLock; use ethportal_api::consensus::header::BeaconBlockHeader; use std::path::PathBuf; -use tokio::spawn; -use tokio::time::sleep; +use tokio::{spawn, time::sleep}; -use crate::config::client_config::Config; -use crate::config::{CheckpointFallback, Network}; -use crate::consensus::errors::ConsensusError; -use crate::consensus::rpc::ConsensusRpc; +use crate::{ + config::{client_config::Config, CheckpointFallback, Network}, + consensus::{errors::ConsensusError, rpc::ConsensusRpc}, +}; -use crate::database::Database; -use crate::errors::NodeError; -use crate::node::Node; +use crate::{database::Database, errors::NodeError, node::Node}; use crate::rpc::Rpc; diff --git a/light-client/src/config/base.rs b/light-client/src/config/base.rs index 8856065ec..15c9189d0 100644 --- a/light-client/src/config/base.rs +++ b/light-client/src/config/base.rs @@ -1,7 +1,6 @@ use serde::Serialize; -use crate::config::utils::bytes_serialize; -use crate::config::{ChainConfig, Forks}; +use crate::config::{utils::bytes_serialize, ChainConfig, Forks}; /// The base configuration for a network. #[derive(Serialize, Default)] diff --git a/light-client/src/config/checkpoints.rs b/light-client/src/config/checkpoints.rs index e5a90faaa..85103c00f 100644 --- a/light-client/src/config/checkpoints.rs +++ b/light-client/src/config/checkpoints.rs @@ -276,8 +276,7 @@ impl CheckpointFallback { #[cfg(test)] mod test { use super::*; - use crate::config; - use crate::config::networks; + use crate::{config, config::networks}; #[tokio::test] async fn test_checkpoint_fallback() { diff --git a/light-client/src/config/client_config.rs b/light-client/src/config/client_config.rs index 532c89bfd..fb1300966 100644 --- a/light-client/src/config/client_config.rs +++ b/light-client/src/config/client_config.rs @@ -5,8 +5,11 @@ use figment::{ use serde::Deserialize; use std::{path::PathBuf, process::exit}; -use crate::config::utils::{bytes_deserialize, bytes_opt_deserialize}; -use crate::config::{networks, BaseConfig, ChainConfig, CliConfig, Forks}; +use crate::config::{ + networks, + utils::{bytes_deserialize, bytes_opt_deserialize}, + BaseConfig, ChainConfig, CliConfig, Forks, +}; #[derive(Deserialize, Debug, Default)] pub struct Config { diff --git a/light-client/src/config/networks.rs b/light-client/src/config/networks.rs index 36ac77dde..45a6843b7 100644 --- a/light-client/src/config/networks.rs +++ b/light-client/src/config/networks.rs @@ -1,8 +1,7 @@ use serde::{Deserialize, Serialize}; use strum::{Display, EnumIter}; -use crate::config::utils::hex_str_to_bytes; -use crate::config::{BaseConfig, ChainConfig, Fork, Forks}; +use crate::config::{utils::hex_str_to_bytes, BaseConfig, ChainConfig, Fork, Forks}; #[derive( Debug, diff --git a/light-client/src/consensus/consensus_client.rs b/light-client/src/consensus/consensus_client.rs index 9eac6b307..ed20155d2 100644 --- a/light-client/src/consensus/consensus_client.rs +++ b/light-client/src/consensus/consensus_client.rs @@ -1,33 +1,30 @@ -use std::cmp; -use std::sync::Arc; +use std::{cmp, sync::Arc}; use chrono::Duration; -use eyre::eyre; -use eyre::Result; -use log::warn; -use log::{debug, info}; +use eyre::{eyre, Result}; +use log::{debug, info, warn}; use milagro_bls::PublicKey; use ssz_rs::prelude::*; -use super::rpc::ConsensusRpc; -use super::types::*; -use super::utils::*; +use super::{rpc::ConsensusRpc, types::*, utils::*}; use super::errors::ConsensusError; -use crate::config::client_config::Config; -use crate::consensus::constants::MAX_REQUEST_LIGHT_CLIENT_UPDATES; -use crate::consensus::rpc::portal_rpc::expected_current_slot; -use crate::types::Bytes32; -use crate::utils::bytes_to_bytes32; +use crate::{ + config::client_config::Config, + consensus::{ + constants::MAX_REQUEST_LIGHT_CLIENT_UPDATES, rpc::portal_rpc::expected_current_slot, + }, + types::Bytes32, + utils::bytes_to_bytes32, +}; use ethereum_types::H256; -use ethportal_api::consensus::header::BeaconBlockHeader; -use ethportal_api::consensus::signature::BlsSignature; -use ethportal_api::light_client::bootstrap::CurrentSyncCommitteeProofLen; -use ethportal_api::light_client::update::FinalizedRootProofLen; -use ethportal_api::utils::bytes::hex_encode; +use ethportal_api::{ + consensus::{header::BeaconBlockHeader, signature::BlsSignature}, + light_client::{bootstrap::CurrentSyncCommitteeProofLen, update::FinalizedRootProofLen}, + utils::bytes::hex_encode, +}; use ssz_types::{typenum, BitVector, FixedVector}; -use std::time::SystemTime; -use std::time::UNIX_EPOCH; +use std::time::{SystemTime, UNIX_EPOCH}; use tree_hash::TreeHash; // https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md @@ -658,18 +655,20 @@ fn is_current_committee_proof_valid( mod tests { use std::sync::Arc; - use ethportal_api::consensus::header::BeaconBlockHeader; - use ethportal_api::consensus::pubkey::PubKey; - use ethportal_api::consensus::signature::BlsSignature; - - use crate::config::client_config::Config; - use crate::config::networks; - use crate::consensus::consensus_client::ConsensusLightClient; - use crate::consensus::constants::MAX_REQUEST_LIGHT_CLIENT_UPDATES; - use crate::consensus::errors::ConsensusError; - use crate::consensus::rpc::mock_rpc::MockRpc; - use crate::consensus::rpc::ConsensusRpc; - use crate::consensus::utils::calc_sync_period; + use ethportal_api::consensus::{ + header::BeaconBlockHeader, pubkey::PubKey, signature::BlsSignature, + }; + + use crate::{ + config::{client_config::Config, networks}, + consensus::{ + consensus_client::ConsensusLightClient, + constants::MAX_REQUEST_LIGHT_CLIENT_UPDATES, + errors::ConsensusError, + rpc::{mock_rpc::MockRpc, ConsensusRpc}, + utils::calc_sync_period, + }, + }; async fn get_client(strict_checkpoint_age: bool) -> ConsensusLightClient { let base_config = networks::mainnet(); diff --git a/light-client/src/consensus/rpc/nimbus_rpc.rs b/light-client/src/consensus/rpc/nimbus_rpc.rs index 8905b6209..d56be9780 100644 --- a/light-client/src/consensus/rpc/nimbus_rpc.rs +++ b/light-client/src/consensus/rpc/nimbus_rpc.rs @@ -4,12 +4,16 @@ use eyre::Result; use std::cmp; use super::ConsensusRpc; -use crate::consensus::constants::MAX_REQUEST_LIGHT_CLIENT_UPDATES; -use crate::consensus::types::{ - LightClientBootstrapCapella, LightClientFinalityUpdateCapella, - LightClientOptimisticUpdateCapella, LightClientUpdateCapella, +use crate::{ + consensus::{ + constants::MAX_REQUEST_LIGHT_CLIENT_UPDATES, + types::{ + LightClientBootstrapCapella, LightClientFinalityUpdateCapella, + LightClientOptimisticUpdateCapella, LightClientUpdateCapella, + }, + }, + errors::RpcError, }; -use crate::errors::RpcError; #[derive(Clone, Debug)] pub struct NimbusRpc { diff --git a/light-client/src/consensus/rpc/portal_rpc.rs b/light-client/src/consensus/rpc/portal_rpc.rs index 32f65df03..f1dcc367f 100644 --- a/light-client/src/consensus/rpc/portal_rpc.rs +++ b/light-client/src/consensus/rpc/portal_rpc.rs @@ -1,16 +1,18 @@ use crate::consensus::rpc::ConsensusRpc; use async_trait::async_trait; -use ethportal_api::consensus::light_client::bootstrap::LightClientBootstrap; -use ethportal_api::light_client::bootstrap::LightClientBootstrapCapella; -use ethportal_api::light_client::finality_update::LightClientFinalityUpdateCapella; -use ethportal_api::light_client::optimistic_update::LightClientOptimisticUpdateCapella; -use ethportal_api::light_client::update::LightClientUpdateCapella; -use ethportal_api::types::consensus::light_client::finality_update::LightClientFinalityUpdate; -use ethportal_api::types::consensus::light_client::optimistic_update::LightClientOptimisticUpdate; -use ethportal_api::types::consensus::light_client::update::LightClientUpdate; -use ethportal_api::types::content_key::beacon::LightClientFinalityUpdateKey; -use ethportal_api::types::content_key::beacon::LightClientOptimisticUpdateKey; use ethportal_api::{ + consensus::light_client::bootstrap::LightClientBootstrap, + light_client::{ + bootstrap::LightClientBootstrapCapella, finality_update::LightClientFinalityUpdateCapella, + optimistic_update::LightClientOptimisticUpdateCapella, update::LightClientUpdateCapella, + }, + types::{ + consensus::light_client::{ + finality_update::LightClientFinalityUpdate, + optimistic_update::LightClientOptimisticUpdate, update::LightClientUpdate, + }, + content_key::beacon::{LightClientFinalityUpdateKey, LightClientOptimisticUpdateKey}, + }, BeaconContentKey, BeaconContentValue, ContentValue, LightClientBootstrapKey, LightClientUpdatesByRangeKey, }; diff --git a/light-client/src/consensus/types.rs b/light-client/src/consensus/types.rs index d98afd53b..c779f177e 100644 --- a/light-client/src/consensus/types.rs +++ b/light-client/src/consensus/types.rs @@ -1,14 +1,16 @@ use ethereum_types::H256; -pub use ethportal_api::consensus::body::SyncAggregate; -use ethportal_api::consensus::header::BeaconBlockHeader; -pub use ethportal_api::consensus::sync_committee::SyncCommittee; -use ethportal_api::light_client::bootstrap::CurrentSyncCommitteeProofLen; -pub use ethportal_api::light_client::bootstrap::LightClientBootstrapCapella; -pub use ethportal_api::light_client::finality_update::LightClientFinalityUpdateCapella; -pub use ethportal_api::light_client::header::LightClientHeaderCapella; -pub use ethportal_api::light_client::optimistic_update::LightClientOptimisticUpdateCapella; -use ethportal_api::light_client::update::FinalizedRootProofLen; -pub use ethportal_api::light_client::update::LightClientUpdateCapella; +use ethportal_api::{ + consensus::header::BeaconBlockHeader, + light_client::{bootstrap::CurrentSyncCommitteeProofLen, update::FinalizedRootProofLen}, +}; +pub use ethportal_api::{ + consensus::{body::SyncAggregate, sync_committee::SyncCommittee}, + light_client::{ + bootstrap::LightClientBootstrapCapella, finality_update::LightClientFinalityUpdateCapella, + header::LightClientHeaderCapella, optimistic_update::LightClientOptimisticUpdateCapella, + update::LightClientUpdateCapella, + }, +}; use eyre::Result; use ssz_types::FixedVector; diff --git a/light-client/src/consensus/utils.rs b/light-client/src/consensus/utils.rs index 958f4ce6c..574142748 100644 --- a/light-client/src/consensus/utils.rs +++ b/light-client/src/consensus/utils.rs @@ -1,7 +1,5 @@ -use crate::types::Bytes32; -use crate::utils::bytes32_to_node; -use ethportal_api::consensus::header::BeaconBlockHeader; -use ethportal_api::consensus::signature::BlsSignature; +use crate::{types::Bytes32, utils::bytes32_to_node}; +use ethportal_api::consensus::{header::BeaconBlockHeader, signature::BlsSignature}; use eyre::Result; use milagro_bls::{AggregateSignature, PublicKey}; use ssz_rs::prelude::*; diff --git a/light-client/src/main.rs b/light-client/src/main.rs index cda8eb09a..4971649e8 100644 --- a/light-client/src/main.rs +++ b/light-client/src/main.rs @@ -1,8 +1,8 @@ use eyre::Result; -use light_client::config::networks; -use light_client::consensus::rpc::nimbus_rpc::NimbusRpc; -use light_client::database::FileDB; -use light_client::{Client, ClientBuilder}; +use light_client::{ + config::networks, consensus::rpc::nimbus_rpc::NimbusRpc, database::FileDB, Client, + ClientBuilder, +}; use std::path::PathBuf; use tracing::info; diff --git a/light-client/src/node.rs b/light-client/src/node.rs index 192bf018a..8272ec16b 100644 --- a/light-client/src/node.rs +++ b/light-client/src/node.rs @@ -1,12 +1,12 @@ -use std::sync::Arc; -use std::time::Duration; +use std::{sync::Arc, time::Duration}; use ethportal_api::consensus::header::BeaconBlockHeader; use eyre::Result; -use crate::config::client_config::Config; -use crate::consensus::rpc::ConsensusRpc; -use crate::consensus::ConsensusLightClient; +use crate::{ + config::client_config::Config, + consensus::{rpc::ConsensusRpc, ConsensusLightClient}, +}; use crate::errors::NodeError; diff --git a/light-client/tests/sync.rs b/light-client/tests/sync.rs index 7efae42e9..6263f40a0 100644 --- a/light-client/tests/sync.rs +++ b/light-client/tests/sync.rs @@ -1,9 +1,9 @@ use std::sync::Arc; -use light_client::config::client_config::Config; -use light_client::config::networks; -use light_client::consensus::rpc::mock_rpc::MockRpc; -use light_client::consensus::ConsensusLightClient; +use light_client::{ + config::{client_config::Config, networks}, + consensus::{rpc::mock_rpc::MockRpc, ConsensusLightClient}, +}; async fn setup() -> ConsensusLightClient { let base_config = networks::mainnet(); diff --git a/portal-bridge/src/api/execution.rs b/portal-bridge/src/api/execution.rs index 2a0281443..a96097a88 100644 --- a/portal-bridge/src/api/execution.rs +++ b/portal-bridge/src/api/execution.rs @@ -2,12 +2,15 @@ use anyhow::{anyhow, bail}; use ethereum_types::H256; use serde_json::{json, Value}; -use crate::pandaops::PandaOpsMiddleware; -use crate::types::full_header::{FullHeader, FullHeaderBatch}; -use ethportal_api::types::jsonrpc::params::Params; -use ethportal_api::types::jsonrpc::request::JsonRequest; -use ethportal_api::utils::bytes::hex_encode; -use ethportal_api::{Header, Receipts}; +use crate::{ + pandaops::PandaOpsMiddleware, + types::full_header::{FullHeader, FullHeaderBatch}, +}; +use ethportal_api::{ + types::jsonrpc::{params::Params, request::JsonRequest}, + utils::bytes::hex_encode, + Header, Receipts, +}; /// Implements endpoints from the Execution API to access data from the execution layer. #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/portal-bridge/src/bridge/beacon.rs b/portal-bridge/src/bridge/beacon.rs index a4d33b70e..4f410b4b8 100644 --- a/portal-bridge/src/bridge/beacon.rs +++ b/portal-bridge/src/bridge/beacon.rs @@ -1,7 +1,9 @@ -use std::cmp::Ordering; -use std::path::PathBuf; -use std::sync::{Arc, Mutex}; -use std::time::SystemTime; +use std::{ + cmp::Ordering, + path::PathBuf, + sync::{Arc, Mutex}, + time::SystemTime, +}; use anyhow::bail; use jsonrpsee::http_client::HttpClient; @@ -10,29 +12,31 @@ use ssz_types::VariableList; use tokio::time::{interval, sleep, Duration, MissedTickBehavior}; use tracing::{info, warn}; -use crate::api::consensus::ConsensusApi; -use crate::constants::BEACON_GENESIS_TIME; -use crate::gossip::gossip_beacon_content; -use crate::stats::{BeaconSlotStats, StatsReporter}; -use crate::types::mode::BridgeMode; -use crate::utils::{ - duration_until_next_update, expected_current_slot, read_test_assets_from_file, TestAssets, -}; -use ethportal_api::types::consensus::fork::ForkName; -use ethportal_api::types::consensus::light_client::bootstrap::LightClientBootstrapCapella; -use ethportal_api::types::consensus::light_client::finality_update::LightClientFinalityUpdateCapella; -use ethportal_api::types::consensus::light_client::optimistic_update::LightClientOptimisticUpdateCapella; -use ethportal_api::types::consensus::light_client::update::{ - LightClientUpdate, LightClientUpdateCapella, -}; -use ethportal_api::types::content_key::beacon::{ - LightClientFinalityUpdateKey, LightClientOptimisticUpdateKey, -}; -use ethportal_api::types::content_value::beacon::{ - ForkVersionedLightClientUpdate, LightClientUpdatesByRange, +use crate::{ + api::consensus::ConsensusApi, + constants::BEACON_GENESIS_TIME, + gossip::gossip_beacon_content, + stats::{BeaconSlotStats, StatsReporter}, + types::mode::BridgeMode, + utils::{ + duration_until_next_update, expected_current_slot, read_test_assets_from_file, TestAssets, + }, }; -use ethportal_api::utils::bytes::hex_decode; use ethportal_api::{ + types::{ + consensus::{ + fork::ForkName, + light_client::{ + bootstrap::LightClientBootstrapCapella, + finality_update::LightClientFinalityUpdateCapella, + optimistic_update::LightClientOptimisticUpdateCapella, + update::{LightClientUpdate, LightClientUpdateCapella}, + }, + }, + content_key::beacon::{LightClientFinalityUpdateKey, LightClientOptimisticUpdateKey}, + content_value::beacon::{ForkVersionedLightClientUpdate, LightClientUpdatesByRange}, + }, + utils::bytes::hex_decode, BeaconContentKey, BeaconContentValue, LightClientBootstrapKey, LightClientUpdatesByRangeKey, }; diff --git a/portal-bridge/src/bridge/history.rs b/portal-bridge/src/bridge/history.rs index 2c7334b0f..70d913256 100644 --- a/portal-bridge/src/bridge/history.rs +++ b/portal-bridge/src/bridge/history.rs @@ -1,7 +1,9 @@ -use std::fs; -use std::ops::Range; -use std::path::PathBuf; -use std::sync::{Arc, Mutex}; +use std::{ + fs, + ops::Range, + path::PathBuf, + sync::{Arc, Mutex}, +}; use anyhow::{anyhow, bail}; use futures::stream::StreamExt; @@ -9,26 +11,28 @@ use ssz::Decode; use tokio::time::{sleep, Duration}; use tracing::{debug, info, warn}; -use crate::api::execution::ExecutionApi; -use crate::gossip::gossip_history_content; -use crate::stats::{HistoryBlockStats, StatsReporter}; -use crate::types::{ - full_header::FullHeader, - mode::{BridgeMode, ModeType}, -}; -use crate::utils::{read_test_assets_from_file, TestAssets}; -use ethportal_api::jsonrpsee::http_client::HttpClient; -use ethportal_api::types::execution::{ - accumulator::EpochAccumulator, - block_body::{ - BlockBody, BlockBodyLegacy, BlockBodyMerge, BlockBodyShanghai, MERGE_TIMESTAMP, - SHANGHAI_TIMESTAMP, +use crate::{ + api::execution::ExecutionApi, + gossip::gossip_history_content, + stats::{HistoryBlockStats, StatsReporter}, + types::{ + full_header::FullHeader, + mode::{BridgeMode, ModeType}, }, - header::{AccumulatorProof, BlockHeaderProof, Header, HeaderWithProof, SszNone}, - receipts::Receipts, + utils::{read_test_assets_from_file, TestAssets}, }; -use ethportal_api::utils::bytes::hex_encode; use ethportal_api::{ + jsonrpsee::http_client::HttpClient, + types::execution::{ + accumulator::EpochAccumulator, + block_body::{ + BlockBody, BlockBodyLegacy, BlockBodyMerge, BlockBodyShanghai, MERGE_TIMESTAMP, + SHANGHAI_TIMESTAMP, + }, + header::{AccumulatorProof, BlockHeaderProof, Header, HeaderWithProof, SszNone}, + receipts::Receipts, + }, + utils::bytes::hex_encode, BlockBodyKey, BlockHeaderKey, BlockReceiptsKey, EpochAccumulatorKey, HistoryContentKey, HistoryContentValue, }; diff --git a/portal-bridge/src/cli.rs b/portal-bridge/src/cli.rs index 107481c31..f551c94f1 100644 --- a/portal-bridge/src/cli.rs +++ b/portal-bridge/src/cli.rs @@ -1,14 +1,14 @@ -use std::path::PathBuf; -use std::str::FromStr; +use std::{path::PathBuf, str::FromStr}; use clap::{Parser, Subcommand}; use ethereum_types::H256; use tokio::process::Child; use url::Url; -use crate::client_handles::{fluffy_handle, trin_handle}; -use crate::types::mode::BridgeMode; -use crate::types::network::NetworkKind; +use crate::{ + client_handles::{fluffy_handle, trin_handle}, + types::{mode::BridgeMode, network::NetworkKind}, +}; use ethportal_api::types::cli::check_private_key_length; // max value of 16 b/c... diff --git a/portal-bridge/src/gossip.rs b/portal-bridge/src/gossip.rs index 5375ffedf..1ad6ee093 100644 --- a/portal-bridge/src/gossip.rs +++ b/portal-bridge/src/gossip.rs @@ -5,9 +5,9 @@ use tokio::time::{sleep, Duration}; use tracing::{debug, warn}; use crate::stats::{BeaconSlotStats, HistoryBlockStats, StatsReporter}; -use ethportal_api::jsonrpsee::core::Error; -use ethportal_api::types::portal::{ContentInfo, TraceGossipInfo}; use ethportal_api::{ + jsonrpsee::core::Error, + types::portal::{ContentInfo, TraceGossipInfo}, BeaconContentKey, BeaconContentValue, BeaconNetworkApiClient, HistoryContentKey, HistoryContentValue, HistoryNetworkApiClient, OverlayContentKey, PossibleBeaconContentValue, PossibleHistoryContentValue, diff --git a/portal-bridge/src/main.rs b/portal-bridge/src/main.rs index e5ac4980c..9521ca287 100644 --- a/portal-bridge/src/main.rs +++ b/portal-bridge/src/main.rs @@ -3,17 +3,20 @@ use std::sync::Arc; use clap::Parser; use tokio::time::{sleep, Duration}; -use ethportal_api::jsonrpsee::http_client::{HttpClient, HttpClientBuilder}; -use ethportal_api::types::cli::{DEFAULT_DISCOVERY_PORT, DEFAULT_WEB3_HTTP_PORT}; -use portal_bridge::api::{consensus::ConsensusApi, execution::ExecutionApi}; -use portal_bridge::bridge::{beacon::BeaconBridge, history::HistoryBridge}; -use portal_bridge::cli::BridgeConfig; -use portal_bridge::pandaops::PandaOpsMiddleware; -use portal_bridge::types::network::NetworkKind; -use portal_bridge::utils::generate_spaced_private_keys; +use ethportal_api::{ + jsonrpsee::http_client::{HttpClient, HttpClientBuilder}, + types::cli::{DEFAULT_DISCOVERY_PORT, DEFAULT_WEB3_HTTP_PORT}, +}; +use portal_bridge::{ + api::{consensus::ConsensusApi, execution::ExecutionApi}, + bridge::{beacon::BeaconBridge, history::HistoryBridge}, + cli::BridgeConfig, + pandaops::PandaOpsMiddleware, + types::network::NetworkKind, + utils::generate_spaced_private_keys, +}; use trin_utils::log::init_tracing_logger; -use trin_validation::accumulator::MasterAccumulator; -use trin_validation::oracle::HeaderOracle; +use trin_validation::{accumulator::MasterAccumulator, oracle::HeaderOracle}; #[tokio::main] async fn main() -> Result<(), Box> { diff --git a/portal-bridge/src/pandaops.rs b/portal-bridge/src/pandaops.rs index b3fdd3bb1..3c9a060b1 100644 --- a/portal-bridge/src/pandaops.rs +++ b/portal-bridge/src/pandaops.rs @@ -8,8 +8,10 @@ use surf::{ use tokio::time::{sleep, Duration}; use tracing::{info, warn}; -use crate::constants::{BASE_CL_ENDPOINT, BASE_EL_ENDPOINT}; -use crate::{PANDAOPS_CLIENT_ID, PANDAOPS_CLIENT_SECRET}; +use crate::{ + constants::{BASE_CL_ENDPOINT, BASE_EL_ENDPOINT}, + PANDAOPS_CLIENT_ID, PANDAOPS_CLIENT_SECRET, +}; use ethportal_api::types::jsonrpc::request::JsonRequest; /// Limit the number of requests in a single batch to avoid exceeding the diff --git a/portal-bridge/src/stats.rs b/portal-bridge/src/stats.rs index b946f6f1e..a1a3c0fd3 100644 --- a/portal-bridge/src/stats.rs +++ b/portal-bridge/src/stats.rs @@ -1,12 +1,12 @@ -use std::collections::HashSet; -use std::str::FromStr; +use std::{collections::HashSet, str::FromStr}; use tracing::{info, trace}; -use ethportal_api::jsonrpsee::core::Error; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::portal::TraceGossipInfo; -use ethportal_api::{BeaconContentKey, HistoryContentKey}; +use ethportal_api::{ + jsonrpsee::core::Error, + types::{enr::Enr, portal::TraceGossipInfo}, + BeaconContentKey, HistoryContentKey, +}; // Trait for tracking / reporting gossip stats pub trait StatsReporter { diff --git a/portal-bridge/src/types/full_header.rs b/portal-bridge/src/types/full_header.rs index 4efbd2b88..c9009a0b1 100644 --- a/portal-bridge/src/types/full_header.rs +++ b/portal-bridge/src/types/full_header.rs @@ -4,10 +4,14 @@ use ethereum_types::H256; use serde::{Deserialize, Deserializer}; use serde_json::Value; -use ethportal_api::types::consensus::withdrawal::Withdrawal; -use ethportal_api::types::execution::accumulator::EpochAccumulator; -use ethportal_api::types::execution::header::{Header, TxHashes}; -use ethportal_api::types::execution::transaction::Transaction; +use ethportal_api::types::{ + consensus::withdrawal::Withdrawal, + execution::{ + accumulator::EpochAccumulator, + header::{Header, TxHashes}, + transaction::Transaction, + }, +}; /// Helper type to deserialize a response from a batched Header request. #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/portal-bridge/src/types/mode.rs b/portal-bridge/src/types/mode.rs index c24038da2..2afbb0d59 100644 --- a/portal-bridge/src/types/mode.rs +++ b/portal-bridge/src/types/mode.rs @@ -1,5 +1,4 @@ -use std::path::PathBuf; -use std::str::FromStr; +use std::{path::PathBuf, str::FromStr}; use trin_validation::constants::EPOCH_SIZE; diff --git a/portal-bridge/src/types/network.rs b/portal-bridge/src/types/network.rs index 03c0fd31b..e06ded45d 100644 --- a/portal-bridge/src/types/network.rs +++ b/portal-bridge/src/types/network.rs @@ -1,5 +1,4 @@ -use std::fmt; -use std::str::FromStr; +use std::{fmt, str::FromStr}; /// The different subnetworks that can be used to run the bridge #[derive(Debug, PartialEq, Clone)] diff --git a/portal-bridge/src/utils.rs b/portal-bridge/src/utils.rs index f81eba1f4..b649a34da 100644 --- a/portal-bridge/src/utils.rs +++ b/portal-bridge/src/utils.rs @@ -1,6 +1,8 @@ -use std::ops::Deref; -use std::path::PathBuf; -use std::time::{SystemTime, UNIX_EPOCH}; +use std::{ + ops::Deref, + path::PathBuf, + time::{SystemTime, UNIX_EPOCH}, +}; use anyhow::bail; use chrono::Duration; @@ -8,9 +10,10 @@ use discv5::enr::{CombinedKey, Enr, NodeId}; use ethereum_types::H256; use serde::{Deserialize, Serialize}; -use ethportal_api::utils::bytes::hex_encode; -use ethportal_api::HistoryContentKey; -use ethportal_api::{BeaconContentKey, BeaconContentValue, HistoryContentValue}; +use ethportal_api::{ + utils::bytes::hex_encode, BeaconContentKey, BeaconContentValue, HistoryContentKey, + HistoryContentValue, +}; /// Generates a set of N private keys, with node ids that are equally spaced /// around the 256-bit keys space. @@ -169,8 +172,10 @@ mod tests { }; use chrono::{DateTime, TimeZone, Utc}; use ethereum_types::U256; - use ethportal_api::types::distance::{Metric, XorMetric}; - use ethportal_api::utils::bytes::hex_decode; + use ethportal_api::{ + types::distance::{Metric, XorMetric}, + utils::bytes::hex_decode, + }; use rstest::rstest; use serde_json::json; diff --git a/portalnet/src/config.rs b/portalnet/src/config.rs index ca7b76c8c..ac3f2962b 100644 --- a/portalnet/src/config.rs +++ b/portalnet/src/config.rs @@ -2,9 +2,7 @@ use std::net::SocketAddr; use ethereum_types::H256; -use ethportal_api::types::bootnodes::Bootnodes; -use ethportal_api::types::cli::TrinConfig; -use ethportal_api::types::distance::Distance; +use ethportal_api::types::{bootnodes::Bootnodes, cli::TrinConfig, distance::Distance}; /// Capacity of the cache for observed `NodeAddress` values. /// Provides capacity for 32 full k-buckets. This capacity will be shared among all active portal diff --git a/portalnet/src/discovery.rs b/portalnet/src/discovery.rs index e72a7f90b..007c55c64 100644 --- a/portalnet/src/discovery.rs +++ b/portalnet/src/discovery.rs @@ -1,9 +1,14 @@ -use std::hash::{Hash, Hasher}; -use std::net::Ipv4Addr; -use std::path::PathBuf; -use std::str::FromStr; -use std::time::Duration; -use std::{convert::TryFrom, fmt, fs, io, net::SocketAddr, sync::Arc}; +use std::{ + convert::TryFrom, + fmt, fs, + hash::{Hash, Hasher}, + io, + net::{Ipv4Addr, SocketAddr}, + path::PathBuf, + str::FromStr, + sync::Arc, + time::Duration, +}; use anyhow::anyhow; use async_trait::async_trait; @@ -21,11 +26,11 @@ use utp_rs::{cid::ConnectionPeer, udp::AsyncUdpSocket}; use super::config::PortalnetConfig; use crate::socket; -use ethportal_api::types::discv5::RoutingTableInfo; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::portal_wire::ProtocolId; -use ethportal_api::utils::bytes::hex_encode; -use ethportal_api::NodeInfo; +use ethportal_api::{ + types::{discv5::RoutingTableInfo, enr::Enr, portal_wire::ProtocolId}, + utils::bytes::hex_encode, + NodeInfo, +}; use trin_utils::version::get_trin_version; /// Size of the buffer of the Discv5 TALKREQ channel. diff --git a/portalnet/src/events.rs b/portalnet/src/events.rs index 6d179f064..02436b113 100644 --- a/portalnet/src/events.rs +++ b/portalnet/src/events.rs @@ -1,5 +1,7 @@ -use std::str::FromStr; -use std::time::{Duration, SystemTime, UNIX_EPOCH}; +use std::{ + str::FromStr, + time::{Duration, SystemTime, UNIX_EPOCH}, +}; use discv5::TalkRequest; use futures::stream::{select_all, StreamExt}; @@ -7,8 +9,10 @@ use tokio::sync::{broadcast, mpsc}; use tokio_stream::wrappers::BroadcastStream; use tracing::{debug, error, trace, warn}; -use ethportal_api::types::portal_wire::ProtocolId; -use ethportal_api::utils::bytes::{hex_encode, hex_encode_upper}; +use ethportal_api::{ + types::portal_wire::ProtocolId, + utils::bytes::{hex_encode, hex_encode_upper}, +}; /// Handles for communication between the main event handler and an overlay. pub struct OverlayHandle { diff --git a/portalnet/src/find/iterators/findcontent.rs b/portalnet/src/find/iterators/findcontent.rs index f0d54fb2e..daf6ae32e 100644 --- a/portalnet/src/find/iterators/findcontent.rs +++ b/portalnet/src/find/iterators/findcontent.rs @@ -21,13 +21,17 @@ // This basis of this file has been taken from the rust-libp2p codebase: // https://github.com/libp2p/rust-libp2p -use std::collections::btree_map::{BTreeMap, Entry}; -use std::time::Instant; +use std::{ + collections::btree_map::{BTreeMap, Entry}, + time::Instant, +}; use discv5::kbucket::{Distance, Key}; -use super::super::query_pool::QueryState; -use super::query::{Query, QueryConfig, QueryPeer, QueryPeerState, QueryProgress}; +use super::{ + super::query_pool::QueryState, + query::{Query, QueryConfig, QueryPeer, QueryPeerState, QueryProgress}, +}; pub enum FindContentQueryResponse { ClosestNodes(Vec), diff --git a/portalnet/src/find/iterators/findnodes.rs b/portalnet/src/find/iterators/findnodes.rs index 261d9e108..787c46e15 100644 --- a/portalnet/src/find/iterators/findnodes.rs +++ b/portalnet/src/find/iterators/findnodes.rs @@ -21,8 +21,10 @@ // This basis of this file has been taken from the rust-libp2p codebase: // https://github.com/libp2p/rust-libp2p -use super::super::query_pool::QueryState; -use super::query::{Query, QueryConfig, QueryPeer, QueryPeerState, QueryProgress}; +use super::{ + super::query_pool::QueryState, + query::{Query, QueryConfig, QueryPeer, QueryPeerState, QueryProgress}, +}; use discv5::kbucket::{Distance, Key}; use std::{ diff --git a/portalnet/src/find/query_info.rs b/portalnet/src/find/query_info.rs index 51724f21d..47965e31f 100644 --- a/portalnet/src/find/query_info.rs +++ b/portalnet/src/find/query_info.rs @@ -3,9 +3,13 @@ use futures::channel::oneshot; use smallvec::SmallVec; use crate::find::query_pool::TargetKey; -use ethportal_api::types::portal_wire::{Content, FindContent, FindNodes, Request}; -use ethportal_api::types::query_trace::QueryTrace; -use ethportal_api::OverlayContentKey; +use ethportal_api::{ + types::{ + portal_wire::{Content, FindContent, FindNodes, Request}, + query_trace::QueryTrace, + }, + OverlayContentKey, +}; /// Information about a query. #[derive(Debug)] diff --git a/portalnet/src/gossip.rs b/portalnet/src/gossip.rs index 8a65aeb93..a6633acab 100644 --- a/portalnet/src/gossip.rs +++ b/portalnet/src/gossip.rs @@ -11,16 +11,19 @@ use serde::{Deserialize, Serialize}; use tokio::sync::mpsc; use tracing::{debug, error, warn}; -use crate::overlay_service::{OverlayCommand, OverlayRequest, RequestDirection}; -use crate::types::node::Node; -use ethportal_api::types::distance::{Metric, XorMetric}; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::portal_wire::{ - PopulatedOffer, PopulatedOfferWithResult, Request, Response, +use crate::{ + overlay_service::{OverlayCommand, OverlayRequest, RequestDirection}, + types::node::Node, +}; +use ethportal_api::{ + types::{ + distance::{Metric, XorMetric}, + enr::Enr, + portal_wire::{PopulatedOffer, PopulatedOfferWithResult, Request, Response}, + }, + utils::bytes::hex_encode, + OverlayContentKey, RawContentKey, }; -use ethportal_api::utils::bytes::hex_encode; -use ethportal_api::OverlayContentKey; -use ethportal_api::RawContentKey; /// Datatype to store the result of a gossip request. #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Default)] diff --git a/portalnet/src/overlay.rs b/portalnet/src/overlay.rs index d19fb0f98..3648ccbdd 100644 --- a/portalnet/src/overlay.rs +++ b/portalnet/src/overlay.rs @@ -10,16 +10,15 @@ use discv5::{ use futures::channel::oneshot; use parking_lot::RwLock; use ssz::Encode; -use std::future::Future; use std::{ collections::{BTreeMap, HashSet}, fmt::{Debug, Display}, + future::Future, marker::{PhantomData, Sync}, sync::Arc, time::Duration, }; -use tokio::sync::broadcast; -use tokio::sync::mpsc::UnboundedSender; +use tokio::sync::{broadcast, mpsc::UnboundedSender}; use tracing::{debug, error, info, warn}; use utp_rs::socket::UtpSocket; @@ -34,17 +33,20 @@ use crate::{ storage::ContentStore, types::node::Node, }; -use ethportal_api::types::bootnodes::Bootnode; -use ethportal_api::types::discv5::RoutingTableInfo; -use ethportal_api::types::distance::{Distance, Metric}; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::portal_wire::{ - Accept, Content, CustomPayload, FindContent, FindNodes, Message, Nodes, Offer, Ping, Pong, - PopulatedOffer, ProtocolId, Request, Response, +use ethportal_api::{ + types::{ + bootnodes::Bootnode, + discv5::RoutingTableInfo, + distance::{Distance, Metric}, + enr::Enr, + portal_wire::{ + Accept, Content, CustomPayload, FindContent, FindNodes, Message, Nodes, Offer, Ping, + Pong, PopulatedOffer, ProtocolId, Request, Response, + }, + }, + utils::bytes::hex_encode, + OverlayContentKey, RawContentKey, }; -use ethportal_api::utils::bytes::hex_encode; -use ethportal_api::OverlayContentKey; -use ethportal_api::RawContentKey; use trin_metrics::{overlay::OverlayMetricsReporter, portalnet::PORTALNET_METRICS}; use trin_validation::validator::Validator; diff --git a/portalnet/src/overlay_service.rs b/portalnet/src/overlay_service.rs index 01c8b657d..80d31e95c 100644 --- a/portalnet/src/overlay_service.rs +++ b/portalnet/src/overlay_service.rs @@ -53,18 +53,21 @@ use crate::{ types::node::Node, utils::portal_wire, }; -use ethportal_api::generate_random_node_id; -use ethportal_api::types::distance::{Distance, Metric}; -use ethportal_api::types::enr::{Enr, SszEnr}; -use ethportal_api::types::portal_wire::{ - Accept, Content, CustomPayload, FindContent, FindNodes, Message, Nodes, Offer, Ping, Pong, - PopulatedOffer, ProtocolId, Request, Response, MAX_PORTAL_CONTENT_PAYLOAD_SIZE, - MAX_PORTAL_NODES_ENRS_SIZE, +use ethportal_api::{ + generate_random_node_id, + types::{ + distance::{Distance, Metric}, + enr::{Enr, SszEnr}, + portal_wire::{ + Accept, Content, CustomPayload, FindContent, FindNodes, Message, Nodes, Offer, Ping, + Pong, PopulatedOffer, ProtocolId, Request, Response, MAX_PORTAL_CONTENT_PAYLOAD_SIZE, + MAX_PORTAL_NODES_ENRS_SIZE, + }, + query_trace::QueryTrace, + }, + utils::bytes::{hex_encode, hex_encode_compact}, + OverlayContentKey, RawContentKey, }; -use ethportal_api::types::query_trace::QueryTrace; -use ethportal_api::utils::bytes::{hex_encode, hex_encode_compact}; -use ethportal_api::OverlayContentKey; -use ethportal_api::RawContentKey; use trin_metrics::{ labels::{UtpDirectionLabel, UtpOutcomeLabel}, overlay::OverlayMetricsReporter, @@ -2640,8 +2643,7 @@ fn pop_while_ssz_bytes_len_gt(enrs: &mut Vec, max_size: usize) { mod tests { use super::*; - use std::net::SocketAddr; - use std::time::Instant; + use std::{net::SocketAddr, time::Instant}; use discv5::kbucket::Entry; use ethereum_types::U256; diff --git a/portalnet/src/storage.rs b/portalnet/src/storage.rs index e048c65b3..3817d3d30 100644 --- a/portalnet/src/storage.rs +++ b/portalnet/src/storage.rs @@ -15,12 +15,15 @@ use rusqlite::params; use thiserror::Error; use tracing::{debug, error, info}; -use ethportal_api::types::distance::{Distance, Metric, XorMetric}; -use ethportal_api::types::portal_wire::ProtocolId; -use ethportal_api::utils::bytes::{hex_decode, hex_encode, ByteUtilsError}; -use ethportal_api::{ContentKeyError, HistoryContentKey, OverlayContentKey}; -use trin_metrics::portalnet::PORTALNET_METRICS; -use trin_metrics::storage::StorageMetricsReporter; +use ethportal_api::{ + types::{ + distance::{Distance, Metric, XorMetric}, + portal_wire::ProtocolId, + }, + utils::bytes::{hex_decode, hex_encode, ByteUtilsError}, + ContentKeyError, HistoryContentKey, OverlayContentKey, +}; +use trin_metrics::{portalnet::PORTALNET_METRICS, storage::StorageMetricsReporter}; const BYTES_IN_MB_U64: u64 = 1000 * 1000; diff --git a/portalnet/src/types/node.rs b/portalnet/src/types/node.rs index 1e366c174..40c0a032e 100644 --- a/portalnet/src/types/node.rs +++ b/portalnet/src/types/node.rs @@ -1,7 +1,6 @@ use std::fmt; -use ethportal_api::types::distance::Distance; -use ethportal_api::types::enr::Enr; +use ethportal_api::types::{distance::Distance, enr::Enr}; /// A node in the overlay network routing table. #[derive(Clone, Debug, Eq, PartialEq)] diff --git a/portalnet/src/utils/db.rs b/portalnet/src/utils/db.rs index cd5534c0f..afa268dbf 100644 --- a/portalnet/src/utils/db.rs +++ b/portalnet/src/utils/db.rs @@ -1,5 +1,7 @@ -use std::path::{Path, PathBuf}; -use std::{env, fs}; +use std::{ + env, fs, + path::{Path, PathBuf}, +}; use anyhow::anyhow; use directories::ProjectDirs; diff --git a/portalnet/tests/overlay.rs b/portalnet/tests/overlay.rs index 517ce00df..e4e0de596 100644 --- a/portalnet/tests/overlay.rs +++ b/portalnet/tests/overlay.rs @@ -1,5 +1,8 @@ -use std::net::{IpAddr, Ipv4Addr}; -use std::{net::SocketAddr, str::FromStr, sync::Arc}; +use std::{ + net::{IpAddr, Ipv4Addr, SocketAddr}, + str::FromStr, + sync::Arc, +}; use discv5::TalkRequest; use parking_lot::RwLock; @@ -9,17 +12,21 @@ use tokio::{ }; use utp_rs::socket::UtpSocket; -use ethportal_api::types::content_key::overlay::IdentityContentKey; -use ethportal_api::types::distance::XorMetric; -use ethportal_api::types::enr::{Enr, SszEnr}; -use ethportal_api::types::portal_wire::{Content, Message, ProtocolId}; -use ethportal_api::utils::bytes::hex_encode_upper; -use portalnet::utils::db::setup_temp_dir; +use ethportal_api::{ + types::{ + content_key::overlay::IdentityContentKey, + distance::XorMetric, + enr::{Enr, SszEnr}, + portal_wire::{Content, Message, ProtocolId}, + }, + utils::bytes::hex_encode_upper, +}; use portalnet::{ config::PortalnetConfig, discovery::{Discovery, Discv5UdpSocket}, overlay::{OverlayConfig, OverlayProtocol}, storage::{ContentStore, DistanceFunction, MemoryContentStore}, + utils::db::setup_temp_dir, }; use trin_validation::validator::MockValidator; diff --git a/rpc/src/beacon_rpc.rs b/rpc/src/beacon_rpc.rs index 7e65fd343..ed3c319d8 100644 --- a/rpc/src/beacon_rpc.rs +++ b/rpc/src/beacon_rpc.rs @@ -1,21 +1,20 @@ -use crate::errors::RpcServeError; -use crate::serde::from_value; +use crate::{errors::RpcServeError, serde::from_value}; use crate::jsonrpsee::core::{async_trait, RpcResult}; use discv5::enr::NodeId; -use ethportal_api::types::constants::CONTENT_ABSENT; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::jsonrpc::endpoints::BeaconEndpoint; -use ethportal_api::types::jsonrpc::request::BeaconJsonRpcRequest; -use ethportal_api::types::portal::{ - AcceptInfo, ContentInfo, DataRadius, FindNodesInfo, PaginateLocalContentInfo, PongInfo, - TraceContentInfo, TraceGossipInfo, +use ethportal_api::{ + types::{ + constants::CONTENT_ABSENT, + enr::Enr, + jsonrpc::{endpoints::BeaconEndpoint, request::BeaconJsonRpcRequest}, + portal::{ + AcceptInfo, ContentInfo, DataRadius, FindNodesInfo, PaginateLocalContentInfo, PongInfo, + TraceContentInfo, TraceGossipInfo, + }, + }, + BeaconContentKey, BeaconContentValue, BeaconNetworkApiServer, PossibleBeaconContentValue, + RoutingTableInfo, }; -use ethportal_api::BeaconContentKey; -use ethportal_api::BeaconContentValue; -use ethportal_api::BeaconNetworkApiServer; -use ethportal_api::PossibleBeaconContentValue; -use ethportal_api::RoutingTableInfo; use serde_json::Value; use tokio::sync::mpsc; diff --git a/rpc/src/builder.rs b/rpc/src/builder.rs index cebd70988..a9405846d 100644 --- a/rpc/src/builder.rs +++ b/rpc/src/builder.rs @@ -1,18 +1,20 @@ -use crate::errors::{RpcError, WsHttpSamePortError}; -use crate::jsonrpsee::{Methods, RpcModule}; -use crate::rpc_server::{RpcServerConfig, RpcServerHandle}; -use crate::{BeaconNetworkApi, Discv5Api, EthApi, HistoryNetworkApi, Web3Api}; -use ethportal_api::types::jsonrpc::request::{ - BeaconJsonRpcRequest, HistoryJsonRpcRequest, StateJsonRpcRequest, +use crate::{ + errors::{RpcError, WsHttpSamePortError}, + jsonrpsee::{Methods, RpcModule}, + rpc_server::{RpcServerConfig, RpcServerHandle}, + BeaconNetworkApi, Discv5Api, EthApi, HistoryNetworkApi, Web3Api, }; use ethportal_api::{ + types::jsonrpc::request::{BeaconJsonRpcRequest, HistoryJsonRpcRequest, StateJsonRpcRequest}, BeaconNetworkApiServer, Discv5ApiServer, EthApiServer, HistoryNetworkApiServer, Web3ApiServer, }; use portalnet::discovery::Discovery; use serde::Deserialize; -use std::collections::{HashMap, HashSet}; -use std::fmt; -use std::sync::Arc; +use std::{ + collections::{HashMap, HashSet}, + fmt, + sync::Arc, +}; use strum::{AsRefStr, EnumString, EnumVariantNames, VariantNames}; use tokio::sync::mpsc; diff --git a/rpc/src/discv5_rpc.rs b/rpc/src/discv5_rpc.rs index d73af7084..1830e06ed 100644 --- a/rpc/src/discv5_rpc.rs +++ b/rpc/src/discv5_rpc.rs @@ -2,9 +2,7 @@ use crate::errors::RpcServeError; use crate::jsonrpsee::core::{async_trait, RpcResult}; use discv5::enr::NodeId; -use ethportal_api::types::enr::Enr; -use ethportal_api::Discv5ApiServer; -use ethportal_api::{NodeInfo, RoutingTableInfo}; +use ethportal_api::{types::enr::Enr, Discv5ApiServer, NodeInfo, RoutingTableInfo}; use portalnet::discovery::Discovery; use std::sync::Arc; diff --git a/rpc/src/errors.rs b/rpc/src/errors.rs index e91837672..9c3bcc4e8 100644 --- a/rpc/src/errors.rs +++ b/rpc/src/errors.rs @@ -1,7 +1,11 @@ -use crate::jsonrpsee::core::Error as JsonRpseeError; -use crate::jsonrpsee::types::{ErrorObject, ErrorObjectOwned}; -use crate::rpc_server::ServerKind; -use crate::PortalRpcModule; +use crate::{ + jsonrpsee::{ + core::Error as JsonRpseeError, + types::{ErrorObject, ErrorObjectOwned}, + }, + rpc_server::ServerKind, + PortalRpcModule, +}; use std::io; /// Rpc Errors. diff --git a/rpc/src/eth_rpc.rs b/rpc/src/eth_rpc.rs index 270dc507c..e46f9139d 100644 --- a/rpc/src/eth_rpc.rs +++ b/rpc/src/eth_rpc.rs @@ -2,14 +2,17 @@ use ethereum_types::{H256, U256}; use reth_rpc_types::{Block, BlockTransactions}; use tokio::sync::mpsc; -use ethportal_api::types::execution::block_body::BlockBody; -use ethportal_api::types::jsonrpc::request::HistoryJsonRpcRequest; -use ethportal_api::EthApiServer; +use ethportal_api::{ + types::{execution::block_body::BlockBody, jsonrpc::request::HistoryJsonRpcRequest}, + EthApiServer, +}; use trin_validation::constants::CHAIN_ID; -use crate::errors::RpcServeError; -use crate::fetch::{find_block_body_by_hash, find_header_by_hash}; -use crate::jsonrpsee::core::{async_trait, RpcResult}; +use crate::{ + errors::RpcServeError, + fetch::{find_block_body_by_hash, find_header_by_hash}, + jsonrpsee::core::{async_trait, RpcResult}, +}; pub struct EthApi { network: mpsc::UnboundedSender, diff --git a/rpc/src/fetch.rs b/rpc/src/fetch.rs index ca4a28e6e..803623c04 100644 --- a/rpc/src/fetch.rs +++ b/rpc/src/fetch.rs @@ -3,13 +3,15 @@ use ethereum_types::H256; use serde_json::Value; use tokio::sync::mpsc; -use ethportal_api::types::constants::CONTENT_ABSENT; -use ethportal_api::types::execution::block_body::BlockBody; -use ethportal_api::types::execution::header::Header; -use ethportal_api::types::jsonrpc::endpoints::HistoryEndpoint; -use ethportal_api::types::jsonrpc::request::HistoryJsonRpcRequest; -use ethportal_api::utils::bytes::hex_decode; -use ethportal_api::{ContentValue, HistoryContentKey, HistoryContentValue}; +use ethportal_api::{ + types::{ + constants::CONTENT_ABSENT, + execution::{block_body::BlockBody, header::Header}, + jsonrpc::{endpoints::HistoryEndpoint, request::HistoryJsonRpcRequest}, + }, + utils::bytes::hex_decode, + ContentValue, HistoryContentKey, HistoryContentValue, +}; use crate::errors::RpcServeError; diff --git a/rpc/src/history_rpc.rs b/rpc/src/history_rpc.rs index 9c40b6324..ac3ac1313 100644 --- a/rpc/src/history_rpc.rs +++ b/rpc/src/history_rpc.rs @@ -1,21 +1,20 @@ -use crate::fetch::proxy_query_to_history_subnet; -use crate::serde::from_value; +use crate::{fetch::proxy_query_to_history_subnet, serde::from_value}; use crate::jsonrpsee::core::{async_trait, RpcResult}; use discv5::enr::NodeId; -use ethportal_api::types::constants::CONTENT_ABSENT; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::jsonrpc::endpoints::HistoryEndpoint; -use ethportal_api::types::jsonrpc::request::HistoryJsonRpcRequest; -use ethportal_api::types::portal::{ - AcceptInfo, ContentInfo, DataRadius, FindNodesInfo, PaginateLocalContentInfo, PongInfo, - TraceContentInfo, TraceGossipInfo, +use ethportal_api::{ + types::{ + constants::CONTENT_ABSENT, + enr::Enr, + jsonrpc::{endpoints::HistoryEndpoint, request::HistoryJsonRpcRequest}, + portal::{ + AcceptInfo, ContentInfo, DataRadius, FindNodesInfo, PaginateLocalContentInfo, PongInfo, + TraceContentInfo, TraceGossipInfo, + }, + }, + HistoryContentKey, HistoryContentValue, HistoryNetworkApiServer, PossibleHistoryContentValue, + RoutingTableInfo, }; -use ethportal_api::HistoryContentKey; -use ethportal_api::HistoryContentValue; -use ethportal_api::HistoryNetworkApiServer; -use ethportal_api::PossibleHistoryContentValue; -use ethportal_api::RoutingTableInfo; use tokio::sync::mpsc; pub struct HistoryNetworkApi { diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index b3ab5a327..9b1d11c68 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -20,12 +20,12 @@ pub use builder::{PortalRpcModule, RpcModuleBuilder, TransportRpcModuleConfig}; use discv5_rpc::Discv5Api; use errors::RpcError; use eth_rpc::EthApi; -use ethportal_api::jsonrpsee; -use ethportal_api::types::cli::{ - TrinConfig, Web3TransportType, BEACON_NETWORK, HISTORY_NETWORK, STATE_NETWORK, -}; -use ethportal_api::types::jsonrpc::request::{ - BeaconJsonRpcRequest, HistoryJsonRpcRequest, StateJsonRpcRequest, +use ethportal_api::{ + jsonrpsee, + types::{ + cli::{TrinConfig, Web3TransportType, BEACON_NETWORK, HISTORY_NETWORK, STATE_NETWORK}, + jsonrpc::request::{BeaconJsonRpcRequest, HistoryJsonRpcRequest, StateJsonRpcRequest}, + }, }; use history_rpc::HistoryNetworkApi; use web3_rpc::Web3Api; @@ -33,8 +33,10 @@ use web3_rpc::Web3Api; use crate::rpc_server::RpcServerConfig; use portalnet::discovery::Discovery; use reth_ipc::server::Builder as IpcServerBuilder; -use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; -use std::sync::Arc; +use std::{ + net::{Ipv4Addr, SocketAddr, SocketAddrV4}, + sync::Arc, +}; use tokio::sync::mpsc; pub async fn launch_jsonrpc_server( diff --git a/rpc/src/rpc_server.rs b/rpc/src/rpc_server.rs index f9d7a1a77..c091c0d71 100644 --- a/rpc/src/rpc_server.rs +++ b/rpc/src/rpc_server.rs @@ -1,18 +1,23 @@ -use crate::builder::TransportRpcModules; -use crate::cors; -use crate::errors::WsHttpSamePortError; -use crate::jsonrpsee::http_client::{HttpClient, HttpClientBuilder}; -use crate::jsonrpsee::server::{IdProvider, Server, ServerBuilder, ServerHandle}; -use crate::jsonrpsee::ws_client::{WsClient, WsClientBuilder}; -use crate::jsonrpsee::RpcModule; -use crate::{RpcError, TransportRpcModuleConfig}; +use crate::{ + builder::TransportRpcModules, + cors, + errors::WsHttpSamePortError, + jsonrpsee::{ + http_client::{HttpClient, HttpClientBuilder}, + server::{IdProvider, Server, ServerBuilder, ServerHandle}, + ws_client::{WsClient, WsClientBuilder}, + RpcModule, + }, + RpcError, TransportRpcModuleConfig, +}; use ethportal_api::types::cli::{ DEFAULT_WEB3_HTTP_PORT, DEFAULT_WEB3_IPC_PATH, DEFAULT_WEB3_WS_PORT, }; -use reth_ipc::server::Builder as IpcServerBuilder; -use reth_ipc::server::{Endpoint, IpcServer}; -use std::fmt; -use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; +use reth_ipc::server::{Builder as IpcServerBuilder, Endpoint, IpcServer}; +use std::{ + fmt, + net::{Ipv4Addr, SocketAddr, SocketAddrV4}, +}; use tower::layer::util::{Identity, Stack}; use tower_http::cors::CorsLayer; use tracing::instrument; @@ -609,12 +614,9 @@ impl WsHttpServerKind { #[allow(clippy::unwrap_used)] mod tests { use super::*; - use crate::builder::RpcModuleSelection; - use crate::{PortalRpcModule, RpcModuleBuilder}; - use portalnet::discovery::Discovery; - use portalnet::utils::db::setup_temp_dir; - use std::io; - use std::sync::Arc; + use crate::{builder::RpcModuleSelection, PortalRpcModule, RpcModuleBuilder}; + use portalnet::{discovery::Discovery, utils::db::setup_temp_dir}; + use std::{io, sync::Arc}; /// Localhost with port 0 so a free port is used. pub fn test_address() -> SocketAddr { diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 000000000..c3c8c3753 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +imports_granularity = "Crate" diff --git a/src/bin/purge_db.rs b/src/bin/purge_db.rs index 038c489d7..a5a25b9dc 100644 --- a/src/bin/purge_db.rs +++ b/src/bin/purge_db.rs @@ -6,15 +6,21 @@ use rocksdb::IteratorMode; use ssz::Decode; use tracing::{info, warn}; -use ethportal_api::types::execution::accumulator::EpochAccumulator; -use ethportal_api::types::execution::block_body::BlockBody; -use ethportal_api::types::execution::header::HeaderWithProof; -use ethportal_api::types::execution::receipts::Receipts; -use ethportal_api::types::portal_wire::ProtocolId; -use ethportal_api::utils::bytes::hex_encode; -use ethportal_api::HistoryContentKey; -use portalnet::storage::{PortalStorage, PortalStorageConfig}; -use portalnet::utils::db::{configure_node_data_dir, configure_trin_data_dir}; +use ethportal_api::{ + types::{ + execution::{ + accumulator::EpochAccumulator, block_body::BlockBody, header::HeaderWithProof, + receipts::Receipts, + }, + portal_wire::ProtocolId, + }, + utils::bytes::hex_encode, + HistoryContentKey, +}; +use portalnet::{ + storage::{PortalStorage, PortalStorageConfig}, + utils::db::{configure_node_data_dir, configure_trin_data_dir}, +}; use trin_utils::log::init_tracing_logger; /// diff --git a/src/lib.rs b/src/lib.rs index 20378c78b..23535e8c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,8 +4,7 @@ use std::sync::Arc; use rpc::{launch_jsonrpc_server, RpcServerHandle}; -use tokio::sync::mpsc; -use tokio::sync::RwLock; +use tokio::sync::{mpsc, RwLock}; use tracing::info; use utp_rs::socket::UtpSocket; diff --git a/tests/rpc_server.rs b/tests/rpc_server.rs index 93294d452..862ed2dea 100644 --- a/tests/rpc_server.rs +++ b/tests/rpc_server.rs @@ -10,11 +10,14 @@ use serde_yaml::Value; use serial_test::serial; use ssz::Decode; -use ethportal_api::types::cli::{TrinConfig, DEFAULT_WEB3_IPC_PATH}; -use ethportal_api::types::execution::block_body::BlockBody; -use ethportal_api::types::execution::header::HeaderWithProof; -use ethportal_api::utils::bytes::{hex_decode, hex_encode}; -use ethportal_api::{HistoryContentKey, HistoryContentValue, HistoryNetworkApiClient}; +use ethportal_api::{ + types::{ + cli::{TrinConfig, DEFAULT_WEB3_IPC_PATH}, + execution::{block_body::BlockBody, header::HeaderWithProof}, + }, + utils::bytes::{hex_decode, hex_encode}, + HistoryContentKey, HistoryContentValue, HistoryNetworkApiClient, +}; use rpc::RpcServerHandle; mod utils; diff --git a/tests/self_peertest.rs b/tests/self_peertest.rs index 9304511cc..f645b12a4 100644 --- a/tests/self_peertest.rs +++ b/tests/self_peertest.rs @@ -1,13 +1,14 @@ #![cfg(unix)] use rpc::RpcServerHandle; -use std::env; -use std::net::{IpAddr, Ipv4Addr}; +use std::{ + env, + net::{IpAddr, Ipv4Addr}, +}; use ethportal_api::types::cli::{TrinConfig, DEFAULT_WEB3_HTTP_ADDRESS, DEFAULT_WEB3_IPC_PATH}; use ethportal_peertest as peertest; use ethportal_peertest::Peertest; -use jsonrpsee::async_client::Client; -use jsonrpsee::http_client::HttpClient; +use jsonrpsee::{async_client::Client, http_client::HttpClient}; use serial_test::serial; use tokio::time::{sleep, Duration}; diff --git a/trin-beacon/src/jsonrpc.rs b/trin-beacon/src/jsonrpc.rs index f9a7d97f3..49b9b8ef4 100644 --- a/trin-beacon/src/jsonrpc.rs +++ b/trin-beacon/src/jsonrpc.rs @@ -1,17 +1,19 @@ use std::sync::Arc; use discv5::enr::NodeId; -use ethportal_api::types::content_value::ContentValue; -use ethportal_api::types::distance::Distance; -use ethportal_api::types::jsonrpc::endpoints::BeaconEndpoint; -use ethportal_api::types::jsonrpc::request::BeaconJsonRpcRequest; -use ethportal_api::types::portal::{ - AcceptInfo, ContentInfo, FindNodesInfo, PongInfo, TraceContentInfo, +use ethportal_api::{ + types::{ + constants::CONTENT_ABSENT, + content_value::ContentValue, + distance::Distance, + jsonrpc::{endpoints::BeaconEndpoint, request::BeaconJsonRpcRequest}, + portal::{AcceptInfo, ContentInfo, FindNodesInfo, PongInfo, TraceContentInfo}, + portal_wire::Content, + query_trace::QueryTrace, + }, + utils::bytes::hex_encode, + BeaconContentKey, BeaconContentValue, OverlayContentKey, RawContentKey, }; -use ethportal_api::types::portal_wire::Content; -use ethportal_api::types::{constants::CONTENT_ABSENT, query_trace::QueryTrace}; -use ethportal_api::utils::bytes::hex_encode; -use ethportal_api::{BeaconContentKey, BeaconContentValue, OverlayContentKey, RawContentKey}; use portalnet::storage::ContentStore; use serde_json::{json, Value}; use ssz::Encode; diff --git a/trin-beacon/src/lib.rs b/trin-beacon/src/lib.rs index 5830a0143..4783a647f 100644 --- a/trin-beacon/src/lib.rs +++ b/trin-beacon/src/lib.rs @@ -17,10 +17,8 @@ use tokio::{ use tracing::info; use utp_rs::socket::UtpSocket; -use crate::network::BeaconNetwork; -use crate::{events::BeaconEvents, jsonrpc::BeaconRequestHandler}; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::jsonrpc::request::BeaconJsonRpcRequest; +use crate::{events::BeaconEvents, jsonrpc::BeaconRequestHandler, network::BeaconNetwork}; +use ethportal_api::types::{enr::Enr, jsonrpc::request::BeaconJsonRpcRequest}; use portalnet::{ config::PortalnetConfig, discovery::{Discovery, UtpEnr}, diff --git a/trin-beacon/src/network.rs b/trin-beacon/src/network.rs index c4c32c344..8cc62bf91 100644 --- a/trin-beacon/src/network.rs +++ b/trin-beacon/src/network.rs @@ -4,12 +4,11 @@ use parking_lot::RwLock as PLRwLock; use tokio::sync::RwLock; use utp_rs::socket::UtpSocket; -use crate::sync::BeaconSync; -use crate::validation::BeaconValidator; -use ethportal_api::types::distance::XorMetric; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::portal_wire::ProtocolId; -use ethportal_api::BeaconContentKey; +use crate::{sync::BeaconSync, validation::BeaconValidator}; +use ethportal_api::{ + types::{distance::XorMetric, enr::Enr, portal_wire::ProtocolId}, + BeaconContentKey, +}; use portalnet::{ config::PortalnetConfig, discovery::{Discovery, UtpEnr}, diff --git a/trin-beacon/src/sync.rs b/trin-beacon/src/sync.rs index dde279df8..9019390c9 100644 --- a/trin-beacon/src/sync.rs +++ b/trin-beacon/src/sync.rs @@ -1,8 +1,8 @@ use ethportal_api::BeaconContentKey; -use light_client::config::networks; -use light_client::consensus::rpc::portal_rpc::PortalRpc; -use light_client::database::FileDB; -use light_client::{Client, ClientBuilder}; +use light_client::{ + config::networks, consensus::rpc::portal_rpc::PortalRpc, database::FileDB, Client, + ClientBuilder, +}; use portalnet::overlay_service::OverlayCommand; use std::path::PathBuf; use tokio::sync::mpsc::UnboundedSender; diff --git a/trin-history/src/jsonrpc.rs b/trin-history/src/jsonrpc.rs index 9528b56b4..176883eaf 100644 --- a/trin-history/src/jsonrpc.rs +++ b/trin-history/src/jsonrpc.rs @@ -1,15 +1,17 @@ use std::sync::Arc; use discv5::enr::NodeId; -use ethportal_api::types::portal_wire::Content; -use ethportal_api::types::{ - constants::CONTENT_ABSENT, distance::Distance, jsonrpc::endpoints::HistoryEndpoint, - jsonrpc::request::HistoryJsonRpcRequest, query_trace::QueryTrace, -}; -use ethportal_api::utils::bytes::hex_encode; use ethportal_api::{ - types::portal::{AcceptInfo, ContentInfo, FindNodesInfo, PongInfo, TraceContentInfo}, - ContentValue, {HistoryContentKey, OverlayContentKey, RawContentKey}, + types::{ + constants::CONTENT_ABSENT, + distance::Distance, + jsonrpc::{endpoints::HistoryEndpoint, request::HistoryJsonRpcRequest}, + portal::{AcceptInfo, ContentInfo, FindNodesInfo, PongInfo, TraceContentInfo}, + portal_wire::Content, + query_trace::QueryTrace, + }, + utils::bytes::hex_encode, + ContentValue, HistoryContentKey, OverlayContentKey, RawContentKey, }; use portalnet::storage::ContentStore; use serde_json::{json, Value}; diff --git a/trin-history/src/lib.rs b/trin-history/src/lib.rs index 4263fd299..fb28fc9da 100644 --- a/trin-history/src/lib.rs +++ b/trin-history/src/lib.rs @@ -19,8 +19,7 @@ use tracing::info; use utp_rs::socket::UtpSocket; use crate::{events::HistoryEvents, jsonrpc::HistoryRequestHandler}; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::jsonrpc::request::HistoryJsonRpcRequest; +use ethportal_api::types::{enr::Enr, jsonrpc::request::HistoryJsonRpcRequest}; use portalnet::{ config::PortalnetConfig, discovery::{Discovery, UtpEnr}, diff --git a/trin-history/src/network.rs b/trin-history/src/network.rs index 6d043c2fd..13d87408d 100644 --- a/trin-history/src/network.rs +++ b/trin-history/src/network.rs @@ -4,10 +4,10 @@ use parking_lot::RwLock as PLRwLock; use tokio::sync::RwLock; use utp_rs::socket::UtpSocket; -use ethportal_api::types::distance::XorMetric; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::portal_wire::ProtocolId; -use ethportal_api::HistoryContentKey; +use ethportal_api::{ + types::{distance::XorMetric, enr::Enr, portal_wire::ProtocolId}, + HistoryContentKey, +}; use portalnet::{ config::PortalnetConfig, discovery::{Discovery, UtpEnr}, diff --git a/trin-history/src/utils.rs b/trin-history/src/utils.rs index 74a2a076c..5535a9406 100644 --- a/trin-history/src/utils.rs +++ b/trin-history/src/utils.rs @@ -5,9 +5,10 @@ use discv5::{ use serde_json::{json, Value}; use std::collections::BTreeMap; -use ethportal_api::types::distance::Distance; -use ethportal_api::types::enr::Enr; -use ethportal_api::utils::bytes::hex_encode; +use ethportal_api::{ + types::{distance::Distance, enr::Enr}, + utils::bytes::hex_encode, +}; type NodeMap = BTreeMap; type NodeTuple = (NodeId, Enr, NodeStatus, Distance, Option); diff --git a/trin-history/src/validation.rs b/trin-history/src/validation.rs index dc009e84b..56007ba08 100644 --- a/trin-history/src/validation.rs +++ b/trin-history/src/validation.rs @@ -7,13 +7,16 @@ use ssz::Decode; use tokio::sync::RwLock; use tree_hash::TreeHash; -use ethportal_api::types::execution::{ - accumulator::EpochAccumulator, - block_body::BlockBody, - header::{Header, HeaderWithProof}, - receipts::Receipts, +use ethportal_api::{ + types::execution::{ + accumulator::EpochAccumulator, + block_body::BlockBody, + header::{Header, HeaderWithProof}, + receipts::Receipts, + }, + utils::bytes::hex_encode, + HistoryContentKey, }; -use ethportal_api::{utils::bytes::hex_encode, HistoryContentKey}; use trin_validation::{oracle::HeaderOracle, validator::Validator}; pub struct ChainHistoryValidator { @@ -128,17 +131,17 @@ impl Validator for ChainHistoryValidator { #[allow(clippy::unwrap_used)] mod tests { use super::*; - use std::fs; - use std::path::PathBuf; + use std::{fs, path::PathBuf}; use ethereum_types::U256; use serde_json::Value; use ssz::Encode; - use ethportal_api::types::cli::DEFAULT_MASTER_ACC_PATH; - use ethportal_api::types::execution::accumulator::HeaderRecord; - use ethportal_api::utils::bytes::hex_decode; - use ethportal_api::{BlockHeaderKey, EpochAccumulatorKey}; + use ethportal_api::{ + types::{cli::DEFAULT_MASTER_ACC_PATH, execution::accumulator::HeaderRecord}, + utils::bytes::hex_decode, + BlockHeaderKey, EpochAccumulatorKey, + }; use trin_validation::accumulator::MasterAccumulator; fn get_hwp_ssz() -> Vec { diff --git a/trin-metrics/src/portalnet.rs b/trin-metrics/src/portalnet.rs index 24662810a..ad7a149b3 100644 --- a/trin-metrics/src/portalnet.rs +++ b/trin-metrics/src/portalnet.rs @@ -1,5 +1,4 @@ -use crate::overlay::OverlayMetrics; -use crate::storage::StorageMetrics; +use crate::{overlay::OverlayMetrics, storage::StorageMetrics}; use lazy_static::lazy_static; use prometheus_exporter::prometheus::default_registry; diff --git a/trin-state/src/lib.rs b/trin-state/src/lib.rs index dddd13577..d374c27be 100644 --- a/trin-state/src/lib.rs +++ b/trin-state/src/lib.rs @@ -12,8 +12,7 @@ use tracing::info; use utp_rs::socket::UtpSocket; use crate::{events::StateEvents, jsonrpc::StateRequestHandler}; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::jsonrpc::request::StateJsonRpcRequest; +use ethportal_api::types::{enr::Enr, jsonrpc::request::StateJsonRpcRequest}; use portalnet::{ config::PortalnetConfig, discovery::{Discovery, UtpEnr}, diff --git a/trin-state/src/network.rs b/trin-state/src/network.rs index d8ecd17e5..43c6764bf 100644 --- a/trin-state/src/network.rs +++ b/trin-state/src/network.rs @@ -5,10 +5,10 @@ use parking_lot::RwLock as PLRwLock; use tokio::sync::RwLock; use utp_rs::socket::UtpSocket; -use ethportal_api::types::distance::XorMetric; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::portal_wire::ProtocolId; -use ethportal_api::StateContentKey; +use ethportal_api::{ + types::{distance::XorMetric, enr::Enr, portal_wire::ProtocolId}, + StateContentKey, +}; use portalnet::{ config::PortalnetConfig, discovery::{Discovery, UtpEnr}, diff --git a/trin-utils/build.rs b/trin-utils/build.rs index 79778c4e2..22b2606b0 100644 --- a/trin-utils/build.rs +++ b/trin-utils/build.rs @@ -1,5 +1,4 @@ -use std::env; -use std::process::Command; +use std::{env, process::Command}; fn main() { let output = Command::new("git") diff --git a/trin-validation/src/accumulator.rs b/trin-validation/src/accumulator.rs index e51d54095..b04bd60c8 100644 --- a/trin-validation/src/accumulator.rs +++ b/trin-validation/src/accumulator.rs @@ -16,12 +16,17 @@ use crate::{ constants::{EPOCH_SIZE, MERGE_BLOCK_NUMBER}, merkle::proof::{verify_merkle_proof, MerkleTree}, }; -use ethportal_api::types::execution::accumulator::EpochAccumulator; -use ethportal_api::types::execution::header::{BlockHeaderProof, Header, HeaderWithProof}; -use ethportal_api::types::jsonrpc::endpoints::HistoryEndpoint; -use ethportal_api::types::jsonrpc::request::HistoryJsonRpcRequest; -use ethportal_api::utils::bytes::hex_decode; -use ethportal_api::{EpochAccumulatorKey, HistoryContentKey}; +use ethportal_api::{ + types::{ + execution::{ + accumulator::EpochAccumulator, + header::{BlockHeaderProof, Header, HeaderWithProof}, + }, + jsonrpc::{endpoints::HistoryEndpoint, request::HistoryJsonRpcRequest}, + }, + utils::bytes::hex_decode, + EpochAccumulatorKey, HistoryContentKey, +}; /// SSZ List[Hash256, max_length = MAX_HISTORICAL_EPOCHS] /// List of historical epoch accumulator merkle roots preceding current epoch. @@ -239,8 +244,7 @@ fn calculate_generalized_index(header: &Header) -> usize { #[allow(clippy::unwrap_used)] mod test { use super::*; - use std::fs; - use std::str::FromStr; + use std::{fs, str::FromStr}; use ethereum_types::{Bloom, H160, U256}; use rstest::*; @@ -248,10 +252,10 @@ mod test { use ssz::Decode; use crate::constants::DEFAULT_MASTER_ACC_HASH; - use ethportal_api::types::execution::header::{ - AccumulatorProof, BlockHeaderProof, HeaderWithProof, SszNone, + use ethportal_api::{ + types::execution::header::{AccumulatorProof, BlockHeaderProof, HeaderWithProof, SszNone}, + utils::bytes::hex_encode, }; - use ethportal_api::utils::bytes::hex_encode; #[rstest] #[case(1_000_001)] diff --git a/trin-validation/src/oracle.rs b/trin-validation/src/oracle.rs index 7c167fd01..9d04854b7 100644 --- a/trin-validation/src/oracle.rs +++ b/trin-validation/src/oracle.rs @@ -4,11 +4,15 @@ use serde_json::Value; use tokio::sync::mpsc; use crate::accumulator::MasterAccumulator; -use ethportal_api::types::execution::header::HeaderWithProof; -use ethportal_api::types::jsonrpc::endpoints::HistoryEndpoint; -use ethportal_api::types::jsonrpc::request::{BeaconJsonRpcRequest, HistoryJsonRpcRequest}; -use ethportal_api::types::portal::ContentInfo; use ethportal_api::{ + types::{ + execution::header::HeaderWithProof, + jsonrpc::{ + endpoints::HistoryEndpoint, + request::{BeaconJsonRpcRequest, HistoryJsonRpcRequest}, + }, + portal::ContentInfo, + }, BlockHeaderKey, HistoryContentKey, HistoryContentValue, PossibleHistoryContentValue, }; diff --git a/utp-testing/src/bin/test_app.rs b/utp-testing/src/bin/test_app.rs index 2d1cdec7f..7a32b6f4e 100644 --- a/utp-testing/src/bin/test_app.rs +++ b/utp-testing/src/bin/test_app.rs @@ -1,6 +1,5 @@ use clap::Parser; -use std::net::SocketAddr; -use std::str::FromStr; +use std::{net::SocketAddr, str::FromStr}; use tracing::info; use trin_utils::log::init_tracing_logger; use utp_testing::run_test_app; diff --git a/utp-testing/src/bin/test_suite.rs b/utp-testing/src/bin/test_suite.rs index b4b4bd887..0e2b73a74 100644 --- a/utp-testing/src/bin/test_suite.rs +++ b/utp-testing/src/bin/test_suite.rs @@ -1,6 +1,4 @@ -use jsonrpsee::core::client::ClientT; -use jsonrpsee::http_client::HttpClientBuilder; -use jsonrpsee::rpc_params; +use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params}; use rand::{thread_rng, Rng}; use std::time::Duration; diff --git a/utp-testing/src/lib.rs b/utp-testing/src/lib.rs index 81cc1666b..723712d76 100644 --- a/utp-testing/src/lib.rs +++ b/utp-testing/src/lib.rs @@ -7,21 +7,22 @@ pub mod rpc; use crate::rpc::RpcServer; use discv5::TalkRequest; -use ethportal_api::types::enr::Enr; -use ethportal_api::types::portal_wire::ProtocolId; -use ethportal_api::utils::bytes::{hex_encode, hex_encode_upper}; -use jsonrpsee::core::{async_trait, RpcResult}; -use jsonrpsee::proc_macros::rpc; -use jsonrpsee::server::{Server, ServerHandle}; -use portalnet::config::PortalnetConfig; -use portalnet::discovery::{Discovery, UtpEnr}; -use portalnet::utils::db::setup_temp_dir; -use std::net::SocketAddr; -use std::str::FromStr; -use std::sync::Arc; -use std::time::Duration; -use tokio::sync::mpsc; -use tokio::sync::RwLock; +use ethportal_api::{ + types::{enr::Enr, portal_wire::ProtocolId}, + utils::bytes::{hex_encode, hex_encode_upper}, +}; +use jsonrpsee::{ + core::{async_trait, RpcResult}, + proc_macros::rpc, + server::{Server, ServerHandle}, +}; +use portalnet::{ + config::PortalnetConfig, + discovery::{Discovery, UtpEnr}, + utils::db::setup_temp_dir, +}; +use std::{net::SocketAddr, str::FromStr, sync::Arc, time::Duration}; +use tokio::sync::{mpsc, RwLock}; use utp_rs::{conn::ConnectionConfig, socket::UtpSocket}; /// uTP test app From 0548911fbcac502e08eed4681694720608c0e377 Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Mon, 25 Dec 2023 20:34:09 +0800 Subject: [PATCH 02/11] fix: use regular nightly image --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index deea3bedb..abb4fc37e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -51,7 +51,7 @@ executors: - image: cimg/rust:1.71.1 docker-nightly: docker: - - image: rustlang/rust:nightly-slim + - image: rustlang/rust:nightly jobs: docker-build: resource_class: xlarge From a8565fe064937e3456383329c139dafcaebedfad Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Mon, 25 Dec 2023 20:42:43 +0800 Subject: [PATCH 03/11] fix: add +nightly to rust fmt commands --- Makefile | 6 +++--- book/src/developers/contributing/git/pull_requests.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 4d8136ef7..f47921a14 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,13 @@ help: @echo "create-docker-image - create docker image" @echo "push-docker-image - push docker image" -lint: +lint: cargo clippy --all --all-targets --all-features --no-deps -- --deny warnings - cargo fmt --all -- --check + cargo +nightly fmt --all -- --check lint-unstable: cargo clippy --all --all-targets --all-features --no-deps -- -Wclippy::cargo - cargo fmt --all -- --check + cargo +nightly fmt --all -- --check RUSTFLAGS="-W unused_crate_dependencies" cargo build create-docker-image: diff --git a/book/src/developers/contributing/git/pull_requests.md b/book/src/developers/contributing/git/pull_requests.md index 4e582634b..0abe218c1 100644 --- a/book/src/developers/contributing/git/pull_requests.md +++ b/book/src/developers/contributing/git/pull_requests.md @@ -9,7 +9,7 @@ through github via pull requests. * Mark unfinished pull requests with the "Work in Progress" label. * Before submitting a pr for review, you should run the following commands locally and make sure they are passing, otherwise CI will raise an error. - * `cargo fmt --all -- --check` and `cargo clippy --all --all-targets --all-features -- --deny warnings` for linting checks + * `cargo +nightly fmt --all -- --check` and `cargo clippy --all --all-targets --all-features -- --deny warnings` for linting checks * `RUSTFLAGS='-D warnings' cargo test --workspace` to run all tests * Pull requests **should** always be reviewed by another member of the team prior to being merged. From 4c7f4cc1514e43769fd0ea0eb26237eb8d9e8281 Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Thu, 4 Jan 2024 10:43:14 +0800 Subject: [PATCH 04/11] fix: try remove sudo for nightly image --- .circleci/config.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index abb4fc37e..b2f251b07 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -40,6 +40,17 @@ commands: - run: name: Install libclang for rocksdb command: sudo apt install clang + install-depends-nightly: + steps: + - run: + name: Prepare for apt upgrades + command: apt update + - run: + name: Install libssl-dev for openssl-sys + command: apt install -y libssl-dev + - run: + name: Install libclang for rocksdb + command: apt install clang orbs: rust: circleci/rust@1.6.0 win: circleci/windows@5.0 @@ -131,7 +142,7 @@ jobs: RUST_LOG: "debug" steps: - checkout - - install-depends + - install-depends-nightly - run: name: Run rustfmt command: cargo +nightly fmt --all -- --check From 62a183b8969ef5aaf255ea3e2bbd47dae63a71e2 Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Thu, 4 Jan 2024 10:47:39 +0800 Subject: [PATCH 05/11] fix: ci apt install clang with yes flag --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b2f251b07..9b841da5f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -50,7 +50,7 @@ commands: command: apt install -y libssl-dev - run: name: Install libclang for rocksdb - command: apt install clang + command: apt install -y clang orbs: rust: circleci/rust@1.6.0 win: circleci/windows@5.0 From d61aa0d04cdbf87948ce5dc868add6bc61ee39a2 Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Thu, 4 Jan 2024 11:00:06 +0800 Subject: [PATCH 06/11] fix: add rust-toolchain --- rust-toolchain | 1 + 1 file changed, 1 insertion(+) create mode 100644 rust-toolchain diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 000000000..07ade694b --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly \ No newline at end of file From 1a6f8d136c8b730495207129b5b91c1f2b65a672 Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Thu, 4 Jan 2024 11:19:43 +0800 Subject: [PATCH 07/11] fix: clippy error after using nightly --- ethportal-api/src/types/portal_wire.rs | 7 +++---- portalnet/src/gossip.rs | 3 ++- portalnet/src/overlay.rs | 2 +- portalnet/src/storage.rs | 2 +- trin-validation/src/merkle/proof.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ethportal-api/src/types/portal_wire.rs b/ethportal-api/src/types/portal_wire.rs index f8ec2754f..6bc7be9e2 100644 --- a/ethportal-api/src/types/portal_wire.rs +++ b/ethportal-api/src/types/portal_wire.rs @@ -86,10 +86,9 @@ impl TryFrom<&Value> for CustomPayload { "Unable to decode hex payload into bytes", ))?, }; - match ByteList::try_from(payload) { - Ok(payload) => Ok(Self { payload }), - Err(_) => Err(ValidationError::new("Invalid custom payload value")), - } + Ok(Self { + payload: ByteList::from(payload), + }) } } diff --git a/portalnet/src/gossip.rs b/portalnet/src/gossip.rs index a6633acab..c59e0a8ed 100644 --- a/portalnet/src/gossip.rs +++ b/portalnet/src/gossip.rs @@ -196,13 +196,14 @@ pub async fn trace_propagate_gossip_cross_thread /// Filter all nodes from overlay routing table where XOR_distance(content_id, nodeId) < node radius fn calculate_interested_enrs( content_key: &TContentKey, - all_nodes: &Vec<&kbucket::Node>, + all_nodes: &[&kbucket::Node], ) -> Vec { // HashMap to temporarily store all interested ENRs and the content. // Key is base64 string of node's ENR. // Filter all nodes from overlay routing table where XOR_distance(content_id, nodeId) < node radius let mut interested_enrs: Vec = all_nodes + .to_owned() .clone() .into_iter() .filter(|node| { diff --git a/portalnet/src/overlay.rs b/portalnet/src/overlay.rs index 3648ccbdd..86227636e 100644 --- a/portalnet/src/overlay.rs +++ b/portalnet/src/overlay.rs @@ -788,7 +788,7 @@ where } } -fn validate_find_nodes_distances(distances: &Vec) -> Result<(), OverlayRequestError> { +fn validate_find_nodes_distances(distances: &[u16]) -> Result<(), OverlayRequestError> { if distances.is_empty() { return Err(OverlayRequestError::InvalidRequest( "Invalid distances: Empty list".to_string(), diff --git a/portalnet/src/storage.rs b/portalnet/src/storage.rs index 3817d3d30..02d5d83c9 100644 --- a/portalnet/src/storage.rs +++ b/portalnet/src/storage.rs @@ -571,7 +571,7 @@ impl PortalStorage { &self, content_id: &[u8; 32], content_key: &String, - value: &Vec, + value: &[u8], ) -> Result<(), ContentStoreError> { let content_id_as_u32: u32 = Self::byte_vector_to_u32(content_id.to_vec()); let value_size = value.len(); diff --git a/trin-validation/src/merkle/proof.rs b/trin-validation/src/merkle/proof.rs index 032f3a649..7eb97cffa 100644 --- a/trin-validation/src/merkle/proof.rs +++ b/trin-validation/src/merkle/proof.rs @@ -254,7 +254,7 @@ impl MerkleTree { if deposit_count == (0x1 << level) { return Ok(MerkleTree::Finalized( *finalized_branch - .get(0) + .first() .ok_or(MerkleTreeError::PleaseNotifyTheDevs)?, )); } From 0a93b3ec8d06b98064f7245b0412ab9c35df62a4 Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Thu, 4 Jan 2024 18:37:51 +0800 Subject: [PATCH 08/11] feat: add more rustfmt options --- ethportal-api/src/beacon.rs | 15 ++++---- ethportal-api/src/dashboard/grafana.rs | 8 ++-- ethportal-api/src/history.rs | 15 ++++---- ethportal-api/src/types/bootnodes.rs | 3 +- ethportal-api/src/types/execution/receipts.rs | 4 +- ethportal-api/src/types/query_trace.rs | 3 +- light-client/src/config/checkpoints.rs | 11 ++++-- portal-bridge/src/api/consensus.rs | 3 +- portal-bridge/src/bridge/beacon.rs | 9 +++-- portal-bridge/src/cli.rs | 3 +- portal-bridge/src/main.rs | 3 +- portal-bridge/src/pandaops.rs | 4 +- portal-bridge/src/types/full_header.rs | 4 +- portalnet/src/discovery.rs | 16 ++++---- portalnet/src/find/query_info.rs | 3 +- portalnet/src/gossip.rs | 6 ++- portalnet/src/overlay.rs | 4 +- portalnet/src/overlay_service.rs | 37 ++++++++++++------- portalnet/src/storage.rs | 13 ++++--- portalnet/src/utils/portal_wire.rs | 7 ++-- rpc/src/beacon_rpc.rs | 15 ++++---- rpc/src/history_rpc.rs | 15 ++++---- rustfmt.toml | 4 ++ src/bin/purge_db.rs | 4 +- trin-beacon/src/network.rs | 3 +- trin-history/src/network.rs | 3 +- trin-history/src/utils.rs | 3 +- trin-metrics/src/labels.rs | 3 +- trin-state/src/network.rs | 3 +- trin-validation/src/accumulator.rs | 6 +-- trin-validation/src/merkle/proof.rs | 4 +- trin-validation/src/merkle/safe_arith.rs | 1 - 32 files changed, 139 insertions(+), 96 deletions(-) diff --git a/ethportal-api/src/beacon.rs b/ethportal-api/src/beacon.rs index edfc8cb4d..ef1463f60 100644 --- a/ethportal-api/src/beacon.rs +++ b/ethportal-api/src/beacon.rs @@ -43,8 +43,8 @@ pub trait BeaconNetworkApi { #[method(name = "beaconPing")] async fn ping(&self, enr: Enr) -> RpcResult; - /// Send a FINDNODES request for nodes that fall within the given set of distances, to the designated - /// peer and wait for a response + /// Send a FINDNODES request for nodes that fall within the given set of distances, to the + /// designated peer and wait for a response #[method(name = "beaconFindNodes")] async fn find_nodes(&self, enr: Enr, distances: Vec) -> RpcResult; @@ -79,8 +79,8 @@ pub trait BeaconNetworkApi { limit: u64, ) -> RpcResult; - /// Send the provided content value to interested peers. Clients may choose to send to some or all peers. - /// Return the number of peers that the content was gossiped to. + /// Send the provided content value to interested peers. Clients may choose to send to some or + /// all peers. Return the number of peers that the content was gossiped to. #[method(name = "beaconGossip")] async fn gossip( &self, @@ -88,8 +88,8 @@ pub trait BeaconNetworkApi { content_value: BeaconContentValue, ) -> RpcResult; - /// Send the provided content value to interested peers. Clients may choose to send to some or all peers. - /// Return tracing info detailing the gossip propagation. + /// Send the provided content value to interested peers. Clients may choose to send to some or + /// all peers. Return tracing info detailing the gossip propagation. #[method(name = "beaconTraceGossip")] async fn trace_gossip( &self, @@ -98,7 +98,8 @@ pub trait BeaconNetworkApi { ) -> RpcResult; /// Send an OFFER request with given ContentKey, to the designated peer and wait for a response. - /// Returns the content keys bitlist upon successful content transmission or empty bitlist receive. + /// Returns the content keys bitlist upon successful content transmission or empty bitlist + /// receive. #[method(name = "beaconOffer")] async fn offer( &self, diff --git a/ethportal-api/src/dashboard/grafana.rs b/ethportal-api/src/dashboard/grafana.rs index b721b34b0..c0d7a4b03 100644 --- a/ethportal-api/src/dashboard/grafana.rs +++ b/ethportal-api/src/dashboard/grafana.rs @@ -62,7 +62,8 @@ impl GrafanaAPI { // If this is failing with a 409 error, it means that there is likely a problem with the // template, make sure that ... - // - All "uid" fields inside a prometheus datasource object contain `"uid": "{prometheus_id}"` + // - All "uid" fields inside a prometheus datasource object contain `"uid": + // "{prometheus_id}"` // - The root level `"id"` field is set to `null` (`"id": null`) // - The root level `"title"` field is set to "Trin Metrics" (`"title": "Trin Metrics"`) // - The root level `"uid"` field is set to "trin-metrics" (`"uid": "trin-metrics"`) @@ -85,8 +86,9 @@ impl GrafanaAPI { &template_string[..], [ ("prometheus_uid", prometheus_uid), - ("", "{}"), // The templating library picks up an empty json object as a placeholder, - // so replace it with another empty json object. + ("", "{}"), /* The templating library picks up an empty json object as a + * placeholder, so replace it with + * another empty json object. */ ], )?; Ok(populated_template) diff --git a/ethportal-api/src/history.rs b/ethportal-api/src/history.rs index c0cbbac3a..d665d02c8 100644 --- a/ethportal-api/src/history.rs +++ b/ethportal-api/src/history.rs @@ -43,8 +43,8 @@ pub trait HistoryNetworkApi { #[method(name = "historyPing")] async fn ping(&self, enr: Enr) -> RpcResult; - /// Send a FINDNODES request for nodes that fall within the given set of distances, to the designated - /// peer and wait for a response + /// Send a FINDNODES request for nodes that fall within the given set of distances, to the + /// designated peer and wait for a response #[method(name = "historyFindNodes")] async fn find_nodes(&self, enr: Enr, distances: Vec) -> RpcResult; @@ -82,8 +82,8 @@ pub trait HistoryNetworkApi { limit: u64, ) -> RpcResult; - /// Send the provided content value to interested peers. Clients may choose to send to some or all peers. - /// Return the number of peers that the content was gossiped to. + /// Send the provided content value to interested peers. Clients may choose to send to some or + /// all peers. Return the number of peers that the content was gossiped to. #[method(name = "historyGossip")] async fn gossip( &self, @@ -91,8 +91,8 @@ pub trait HistoryNetworkApi { content_value: HistoryContentValue, ) -> RpcResult; - /// Send the provided content value to interested peers. Clients may choose to send to some or all peers. - /// Return tracing info detailing the gossip propagation. + /// Send the provided content value to interested peers. Clients may choose to send to some or + /// all peers. Return tracing info detailing the gossip propagation. #[method(name = "historyTraceGossip")] async fn trace_gossip( &self, @@ -101,7 +101,8 @@ pub trait HistoryNetworkApi { ) -> RpcResult; /// Send an OFFER request with given ContentKey, to the designated peer and wait for a response. - /// Returns the content keys bitlist upon successful content transmission or empty bitlist receive. + /// Returns the content keys bitlist upon successful content transmission or empty bitlist + /// receive. #[method(name = "historyOffer")] async fn offer( &self, diff --git a/ethportal-api/src/types/bootnodes.rs b/ethportal-api/src/types/bootnodes.rs index fe84155e7..12aaccbbc 100644 --- a/ethportal-api/src/types/bootnodes.rs +++ b/ethportal-api/src/types/bootnodes.rs @@ -76,7 +76,8 @@ lazy_static! { pub enum Bootnodes { #[default] Default, - // use explicit None here instead of Option, since default value is DEFAULT_BOOTNODES + // use explicit None here instead of Option, since default value is + // DEFAULT_BOOTNODES None, Custom(Vec), } diff --git a/ethportal-api/src/types/execution/receipts.rs b/ethportal-api/src/types/execution/receipts.rs index a92bb43a6..5fc3d0b18 100644 --- a/ethportal-api/src/types/execution/receipts.rs +++ b/ethportal-api/src/types/execution/receipts.rs @@ -733,8 +733,8 @@ mod tests { #[test_log::test] fn receipts_batch() { - // this block (15573637) was chosen since it contains all tx types (legacy, access list, eip1559) - // as well as contract creation txs + // this block (15573637) was chosen since it contains all tx types (legacy, access list, + // eip1559) as well as contract creation txs let expected: String = std::fs::read_to_string("../test_assets/geth_batch/receipts.json").unwrap(); let receipts: Receipts = serde_json::from_str(&expected).unwrap(); diff --git a/ethportal-api/src/types/query_trace.rs b/ethportal-api/src/types/query_trace.rs index 403aefc04..8d816ed05 100644 --- a/ethportal-api/src/types/query_trace.rs +++ b/ethportal-api/src/types/query_trace.rs @@ -92,7 +92,8 @@ impl QueryTrace { .duration_since(since) .unwrap_or_default() .as_millis(); - // JSON serialization does not support u128. u64 can hold a few million years worth of milliseconds. + // JSON serialization does not support u128. u64 can hold a few million years worth of + // milliseconds. u64::try_from(timestamp_millis_u128).unwrap_or(u64::MAX) } diff --git a/light-client/src/config/checkpoints.rs b/light-client/src/config/checkpoints.rs index 85103c00f..34c35805e 100644 --- a/light-client/src/config/checkpoints.rs +++ b/light-client/src/config/checkpoints.rs @@ -130,7 +130,8 @@ impl CheckpointFallback { pub async fn fetch_latest_checkpoint_from_services( services: &[CheckpointFallbackService], ) -> eyre::Result { - // Iterate over all mainnet checkpoint sync services and get the latest checkpoint slot for each. + // Iterate over all mainnet checkpoint sync services and get the latest checkpoint slot for + // each. let tasks: Vec<_> = services .iter() .map(|service| async move { @@ -213,7 +214,10 @@ impl CheckpointFallback { /// use light_client::config::CheckpointFallback; /// /// let url = CheckpointFallback::construct_url("https://sync-mainnet.beaconcha.in"); - /// assert_eq!("https://sync-mainnet.beaconcha.in/checkpointz/v1/beacon/slots", url); + /// assert_eq!( + /// "https://sync-mainnet.beaconcha.in/checkpointz/v1/beacon/slots", + /// url + /// ); /// ``` pub fn construct_url(endpoint: &str) -> String { format!("{endpoint}/checkpointz/v1/beacon/slots") @@ -223,7 +227,8 @@ impl CheckpointFallback { /// /// ### Warning /// - /// These services are not healthchecked **nor** trustworthy and may act with malice by returning invalid checkpoints. + /// These services are not healthchecked **nor** trustworthy and may act with malice by + /// returning invalid checkpoints. #[allow(unused)] pub fn get_all_fallback_endpoints(&self, network: &networks::Network) -> Vec { self.services[network] diff --git a/portal-bridge/src/api/consensus.rs b/portal-bridge/src/api/consensus.rs index 04bf41ef9..9de981bac 100644 --- a/portal-bridge/src/api/consensus.rs +++ b/portal-bridge/src/api/consensus.rs @@ -13,7 +13,8 @@ impl ConsensusApi { Self { middleware } } - /// Requests the `LightClientBootstrap` structure corresponding to a given post-Altair beacon block root. + /// Requests the `LightClientBootstrap` structure corresponding to a given post-Altair beacon + /// block root. pub async fn get_lc_bootstrap + Display>( &self, block_root: S, diff --git a/portal-bridge/src/bridge/beacon.rs b/portal-bridge/src/bridge/beacon.rs index 4f410b4b8..a76ae5515 100644 --- a/portal-bridge/src/bridge/beacon.rs +++ b/portal-bridge/src/bridge/beacon.rs @@ -285,7 +285,8 @@ impl BeaconBridge { expected_current_slot(BEACON_GENESIS_TIME, now) / SLOTS_PER_PERIOD; match expected_current_period.cmp(¤t_period) { Ordering::Equal => { - // We already gossiped the latest data from the current period, no need to serve it again. + // We already gossiped the latest data from the current period, no need to serve it + // again. return Ok(current_period); } Ordering::Less => { @@ -302,7 +303,8 @@ impl BeaconBridge { let update: LightClientUpdateCapella = serde_json::from_value(update[0]["data"].clone())?; let finalized_header_period = update.finalized_header.beacon.slot / SLOTS_PER_PERIOD; - // We don't serve a `LightClientUpdate` if its finalized header slot is not within the expected current period. + // We don't serve a `LightClientUpdate` if its finalized header slot is not within the + // expected current period. if finalized_header_period != expected_current_period { warn!( "LightClientUpdate finalized header is not for the expected period: Expected: {expected_current_period}, Actual: {actual_period}", @@ -376,7 +378,8 @@ impl BeaconBridge { match new_finalized_slot.cmp(&finalized_slot) { Ordering::Equal => { - // We already gossiped the latest finality updated with the same finalized slot, no need to serve it again. + // We already gossiped the latest finality updated with the same finalized slot, no + // need to serve it again. return Ok(finalized_slot); } Ordering::Less => { diff --git a/portal-bridge/src/cli.rs b/portal-bridge/src/cli.rs index f551c94f1..c83ace79a 100644 --- a/portal-bridge/src/cli.rs +++ b/portal-bridge/src/cli.rs @@ -13,8 +13,7 @@ use ethportal_api::types::cli::check_private_key_length; // max value of 16 b/c... // - reliably calculate spaced private keys in a reasonable time -// - for values b/w 16 - 256, calculated spaced private keys are -// less and less evenly spread +// - for values b/w 16 - 256, calculated spaced private keys are less and less evenly spread // - running more than 16 nodes simultaneously is not thoroughly tested pub const MAX_NODE_COUNT: u8 = 16; const DEFAULT_SUBNETWORK: &str = "history"; diff --git a/portal-bridge/src/main.rs b/portal-bridge/src/main.rs index 9521ca287..c3668f50f 100644 --- a/portal-bridge/src/main.rs +++ b/portal-bridge/src/main.rs @@ -46,7 +46,8 @@ async fn main() -> Result<(), Box> { .iter() .map(|address| { HttpClientBuilder::default() - // increase default timeout to allow for trace_gossip requests that can take a long time + // increase default timeout to allow for trace_gossip requests that can take a long + // time .request_timeout(Duration::from_secs(120)) .build(address) .map_err(|e| e.to_string()) diff --git a/portal-bridge/src/pandaops.rs b/portal-bridge/src/pandaops.rs index 3c9a060b1..c1846d84b 100644 --- a/portal-bridge/src/pandaops.rs +++ b/portal-bridge/src/pandaops.rs @@ -55,8 +55,8 @@ impl Default for PandaOpsMiddleware { impl PandaOpsMiddleware { /// Used the "surf" library here instead of "ureq" since "surf" is much more capable of handling - /// multiple async requests. Using "ureq" consistently resulted in errors as soon as the number of - /// concurrent tasks increased significantly. + /// multiple async requests. Using "ureq" consistently resulted in errors as soon as the number + /// of concurrent tasks increased significantly. pub async fn batch_requests(&self, obj: Vec) -> anyhow::Result { let batched_request_futures = obj .chunks(BATCH_LIMIT) diff --git a/portal-bridge/src/types/full_header.rs b/portal-bridge/src/types/full_header.rs index c9009a0b1..67928285f 100644 --- a/portal-bridge/src/types/full_header.rs +++ b/portal-bridge/src/types/full_header.rs @@ -128,8 +128,8 @@ mod tests { #[test_log::test] fn full_header_batch() { - // this block (15573637) was chosen since it contains all tx types (legacy, access list, eip1559) - // as well as contract creation txs + // this block (15573637) was chosen since it contains all tx types (legacy, access list, + // eip1559) as well as contract creation txs let expected: String = std::fs::read_to_string("../test_assets/geth_batch/headers.json").unwrap(); let full_headers: FullHeaderBatch = serde_json::from_str(&expected).unwrap(); diff --git a/portalnet/src/discovery.rs b/portalnet/src/discovery.rs index 007c55c64..853c183db 100644 --- a/portalnet/src/discovery.rs +++ b/portalnet/src/discovery.rs @@ -275,7 +275,8 @@ impl Discovery { }) } - /// Returns the local node-id and a nested array of node-ids contained in each of this node's k-buckets. + /// Returns the local node-id and a nested array of node-ids contained in each of this node's + /// k-buckets. pub fn routing_table_info(&self) -> RoutingTableInfo { RoutingTableInfo { local_node_id: hex_encode(self.discv5.local_enr().node_id().raw()), @@ -308,8 +309,8 @@ impl Discovery { self.node_addr_cache.write().get(node_id).cloned() } - /// Put a `NodeAddress` into cache. If the key already exists in the cache, then it updates the key's value and - /// returns the old value. Otherwise, `None` is returned. + /// Put a `NodeAddress` into cache. If the key already exists in the cache, then it updates the + /// key's value and returns the old value. Otherwise, `None` is returned. pub fn put_cached_node_addr(&self, node_addr: NodeAddress) -> Option { self.node_addr_cache .write() @@ -362,10 +363,11 @@ impl UtpEnr { // UtpEnr is used as an element of the key for a Connections HashTable in our uTP library. // Enr's can change and are not stable, so if we initiate a ``connect_with_cid`` we are inserting // our known Enr for the peer, but if the peer has a more upto date Enr, values will be different -// and the Hash for the old Enr and New Enr will be different, along with equating the two structs will return false. -// This leads us to a situation where our peer sends us a uTP messages back and our code thinks the same peer -// is instead 2 different peers causing uTP to ignore the messages. We fixed this by implementing Eq and -// Hash only using the NodeId of the Enr as it is the only stable non-updatable field in the Enr. +// and the Hash for the old Enr and New Enr will be different, along with equating the two structs +// will return false. This leads us to a situation where our peer sends us a uTP messages back and +// our code thinks the same peer is instead 2 different peers causing uTP to ignore the messages. We +// fixed this by implementing Eq and Hash only using the NodeId of the Enr as it is the only stable +// non-updatable field in the Enr. impl Hash for UtpEnr { fn hash(&self, state: &mut H) { self.0.node_id().hash(state); diff --git a/portalnet/src/find/query_info.rs b/portalnet/src/find/query_info.rs index 47965e31f..1bc055756 100644 --- a/portalnet/src/find/query_info.rs +++ b/portalnet/src/find/query_info.rs @@ -99,7 +99,8 @@ impl TargetKey for QueryInfo Option> { if size > 127 { // invoke and endless loop - coding error diff --git a/portalnet/src/gossip.rs b/portalnet/src/gossip.rs index c59e0a8ed..b19c962b8 100644 --- a/portalnet/src/gossip.rs +++ b/portalnet/src/gossip.rs @@ -201,7 +201,8 @@ fn calculate_interested_enrs( // HashMap to temporarily store all interested ENRs and the content. // Key is base64 string of node's ENR. - // Filter all nodes from overlay routing table where XOR_distance(content_id, nodeId) < node radius + // Filter all nodes from overlay routing table where XOR_distance(content_id, nodeId) < node + // radius let mut interested_enrs: Vec = all_nodes .to_owned() .clone() @@ -249,7 +250,8 @@ const NUM_FARTHER_NODES: usize = 4; /// Selects gossip recipients from a vec of sorted interested ENRs. /// Returned vec is a concatenation of, at most: /// 1. First `NUM_CLOSEST_NODES` elements of `interested_sorted_enrs`. -/// 2. `NUM_FARTHER_NODES` elements randomly selected from `interested_sorted_enrs[NUM_CLOSEST_NODES..]` +/// 2. `NUM_FARTHER_NODES` elements randomly selected from +/// `interested_sorted_enrs[NUM_CLOSEST_NODES..]` fn select_gossip_recipients(interested_sorted_enrs: Vec) -> Vec { let mut gossip_recipients: Vec = vec![]; diff --git a/portalnet/src/overlay.rs b/portalnet/src/overlay.rs index 86227636e..c792a3899 100644 --- a/portalnet/src/overlay.rs +++ b/portalnet/src/overlay.rs @@ -92,8 +92,8 @@ type BucketEntry = (NodeId, Enr, NodeStatus, Distance, Option); /// Overlay protocol is a layer on top of discv5 that handles all requests from the overlay networks /// (state, history etc.) and dispatch them to the discv5 protocol TalkReq. Each network should -/// implement the overlay protocol and the overlay protocol is where we can encapsulate the logic for -/// handling common network requests/responses. +/// implement the overlay protocol and the overlay protocol is where we can encapsulate the logic +/// for handling common network requests/responses. #[derive(Clone)] pub struct OverlayProtocol { /// Reference to the underlying discv5 protocol diff --git a/portalnet/src/overlay_service.rs b/portalnet/src/overlay_service.rs index 80d31e95c..1dbd8dd4c 100644 --- a/portalnet/src/overlay_service.rs +++ b/portalnet/src/overlay_service.rs @@ -80,7 +80,8 @@ pub const FIND_NODES_MAX_NODES: usize = 32; pub const FIND_CONTENT_MAX_NODES: usize = 32; /// With even distribution assumptions, 2**17 is enough to put each node (estimating 100k nodes, -/// which is more than 10x the ethereum mainnet node count) into a unique bucket by the 17th bucket index. +/// which is more than 10x the ethereum mainnet node count) into a unique bucket by the 17th bucket +/// index. const EXPECTED_NON_EMPTY_BUCKETS: usize = 17; /// Bucket refresh lookup interval in seconds @@ -403,7 +404,8 @@ where /// Insert a vector of enrs into the routing table /// set_connected: should only be true for tests, false for production code - /// Tests that use this function are testing if adding to queues work, not if our connection code works. + /// Tests that use this function are testing if adding to queues work, not if our connection + /// code works. fn add_bootnodes(&mut self, bootnode_enrs: Vec, set_connected: bool) { // Attempt to insert bootnodes into the routing table in a disconnected state. // If successful, then add the node to the ping queue. A subsequent successful ping @@ -888,7 +890,8 @@ where return; } - // report utp tx as successful, even if we go on to fail to process the payload + // report utp tx as successful, even if we go on to fail to process the + // payload metrics.report_utp_outcome( UtpDirectionLabel::Inbound, UtpOutcomeLabel::Success, @@ -1425,8 +1428,8 @@ where // network, so there may need to be some way to parameterize the update for a // ping/pong. - // If the ENR sequence number in pong is less than the ENR sequence number for the routing - // table entry, then request the node. + // If the ENR sequence number in pong is less than the ENR sequence number for the + // routing table entry, then request the node. if node.enr().seq() < ping.enr_seq { self.request_node(&node.enr()); } @@ -1536,7 +1539,8 @@ where } }; - // Do not initialize uTP stream if remote node doesn't have interest in the offered content keys + // Do not initialize uTP stream if remote node doesn't have interest in the offered content + // keys if response.content_keys.is_zero() { if let Some(tx) = gossip_result_tx { let _ = tx.send(false); @@ -1719,7 +1723,8 @@ where } metrics.report_validation(true); - // Check if data should be stored, and store if it is within our radius and not already stored. + // Check if data should be stored, and store if it is within our radius and not + // already stored. let key_desired = store.read().is_key_within_radius_and_unavailable(&key); match key_desired { Ok(ShouldWeStoreContent::Store) => { @@ -2017,8 +2022,8 @@ where // If the node is in the routing table, then check to see if we should update its entry. // If the node is not in the routing table, then add the node in a disconnected state. - // A subsequent ping will establish connectivity with the node. If the insertion succeeds, - // then add the node to the ping queue. Ignore insertion failures. + // A subsequent ping will establish connectivity with the node. If the insertion + // succeeds, then add the node to the ping queue. Ignore insertion failures. if let Some(node) = optional_node { if node.enr().seq() < enr.seq() { let updated_node = Node { @@ -2026,8 +2031,9 @@ where data_radius: node.data_radius(), }; - // The update removed the node because it would violate the incoming peers condition - // or a bucket/table filter. Remove the node from the ping queue. + // The update removed the node because it would violate the incoming peers + // condition or a bucket/table filter. Remove the node from + // the ping queue. if let UpdateResult::Failed(reason) = kbuckets.update_node(&key, updated_node, None) { @@ -2116,7 +2122,8 @@ where } /// Advances a find node query (if one is active for the node) using the received ENRs. - /// Does nothing if called with a node_id that does not have a corresponding active query request. + /// Does nothing if called with a node_id that does not have a corresponding active query + /// request. fn advance_find_node_query(&mut self, source: Enr, enrs: Vec, query_id: QueryId) { // Check whether this request was sent on behalf of a query. // If so, advance the query with the returned data. @@ -2357,7 +2364,8 @@ where } } - /// Returns a vector of all the ENRs of nodes currently contained in the routing table which are connected. + /// Returns a vector of all the ENRs of nodes currently contained in the routing table which are + /// connected. fn table_entries_enr(&self) -> Vec { self.kbuckets .write() @@ -2424,7 +2432,8 @@ where Ok(closest_nodes) } - /// Returns a vector of ENRs of the `max_nodes` closest connected nodes to the target from our routing table. + /// Returns a vector of ENRs of the `max_nodes` closest connected nodes to the target from our + /// routing table. fn closest_connected_nodes(&self, target_key: &Key, max_nodes: usize) -> Vec { // Filter out all disconnected nodes let kbuckets = self.kbuckets.read(); diff --git a/portalnet/src/storage.rs b/portalnet/src/storage.rs index 02d5d83c9..15bdae9f6 100644 --- a/portalnet/src/storage.rs +++ b/portalnet/src/storage.rs @@ -70,7 +70,8 @@ pub enum ContentStoreError { ContentKey(#[from] ContentKeyError), } -/// An enum which tells us if we should store or not store content, and if not why for better errors. +/// An enum which tells us if we should store or not store content, and if not why for better +/// errors. #[derive(Debug, PartialEq)] pub enum ShouldWeStoreContent { Store, @@ -553,8 +554,9 @@ impl PortalStorage { self.radius } - /// Public method for determining how much actual disk space is being used to store this node's Portal Network data. - /// Intended for analysis purposes. PortalStorage's capacity decision-making is not based off of this method. + /// Public method for determining how much actual disk space is being used to store this node's + /// Portal Network data. Intended for analysis purposes. PortalStorage's capacity + /// decision-making is not based off of this method. pub fn get_total_storage_usage_in_bytes_on_disk(&self) -> Result { let storage_usage = Self::get_total_size_of_directory_in_bytes(&self.node_data_dir)?; Ok(storage_usage) @@ -633,8 +635,9 @@ impl PortalStorage { Ok(sum as u64) } - /// Internal method for finding the piece of stored data that has the farthest content id from our - /// node id, according to xor distance. Used to determine which data to drop when at a capacity. + /// Internal method for finding the piece of stored data that has the farthest content id from + /// our node id, according to xor distance. Used to determine which data to drop when at a + /// capacity. fn find_farthest_content_id(&self) -> Result, ContentStoreError> { let result = match self.distance_fn { DistanceFunction::Xor => { diff --git a/portalnet/src/utils/portal_wire.rs b/portalnet/src/utils/portal_wire.rs index 2dc11a1a7..0fb7de9ae 100644 --- a/portalnet/src/utils/portal_wire.rs +++ b/portalnet/src/utils/portal_wire.rs @@ -2,8 +2,8 @@ use anyhow::anyhow; use bytes::{Buf, BufMut, Bytes, BytesMut}; use std::io::{Read, Write}; -/// Decode content values from uTP payload. All content values are encoded with a LEB128 varint prefix -/// which indicates the length in bytes of the consecutive content item. +/// Decode content values from uTP payload. All content values are encoded with a LEB128 varint +/// prefix which indicates the length in bytes of the consecutive content item. pub fn decode_content_payload(payload: Vec) -> anyhow::Result>> { let mut payload = BytesMut::from(&payload[..]).reader(); @@ -52,7 +52,8 @@ pub fn encode_content_payload(content_items: &[Bytes]) -> anyhow::Result anyhow::Result<(usize, u32)> { for i in 1..6 { match leb128::read::unsigned(&mut &buf[0..i]) { diff --git a/rpc/src/beacon_rpc.rs b/rpc/src/beacon_rpc.rs index ed3c319d8..ed393c2e4 100644 --- a/rpc/src/beacon_rpc.rs +++ b/rpc/src/beacon_rpc.rs @@ -101,8 +101,8 @@ impl BeaconNetworkApiServer for BeaconNetworkApi { Ok(result) } - /// Send a FINDNODES request for nodes that fall within the given set of distances, to the designated - /// peer and wait for a response + /// Send a FINDNODES request for nodes that fall within the given set of distances, to the + /// designated peer and wait for a response async fn find_nodes(&self, enr: Enr, distances: Vec) -> RpcResult { let endpoint = BeaconEndpoint::FindNodes(enr, distances); let result = self.proxy_query_to_beacon_subnet(endpoint).await?; @@ -175,8 +175,8 @@ impl BeaconNetworkApiServer for BeaconNetworkApi { Ok(result) } - /// Send the provided content to interested peers. Clients may choose to send to some or all peers. - /// Return the number of peers that the content was gossiped to. + /// Send the provided content to interested peers. Clients may choose to send to some or all + /// peers. Return the number of peers that the content was gossiped to. async fn gossip( &self, content_key: BeaconContentKey, @@ -188,8 +188,8 @@ impl BeaconNetworkApiServer for BeaconNetworkApi { Ok(result) } - /// Send the provided content to interested peers. Clients may choose to send to some or all peers. - /// Return tracing info. + /// Send the provided content to interested peers. Clients may choose to send to some or all + /// peers. Return tracing info. async fn trace_gossip( &self, content_key: BeaconContentKey, @@ -202,7 +202,8 @@ impl BeaconNetworkApiServer for BeaconNetworkApi { } /// Send an OFFER request with given ContentKey, to the designated peer and wait for a response. - /// Returns the content keys bitlist upon successful content transmission or empty bitlist receive. + /// Returns the content keys bitlist upon successful content transmission or empty bitlist + /// receive. async fn offer( &self, enr: Enr, diff --git a/rpc/src/history_rpc.rs b/rpc/src/history_rpc.rs index ac3ac1313..59a0d0851 100644 --- a/rpc/src/history_rpc.rs +++ b/rpc/src/history_rpc.rs @@ -77,8 +77,8 @@ impl HistoryNetworkApiServer for HistoryNetworkApi { Ok(result) } - /// Send a FINDNODES request for nodes that fall within the given set of distances, to the designated - /// peer and wait for a response + /// Send a FINDNODES request for nodes that fall within the given set of distances, to the + /// designated peer and wait for a response async fn find_nodes(&self, enr: Enr, distances: Vec) -> RpcResult { let endpoint = HistoryEndpoint::FindNodes(enr, distances); let result = proxy_query_to_history_subnet(&self.network, endpoint).await?; @@ -154,8 +154,8 @@ impl HistoryNetworkApiServer for HistoryNetworkApi { Ok(result) } - /// Send the provided content to interested peers. Clients may choose to send to some or all peers. - /// Return the number of peers that the content was gossiped to. + /// Send the provided content to interested peers. Clients may choose to send to some or all + /// peers. Return the number of peers that the content was gossiped to. async fn gossip( &self, content_key: HistoryContentKey, @@ -167,8 +167,8 @@ impl HistoryNetworkApiServer for HistoryNetworkApi { Ok(result) } - /// Send the provided content to interested peers. Clients may choose to send to some or all peers. - /// Return tracing info. + /// Send the provided content to interested peers. Clients may choose to send to some or all + /// peers. Return tracing info. async fn trace_gossip( &self, content_key: HistoryContentKey, @@ -181,7 +181,8 @@ impl HistoryNetworkApiServer for HistoryNetworkApi { } /// Send an OFFER request with given ContentKey, to the designated peer and wait for a response. - /// Returns the content keys bitlist upon successful content transmission or empty bitlist receive. + /// Returns the content keys bitlist upon successful content transmission or empty bitlist + /// receive. async fn offer( &self, enr: Enr, diff --git a/rustfmt.toml b/rustfmt.toml index c3c8c3753..b298d0cae 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,5 @@ imports_granularity = "Crate" +comment_width = 100 +wrap_comments = true +format_code_in_doc_comments = true +doc_comment_code_block_width = 100 diff --git a/src/bin/purge_db.rs b/src/bin/purge_db.rs index a5a25b9dc..9da0031ee 100644 --- a/src/bin/purge_db.rs +++ b/src/bin/purge_db.rs @@ -29,7 +29,6 @@ use trin_utils::log::init_tracing_logger; /// non-history network content. Since we only support history network content, this /// shouldn't be a problem, but as we add support for more sub-networks this script will /// need to be updated to avoid panicking. -/// pub fn main() -> Result<()> { init_tracing_logger(); let purge_config = PurgeConfig::parse(); @@ -45,7 +44,8 @@ pub fn main() -> Result<()> { info!("Purging data for NodeID: {node_id}"); info!("DB Path: {node_data_dir:?}"); - // Capacity is 0 since it (eg. for data radius calculation) is irrelevant when only removing data. + // Capacity is 0 since it (eg. for data radius calculation) is irrelevant when only removing + // data. let capacity = 0; let protocol = ProtocolId::History; let config = PortalStorageConfig::new(capacity, node_data_dir, node_id)?; diff --git a/trin-beacon/src/network.rs b/trin-beacon/src/network.rs index 8cc62bf91..8b7f51508 100644 --- a/trin-beacon/src/network.rs +++ b/trin-beacon/src/network.rs @@ -17,7 +17,8 @@ use portalnet::{ }; use trin_validation::oracle::HeaderOracle; -/// Beacon network layer on top of the overlay protocol. Encapsulates beacon network specific data and logic. +/// Beacon network layer on top of the overlay protocol. Encapsulates beacon network specific data +/// and logic. #[derive(Clone)] pub struct BeaconNetwork { pub overlay: Arc>, diff --git a/trin-history/src/network.rs b/trin-history/src/network.rs index 13d87408d..8996f2d26 100644 --- a/trin-history/src/network.rs +++ b/trin-history/src/network.rs @@ -18,7 +18,8 @@ use trin_validation::oracle::HeaderOracle; use crate::validation::ChainHistoryValidator; -/// History network layer on top of the overlay protocol. Encapsulates history network specific data and logic. +/// History network layer on top of the overlay protocol. Encapsulates history network specific data +/// and logic. #[derive(Clone)] pub struct HistoryNetwork { pub overlay: diff --git a/trin-history/src/utils.rs b/trin-history/src/utils.rs index 5535a9406..8e4c31c46 100644 --- a/trin-history/src/utils.rs +++ b/trin-history/src/utils.rs @@ -46,7 +46,8 @@ pub fn bucket_entries_to_json(bucket_entries: BTreeMap>) - }; } else { // Include address (IP:port) for convenience. - // TODO: Can be removed once a portal dashboard does UI-side ENR decoding. + // TODO: Can be removed once a portal dashboard does UI-side ENR + // decoding. let port = match enr.udp4_socket() { Some(port) => format!("{port}"), None => "None".to_string(), diff --git a/trin-metrics/src/labels.rs b/trin-metrics/src/labels.rs index 8876c66ea..3428f09cf 100644 --- a/trin-metrics/src/labels.rs +++ b/trin-metrics/src/labels.rs @@ -66,7 +66,8 @@ impl From<&Request> for MessageLabel { Request::Offer(_) => MessageLabel::Offer, // Populated offers are the same as regular offers, from a metrics point of view Request::PopulatedOffer(_) => MessageLabel::Offer, - // Populated offers with result are the same as regular offers, from a metrics point of view + // Populated offers with result are the same as regular offers, from a metrics point of + // view Request::PopulatedOfferWithResult(_) => MessageLabel::Offer, } } diff --git a/trin-state/src/network.rs b/trin-state/src/network.rs index 43c6764bf..6aa0d5099 100644 --- a/trin-state/src/network.rs +++ b/trin-state/src/network.rs @@ -19,7 +19,8 @@ use trin_validation::oracle::HeaderOracle; use crate::{trie::TrieDB, validation::StateValidator}; -/// State network layer on top of the overlay protocol. Encapsulates state network specific data and logic. +/// State network layer on top of the overlay protocol. Encapsulates state network specific data and +/// logic. #[derive(Clone)] pub struct StateNetwork { pub overlay: Arc>, diff --git a/trin-validation/src/accumulator.rs b/trin-validation/src/accumulator.rs index b04bd60c8..3b8939efc 100644 --- a/trin-validation/src/accumulator.rs +++ b/trin-validation/src/accumulator.rs @@ -193,9 +193,9 @@ impl MasterAccumulator { } // Create a merkle tree from epoch accumulator. - // To construct a valid proof for the header hash, we add both the hash and the total difficulty - // as individual leaves for each header record. This will ensure that the total difficulty - // is included as the first element in the proof. + // To construct a valid proof for the header hash, we add both the hash and the total + // difficulty as individual leaves for each header record. This will ensure that the + // total difficulty is included as the first element in the proof. let mut leaves = vec![]; // iterate over every header record in the epoch acc for record in epoch_acc.into_iter() { diff --git a/trin-validation/src/merkle/proof.rs b/trin-validation/src/merkle/proof.rs index 7eb97cffa..5c175844a 100644 --- a/trin-validation/src/merkle/proof.rs +++ b/trin-validation/src/merkle/proof.rs @@ -1,7 +1,6 @@ /// /// Code sourced from: /// https://github.com/sigp/lighthouse/blob/bf533c8e42/consensus/merkle_proof/src/lib.rs -/// use crate::merkle::safe_arith::ArithError; use eth2_hashing::{hash, hash32_concat, ZERO_HASHES}; use ethereum_types::H256; @@ -136,7 +135,8 @@ impl MerkleTree { (Leaf(_), Zero(_)) | (Finalized(_), Zero(_)) => { *right = MerkleTree::create(&[elem], depth - 1); } - // Try inserting on the left node -> if it fails because it is full, insert in right side. + // Try inserting on the left node -> if it fails because it is full, insert in + // right side. (Node(_, _, _), Zero(_)) => { match left.push_leaf(elem, depth - 1) { Ok(_) => (), diff --git a/trin-validation/src/merkle/safe_arith.rs b/trin-validation/src/merkle/safe_arith.rs index 6ffa505b7..7dd72b70d 100644 --- a/trin-validation/src/merkle/safe_arith.rs +++ b/trin-validation/src/merkle/safe_arith.rs @@ -1,7 +1,6 @@ /// /// Code sourced from: /// https://github.com/sigp/lighthouse/blob/bf533c8e42/consensus/safe_arith/src/lib.rs -/// /// Extension trait for iterators, providing a safe replacement for `sum`. pub trait SafeArithIter { From b935fc57558233e814d8648961f5122c720e2f40 Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Thu, 4 Jan 2024 18:38:50 +0800 Subject: [PATCH 09/11] fix: remove rust-toolchain --- rust-toolchain | 1 - 1 file changed, 1 deletion(-) delete mode 100644 rust-toolchain diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index 07ade694b..000000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly \ No newline at end of file From 8ae82c0dc61493d9cd0876b34eb5c06e962a6b76 Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Thu, 4 Jan 2024 18:44:43 +0800 Subject: [PATCH 10/11] fix: ci separate rustfmt and clippy --- .circleci/config.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9b841da5f..4741d44d7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -132,9 +132,9 @@ jobs: command: | echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin docker push $IMAGE_NAME:latest-bridge - lint: + cargo-fmt: description: | - Check linting with Clippy and rustfmt. + Check linting with rustfmt. resource_class: xlarge executor: docker-nightly environment: @@ -146,6 +146,19 @@ jobs: - run: name: Run rustfmt command: cargo +nightly fmt --all -- --check + cargo-clippy: + description: | + Check linting with Clippy. + resource_class: xlarge + executor: + name: rust/default + tag: 1.71.1 + environment: + RUSTFLAGS: "-D warnings" + RUST_LOG: "debug" + steps: + - checkout + - install-depends - run: name: Install Clippy command: rustup component add clippy @@ -288,7 +301,8 @@ workflows: filters: branches: only: master - - lint + - cargo-fmt + - cargo-clippy - build - test - check-windows From c4b24e24003e0303f610a94988bf668bf38a6b8d Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Thu, 4 Jan 2024 18:46:11 +0800 Subject: [PATCH 11/11] Revert "fix: clippy error after using nightly" This reverts commit 1a6f8d136c8b730495207129b5b91c1f2b65a672. --- ethportal-api/src/types/portal_wire.rs | 7 ++++--- portalnet/src/gossip.rs | 3 +-- portalnet/src/overlay.rs | 2 +- portalnet/src/storage.rs | 2 +- trin-validation/src/merkle/proof.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ethportal-api/src/types/portal_wire.rs b/ethportal-api/src/types/portal_wire.rs index 6bc7be9e2..f8ec2754f 100644 --- a/ethportal-api/src/types/portal_wire.rs +++ b/ethportal-api/src/types/portal_wire.rs @@ -86,9 +86,10 @@ impl TryFrom<&Value> for CustomPayload { "Unable to decode hex payload into bytes", ))?, }; - Ok(Self { - payload: ByteList::from(payload), - }) + match ByteList::try_from(payload) { + Ok(payload) => Ok(Self { payload }), + Err(_) => Err(ValidationError::new("Invalid custom payload value")), + } } } diff --git a/portalnet/src/gossip.rs b/portalnet/src/gossip.rs index b19c962b8..404dc4e51 100644 --- a/portalnet/src/gossip.rs +++ b/portalnet/src/gossip.rs @@ -196,7 +196,7 @@ pub async fn trace_propagate_gossip_cross_thread /// Filter all nodes from overlay routing table where XOR_distance(content_id, nodeId) < node radius fn calculate_interested_enrs( content_key: &TContentKey, - all_nodes: &[&kbucket::Node], + all_nodes: &Vec<&kbucket::Node>, ) -> Vec { // HashMap to temporarily store all interested ENRs and the content. // Key is base64 string of node's ENR. @@ -204,7 +204,6 @@ fn calculate_interested_enrs( // Filter all nodes from overlay routing table where XOR_distance(content_id, nodeId) < node // radius let mut interested_enrs: Vec = all_nodes - .to_owned() .clone() .into_iter() .filter(|node| { diff --git a/portalnet/src/overlay.rs b/portalnet/src/overlay.rs index c792a3899..58346c43c 100644 --- a/portalnet/src/overlay.rs +++ b/portalnet/src/overlay.rs @@ -788,7 +788,7 @@ where } } -fn validate_find_nodes_distances(distances: &[u16]) -> Result<(), OverlayRequestError> { +fn validate_find_nodes_distances(distances: &Vec) -> Result<(), OverlayRequestError> { if distances.is_empty() { return Err(OverlayRequestError::InvalidRequest( "Invalid distances: Empty list".to_string(), diff --git a/portalnet/src/storage.rs b/portalnet/src/storage.rs index 15bdae9f6..e271f98a9 100644 --- a/portalnet/src/storage.rs +++ b/portalnet/src/storage.rs @@ -573,7 +573,7 @@ impl PortalStorage { &self, content_id: &[u8; 32], content_key: &String, - value: &[u8], + value: &Vec, ) -> Result<(), ContentStoreError> { let content_id_as_u32: u32 = Self::byte_vector_to_u32(content_id.to_vec()); let value_size = value.len(); diff --git a/trin-validation/src/merkle/proof.rs b/trin-validation/src/merkle/proof.rs index 5c175844a..8688763d9 100644 --- a/trin-validation/src/merkle/proof.rs +++ b/trin-validation/src/merkle/proof.rs @@ -254,7 +254,7 @@ impl MerkleTree { if deposit_count == (0x1 << level) { return Ok(MerkleTree::Finalized( *finalized_branch - .first() + .get(0) .ok_or(MerkleTreeError::PleaseNotifyTheDevs)?, )); }