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

txpool: LOG_TARGET const added #13180

Merged
merged 5 commits into from
Jan 19, 2023
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
6 changes: 4 additions & 2 deletions client/transaction-pool/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use sp_runtime::{
};
use std::{collections::HashMap, hash::Hash, pin::Pin, sync::Arc};

const LOG_TARGET: &str = "txpool::api";

pub use sp_runtime::transaction_validity::{
TransactionLongevity, TransactionPriority, TransactionSource, TransactionTag,
};
Expand Down Expand Up @@ -353,7 +355,7 @@ impl<TPool: LocalTransactionPool> OffchainSubmitTransaction<TPool::Block> for TP
extrinsic: <TPool::Block as BlockT>::Extrinsic,
) -> Result<(), ()> {
log::debug!(
target: "txpool",
target: LOG_TARGET,
"(offchain call) Submitting a transaction to the pool: {:?}",
extrinsic
);
Expand All @@ -362,7 +364,7 @@ impl<TPool: LocalTransactionPool> OffchainSubmitTransaction<TPool::Block> for TP

result.map(|_| ()).map_err(|e| {
log::warn!(
target: "txpool",
target: LOG_TARGET,
"(offchain call) Error submitting a transaction to the pool: {}",
e
)
Expand Down
3 changes: 2 additions & 1 deletion client/transaction-pool/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

//! Chain api required for the transaction pool.

use crate::LOG_TARGET;
use codec::Encode;
use futures::{
channel::{mpsc, oneshot},
Expand Down Expand Up @@ -85,7 +86,7 @@ impl<Client, Block> FullChainApi<Client, Block> {
let metrics = prometheus.map(ApiMetrics::register).and_then(|r| match r {
Err(err) => {
log::warn!(
target: "txpool",
target: LOG_TARGET,
"Failed to register transaction pool api prometheus metrics: {:?}",
err,
);
Expand Down
27 changes: 19 additions & 8 deletions client/transaction-pool/src/enactment_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

//! Substrate transaction pool implementation.

use crate::LOG_TARGET;
use num_traits::CheckedSub;
use sc_transaction_pool_api::ChainEvent;
use sp_blockchain::TreeRoute;
Expand Down Expand Up @@ -113,14 +114,14 @@ where
};

if skip_maintenance {
log::debug!(target: "txpool", "skip maintain: tree_route would be too long");
log::debug!(target: LOG_TARGET, "skip maintain: tree_route would be too long");
self.force_update(event);
return Ok(EnactmentAction::Skip)
}

// block was already finalized
if self.recent_finalized_block == new_hash {
log::debug!(target: "txpool", "handle_enactment: block already finalized");
log::debug!(target: LOG_TARGET, "handle_enactment: block already finalized");
return Ok(EnactmentAction::Skip)
}

Expand All @@ -129,19 +130,24 @@ where
let tree_route = tree_route(self.recent_best_block, new_hash)?;

log::debug!(
target: "txpool",
target: LOG_TARGET,
"resolve hash:{:?} finalized:{:?} tree_route:{:?} best_block:{:?} finalized_block:{:?}",
new_hash, finalized, tree_route, self.recent_best_block, self.recent_finalized_block
new_hash,
finalized,
tree_route,
self.recent_best_block,
self.recent_finalized_block
);

// check if recently finalized block is on retracted path. this could be
// happening if we first received a finalization event and then a new
// best event for some old stale best head.
if tree_route.retracted().iter().any(|x| x.hash == self.recent_finalized_block) {
log::debug!(
target: "txpool",
target: LOG_TARGET,
"Recently finalized block {} would be retracted by ChainEvent {}, skipping",
self.recent_finalized_block, new_hash
self.recent_finalized_block,
new_hash
);
return Ok(EnactmentAction::Skip)
}
Expand All @@ -155,7 +161,7 @@ where
// remains valid.
if tree_route.enacted().is_empty() {
log::trace!(
target: "txpool",
target: LOG_TARGET,
"handle_enactment: no newly enacted blocks since recent best block"
);
return Ok(EnactmentAction::HandleFinalization)
Expand All @@ -176,7 +182,12 @@ where
ChainEvent::NewBestBlock { hash, .. } => self.recent_best_block = *hash,
ChainEvent::Finalized { hash, .. } => self.recent_finalized_block = *hash,
};
log::debug!(target: "txpool", "forced update: {:?}, {:?}", self.recent_best_block, self.recent_finalized_block);
log::debug!(
target: LOG_TARGET,
"forced update: {:?}, {:?}",
self.recent_best_block,
self.recent_finalized_block,
);
}
}

Expand Down
14 changes: 9 additions & 5 deletions client/transaction-pool/src/graph/base_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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);
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
},
}
Expand Down
20 changes: 13 additions & 7 deletions client/transaction-pool/src/graph/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
Expand All @@ -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(),
Expand All @@ -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());
Expand Down Expand Up @@ -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))
}
}
Expand Down
15 changes: 10 additions & 5 deletions client/transaction-pool/src/graph/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:?}",
);
}
},
}
Expand Down Expand Up @@ -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)?;

Expand All @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions client/transaction-pool/src/graph/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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
);
Expand All @@ -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
}
Expand Down
Loading