txpool: LOG_TARGET const added (#13180)

* txpool: LOG_TARGET const added

part of: #12873

* LOG_TARGET added to tests mod

* txpool::api for api

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>

* ".git/.scripts/commands/fmt/fmt.sh"

Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: command-bot <>
This commit is contained in:
Michal Kucharczyk
2023-01-19 23:21:41 +01:00
committed by GitHub
parent cce6d406bf
commit 57b1de3f47
11 changed files with 135 additions and 81 deletions
@@ -22,6 +22,7 @@
use std::{cmp::Ordering, collections::HashSet, fmt, hash, sync::Arc};
use crate::LOG_TARGET;
use log::{debug, trace, warn};
use sc_transaction_pool_api::{error, InPoolTransaction, PoolStatus};
use serde::Serialize;
@@ -272,9 +273,9 @@ impl<Hash: hash::Hash + Member + Serialize, Ex: std::fmt::Debug> BasePool<Hash,
}
let tx = WaitingTransaction::new(tx, self.ready.provided_tags(), &self.recently_pruned);
trace!(target: "txpool", "[{:?}] {:?}", tx.transaction.hash, tx);
trace!(target: LOG_TARGET, "[{:?}] {:?}", tx.transaction.hash, tx);
debug!(
target: "txpool",
target: LOG_TARGET,
"[{:?}] Importing to {}",
tx.transaction.hash,
if tx.is_ready() { "ready" } else { "future" }
@@ -328,7 +329,7 @@ impl<Hash: hash::Hash + Member + Serialize, Ex: std::fmt::Debug> BasePool<Hash,
// transaction failed to be imported.
Err(e) =>
if first {
debug!(target: "txpool", "[{:?}] Error importing: {:?}", current_hash, e);
debug!(target: LOG_TARGET, "[{:?}] Error importing: {:?}", current_hash, e);
return Err(e)
} else {
failed.push(current_hash);
@@ -347,7 +348,7 @@ impl<Hash: hash::Hash + Member + Serialize, Ex: std::fmt::Debug> BasePool<Hash,
// since they depend on each other and will never get to the best iterator.
self.ready.remove_subtree(&promoted);
debug!(target: "txpool", "[{:?}] Cycle detected, bailing.", hash);
debug!(target: LOG_TARGET, "[{:?}] Cycle detected, bailing.", hash);
return Err(error::Error::CycleDetected)
}
@@ -490,7 +491,10 @@ impl<Hash: hash::Hash + Member + Serialize, Ex: std::fmt::Debug> BasePool<Hash,
match self.import_to_ready(tx) {
Ok(res) => promoted.push(res),
Err(e) => {
warn!(target: "txpool", "[{:?}] Failed to promote during pruning: {:?}", hash, e);
warn!(
target: LOG_TARGET,
"[{:?}] Failed to promote during pruning: {:?}", hash, e,
);
failed.push(hash)
},
}
@@ -18,6 +18,7 @@
use std::{collections::HashMap, fmt::Debug, hash};
use crate::LOG_TARGET;
use linked_hash_map::LinkedHashMap;
use log::{debug, trace};
use serde::Serialize;
@@ -67,13 +68,13 @@ impl<H: hash::Hash + traits::Member + Serialize, C: ChainApi> Listener<H, C> {
/// Notify the listeners about extrinsic broadcast.
pub fn broadcasted(&mut self, hash: &H, peers: Vec<String>) {
trace!(target: "txpool", "[{:?}] Broadcasted", hash);
trace!(target: LOG_TARGET, "[{:?}] 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 with {:?})", tx, old);
trace!(target: LOG_TARGET, "[{:?}] Ready (replaced with {:?})", tx, old);
self.fire(tx, |watcher| watcher.ready());
if let Some(old) = old {
self.fire(old, |watcher| watcher.usurped(tx.clone()));
@@ -82,13 +83,13 @@ impl<H: hash::Hash + traits::Member + Serialize, C: ChainApi> Listener<H, C> {
/// New transaction was added to the future pool.
pub fn future(&mut self, tx: &H) {
trace!(target: "txpool", "[{:?}] Future", tx);
trace!(target: LOG_TARGET, "[{:?}] 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 with {:?})", tx, by);
trace!(target: LOG_TARGET, "[{:?}] Dropped (replaced with {:?})", tx, by);
self.fire(tx, |watcher| match by {
Some(t) => watcher.usurped(t.clone()),
None => watcher.dropped(),
@@ -97,13 +98,13 @@ impl<H: hash::Hash + traits::Member + Serialize, C: ChainApi> Listener<H, C> {
/// Transaction was removed as invalid.
pub fn invalid(&mut self, tx: &H) {
debug!(target: "txpool", "[{:?}] Extrinsic invalid", tx);
debug!(target: LOG_TARGET, "[{:?}] Extrinsic invalid", tx);
self.fire(tx, |watcher| watcher.invalid());
}
/// Transaction was pruned from the pool.
pub fn pruned(&mut self, block_hash: BlockHash<C>, tx: &H) {
debug!(target: "txpool", "[{:?}] Pruned at {:?}", tx, block_hash);
debug!(target: LOG_TARGET, "[{:?}] Pruned at {:?}", tx, block_hash);
// Get the transactions included in the given block hash.
let txs = self.finality_watchers.entry(block_hash).or_insert(vec![]);
txs.push(tx.clone());
@@ -134,7 +135,12 @@ impl<H: hash::Hash + traits::Member + Serialize, C: ChainApi> Listener<H, C> {
pub fn finalized(&mut self, block_hash: BlockHash<C>) {
if let Some(hashes) = self.finality_watchers.remove(&block_hash) {
for (tx_index, hash) in hashes.into_iter().enumerate() {
log::debug!(target: "txpool", "[{:?}] Sent finalization event (block {:?})", hash, block_hash);
log::debug!(
target: LOG_TARGET,
"[{:?}] Sent finalization event (block {:?})",
hash,
block_hash,
);
self.fire(&hash, |watcher| watcher.finalized(block_hash, tx_index))
}
}
@@ -18,6 +18,7 @@
use std::{collections::HashMap, sync::Arc, time::Duration};
use crate::LOG_TARGET;
use futures::{channel::mpsc::Receiver, Future};
use sc_transaction_pool_api::error;
use sp_blockchain::TreeRoute;
@@ -208,7 +209,8 @@ impl<B: ChainApi> Pool<B> {
) {
let now = Instant::now();
self.validated_pool.resubmit(revalidated_transactions);
log::debug!(target: "txpool",
log::debug!(
target: LOG_TARGET,
"Resubmitted. Took {} ms. Status: {:?}",
now.elapsed().as_millis(),
self.validated_pool.status()
@@ -249,7 +251,7 @@ impl<B: ChainApi> Pool<B> {
extrinsics: &[ExtrinsicFor<B>],
) -> Result<(), B::Error> {
log::debug!(
target: "txpool",
target: LOG_TARGET,
"Starting pruning of block {:?} (extrinsics: {})",
at,
extrinsics.len()
@@ -287,7 +289,10 @@ impl<B: ChainApi> Pool<B> {
future_tags.extend(validity.provides);
}
} else {
log::trace!(target: "txpool", "txpool is empty, skipping validation for block {at:?}");
log::trace!(
target: LOG_TARGET,
"txpool is empty, skipping validation for block {at:?}",
);
}
},
}
@@ -323,7 +328,7 @@ impl<B: ChainApi> Pool<B> {
tags: impl IntoIterator<Item = Tag>,
known_imported_hashes: impl IntoIterator<Item = ExtrinsicHash<B>> + Clone,
) -> Result<(), B::Error> {
log::debug!(target: "txpool", "Pruning at {:?}", at);
log::debug!(target: LOG_TARGET, "Pruning at {:?}", at);
// Prune all transactions that provide given tags
let prune_status = self.validated_pool.prune_tags(tags)?;
@@ -342,7 +347,7 @@ impl<B: ChainApi> Pool<B> {
let reverified_transactions =
self.verify(at, pruned_transactions, CheckBannedBeforeVerify::Yes).await?;
log::trace!(target: "txpool", "Pruning at {:?}. Resubmitting transactions.", at);
log::trace!(target: LOG_TARGET, "Pruning at {:?}. Resubmitting transactions.", at);
// And finally - submit reverified transactions back to the pool
self.validated_pool.resubmit_pruned(
@@ -23,6 +23,7 @@ use std::{
sync::Arc,
};
use crate::LOG_TARGET;
use log::{debug, trace};
use sc_transaction_pool_api::error;
use serde::Serialize;
@@ -314,7 +315,7 @@ impl<Hash: hash::Hash + Member + Serialize, Ex> ReadyTransactions<Hash, Ex> {
}
// add to removed
trace!(target: "txpool", "[{:?}] Removed as part of the subtree.", hash);
trace!(target: LOG_TARGET, "[{:?}] Removed as part of the subtree.", hash);
removed.push(tx.transaction.transaction);
}
}
@@ -521,7 +522,7 @@ impl<Hash: hash::Hash + Member, Ex> BestIterator<Hash, Ex> {
pub fn report_invalid(&mut self, tx: &Arc<Transaction<Hash, Ex>>) {
if let Some(to_report) = self.all.get(&tx.hash) {
debug!(
target: "txpool",
target: LOG_TARGET,
"[{:?}] Reported as invalid. Will skip sub-chains while iterating.",
to_report.transaction.transaction.hash
);
@@ -544,9 +545,8 @@ impl<Hash: hash::Hash + Member, Ex> Iterator for BestIterator<Hash, Ex> {
// Check if the transaction was marked invalid.
if self.invalid.contains(hash) {
debug!(
target: "txpool",
"[{:?}] Skipping invalid child transaction while iterating.",
hash
target: LOG_TARGET,
"[{:?}] Skipping invalid child transaction while iterating.", hash,
);
continue
}
@@ -22,6 +22,7 @@ use std::{
sync::Arc,
};
use crate::LOG_TARGET;
use futures::channel::mpsc::{channel, Sender};
use parking_lot::{Mutex, RwLock};
use sc_transaction_pool_api::{error, PoolStatus, ReadyTransactions};
@@ -199,7 +200,7 @@ impl<B: ChainApi> ValidatedPool<B> {
Err(e) =>
if e.is_full() {
log::warn!(
target: "txpool",
target: LOG_TARGET,
"[{:?}] Trying to notify an import but the channel is full",
hash,
);
@@ -230,15 +231,17 @@ impl<B: ChainApi> ValidatedPool<B> {
let ready_limit = &self.options.ready;
let future_limit = &self.options.future;
log::debug!(target: "txpool", "Pool Status: {:?}", status);
log::debug!(target: LOG_TARGET, "Pool Status: {:?}", status);
if ready_limit.is_exceeded(status.ready, status.ready_bytes) ||
future_limit.is_exceeded(status.future, status.future_bytes)
{
log::debug!(
target: "txpool",
target: LOG_TARGET,
"Enforcing limits ({}/{}kB ready, {}/{}kB future",
ready_limit.count, ready_limit.total_bytes / 1024,
future_limit.count, future_limit.total_bytes / 1024,
ready_limit.count,
ready_limit.total_bytes / 1024,
future_limit.count,
future_limit.total_bytes / 1024,
);
// clean up the pool
@@ -254,7 +257,7 @@ impl<B: ChainApi> ValidatedPool<B> {
removed
};
if !removed.is_empty() {
log::debug!(target: "txpool", "Enforcing limits: {} dropped", removed.len());
log::debug!(target: LOG_TARGET, "Enforcing limits: {} dropped", removed.len());
}
// run notifications
@@ -385,7 +388,7 @@ impl<B: ChainApi> ValidatedPool<B> {
// unknown to caller => let's just notify listeners (and issue debug
// message)
log::warn!(
target: "txpool",
target: LOG_TARGET,
"[{:?}] Removing invalid transaction from update: {}",
hash,
err,
@@ -595,14 +598,14 @@ impl<B: ChainApi> ValidatedPool<B> {
return vec![]
}
log::debug!(target: "txpool", "Removing invalid transactions: {:?}", hashes);
log::debug!(target: LOG_TARGET, "Removing invalid transactions: {:?}", hashes);
// temporarily ban invalid transactions
self.rotator.ban(&Instant::now(), hashes.iter().cloned());
let invalid = self.pool.write().remove_subtree(hashes);
log::debug!(target: "txpool", "Removed invalid transactions: {:?}", invalid);
log::debug!(target: LOG_TARGET, "Removed invalid transactions: {:?}", invalid);
let mut listener = self.listener.write();
for tx in &invalid {
@@ -629,7 +632,11 @@ impl<B: ChainApi> ValidatedPool<B> {
/// Notify all watchers that transactions in the block with hash have been finalized
pub async fn on_block_finalized(&self, block_hash: BlockHash<B>) -> Result<(), B::Error> {
log::trace!(target: "txpool", "Attempting to notify watchers of finalization for {}", block_hash);
log::trace!(
target: LOG_TARGET,
"Attempting to notify watchers of finalization for {}",
block_hash,
);
self.listener.write().finalized(block_hash);
Ok(())
}