From 6870c41fb013e04e5a05955adc688bff38f6c826 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 10 Dec 2022 18:12:16 +0100 Subject: [PATCH] chore(txpool): deny additional lints (#379) --- crates/transaction-pool/src/identifier.rs | 8 ++++---- crates/transaction-pool/src/lib.rs | 10 ++++++++-- crates/transaction-pool/src/pool/best.rs | 2 +- crates/transaction-pool/src/pool/listener.rs | 2 +- crates/transaction-pool/src/pool/mod.rs | 10 ++++++++-- crates/transaction-pool/src/pool/parked.rs | 6 ++++-- crates/transaction-pool/src/pool/txpool.rs | 12 +++++++++--- crates/transaction-pool/src/test_util/mock.rs | 2 +- crates/transaction-pool/src/test_util/mod.rs | 2 +- crates/transaction-pool/src/traits.rs | 2 +- crates/transaction-pool/src/validate.rs | 1 + 11 files changed, 39 insertions(+), 18 deletions(-) diff --git a/crates/transaction-pool/src/identifier.rs b/crates/transaction-pool/src/identifier.rs index 07098b68a1..0c2df6d211 100644 --- a/crates/transaction-pool/src/identifier.rs +++ b/crates/transaction-pool/src/identifier.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; /// /// This assigns a _unique_ `SenderId` for a new `Address`. #[derive(Debug, Default)] -pub struct SenderIdentifiers { +pub(crate) struct SenderIdentifiers { /// The identifier to use next. id: u64, /// Assigned `SenderId` for an `Address`. @@ -18,17 +18,17 @@ pub struct SenderIdentifiers { impl SenderIdentifiers { /// Returns the address for the given identifier. #[allow(unused)] - pub fn address(&self, id: &SenderId) -> Option<&Address> { + pub(crate) fn address(&self, id: &SenderId) -> Option<&Address> { self.sender_to_address.get(id) } /// Returns the `SenderId` that belongs to the given address, if it exists - pub fn sender_id(&self, addr: &Address) -> Option { + pub(crate) fn sender_id(&self, addr: &Address) -> Option { self.address_to_id.get(addr).copied() } /// Returns the existing `SendId` or assigns a new one if it's missing - pub fn sender_id_or_create(&mut self, addr: Address) -> SenderId { + pub(crate) fn sender_id_or_create(&mut self, addr: Address) -> SenderId { if let Some(id) = self.sender_id(&addr) { return id } diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index f0b9a9ef80..1bf0a3ed95 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -1,6 +1,11 @@ #![warn(missing_docs)] -// unreachable_pub, missing_debug_implementations -#![deny(unused_must_use, rust_2018_idioms)] +#![deny( + unused_must_use, + rust_2018_idioms, + unreachable_pub, + missing_debug_implementations, + rustdoc::broken_intra_doc_links +)] #![doc(test( no_crate_inject, attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables)) @@ -105,6 +110,7 @@ mod validate; mod test_util; /// A shareable, generic, customizable `TransactionPool` implementation. +#[derive(Debug)] pub struct Pool { /// Arc'ed instance of the pool internals pool: Arc>, diff --git a/crates/transaction-pool/src/pool/best.rs b/crates/transaction-pool/src/pool/best.rs index 52c0e26f97..954538e4a5 100644 --- a/crates/transaction-pool/src/pool/best.rs +++ b/crates/transaction-pool/src/pool/best.rs @@ -17,7 +17,7 @@ use tracing::debug; /// only yields transactions that are ready to be executed now. /// While it contains all gapless transactions of a sender, it _always_ only returns the transaction /// with the current on chain nonce. -pub struct BestTransactions { +pub(crate) struct BestTransactions { /// Contains a copy of _all_ transactions of the pending pool at the point in time this /// iterator was created. pub(crate) all: BTreeMap>>, diff --git a/crates/transaction-pool/src/pool/listener.rs b/crates/transaction-pool/src/pool/listener.rs index c8c1f26a35..9a44cc01e1 100644 --- a/crates/transaction-pool/src/pool/listener.rs +++ b/crates/transaction-pool/src/pool/listener.rs @@ -11,7 +11,7 @@ type EventBroadcast = UnboundedSender; /// /// This is essentially a multi-producer, multi-consumer channel where each event is broadcasted to /// all active receivers. -#[derive(Default)] +#[derive(Debug, Default)] pub(crate) struct PoolEventBroadcast { /// All listeners for certain transaction events. broadcasters: HashMap, diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index 766a75e809..06283fdec9 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -81,7 +81,7 @@ use best::BestTransactions; pub use events::TransactionEvent; use parking_lot::{Mutex, RwLock}; use reth_primitives::{Address, TxHash, H256}; -use std::{collections::HashSet, sync::Arc, time::Instant}; +use std::{collections::HashSet, fmt, sync::Arc, time::Instant}; use tokio::sync::mpsc; use tracing::warn; @@ -122,7 +122,7 @@ where T: TransactionOrdering::Transaction>, { /// Create a new transaction pool instance. - pub fn new(validator: Arc, ordering: Arc, config: PoolConfig) -> Self { + pub(crate) fn new(validator: Arc, ordering: Arc, config: PoolConfig) -> Self { Self { identifiers: Default::default(), validator, @@ -381,6 +381,12 @@ where } } +impl fmt::Debug for PoolInner { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("PoolInner").field("config", &self.config).finish_non_exhaustive() + } +} + /// Tracks an added transaction and all graph changes caused by adding it. #[derive(Debug, Clone)] pub struct AddedPendingTransaction { diff --git a/crates/transaction-pool/src/pool/parked.rs b/crates/transaction-pool/src/pool/parked.rs index b0bebc98ae..94105a1609 100644 --- a/crates/transaction-pool/src/pool/parked.rs +++ b/crates/transaction-pool/src/pool/parked.rs @@ -208,7 +208,8 @@ macro_rules! impl_ord_wrapper { /// This sorts transactions by their base fee. /// /// Caution: This assumes all transaction in the `BaseFee` sub-pool have a fee value. -pub struct BasefeeOrd(Arc>); +#[derive(Debug)] +pub(crate) struct BasefeeOrd(Arc>); impl_ord_wrapper!(BasefeeOrd); @@ -232,7 +233,8 @@ impl Ord for BasefeeOrd { /// /// The primary order function for is always compares via the timestamp when the transaction was /// created -pub struct QueuedOrd(Arc>); +#[derive(Debug)] +pub(crate) struct QueuedOrd(Arc>); impl_ord_wrapper!(QueuedOrd); diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index 7dc6fc430f..14d98e33cb 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -91,7 +91,7 @@ pub struct TxPool { impl TxPool { /// Create a new graph pool instance. - pub fn new(ordering: Arc, config: PoolConfig) -> Self { + pub(crate) fn new(ordering: Arc, config: PoolConfig) -> Self { Self { sender_info: Default::default(), pending_pool: PendingPool::new(ordering), @@ -376,7 +376,7 @@ impl TxPool { /// /// If the current size exceeds the given bounds, the worst transactions are evicted from the /// pool and returned. - pub fn discard_worst(&mut self) -> Vec>> { + pub(crate) fn discard_worst(&mut self) -> Vec>> { let mut removed = Vec::new(); // Helper macro that discards the worst transactions for the pools @@ -438,11 +438,17 @@ impl TxPool { } } +impl fmt::Debug for TxPool { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("TxPool").field("config", &self.config).finish_non_exhaustive() + } +} + /// Container for _all_ transaction in the pool. /// /// This is the sole entrypoint that's guarding all sub-pools, all sub-pool actions are always /// derived from this set. Updates returned from this type must be applied to the sub-pools. -pub struct AllTransactions { +pub(crate) struct AllTransactions { /// Expected base fee for the pending block. pending_basefee: U256, /// Minimum base fee required by the protol. diff --git a/crates/transaction-pool/src/test_util/mock.rs b/crates/transaction-pool/src/test_util/mock.rs index b4f3b1cd3f..6a596df6eb 100644 --- a/crates/transaction-pool/src/test_util/mock.rs +++ b/crates/transaction-pool/src/test_util/mock.rs @@ -386,7 +386,7 @@ impl FromRecoveredTransaction for MockTransaction { #[derive(Default)] pub struct MockTransactionFactory { - pub ids: SenderIdentifiers, + pub(crate) ids: SenderIdentifiers, } // === impl MockTransactionFactory === diff --git a/crates/transaction-pool/src/test_util/mod.rs b/crates/transaction-pool/src/test_util/mod.rs index 53de245740..ad126940f0 100644 --- a/crates/transaction-pool/src/test_util/mod.rs +++ b/crates/transaction-pool/src/test_util/mod.rs @@ -1,5 +1,5 @@ //! Internal helpers for testing. -#![allow(missing_docs, unused)] +#![allow(missing_docs, unused, missing_debug_implementations, unreachable_pub)] mod mock; mod pool; diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index f15092444e..78f96f6298 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -172,7 +172,7 @@ impl Clone for NewTransactionEvent { /// /// Depending on where the transaction was picked up, it affects how the transaction is handled /// internally, e.g. limits for simultaneous transaction of one sender. -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum TransactionOrigin { /// Transaction is coming from a local source. Local, diff --git a/crates/transaction-pool/src/validate.rs b/crates/transaction-pool/src/validate.rs index 1d46c87905..68e9748b3f 100644 --- a/crates/transaction-pool/src/validate.rs +++ b/crates/transaction-pool/src/validate.rs @@ -9,6 +9,7 @@ use reth_primitives::{rpc::Address, TxHash, U256}; use std::{fmt, time::Instant}; /// A Result type returned after checking a transaction's validity. +#[derive(Debug)] pub enum TransactionValidationOutcome { /// Transaction successfully validated Valid {