Skip to content

Commit

Permalink
log: add tx status log (#2271)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanne007 authored Mar 15, 2021
1 parent 07fea8b commit b50e36f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
46 changes: 46 additions & 0 deletions txpool/src/pool/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,52 @@ impl tx_pool::Listener<Transaction> for Logger {
}
}

/// Transaction status logger.
#[derive(Default, Debug)]
pub struct StatusLogger;
impl StatusLogger {
fn log_status(tx: &Arc<Transaction>, status: TxStatus) {
debug!(
target: "tx-status",
"[tx-status] hash: {hash}, status: {status}",
hash = tx.hash(),
status = status
);
}
}
impl tx_pool::Listener<Transaction> for StatusLogger {
fn added(&mut self, tx: &Arc<Transaction>, old: Option<&Arc<Transaction>>) {
Self::log_status(tx, TxStatus::Added);
if let Some(old) = old {
Self::log_status(old, TxStatus::Dropped);
}
}

fn rejected<H: fmt::Debug + fmt::LowerHex>(
&mut self,
tx: &Arc<Transaction>,
_reason: &tx_pool::Error<H>,
) {
Self::log_status(tx, TxStatus::Rejected);
}

fn dropped(&mut self, tx: &Arc<Transaction>, _new: Option<&Transaction>) {
Self::log_status(tx, TxStatus::Dropped);
}

fn invalid(&mut self, tx: &Arc<Transaction>) {
Self::log_status(tx, TxStatus::Invalid);
}

fn canceled(&mut self, tx: &Arc<Transaction>) {
Self::log_status(tx, TxStatus::Canceled);
}

fn culled(&mut self, tx: &Arc<Transaction>) {
Self::log_status(tx, TxStatus::Culled);
}
}

/// Transactions pool notifier
#[derive(Default)]
pub struct TransactionsPoolNotifier {
Expand Down
5 changes: 4 additions & 1 deletion txpool/src/pool/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ use types::{account_address::AccountAddress as Address, transaction};

type Listener = (
LocalTransactionsList,
(listener::TransactionsPoolNotifier, listener::Logger),
(
listener::TransactionsPoolNotifier,
(listener::Logger, listener::StatusLogger),
),
);
type Pool = tx_pool::Pool<pool::VerifiedTransaction, scoring::SeqNumberAndGasPrice, Listener>;

Expand Down

0 comments on commit b50e36f

Please sign in to comment.