Skip to content

Commit

Permalink
chore: some small improvements (#1461)
Browse files Browse the repository at this point in the history
chore: some improvements
  • Loading branch information
tcoratger authored Oct 13, 2024
1 parent a64e3ac commit f104f51
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 22 deletions.
8 changes: 4 additions & 4 deletions crates/consensus/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u64>());
Expand All @@ -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)?);
Expand All @@ -515,15 +515,15 @@ 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::<u64>());
}
}

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::<u64>());
Expand Down
2 changes: 1 addition & 1 deletion crates/eips/src/eip4844/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl<T: SidecarCoder> SidecarBuilder<T> {
) -> Result<BlobTransactionSidecar, c_kzg::Error> {
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)?;
Expand Down
8 changes: 4 additions & 4 deletions crates/node-bindings/src/nodes/reth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/fillers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub trait TxFiller<N: Network = Ethereum>: Clone + Send + Sync + std::fmt::Debug

/// Returns `true` if the filler is should continue filling.
fn continue_filling(&self, tx: &SendableTx<N>) -> 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.
Expand Down
1 change: 0 additions & 1 deletion crates/provider/src/provider/eth_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ where
}

#[cfg(test)]

mod test {
use super::*;
use alloy_eips::BlockNumberOrTag;
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc-client/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc-types-engine/src/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ impl JwtSecret {
/// This strips the leading `0x`, if any.
pub fn from_hex<S: AsRef<str>>(hex: S) -> Result<Self, JwtError> {
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()))
}
}

Expand Down
11 changes: 7 additions & 4 deletions crates/rpc-types-eth/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -37,7 +40,7 @@ pub struct FilterSet<T: Eq + Hash>(HashSet<T>);

impl<T: Eq + Hash> From<T> for FilterSet<T> {
fn from(src: T) -> Self {
Self(FromIterator::from_iter(core::iter::once(src)))
Self(core::iter::once(src).collect())
}
}

Expand All @@ -51,7 +54,7 @@ impl<T: Eq + Hash> Hash for FilterSet<T> {

impl<T: Eq + Hash> From<Vec<T>> for FilterSet<T> {
fn from(src: Vec<T>) -> Self {
Self(HashSet::from_iter(src.into_iter().map(Into::into)))
Self(src.into_iter().map(Into::into).collect())
}
}

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc-types-trace/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc-types-trace/src/geth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ fn serialize_string_storage_map_opt<S: Serializer>(
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
Expand Down

0 comments on commit f104f51

Please sign in to comment.