From b7ac2d6fd2ee32084f4d194314f7b38521974ca2 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sat, 24 Feb 2024 13:40:19 +0200 Subject: [PATCH] chore: use fmt::Formatter helpers (#6775) --- Cargo.lock | 1 + crates/transaction-pool/Cargo.toml | 1 + crates/transaction-pool/src/pool/txpool.rs | 31 +++++++++++----------- crates/transaction-pool/src/traits.rs | 14 +++++++--- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3f37433f72..1a16213517 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6956,6 +6956,7 @@ dependencies = [ "criterion", "fnv", "futures-util", + "itertools 0.12.1", "metrics", "parking_lot 0.12.1", "paste", diff --git a/crates/transaction-pool/Cargo.toml b/crates/transaction-pool/Cargo.toml index 882bc9cc71..41dece4308 100644 --- a/crates/transaction-pool/Cargo.toml +++ b/crates/transaction-pool/Cargo.toml @@ -49,6 +49,7 @@ fnv = "1.0.7" bitflags.workspace = true auto_impl = "1.0" smallvec.workspace = true +itertools.workspace = true # testing rand = { workspace = true, optional = true } diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index 6be65228a5..c43868d36e 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -19,6 +19,7 @@ use crate::{ ValidPoolTransaction, U256, }; use fnv::FnvHashMap; +use itertools::Itertools; use reth_primitives::{ constants::{ eip4844::BLOB_TX_MIN_BLOB_GASPRICE, ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE, @@ -1819,21 +1820,21 @@ pub struct PruneResult { } impl fmt::Debug for PruneResult { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(fmt, "PruneResult {{ ")?; - write!( - fmt, - "promoted: {:?}, ", - self.promoted.iter().map(|tx| *tx.hash()).collect::>() - )?; - write!(fmt, "failed: {:?}, ", self.failed)?; - write!( - fmt, - "pruned: {:?}, ", - self.pruned.iter().map(|tx| *tx.transaction.hash()).collect::>() - )?; - write!(fmt, "}}")?; - Ok(()) + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("PruneResult") + .field( + "promoted", + &format_args!("[{}]", self.promoted.iter().map(|tx| tx.hash()).format(", ")), + ) + .field("failed", &self.failed) + .field( + "pruned", + &format_args!( + "[{}]", + self.pruned.iter().map(|tx| tx.transaction.hash()).format(", ") + ), + ) + .finish() } } diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index 178f882645..0de5a48450 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -568,7 +568,7 @@ impl TransactionOrigin { /// known block hash. /// /// This is used to update the pool state accordingly. -#[derive(Debug, Clone)] +#[derive(Clone, Debug)] pub struct CanonicalStateUpdate<'a> { /// Hash of the tip block. pub new_tip: &'a SealedBlock, @@ -613,10 +613,16 @@ impl<'a> CanonicalStateUpdate<'a> { } } -impl<'a> fmt::Display for CanonicalStateUpdate<'a> { +impl fmt::Display for CanonicalStateUpdate<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{{ hash: {}, number: {}, pending_block_base_fee: {}, pending_block_blob_fee: {:?}, changed_accounts: {}, mined_transactions: {} }}", - self.hash(), self.number(), self.pending_block_base_fee, self.pending_block_blob_fee, self.changed_accounts.len(), self.mined_transactions.len()) + f.debug_struct("CanonicalStateUpdate") + .field("hash", &self.hash()) + .field("number", &self.number()) + .field("pending_block_base_fee", &self.pending_block_base_fee) + .field("pending_block_blob_fee", &self.pending_block_blob_fee) + .field("changed_accounts", &self.changed_accounts.len()) + .field("mined_transactions", &self.mined_transactions.len()) + .finish() } }