From 15bab9e0f4efc60e6d2087098af99fa21b8b4dd3 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Sun, 13 Oct 2024 17:38:51 +0200 Subject: [PATCH] chore: some improvements --- crates/consensus/src/header.rs | 8 ++++---- crates/eips/src/eip4844/builder.rs | 2 +- crates/node-bindings/src/nodes/reth.rs | 8 ++++---- crates/provider/src/fillers/mod.rs | 2 +- crates/provider/src/provider/eth_call.rs | 1 - crates/rpc-client/src/batch.rs | 2 +- crates/rpc-types-engine/src/jwt.rs | 6 +++--- crates/rpc-types-eth/src/filter.rs | 11 +++++++---- crates/rpc-types-trace/src/filter.rs | 4 ++-- crates/rpc-types-trace/src/geth/mod.rs | 2 +- 10 files changed, 24 insertions(+), 22 deletions(-) diff --git a/crates/consensus/src/header.rs b/crates/consensus/src/header.rs index f84dd540df6..87c93234b6d 100644 --- a/crates/consensus/src/header.rs +++ b/crates/consensus/src/header.rs @@ -497,7 +497,7 @@ impl Decodable for Header { }; if started_len - buf.len() < rlp_head.payload_length { - if buf.first().map(|b| *b == EMPTY_LIST_CODE).unwrap_or_default() { + if buf.first().is_some_and(|b| *b == EMPTY_LIST_CODE) { buf.advance(1) } else { this.base_fee_per_gas = Some(U256::decode(buf)?.to::()); @@ -506,7 +506,7 @@ impl Decodable for Header { // Withdrawals root for post-shanghai headers if started_len - buf.len() < rlp_head.payload_length { - if buf.first().map(|b| *b == EMPTY_STRING_CODE).unwrap_or_default() { + if buf.first().is_some_and(|b| *b == EMPTY_STRING_CODE) { buf.advance(1) } else { this.withdrawals_root = Some(Decodable::decode(buf)?); @@ -515,7 +515,7 @@ impl Decodable for Header { // Blob gas used and excess blob gas for post-cancun headers if started_len - buf.len() < rlp_head.payload_length { - if buf.first().map(|b| *b == EMPTY_LIST_CODE).unwrap_or_default() { + if buf.first().is_some_and(|b| *b == EMPTY_LIST_CODE) { buf.advance(1) } else { this.blob_gas_used = Some(U256::decode(buf)?.to::()); @@ -523,7 +523,7 @@ impl Decodable for Header { } if started_len - buf.len() < rlp_head.payload_length { - if buf.first().map(|b| *b == EMPTY_LIST_CODE).unwrap_or_default() { + if buf.first().is_some_and(|b| *b == EMPTY_LIST_CODE) { buf.advance(1) } else { this.excess_blob_gas = Some(U256::decode(buf)?.to::()); diff --git a/crates/eips/src/eip4844/builder.rs b/crates/eips/src/eip4844/builder.rs index 75e9a83eee5..30f09405872 100644 --- a/crates/eips/src/eip4844/builder.rs +++ b/crates/eips/src/eip4844/builder.rs @@ -364,7 +364,7 @@ impl SidecarBuilder { ) -> Result { let mut commitments = Vec::with_capacity(self.inner.blobs.len()); let mut proofs = Vec::with_capacity(self.inner.blobs.len()); - for blob in self.inner.blobs.iter() { + for blob in &self.inner.blobs { // SAFETY: same size let blob = unsafe { core::mem::transmute::<&Blob, &c_kzg::Blob>(blob) }; let commitment = KzgCommitment::blob_to_kzg_commitment(blob, settings)?; diff --git a/crates/node-bindings/src/nodes/reth.rs b/crates/node-bindings/src/nodes/reth.rs index 9169893cd51..b61653be5bf 100644 --- a/crates/node-bindings/src/nodes/reth.rs +++ b/crates/node-bindings/src/nodes/reth.rs @@ -423,12 +423,12 @@ impl Reth { } } - if !self.discovery_enabled { - cmd.arg("--disable-discovery"); - cmd.arg("--no-persist-peers"); - } else { + if self.discovery_enabled { // Verbosity is required to read the P2P port from the logs. cmd.arg("--verbosity").arg("-vvv"); + } else { + cmd.arg("--disable-discovery"); + cmd.arg("--no-persist-peers"); } if let Some(chain_or_path) = self.chain_or_path { diff --git a/crates/provider/src/fillers/mod.rs b/crates/provider/src/fillers/mod.rs index 7f4b40332e7..bdfe33a6d98 100644 --- a/crates/provider/src/fillers/mod.rs +++ b/crates/provider/src/fillers/mod.rs @@ -148,7 +148,7 @@ pub trait TxFiller: Clone + Send + Sync + std::fmt::Debug /// Returns `true` if the filler is should continue filling. fn continue_filling(&self, tx: &SendableTx) -> bool { - tx.as_builder().map(|tx| self.status(tx).is_ready()).unwrap_or_default() + tx.as_builder().is_some_and(|tx| self.status(tx).is_ready()) } /// Returns `true` if the filler is ready to fill in the transaction request. diff --git a/crates/provider/src/provider/eth_call.rs b/crates/provider/src/provider/eth_call.rs index 83433490568..f986c360938 100644 --- a/crates/provider/src/provider/eth_call.rs +++ b/crates/provider/src/provider/eth_call.rs @@ -319,7 +319,6 @@ where } #[cfg(test)] - mod test { use super::*; use alloy_eips::BlockNumberOrTag; diff --git a/crates/rpc-client/src/batch.rs b/crates/rpc-client/src/batch.rs index 010d8ae65c2..978aa50e320 100644 --- a/crates/rpc-client/src/batch.rs +++ b/crates/rpc-client/src/batch.rs @@ -236,7 +236,7 @@ where } } ResponsePacket::Batch(responses) => { - for response in responses.into_iter() { + for response in responses { if let Some(tx) = channels.remove(&response.id) { let _ = tx.send(transform_response(response)); } diff --git a/crates/rpc-types-engine/src/jwt.rs b/crates/rpc-types-engine/src/jwt.rs index 9d61fcabd38..9882892b5f0 100644 --- a/crates/rpc-types-engine/src/jwt.rs +++ b/crates/rpc-types-engine/src/jwt.rs @@ -173,13 +173,13 @@ impl JwtSecret { /// This strips the leading `0x`, if any. pub fn from_hex>(hex: S) -> Result { let hex: &str = hex.as_ref().trim().trim_start_matches("0x"); - if hex.len() != JWT_SECRET_LEN { - Err(JwtError::InvalidLength(JWT_SECRET_LEN, hex.len())) - } else { + if hex.len() == JWT_SECRET_LEN { let hex_bytes = hex::decode(hex)?; // is 32bytes, see length check let bytes = hex_bytes.try_into().expect("is expected len"); Ok(Self(bytes)) + } else { + Err(JwtError::InvalidLength(JWT_SECRET_LEN, hex.len())) } } diff --git a/crates/rpc-types-eth/src/filter.rs b/crates/rpc-types-eth/src/filter.rs index 8aa70329d04..6300c88a6b0 100644 --- a/crates/rpc-types-eth/src/filter.rs +++ b/crates/rpc-types-eth/src/filter.rs @@ -9,7 +9,10 @@ use core::{ hash::Hash, ops::{RangeFrom, RangeInclusive, RangeToInclusive}, }; -use itertools::{EitherOrBoth::*, Itertools}; +use itertools::{ + EitherOrBoth::{Both, Left, Right}, + Itertools, +}; /// Helper type to represent a bloom filter used for matching logs. #[derive(Debug, Default)] @@ -37,7 +40,7 @@ pub struct FilterSet(HashSet); impl From for FilterSet { fn from(src: T) -> Self { - Self(FromIterator::from_iter(core::iter::once(src))) + Self(core::iter::once(src).collect()) } } @@ -51,7 +54,7 @@ impl Hash for FilterSet { impl From> for FilterSet { fn from(src: Vec) -> Self { - Self(HashSet::from_iter(src.into_iter().map(Into::into))) + Self(src.into_iter().map(Into::into).collect()) } } @@ -837,7 +840,7 @@ impl FilteredParams { // for each filter, iterate through the list of filter blooms. for each set of filter // (each BloomFilter), the given `bloom` must match at least one of them, unless the list is // empty (no filters). - for filter in topic_filters.iter() { + for filter in topic_filters { if !filter.matches(bloom) { return false; } diff --git a/crates/rpc-types-trace/src/filter.rs b/crates/rpc-types-trace/src/filter.rs index 6c02afe6d74..fc8c98e4a9f 100644 --- a/crates/rpc-types-trace/src/filter.rs +++ b/crates/rpc-types-trace/src/filter.rs @@ -80,8 +80,8 @@ impl TraceFilter { /// Returns a `TraceFilterMatcher` for this filter. pub fn matcher(&self) -> TraceFilterMatcher { - let from_addresses = self.from_address.iter().cloned().collect(); - let to_addresses = self.to_address.iter().cloned().collect(); + let from_addresses = self.from_address.iter().copied().collect(); + let to_addresses = self.to_address.iter().copied().collect(); TraceFilterMatcher { mode: self.mode, from_addresses, to_addresses } } } diff --git a/crates/rpc-types-trace/src/geth/mod.rs b/crates/rpc-types-trace/src/geth/mod.rs index 9181939c9f0..5f6c8517bd6 100644 --- a/crates/rpc-types-trace/src/geth/mod.rs +++ b/crates/rpc-types-trace/src/geth/mod.rs @@ -692,7 +692,7 @@ fn serialize_string_storage_map_opt( None => s.serialize_none(), Some(storage) => { let mut m = s.serialize_map(Some(storage.len()))?; - for (key, val) in storage.iter() { + for (key, val) in storage { let key = format!("{:?}", key); let val = format!("{:?}", val); // skip the 0x prefix