chore(txpool): deny additional lints (#379)

This commit is contained in:
Matthias Seitz
2022-12-10 18:12:16 +01:00
committed by GitHub
parent e014eaad33
commit 6870c41fb0
11 changed files with 39 additions and 18 deletions

View File

@ -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<SenderId> {
pub(crate) fn sender_id(&self, addr: &Address) -> Option<SenderId> {
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
}

View File

@ -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<V: TransactionValidator, T: TransactionOrdering> {
/// Arc'ed instance of the pool internals
pool: Arc<PoolInner<V, T>>,

View File

@ -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<T: TransactionOrdering> {
pub(crate) struct BestTransactions<T: TransactionOrdering> {
/// Contains a copy of _all_ transactions of the pending pool at the point in time this
/// iterator was created.
pub(crate) all: BTreeMap<TransactionId, Arc<PendingTransaction<T>>>,

View File

@ -11,7 +11,7 @@ type EventBroadcast = UnboundedSender<TransactionEvent>;
///
/// 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<TxHash, PoolEventBroadcaster>,

View File

@ -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 = <V as TransactionValidator>::Transaction>,
{
/// Create a new transaction pool instance.
pub fn new(validator: Arc<V>, ordering: Arc<T>, config: PoolConfig) -> Self {
pub(crate) fn new(validator: Arc<V>, ordering: Arc<T>, config: PoolConfig) -> Self {
Self {
identifiers: Default::default(),
validator,
@ -381,6 +381,12 @@ where
}
}
impl<V: TransactionValidator, T: TransactionOrdering> fmt::Debug for PoolInner<V, T> {
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<T: PoolTransaction> {

View File

@ -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<T: PoolTransaction>(Arc<ValidPoolTransaction<T>>);
#[derive(Debug)]
pub(crate) struct BasefeeOrd<T: PoolTransaction>(Arc<ValidPoolTransaction<T>>);
impl_ord_wrapper!(BasefeeOrd);
@ -232,7 +233,8 @@ impl<T: PoolTransaction> Ord for BasefeeOrd<T> {
///
/// The primary order function for is always compares via the timestamp when the transaction was
/// created
pub struct QueuedOrd<T: PoolTransaction>(Arc<ValidPoolTransaction<T>>);
#[derive(Debug)]
pub(crate) struct QueuedOrd<T: PoolTransaction>(Arc<ValidPoolTransaction<T>>);
impl_ord_wrapper!(QueuedOrd);

View File

@ -91,7 +91,7 @@ pub struct TxPool<T: TransactionOrdering> {
impl<T: TransactionOrdering> TxPool<T> {
/// Create a new graph pool instance.
pub fn new(ordering: Arc<T>, config: PoolConfig) -> Self {
pub(crate) fn new(ordering: Arc<T>, config: PoolConfig) -> Self {
Self {
sender_info: Default::default(),
pending_pool: PendingPool::new(ordering),
@ -376,7 +376,7 @@ impl<T: TransactionOrdering> TxPool<T> {
///
/// 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<Arc<ValidPoolTransaction<T::Transaction>>> {
pub(crate) fn discard_worst(&mut self) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
let mut removed = Vec::new();
// Helper macro that discards the worst transactions for the pools
@ -438,11 +438,17 @@ impl<T: TransactionOrdering> TxPool<T> {
}
}
impl<T: TransactionOrdering> fmt::Debug for TxPool<T> {
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<T: PoolTransaction> {
pub(crate) struct AllTransactions<T: PoolTransaction> {
/// Expected base fee for the pending block.
pending_basefee: U256,
/// Minimum base fee required by the protol.

View File

@ -386,7 +386,7 @@ impl FromRecoveredTransaction for MockTransaction {
#[derive(Default)]
pub struct MockTransactionFactory {
pub ids: SenderIdentifiers,
pub(crate) ids: SenderIdentifiers,
}
// === impl MockTransactionFactory ===

View File

@ -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;

View File

@ -172,7 +172,7 @@ impl<T: PoolTransaction> Clone for NewTransactionEvent<T> {
///
/// 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,

View File

@ -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<T: PoolTransaction> {
/// Transaction successfully validated
Valid {