Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Additional logging for the transaction pool. #4068

Merged
merged 3 commits into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions core/transaction-pool/graph/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

use std::{
collections::HashMap,
fmt,
hash,
};
use serde::Serialize;
use crate::watcher;
use sr_primitives::traits;
use log::warn;
use log::{debug, trace, warn};

/// Extrinsic pool default listener.
pub struct Listener<H: hash::Hash + Eq, H2> {
Expand All @@ -37,7 +38,7 @@ impl<H: hash::Hash + Eq, H2> Default for Listener<H, H2> {
}
}

impl<H: hash::Hash + traits::Member + Serialize, H2: Clone> Listener<H, H2> {
impl<H: hash::Hash + traits::Member + Serialize, H2: Clone + fmt::Debug> Listener<H, H2> {
fn fire<F>(&mut self, hash: &H, fun: F) where F: FnOnce(&mut watcher::Sender<H, H2>) {
let clean = if let Some(h) = self.watchers.get_mut(hash) {
fun(h);
Expand All @@ -61,11 +62,13 @@ impl<H: hash::Hash + traits::Member + Serialize, H2: Clone> Listener<H, H2> {

/// Notify the listeners about extrinsic broadcast.
pub fn broadcasted(&mut self, hash: &H, peers: Vec<String>) {
trace!(target: "txpool", "[{:?}] Broadcasted", hash);
self.fire(hash, |watcher| watcher.broadcast(peers));
}

/// New transaction was added to the ready pool or promoted from the future pool.
pub fn ready(&mut self, tx: &H, old: Option<&H>) {
trace!(target: "txpool", "[{:?}] Ready (replaced: {:?})", tx, old);
self.fire(tx, |watcher| watcher.ready());
if let Some(old) = old {
self.fire(old, |watcher| watcher.usurped(tx.clone()));
Expand All @@ -74,11 +77,13 @@ impl<H: hash::Hash + traits::Member + Serialize, H2: Clone> Listener<H, H2> {

/// New transaction was added to the future pool.
pub fn future(&mut self, tx: &H) {
trace!(target: "txpool", "[{:?}] Future", tx);
self.fire(tx, |watcher| watcher.future());
}

/// Transaction was dropped from the pool because of the limit.
pub fn dropped(&mut self, tx: &H, by: Option<&H>) {
trace!(target: "txpool", "[{:?}] Dropped (replaced by {:?})", tx, by);
self.fire(tx, |watcher| match by {
Some(t) => watcher.usurped(t.clone()),
None => watcher.dropped(),
Expand All @@ -93,6 +98,7 @@ impl<H: hash::Hash + traits::Member + Serialize, H2: Clone> Listener<H, H2> {

/// Transaction was pruned from the pool.
pub fn pruned(&mut self, header_hash: H2, tx: &H) {
debug!(target: "txpool", "[{:?}] Pruned at {:?}", tx, header_hash);
self.fire(tx, |watcher| watcher.finalized(header_hash))
}
}
6 changes: 6 additions & 0 deletions core/transaction-pool/graph/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ impl<B: ChainApi> Pool<B> {
parent: &BlockId<B::Block>,
extrinsics: &[ExtrinsicFor<B>],
) -> impl Future<Output=Result<(), B::Error>> {
log::debug!(
target: "txpool",
"Starting pruning of block {:?} (extrinsics: {})",
at,
extrinsics.len()
);
// Get details of all extrinsics that are already in the pool
let (in_pool_hashes, in_pool_tags) = self.validated_pool.extrinsics_tags(extrinsics);

Expand Down
3 changes: 2 additions & 1 deletion core/transaction-pool/graph/src/validated_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use std::{
collections::{HashSet, HashMap},
fmt,
hash,
time,
};
Expand Down Expand Up @@ -355,7 +356,7 @@ fn fire_events<H, H2, Ex>(
imported: &base::Imported<H, Ex>,
) where
H: hash::Hash + Eq + traits::Member + Serialize,
H2: Clone,
H2: Clone + fmt::Debug,
{
match *imported {
base::Imported::Ready { ref promoted, ref failed, ref removed, ref hash } => {
Expand Down