mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Add clippy fixes and minor refactoring (#6450)
This commit is contained in:
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@ -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>,
|
||||
@ -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,
|
||||
@ -927,6 +928,7 @@ impl HeadersRequestOutcome {
|
||||
}
|
||||
|
||||
/// Wrapper type to order responses
|
||||
#[derive(Debug)]
|
||||
struct OrderedHeadersResponse {
|
||||
headers: Vec<Header>,
|
||||
request: HeadersRequest,
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
#![allow(missing_docs)]
|
||||
use std::sync::Arc;
|
||||
|
||||
use alloy_primitives::hex;
|
||||
use c_kzg::{KzgCommitment, KzgSettings};
|
||||
use criterion::{
|
||||
@ -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");
|
||||
|
||||
@ -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]
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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)]
|
||||
@ -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)),
|
||||
3 => MockTransaction::eip4844()
|
||||
.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_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);
|
||||
|
||||
@ -17,6 +17,12 @@ 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.
|
||||
@ -24,8 +30,7 @@ use tokio_stream::wrappers::ReceiverStream;
|
||||
/// 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 {
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user