mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
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:
committed by
GitHub
parent
cce6d406bf
commit
57b1de3f47
@@ -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,
|
||||
};
|
||||
@@ -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
|
||||
);
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
//! Chain api required for the transaction pool.
|
||||
|
||||
use crate::LOG_TARGET;
|
||||
use codec::Encode;
|
||||
use futures::{
|
||||
channel::{mpsc, oneshot},
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -129,9 +130,13 @@ 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
|
||||
@@ -139,9 +144,10 @@ where
|
||||
// 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)
|
||||
}
|
||||
@@ -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)
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -67,6 +67,8 @@ use prometheus_endpoint::Registry as PrometheusRegistry;
|
||||
|
||||
use sp_blockchain::{HashAndNumber, TreeRoute};
|
||||
|
||||
pub(crate) const LOG_TARGET: &str = "txpool";
|
||||
|
||||
type BoxedReadyIterator<Hash, Data> =
|
||||
Box<dyn ReadyTransactions<Item = Arc<graph::base_pool::Transaction<Hash, Data>>> + Send>;
|
||||
|
||||
@@ -116,7 +118,7 @@ impl<T, Block: BlockT> ReadyPoll<T, Block> {
|
||||
while idx < self.pollers.len() {
|
||||
if self.pollers[idx].0 <= number {
|
||||
let poller_sender = self.pollers.swap_remove(idx);
|
||||
log::debug!(target: "txpool", "Sending ready signal at block {}", number);
|
||||
log::debug!(target: LOG_TARGET, "Sending ready signal at block {}", number);
|
||||
let _ = poller_sender.1.send(iterator_factory());
|
||||
} else {
|
||||
idx += 1;
|
||||
@@ -336,7 +338,7 @@ where
|
||||
}
|
||||
|
||||
if self.ready_poll.lock().updated_at() >= at {
|
||||
log::trace!(target: "txpool", "Transaction pool already processed block #{}", at);
|
||||
log::trace!(target: LOG_TARGET, "Transaction pool already processed block #{}", at);
|
||||
let iterator: ReadyIteratorFor<PoolApi> = Box::new(self.pool.validated_pool().ready());
|
||||
return async move { iterator }.boxed()
|
||||
}
|
||||
@@ -554,16 +556,16 @@ async fn prune_known_txs_for_block<Block: BlockT, Api: graph::ChainApi<Block = B
|
||||
|
||||
let hashes = extrinsics.iter().map(|tx| pool.hash_of(tx)).collect::<Vec<_>>();
|
||||
|
||||
log::trace!(target: "txpool", "Pruning transactions: {:?}", hashes);
|
||||
log::trace!(target: LOG_TARGET, "Pruning transactions: {:?}", hashes);
|
||||
|
||||
let header = match api.block_header(block_hash) {
|
||||
Ok(Some(h)) => h,
|
||||
Ok(None) => {
|
||||
log::debug!(target: "txpool", "Could not find header for {:?}.", block_hash);
|
||||
log::debug!(target: LOG_TARGET, "Could not find header for {:?}.", block_hash);
|
||||
return hashes
|
||||
},
|
||||
Err(e) => {
|
||||
log::debug!(target: "txpool", "Error retrieving header for {:?}: {}", block_hash, e);
|
||||
log::debug!(target: LOG_TARGET, "Error retrieving header for {:?}: {}", block_hash, e);
|
||||
return hashes
|
||||
},
|
||||
};
|
||||
@@ -587,7 +589,7 @@ where
|
||||
/// (that have already been enacted) and resubmits transactions that were
|
||||
/// retracted.
|
||||
async fn handle_enactment(&self, tree_route: TreeRoute<Block>) {
|
||||
log::trace!(target: "txpool", "handle_enactment tree_route: {tree_route:?}");
|
||||
log::trace!(target: LOG_TARGET, "handle_enactment tree_route: {tree_route:?}");
|
||||
let pool = self.pool.clone();
|
||||
let api = self.api.clone();
|
||||
|
||||
@@ -595,7 +597,7 @@ where
|
||||
Some(HashAndNumber { hash, number }) => (hash, number),
|
||||
None => {
|
||||
log::warn!(
|
||||
target: "txpool",
|
||||
target: LOG_TARGET,
|
||||
"Skipping ChainEvent - no last block in tree route {:?}",
|
||||
tree_route,
|
||||
);
|
||||
@@ -666,7 +668,7 @@ where
|
||||
|
||||
if !contains {
|
||||
log::debug!(
|
||||
target: "txpool",
|
||||
target: LOG_TARGET,
|
||||
"[{:?}]: Resubmitting from retracted block {:?}",
|
||||
tx_hash,
|
||||
hash,
|
||||
@@ -691,7 +693,7 @@ where
|
||||
.await
|
||||
{
|
||||
log::debug!(
|
||||
target: "txpool",
|
||||
target: LOG_TARGET,
|
||||
"[{:?}] Error re-submitting transactions: {}",
|
||||
hash,
|
||||
e,
|
||||
@@ -742,7 +744,7 @@ where
|
||||
|
||||
match result {
|
||||
Err(msg) => {
|
||||
log::debug!(target: "txpool", "{msg}");
|
||||
log::debug!(target: LOG_TARGET, "{msg}");
|
||||
self.enactment_state.lock().force_update(&event);
|
||||
},
|
||||
Ok(EnactmentAction::Skip) => return,
|
||||
@@ -754,7 +756,7 @@ where
|
||||
|
||||
if let ChainEvent::Finalized { hash, tree_route } = event {
|
||||
log::trace!(
|
||||
target: "txpool",
|
||||
target: LOG_TARGET,
|
||||
"on-finalized enacted: {tree_route:?}, previously finalized: \
|
||||
{prev_finalized_block:?}",
|
||||
);
|
||||
@@ -762,7 +764,7 @@ where
|
||||
for hash in tree_route.iter().chain(std::iter::once(&hash)) {
|
||||
if let Err(e) = self.pool.validated_pool().on_block_finalized(*hash).await {
|
||||
log::warn!(
|
||||
target: "txpool",
|
||||
target: LOG_TARGET,
|
||||
"Error occurred while attempting to notify watchers about finalization {}: {}",
|
||||
hash, e
|
||||
)
|
||||
|
||||
@@ -24,7 +24,10 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use crate::graph::{ChainApi, ExtrinsicHash, NumberFor, Pool, ValidatedTransaction};
|
||||
use crate::{
|
||||
graph::{ChainApi, ExtrinsicHash, NumberFor, Pool, ValidatedTransaction},
|
||||
LOG_TARGET,
|
||||
};
|
||||
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
@@ -82,13 +85,23 @@ async fn batch_revalidate<Api: ChainApi>(
|
||||
for (validation_result, ext_hash, ext) in validation_results {
|
||||
match validation_result {
|
||||
Ok(Err(TransactionValidityError::Invalid(err))) => {
|
||||
log::debug!(target: "txpool", "[{:?}]: Revalidation: invalid {:?}", ext_hash, err);
|
||||
log::debug!(
|
||||
target: LOG_TARGET,
|
||||
"[{:?}]: Revalidation: invalid {:?}",
|
||||
ext_hash,
|
||||
err,
|
||||
);
|
||||
invalid_hashes.push(ext_hash);
|
||||
},
|
||||
Ok(Err(TransactionValidityError::Unknown(err))) => {
|
||||
// skipping unknown, they might be pushed by valid or invalid transaction
|
||||
// when latter resubmitted.
|
||||
log::trace!(target: "txpool", "[{:?}]: Unknown during revalidation: {:?}", ext_hash, err);
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
"[{:?}]: Unknown during revalidation: {:?}",
|
||||
ext_hash,
|
||||
err,
|
||||
);
|
||||
},
|
||||
Ok(Ok(validity)) => {
|
||||
revalidated.insert(
|
||||
@@ -105,7 +118,7 @@ async fn batch_revalidate<Api: ChainApi>(
|
||||
},
|
||||
Err(validation_err) => {
|
||||
log::debug!(
|
||||
target: "txpool",
|
||||
target: LOG_TARGET,
|
||||
"[{:?}]: Removing due to error during revalidation: {}",
|
||||
ext_hash,
|
||||
validation_err
|
||||
@@ -183,7 +196,7 @@ impl<Api: ChainApi> RevalidationWorker<Api> {
|
||||
// we don't add something that already scheduled for revalidation
|
||||
if self.members.contains_key(&ext_hash) {
|
||||
log::trace!(
|
||||
target: "txpool",
|
||||
target: LOG_TARGET,
|
||||
"[{:?}] Skipped adding for revalidation: Already there.",
|
||||
ext_hash,
|
||||
);
|
||||
@@ -231,7 +244,7 @@ impl<Api: ChainApi> RevalidationWorker<Api> {
|
||||
|
||||
if batch_len > 0 || this.len() > 0 {
|
||||
log::debug!(
|
||||
target: "txpool",
|
||||
target: LOG_TARGET,
|
||||
"Revalidated {} transactions. Left in the queue for revalidation: {}.",
|
||||
batch_len,
|
||||
this.len(),
|
||||
@@ -248,7 +261,7 @@ impl<Api: ChainApi> RevalidationWorker<Api> {
|
||||
|
||||
if this.members.len() > 0 {
|
||||
log::debug!(
|
||||
target: "txpool",
|
||||
target: LOG_TARGET,
|
||||
"Updated revalidation queue at {:?}. Transactions: {:?}",
|
||||
this.best_block,
|
||||
this.members,
|
||||
@@ -320,14 +333,15 @@ where
|
||||
) {
|
||||
if transactions.len() > 0 {
|
||||
log::debug!(
|
||||
target: "txpool", "Sent {} transactions to revalidation queue",
|
||||
target: LOG_TARGET,
|
||||
"Sent {} transactions to revalidation queue",
|
||||
transactions.len(),
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(ref to_worker) = self.background {
|
||||
if let Err(e) = to_worker.unbounded_send(WorkerPayload { at, transactions }) {
|
||||
log::warn!(target: "txpool", "Failed to update background worker: {:?}", e);
|
||||
log::warn!(target: LOG_TARGET, "Failed to update background worker: {:?}", e);
|
||||
}
|
||||
} else {
|
||||
let pool = self.pool.clone();
|
||||
|
||||
@@ -45,6 +45,8 @@ use substrate_test_runtime_client::{
|
||||
};
|
||||
use substrate_test_runtime_transaction_pool::{uxt, TestApi};
|
||||
|
||||
const LOG_TARGET: &str = "txpool";
|
||||
|
||||
fn pool() -> Pool<TestApi> {
|
||||
Pool::new(Default::default(), true.into(), TestApi::with_alice_nonce(209).into())
|
||||
}
|
||||
@@ -505,7 +507,7 @@ fn fork_aware_finalization() {
|
||||
canon_watchers.push((watcher, header.hash()));
|
||||
assert_eq!(pool.status().ready, 1);
|
||||
|
||||
log::trace!(target:"txpool", ">> B1: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> B1: {:?} {:?}", header.hash(), header);
|
||||
let event = ChainEvent::NewBestBlock { hash: header.hash(), tree_route: None };
|
||||
b1 = header.hash();
|
||||
block_on(pool.maintain(event));
|
||||
@@ -521,7 +523,7 @@ fn fork_aware_finalization() {
|
||||
block_on(pool.submit_and_watch(&BlockId::number(1), SOURCE, from_dave.clone()))
|
||||
.expect("1. Imported");
|
||||
assert_eq!(pool.status().ready, 1);
|
||||
log::trace!(target:"txpool", ">> C2: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> C2: {:?} {:?}", header.hash(), header);
|
||||
let event = ChainEvent::NewBestBlock { hash: header.hash(), tree_route: None };
|
||||
c2 = header.hash();
|
||||
block_on(pool.maintain(event));
|
||||
@@ -536,7 +538,7 @@ fn fork_aware_finalization() {
|
||||
assert_eq!(pool.status().ready, 1);
|
||||
let header = pool.api().push_block_with_parent(c2, vec![from_bob.clone()], true);
|
||||
|
||||
log::trace!(target:"txpool", ">> D2: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> D2: {:?} {:?}", header.hash(), header);
|
||||
let event = ChainEvent::NewBestBlock { hash: header.hash(), tree_route: None };
|
||||
d2 = header.hash();
|
||||
block_on(pool.maintain(event));
|
||||
@@ -550,7 +552,7 @@ fn fork_aware_finalization() {
|
||||
.expect("1.Imported");
|
||||
assert_eq!(pool.status().ready, 1);
|
||||
let header = pool.api().push_block_with_parent(b1, vec![from_charlie.clone()], true);
|
||||
log::trace!(target:"txpool", ">> C1: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> C1: {:?} {:?}", header.hash(), header);
|
||||
c1 = header.hash();
|
||||
canon_watchers.push((watcher, header.hash()));
|
||||
let event = block_event_with_retracted(header.clone(), d2, pool.api());
|
||||
@@ -568,7 +570,7 @@ fn fork_aware_finalization() {
|
||||
.expect("1. Imported");
|
||||
assert_eq!(pool.status().ready, 3);
|
||||
let header = pool.api().push_block_with_parent(c1, vec![xt.clone()], true);
|
||||
log::trace!(target:"txpool", ">> D1: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> D1: {:?} {:?}", header.hash(), header);
|
||||
d1 = header.hash();
|
||||
canon_watchers.push((w, header.hash()));
|
||||
|
||||
@@ -584,7 +586,7 @@ fn fork_aware_finalization() {
|
||||
// block E1
|
||||
{
|
||||
let header = pool.api().push_block_with_parent(d1, vec![from_dave, from_bob], true);
|
||||
log::trace!(target:"txpool", ">> E1: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> E1: {:?} {:?}", header.hash(), header);
|
||||
e1 = header.hash();
|
||||
let event = ChainEvent::NewBestBlock { hash: header.hash(), tree_route: None };
|
||||
block_on(pool.maintain(event));
|
||||
@@ -1115,7 +1117,7 @@ fn switching_fork_with_finalized_works() {
|
||||
pool.api()
|
||||
.push_block_with_parent(a_header.hash(), vec![from_alice.clone()], true);
|
||||
assert_eq!(pool.status().ready, 1);
|
||||
log::trace!(target:"txpool", ">> B1: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> B1: {:?} {:?}", header.hash(), header);
|
||||
b1_header = header;
|
||||
}
|
||||
|
||||
@@ -1131,7 +1133,7 @@ fn switching_fork_with_finalized_works() {
|
||||
);
|
||||
assert_eq!(pool.status().ready, 2);
|
||||
|
||||
log::trace!(target:"txpool", ">> B2: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> B2: {:?} {:?}", header.hash(), header);
|
||||
b2_header = header;
|
||||
}
|
||||
|
||||
@@ -1193,7 +1195,7 @@ fn switching_fork_multiple_times_works() {
|
||||
pool.api()
|
||||
.push_block_with_parent(a_header.hash(), vec![from_alice.clone()], true);
|
||||
assert_eq!(pool.status().ready, 1);
|
||||
log::trace!(target:"txpool", ">> B1: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> B1: {:?} {:?}", header.hash(), header);
|
||||
b1_header = header;
|
||||
}
|
||||
|
||||
@@ -1209,7 +1211,7 @@ fn switching_fork_multiple_times_works() {
|
||||
);
|
||||
assert_eq!(pool.status().ready, 2);
|
||||
|
||||
log::trace!(target:"txpool", ">> B2: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> B2: {:?} {:?}", header.hash(), header);
|
||||
b2_header = header;
|
||||
}
|
||||
|
||||
@@ -1306,7 +1308,7 @@ fn two_blocks_delayed_finalization_works() {
|
||||
.push_block_with_parent(a_header.hash(), vec![from_alice.clone()], true);
|
||||
assert_eq!(pool.status().ready, 1);
|
||||
|
||||
log::trace!(target:"txpool", ">> B1: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> B1: {:?} {:?}", header.hash(), header);
|
||||
b1_header = header;
|
||||
}
|
||||
|
||||
@@ -1320,7 +1322,7 @@ fn two_blocks_delayed_finalization_works() {
|
||||
.push_block_with_parent(b1_header.hash(), vec![from_bob.clone()], true);
|
||||
assert_eq!(pool.status().ready, 2);
|
||||
|
||||
log::trace!(target:"txpool", ">> C1: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> C1: {:?} {:?}", header.hash(), header);
|
||||
c1_header = header;
|
||||
}
|
||||
|
||||
@@ -1334,7 +1336,7 @@ fn two_blocks_delayed_finalization_works() {
|
||||
.push_block_with_parent(c1_header.hash(), vec![from_charlie.clone()], true);
|
||||
assert_eq!(pool.status().ready, 3);
|
||||
|
||||
log::trace!(target:"txpool", ">> D1: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> D1: {:?} {:?}", header.hash(), header);
|
||||
d1_header = header;
|
||||
}
|
||||
|
||||
@@ -1418,7 +1420,7 @@ fn delayed_finalization_does_not_retract() {
|
||||
.push_block_with_parent(a_header.hash(), vec![from_alice.clone()], true);
|
||||
assert_eq!(pool.status().ready, 1);
|
||||
|
||||
log::trace!(target:"txpool", ">> B1: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> B1: {:?} {:?}", header.hash(), header);
|
||||
b1_header = header;
|
||||
}
|
||||
|
||||
@@ -1432,7 +1434,7 @@ fn delayed_finalization_does_not_retract() {
|
||||
.push_block_with_parent(b1_header.hash(), vec![from_bob.clone()], true);
|
||||
assert_eq!(pool.status().ready, 2);
|
||||
|
||||
log::trace!(target:"txpool", ">> C1: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> C1: {:?} {:?}", header.hash(), header);
|
||||
c1_header = header;
|
||||
}
|
||||
|
||||
@@ -1513,7 +1515,7 @@ fn best_block_after_finalization_does_not_retract() {
|
||||
.push_block_with_parent(a_header.hash(), vec![from_alice.clone()], true);
|
||||
assert_eq!(pool.status().ready, 1);
|
||||
|
||||
log::trace!(target:"txpool", ">> B1: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> B1: {:?} {:?}", header.hash(), header);
|
||||
b1_header = header;
|
||||
}
|
||||
|
||||
@@ -1527,7 +1529,7 @@ fn best_block_after_finalization_does_not_retract() {
|
||||
.push_block_with_parent(b1_header.hash(), vec![from_bob.clone()], true);
|
||||
assert_eq!(pool.status().ready, 2);
|
||||
|
||||
log::trace!(target:"txpool", ">> C1: {:?} {:?}", header.hash(), header);
|
||||
log::trace!(target: LOG_TARGET, ">> C1: {:?} {:?}", header.hash(), header);
|
||||
c1_header = header;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user