Skip to content

Commit

Permalink
chore: use fmt::Formatter helpers (paradigmxyz#6775)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Feb 24, 2024
1 parent 12b3bae commit b7ac2d6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/transaction-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
31 changes: 16 additions & 15 deletions crates/transaction-pool/src/pool/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1819,21 +1820,21 @@ pub struct PruneResult<T: PoolTransaction> {
}

impl<T: PoolTransaction> fmt::Debug for PruneResult<T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "PruneResult {{ ")?;
write!(
fmt,
"promoted: {:?}, ",
self.promoted.iter().map(|tx| *tx.hash()).collect::<Vec<_>>()
)?;
write!(fmt, "failed: {:?}, ", self.failed)?;
write!(
fmt,
"pruned: {:?}, ",
self.pruned.iter().map(|tx| *tx.transaction.hash()).collect::<Vec<_>>()
)?;
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()
}
}

Expand Down
14 changes: 10 additions & 4 deletions crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
}

Expand Down

0 comments on commit b7ac2d6

Please sign in to comment.