Skip to content

Commit

Permalink
Add clippy fixes and minor refactoring (#6450)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Feb 6, 2024
1 parent 189d767 commit 37a8780
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 54 deletions.
13 changes: 6 additions & 7 deletions crates/consensus/beacon/src/engine/forkchoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,12 @@ impl ForkchoiceStatus {
/// Converts the general purpose [PayloadStatusEnum] into a [ForkchoiceStatus].
pub(crate) fn from_payload_status(status: &PayloadStatusEnum) -> Self {
match status {
PayloadStatusEnum::Valid => ForkchoiceStatus::Valid,
PayloadStatusEnum::Invalid { .. } => ForkchoiceStatus::Invalid,
PayloadStatusEnum::Syncing => ForkchoiceStatus::Syncing,
PayloadStatusEnum::Accepted => {
// This is only returned on `newPayload` accepted would be a valid state here.
PayloadStatusEnum::Valid | PayloadStatusEnum::Accepted => {
// `Accepted` is only returned on `newPayload`. It would be a valid state here.
ForkchoiceStatus::Valid
}
PayloadStatusEnum::Invalid { .. } => ForkchoiceStatus::Invalid,
PayloadStatusEnum::Syncing => ForkchoiceStatus::Syncing,
}
}
}
Expand Down Expand Up @@ -169,8 +168,8 @@ impl ForkchoiceStateHash {
impl AsRef<B256> for ForkchoiceStateHash {
fn as_ref(&self) -> &B256 {
match self {
ForkchoiceStateHash::Head(h) => h,
ForkchoiceStateHash::Safe(h) => h,
ForkchoiceStateHash::Head(h) |
ForkchoiceStateHash::Safe(h) |
ForkchoiceStateHash::Finalized(h) => h,
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/net/downloaders/src/headers/reverse_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl From<HeadersResponseError> for ReverseHeadersDownloaderError {
/// the batches of headers that this downloader yields will start at the chain tip and move towards
/// the local head: falling block numbers.
#[must_use = "Stream does nothing unless polled"]
#[allow(missing_debug_implementations)]
#[derive(Debug)]
pub struct ReverseHeadersDownloader<H: HeadersClient> {
/// Consensus client used to validate headers
consensus: Arc<dyn Consensus>,
Expand Down Expand Up @@ -892,6 +892,7 @@ where
}

/// A future that returns a list of [`Header`] on success.
#[derive(Debug)]
struct HeadersRequestFuture<F> {
request: Option<HeadersRequest>,
fut: F,
Expand Down Expand Up @@ -927,6 +928,7 @@ impl HeadersRequestOutcome {
}

/// Wrapper type to order responses
#[derive(Debug)]
struct OrderedHeadersResponse {
headers: Vec<Header>,
request: HeadersRequest,
Expand Down
3 changes: 1 addition & 2 deletions crates/primitives/benches/validate_blob_tx.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#![allow(missing_docs)]
use std::sync::Arc;

use alloy_primitives::hex;
use c_kzg::{KzgCommitment, KzgSettings};
use criterion::{
Expand All @@ -16,6 +14,7 @@ use reth_primitives::{
BlobTransactionSidecar, TxEip4844,
};
use revm_primitives::MAX_BLOB_NUMBER_PER_BLOCK;
use std::sync::Arc;

// constant seed to use for the rng
const SEED: [u8; 32] = hex!("1337133713371337133713371337133713371337133713371337133713371337");
Expand Down
5 changes: 2 additions & 3 deletions crates/primitives/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ use crate::{
};
use alloy_rlp::{length_of_length, Decodable, Encodable};
use bytes::{Buf, BufMut, BytesMut};
#[cfg(any(test, feature = "arbitrary"))]
use proptest::strategy::Strategy;
use reth_codecs::{add_arbitrary_tests, main_codec, Compact, CompactZstd};
use std::{
cmp::Ordering,
ops::{Deref, DerefMut},
};

#[cfg(any(test, feature = "arbitrary"))]
use proptest::strategy::Strategy;

/// Receipt containing result of transaction execution.
#[main_codec(no_arbitrary, zstd)]
#[add_arbitrary_tests]
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/layers/auth_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ where

/// This type is the actual implementation of the middleware. It follows the [`Service`]
/// specification to correctly proxy Http requests to its inner service after headers validation.
#[allow(missing_debug_implementations)]
#[derive(Debug)]
pub struct AuthService<S, V> {
/// Performs auth validation logics
validator: V,
Expand Down
8 changes: 1 addition & 7 deletions crates/rpc/rpc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,7 @@ where
hash: B256,
index: usize,
) -> EthResult<Option<LocalizedTransactionTrace>> {
match self.trace_transaction(hash).await? {
None => Ok(None),
Some(traces) => {
let trace = traces.into_iter().nth(index);
Ok(trace)
}
}
Ok(self.trace_transaction(hash).await?.and_then(|traces| traces.into_iter().nth(index)))
}

/// Returns all transaction traces that match the given filter.
Expand Down
39 changes: 14 additions & 25 deletions crates/transaction-pool/src/test_utils/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,9 @@ macro_rules! set_value {
($this:ident => $field:ident) => {
let new_value = $field;
match $this {
MockTransaction::Legacy { ref mut $field, .. } => {
*$field = new_value;
}
MockTransaction::Eip1559 { ref mut $field, .. } => {
*$field = new_value;
}
MockTransaction::Eip4844 { ref mut $field, .. } => {
*$field = new_value;
}
MockTransaction::Legacy { ref mut $field, .. } |
MockTransaction::Eip1559 { ref mut $field, .. } |
MockTransaction::Eip4844 { ref mut $field, .. } |
MockTransaction::Eip2930 { ref mut $field, .. } => {
*$field = new_value;
}
Expand All @@ -109,9 +103,9 @@ macro_rules! set_value {
macro_rules! get_value {
($this:tt => $field:ident) => {
match $this {
MockTransaction::Legacy { $field, .. } => $field.clone(),
MockTransaction::Eip1559 { $field, .. } => $field.clone(),
MockTransaction::Eip4844 { $field, .. } => $field.clone(),
MockTransaction::Legacy { $field, .. } |
MockTransaction::Eip1559 { $field, .. } |
MockTransaction::Eip4844 { $field, .. } |
MockTransaction::Eip2930 { $field, .. } => $field.clone(),
#[cfg(feature = "optimism")]
#[allow(unused_variables)]
Expand Down Expand Up @@ -1377,22 +1371,17 @@ impl MockTransactionDistribution {

/// Generates a new transaction
pub fn tx(&self, nonce: u64, rng: &mut impl rand::Rng) -> MockTransaction {
let transaction_sample = self.transaction_ratio.sample(rng);
let tx = if transaction_sample == 0 {
MockTransaction::legacy().with_gas_price(self.fee_ranges.sample_gas_price(rng))
} else if transaction_sample == 1 {
MockTransaction::eip2930().with_gas_price(self.fee_ranges.sample_gas_price(rng))
} else if transaction_sample == 2 {
MockTransaction::eip1559()
let tx = match self.transaction_ratio.sample(rng) {
0 => MockTransaction::legacy().with_gas_price(self.fee_ranges.sample_gas_price(rng)),
1 => MockTransaction::eip2930().with_gas_price(self.fee_ranges.sample_gas_price(rng)),
2 => MockTransaction::eip1559()
.with_priority_fee(self.fee_ranges.sample_priority_fee(rng))
.with_max_fee(self.fee_ranges.sample_max_fee(rng))
} else if transaction_sample == 3 {
MockTransaction::eip4844()
.with_max_fee(self.fee_ranges.sample_max_fee(rng)),
3 => MockTransaction::eip4844()
.with_priority_fee(self.fee_ranges.sample_priority_fee(rng))
.with_max_fee(self.fee_ranges.sample_max_fee(rng))
.with_blob_fee(self.fee_ranges.sample_max_fee_blob(rng))
} else {
unreachable!("unknown transaction type returned by the weighted index")
.with_blob_fee(self.fee_ranges.sample_max_fee_blob(rng)),
_ => unreachable!("unknown transaction type returned by the weighted index"),
};

let size = self.size_range.sample(rng);
Expand Down
17 changes: 9 additions & 8 deletions crates/transaction-pool/src/validate/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ use tokio::{
};
use tokio_stream::wrappers::ReceiverStream;

/// Represents a future outputting unit type and is sendable.
type ValidationFuture = Pin<Box<dyn Future<Output = ()> + Send>>;

/// Represents a stream of validation futures.
type ValidationStream = ReceiverStream<ValidationFuture>;

/// A service that performs validation jobs.
///
/// This listens for incoming validation jobs and executes them.
///
/// This should be spawned as a task: [ValidationTask::run]
#[derive(Clone)]
pub struct ValidationTask {
#[allow(clippy::type_complexity)]
validation_jobs: Arc<Mutex<ReceiverStream<Pin<Box<dyn Future<Output = ()> + Send>>>>>,
validation_jobs: Arc<Mutex<ValidationStream>>,
}

impl ValidationTask {
Expand All @@ -44,12 +49,8 @@ impl ValidationTask {
///
/// This will run as long as the channel is alive and is expected to be spawned as a task.
pub async fn run(self) {
loop {
let task = self.validation_jobs.lock().await.next().await;
match task {
None => return,
Some(task) => task.await,
}
while let Some(task) = self.validation_jobs.lock().await.next().await {
task.await;
}
}
}
Expand Down

0 comments on commit 37a8780

Please sign in to comment.