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

Commit c6dbee7

Browse files
txpool: LOG_TARGET const added
part of: #12873
1 parent 0b6aec5 commit c6dbee7

File tree

10 files changed

+117
-64
lines changed

10 files changed

+117
-64
lines changed

client/transaction-pool/api/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ use sp_runtime::{
3030
};
3131
use std::{collections::HashMap, hash::Hash, pin::Pin, sync::Arc};
3232

33+
#[allow(missing_docs)]
34+
const LOG_TARGET: &str = "txpool";
35+
3336
pub use sp_runtime::transaction_validity::{
3437
TransactionLongevity, TransactionPriority, TransactionSource, TransactionTag,
3538
};
@@ -353,7 +356,7 @@ impl<TPool: LocalTransactionPool> OffchainSubmitTransaction<TPool::Block> for TP
353356
extrinsic: <TPool::Block as BlockT>::Extrinsic,
354357
) -> Result<(), ()> {
355358
log::debug!(
356-
target: "txpool",
359+
target: LOG_TARGET,
357360
"(offchain call) Submitting a transaction to the pool: {:?}",
358361
extrinsic
359362
);
@@ -362,7 +365,7 @@ impl<TPool: LocalTransactionPool> OffchainSubmitTransaction<TPool::Block> for TP
362365

363366
result.map(|_| ()).map_err(|e| {
364367
log::warn!(
365-
target: "txpool",
368+
target: LOG_TARGET,
366369
"(offchain call) Error submitting a transaction to the pool: {}",
367370
e
368371
)

client/transaction-pool/src/api.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
//! Chain api required for the transaction pool.
2020
21+
use crate::LOG_TARGET;
2122
use codec::Encode;
2223
use futures::{
2324
channel::{mpsc, oneshot},
@@ -85,7 +86,7 @@ impl<Client, Block> FullChainApi<Client, Block> {
8586
let metrics = prometheus.map(ApiMetrics::register).and_then(|r| match r {
8687
Err(err) => {
8788
log::warn!(
88-
target: "txpool",
89+
target: LOG_TARGET,
8990
"Failed to register transaction pool api prometheus metrics: {:?}",
9091
err,
9192
);

client/transaction-pool/src/enactment_state.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
//! Substrate transaction pool implementation.
2020
21+
use crate::LOG_TARGET;
2122
use num_traits::CheckedSub;
2223
use sc_transaction_pool_api::ChainEvent;
2324
use sp_blockchain::TreeRoute;
@@ -113,14 +114,14 @@ where
113114
};
114115

115116
if skip_maintenance {
116-
log::debug!(target: "txpool", "skip maintain: tree_route would be too long");
117+
log::debug!(target: LOG_TARGET, "skip maintain: tree_route would be too long");
117118
self.force_update(event);
118119
return Ok(EnactmentAction::Skip)
119120
}
120121

121122
// block was already finalized
122123
if self.recent_finalized_block == new_hash {
123-
log::debug!(target: "txpool", "handle_enactment: block already finalized");
124+
log::debug!(target: LOG_TARGET, "handle_enactment: block already finalized");
124125
return Ok(EnactmentAction::Skip)
125126
}
126127

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

131132
log::debug!(
132-
target: "txpool",
133+
target: LOG_TARGET,
133134
"resolve hash:{:?} finalized:{:?} tree_route:{:?} best_block:{:?} finalized_block:{:?}",
134-
new_hash, finalized, tree_route, self.recent_best_block, self.recent_finalized_block
135+
new_hash,
136+
finalized,
137+
tree_route,
138+
self.recent_best_block,
139+
self.recent_finalized_block
135140
);
136141

137142
// check if recently finalized block is on retracted path. this could be
138143
// happening if we first received a finalization event and then a new
139144
// best event for some old stale best head.
140145
if tree_route.retracted().iter().any(|x| x.hash == self.recent_finalized_block) {
141146
log::debug!(
142-
target: "txpool",
147+
target: LOG_TARGET,
143148
"Recently finalized block {} would be retracted by ChainEvent {}, skipping",
144-
self.recent_finalized_block, new_hash
149+
self.recent_finalized_block,
150+
new_hash
145151
);
146152
return Ok(EnactmentAction::Skip)
147153
}
@@ -155,7 +161,7 @@ where
155161
// remains valid.
156162
if tree_route.enacted().is_empty() {
157163
log::trace!(
158-
target: "txpool",
164+
target: LOG_TARGET,
159165
"handle_enactment: no newly enacted blocks since recent best block"
160166
);
161167
return Ok(EnactmentAction::HandleFinalization)
@@ -176,7 +182,12 @@ where
176182
ChainEvent::NewBestBlock { hash, .. } => self.recent_best_block = *hash,
177183
ChainEvent::Finalized { hash, .. } => self.recent_finalized_block = *hash,
178184
};
179-
log::debug!(target: "txpool", "forced update: {:?}, {:?}", self.recent_best_block, self.recent_finalized_block);
185+
log::debug!(
186+
target: LOG_TARGET,
187+
"forced update: {:?}, {:?}",
188+
self.recent_best_block,
189+
self.recent_finalized_block
190+
);
180191
}
181192
}
182193

client/transaction-pool/src/graph/base_pool.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
2323
use std::{cmp::Ordering, collections::HashSet, fmt, hash, sync::Arc};
2424

25+
use crate::LOG_TARGET;
2526
use log::{debug, trace, warn};
2627
use sc_transaction_pool_api::{error, InPoolTransaction, PoolStatus};
2728
use serde::Serialize;
@@ -272,9 +273,9 @@ impl<Hash: hash::Hash + Member + Serialize, Ex: std::fmt::Debug> BasePool<Hash,
272273
}
273274

274275
let tx = WaitingTransaction::new(tx, self.ready.provided_tags(), &self.recently_pruned);
275-
trace!(target: "txpool", "[{:?}] {:?}", tx.transaction.hash, tx);
276+
trace!(target: LOG_TARGET, "[{:?}] {:?}", tx.transaction.hash, tx);
276277
debug!(
277-
target: "txpool",
278+
target: LOG_TARGET,
278279
"[{:?}] Importing to {}",
279280
tx.transaction.hash,
280281
if tx.is_ready() { "ready" } else { "future" }
@@ -328,7 +329,7 @@ impl<Hash: hash::Hash + Member + Serialize, Ex: std::fmt::Debug> BasePool<Hash,
328329
// transaction failed to be imported.
329330
Err(e) =>
330331
if first {
331-
debug!(target: "txpool", "[{:?}] Error importing: {:?}", current_hash, e);
332+
debug!(target: LOG_TARGET, "[{:?}] Error importing: {:?}", current_hash, e);
332333
return Err(e)
333334
} else {
334335
failed.push(current_hash);
@@ -347,7 +348,7 @@ impl<Hash: hash::Hash + Member + Serialize, Ex: std::fmt::Debug> BasePool<Hash,
347348
// since they depend on each other and will never get to the best iterator.
348349
self.ready.remove_subtree(&promoted);
349350

350-
debug!(target: "txpool", "[{:?}] Cycle detected, bailing.", hash);
351+
debug!(target: LOG_TARGET, "[{:?}] Cycle detected, bailing.", hash);
351352
return Err(error::Error::CycleDetected)
352353
}
353354

@@ -490,7 +491,10 @@ impl<Hash: hash::Hash + Member + Serialize, Ex: std::fmt::Debug> BasePool<Hash,
490491
match self.import_to_ready(tx) {
491492
Ok(res) => promoted.push(res),
492493
Err(e) => {
493-
warn!(target: "txpool", "[{:?}] Failed to promote during pruning: {:?}", hash, e);
494+
warn!(
495+
target: LOG_TARGET,
496+
"[{:?}] Failed to promote during pruning: {:?}", hash, e
497+
);
494498
failed.push(hash)
495499
},
496500
}

client/transaction-pool/src/graph/listener.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use std::{collections::HashMap, fmt::Debug, hash};
2020

21+
use crate::LOG_TARGET;
2122
use linked_hash_map::LinkedHashMap;
2223
use log::{debug, trace};
2324
use serde::Serialize;
@@ -67,13 +68,13 @@ impl<H: hash::Hash + traits::Member + Serialize, C: ChainApi> Listener<H, C> {
6768

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

7475
/// New transaction was added to the ready pool or promoted from the future pool.
7576
pub fn ready(&mut self, tx: &H, old: Option<&H>) {
76-
trace!(target: "txpool", "[{:?}] Ready (replaced with {:?})", tx, old);
77+
trace!(target: LOG_TARGET, "[{:?}] Ready (replaced with {:?})", tx, old);
7778
self.fire(tx, |watcher| watcher.ready());
7879
if let Some(old) = old {
7980
self.fire(old, |watcher| watcher.usurped(tx.clone()));
@@ -82,13 +83,13 @@ impl<H: hash::Hash + traits::Member + Serialize, C: ChainApi> Listener<H, C> {
8283

8384
/// New transaction was added to the future pool.
8485
pub fn future(&mut self, tx: &H) {
85-
trace!(target: "txpool", "[{:?}] Future", tx);
86+
trace!(target: LOG_TARGET, "[{:?}] Future", tx);
8687
self.fire(tx, |watcher| watcher.future());
8788
}
8889

8990
/// Transaction was dropped from the pool because of the limit.
9091
pub fn dropped(&mut self, tx: &H, by: Option<&H>) {
91-
trace!(target: "txpool", "[{:?}] Dropped (replaced with {:?})", tx, by);
92+
trace!(target: LOG_TARGET, "[{:?}] Dropped (replaced with {:?})", tx, by);
9293
self.fire(tx, |watcher| match by {
9394
Some(t) => watcher.usurped(t.clone()),
9495
None => watcher.dropped(),
@@ -97,13 +98,13 @@ impl<H: hash::Hash + traits::Member + Serialize, C: ChainApi> Listener<H, C> {
9798

9899
/// Transaction was removed as invalid.
99100
pub fn invalid(&mut self, tx: &H) {
100-
debug!(target: "txpool", "[{:?}] Extrinsic invalid", tx);
101+
debug!(target: LOG_TARGET, "[{:?}] Extrinsic invalid", tx);
101102
self.fire(tx, |watcher| watcher.invalid());
102103
}
103104

104105
/// Transaction was pruned from the pool.
105106
pub fn pruned(&mut self, block_hash: BlockHash<C>, tx: &H) {
106-
debug!(target: "txpool", "[{:?}] Pruned at {:?}", tx, block_hash);
107+
debug!(target: LOG_TARGET, "[{:?}] Pruned at {:?}", tx, block_hash);
107108
// Get the transactions included in the given block hash.
108109
let txs = self.finality_watchers.entry(block_hash).or_insert(vec![]);
109110
txs.push(tx.clone());
@@ -134,7 +135,12 @@ impl<H: hash::Hash + traits::Member + Serialize, C: ChainApi> Listener<H, C> {
134135
pub fn finalized(&mut self, block_hash: BlockHash<C>) {
135136
if let Some(hashes) = self.finality_watchers.remove(&block_hash) {
136137
for (tx_index, hash) in hashes.into_iter().enumerate() {
137-
log::debug!(target: "txpool", "[{:?}] Sent finalization event (block {:?})", hash, block_hash);
138+
log::debug!(
139+
target: LOG_TARGET,
140+
"[{:?}] Sent finalization event (block {:?})",
141+
hash,
142+
block_hash
143+
);
138144
self.fire(&hash, |watcher| watcher.finalized(block_hash, tx_index))
139145
}
140146
}

client/transaction-pool/src/graph/pool.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use std::{collections::HashMap, sync::Arc, time::Duration};
2020

21+
use crate::LOG_TARGET;
2122
use futures::{channel::mpsc::Receiver, Future};
2223
use sc_transaction_pool_api::error;
2324
use sp_blockchain::TreeRoute;
@@ -208,7 +209,8 @@ impl<B: ChainApi> Pool<B> {
208209
) {
209210
let now = Instant::now();
210211
self.validated_pool.resubmit(revalidated_transactions);
211-
log::debug!(target: "txpool",
212+
log::debug!(
213+
target: LOG_TARGET,
212214
"Resubmitted. Took {} ms. Status: {:?}",
213215
now.elapsed().as_millis(),
214216
self.validated_pool.status()
@@ -249,7 +251,7 @@ impl<B: ChainApi> Pool<B> {
249251
extrinsics: &[ExtrinsicFor<B>],
250252
) -> Result<(), B::Error> {
251253
log::debug!(
252-
target: "txpool",
254+
target: LOG_TARGET,
253255
"Starting pruning of block {:?} (extrinsics: {})",
254256
at,
255257
extrinsics.len()
@@ -287,7 +289,10 @@ impl<B: ChainApi> Pool<B> {
287289
future_tags.extend(validity.provides);
288290
}
289291
} else {
290-
log::trace!(target: "txpool", "txpool is empty, skipping validation for block {at:?}");
292+
log::trace!(
293+
target: LOG_TARGET,
294+
"txpool is empty, skipping validation for block {at:?}"
295+
);
291296
}
292297
},
293298
}
@@ -323,7 +328,7 @@ impl<B: ChainApi> Pool<B> {
323328
tags: impl IntoIterator<Item = Tag>,
324329
known_imported_hashes: impl IntoIterator<Item = ExtrinsicHash<B>> + Clone,
325330
) -> Result<(), B::Error> {
326-
log::debug!(target: "txpool", "Pruning at {:?}", at);
331+
log::debug!(target: LOG_TARGET, "Pruning at {:?}", at);
327332
// Prune all transactions that provide given tags
328333
let prune_status = self.validated_pool.prune_tags(tags)?;
329334

@@ -342,7 +347,7 @@ impl<B: ChainApi> Pool<B> {
342347
let reverified_transactions =
343348
self.verify(at, pruned_transactions, CheckBannedBeforeVerify::Yes).await?;
344349

345-
log::trace!(target: "txpool", "Pruning at {:?}. Resubmitting transactions.", at);
350+
log::trace!(target: LOG_TARGET, "Pruning at {:?}. Resubmitting transactions.", at);
346351
// And finally - submit reverified transactions back to the pool
347352

348353
self.validated_pool.resubmit_pruned(

client/transaction-pool/src/graph/ready.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::{
2323
sync::Arc,
2424
};
2525

26+
use crate::LOG_TARGET;
2627
use log::{debug, trace};
2728
use sc_transaction_pool_api::error;
2829
use serde::Serialize;
@@ -314,7 +315,7 @@ impl<Hash: hash::Hash + Member + Serialize, Ex> ReadyTransactions<Hash, Ex> {
314315
}
315316

316317
// add to removed
317-
trace!(target: "txpool", "[{:?}] Removed as part of the subtree.", hash);
318+
trace!(target: LOG_TARGET, "[{:?}] Removed as part of the subtree.", hash);
318319
removed.push(tx.transaction.transaction);
319320
}
320321
}
@@ -521,7 +522,7 @@ impl<Hash: hash::Hash + Member, Ex> BestIterator<Hash, Ex> {
521522
pub fn report_invalid(&mut self, tx: &Arc<Transaction<Hash, Ex>>) {
522523
if let Some(to_report) = self.all.get(&tx.hash) {
523524
debug!(
524-
target: "txpool",
525+
target: LOG_TARGET,
525526
"[{:?}] Reported as invalid. Will skip sub-chains while iterating.",
526527
to_report.transaction.transaction.hash
527528
);
@@ -544,9 +545,8 @@ impl<Hash: hash::Hash + Member, Ex> Iterator for BestIterator<Hash, Ex> {
544545
// Check if the transaction was marked invalid.
545546
if self.invalid.contains(hash) {
546547
debug!(
547-
target: "txpool",
548-
"[{:?}] Skipping invalid child transaction while iterating.",
549-
hash
548+
target: LOG_TARGET,
549+
"[{:?}] Skipping invalid child transaction while iterating.", hash
550550
);
551551
continue
552552
}

0 commit comments

Comments
 (0)