Skip to content

Commit 07d4b46

Browse files
fatxpool: use tracing for logging (#6897)
This PR modifies the fatxpool to use tracing instead of log for logging. closes #5490 Polkadot address: 12GyGD3QhT4i2JJpNzvMf96sxxBLWymz4RdGCxRH5Rj5agKW --------- Co-authored-by: Michal Kucharczyk <[email protected]>
1 parent e9e4251 commit 07d4b46

16 files changed

+755
-308
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prdoc/pr_6897.prdoc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
title: 'Tracing Log for fork-aware transaction pool'
2+
doc:
3+
- audience: Node Dev
4+
description: Replacement of log crate with tracing crate for better logging.
5+
crates:
6+
- name: sc-transaction-pool
7+
bump: minor

substrate/client/transaction-pool/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ sp-transaction-pool = { workspace = true, default-features = true }
4040
thiserror = { workspace = true }
4141
tokio = { workspace = true, default-features = true, features = ["macros", "time"] }
4242
tokio-stream = { workspace = true }
43+
tracing = { workspace = true, default-features = true }
4344

4445
[dev-dependencies]
4546
array-bytes = { workspace = true, default-features = true }

substrate/client/transaction-pool/src/common/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub(crate) mod log_xt;
2525
pub(crate) mod metrics;
2626
#[cfg(test)]
2727
pub(crate) mod tests;
28+
pub(crate) mod tracing_log_xt;
2829

2930
use futures::StreamExt;
3031
use std::sync::Arc;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) Parity Technologies (UK) Ltd.
4+
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5+
6+
// This program is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 3 of the License, or
9+
// (at your option) any later version.
10+
11+
// This program is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
16+
// You should have received a copy of the GNU General Public License
17+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
19+
//! Utility for logging transaction collections with tracing crate.
20+
21+
/// Logs every transaction from given `tx_collection` with given level.
22+
macro_rules! log_xt {
23+
(data: hash, target: $target:expr, $level:expr, $tx_collection:expr, $text_with_format:expr) => {
24+
for tx in $tx_collection {
25+
tracing::event!(
26+
$level,
27+
target = $target,
28+
tx_hash = format!("{:?}", tx),
29+
$text_with_format,
30+
);
31+
}
32+
};
33+
(data: hash, target: $target:expr, $level:expr, $tx_collection:expr, $text_with_format:expr, $($arg:expr),*) => {
34+
for tx in $tx_collection {
35+
tracing::event!(
36+
$level,
37+
target = $target,
38+
tx_hash = format!("{:?}", tx),
39+
$text_with_format,
40+
$($arg),*
41+
);
42+
}
43+
};
44+
(data: tuple, target: $target:expr, $level:expr, $tx_collection:expr, $text_with_format:expr) => {
45+
for tx in $tx_collection {
46+
tracing::event!(
47+
$level,
48+
target = $target,
49+
tx_hash = format!("{:?}", tx.0),
50+
$text_with_format,
51+
tx.1
52+
);
53+
}
54+
};
55+
}
56+
macro_rules! log_xt_trace {
57+
(data: $datatype:ident, target: $target:expr, $($arg:tt)+) => {
58+
$crate::common::tracing_log_xt::log_xt!(data: $datatype, target: $target, tracing::Level::TRACE, $($arg)+);
59+
};
60+
(target: $target:expr, $tx_collection:expr, $text_with_format:expr) => {
61+
$crate::common::tracing_log_xt::log_xt!(data: hash, target: $target, tracing::Level::TRACE, $tx_collection, $text_with_format);
62+
};
63+
(target: $target:expr, $tx_collection:expr, $text_with_format:expr, $($arg:expr)*) => {
64+
$crate::common::tracing_log_xt::log_xt!(data: hash, target: $target, tracing::Level::TRACE, $tx_collection, $text_with_format, $($arg)*);
65+
};
66+
}
67+
68+
pub(crate) use log_xt;
69+
pub(crate) use log_xt_trace;

substrate/client/transaction-pool/src/fork_aware_txpool/dropped_watcher.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
//! by any view are detected and properly notified.
2323
2424
use crate::{
25-
common::log_xt::log_xt_trace,
25+
common::tracing_log_xt::log_xt_trace,
2626
fork_aware_txpool::stream_map_util::next_event,
2727
graph::{self, BlockHash, ExtrinsicHash},
2828
LOG_TARGET,
2929
};
3030
use futures::stream::StreamExt;
31-
use log::{debug, trace};
3231
use sc_transaction_pool_api::TransactionStatus;
3332
use sc_utils::mpsc;
3433
use sp_runtime::traits::Block as BlockT;
@@ -41,6 +40,7 @@ use std::{
4140
pin::Pin,
4241
};
4342
use tokio_stream::StreamMap;
43+
use tracing::{debug, trace};
4444

4545
/// Represents a transaction that was removed from the transaction pool, including the reason of its
4646
/// removal.
@@ -225,7 +225,7 @@ where
225225
log_xt_trace!(
226226
target: LOG_TARGET,
227227
xts.clone(),
228-
"[{:?}] dropped_watcher: finalized xt removed"
228+
"dropped_watcher: finalized xt removed"
229229
);
230230
xts.iter().for_each(|xt| {
231231
self.ready_transaction_views.remove(xt);
@@ -279,7 +279,7 @@ where
279279
return Some(DroppedTransaction::new_enforced_by_limts(tx_hash))
280280
}
281281
} else {
282-
debug!("[{:?}] dropped_watcher: removing (non-tracked) tx", tx_hash);
282+
debug!(target: LOG_TARGET, ?tx_hash, "dropped_watcher: removing (non-tracked) tx");
283283
return Some(DroppedTransaction::new_enforced_by_limts(tx_hash))
284284
}
285285
},

0 commit comments

Comments
 (0)