Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fatxpool: use tracing for logging #6897

Merged
Merged
Show file tree
Hide file tree
Changes from 14 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions prdoc/pr_6897.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: 'Tracing Log for fork-aware transaction pool'
doc:
- audience: Node Dev
description: Replacement of log crate with tracing crate for better logging.
crates:
- name: sc-transaction-pool
bump: minor
1 change: 1 addition & 0 deletions substrate/client/transaction-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ sp-transaction-pool = { workspace = true, default-features = true }
thiserror = { workspace = true }
tokio = { workspace = true, default-features = true, features = ["macros", "time"] }
tokio-stream = { workspace = true }
tracing = { workspace = true, default-features = true }
iulianbarbu marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
array-bytes = { workspace = true, default-features = true }
Expand Down
1 change: 1 addition & 0 deletions substrate/client/transaction-pool/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub(crate) mod log_xt;
pub(crate) mod metrics;
#[cfg(test)]
pub(crate) mod tests;
pub(crate) mod tracing_log_xt;

use futures::StreamExt;
use std::sync::Arc;
Expand Down
69 changes: 69 additions & 0 deletions substrate/client/transaction-pool/src/common/tracing_log_xt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Utility for logging transaction collections with tracing crate.
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved

/// Logs every transaction from given `tx_collection` with given level.
macro_rules! log_xt {
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
(data: hash, target: $target:expr, $level:expr, $tx_collection:expr, $text_with_format:expr) => {
for tx in $tx_collection {
tracing::event!(
$level,
target = $target,
tx_hash = format!("{:?}", tx),
$text_with_format,
);
}
};
(data: hash, target: $target:expr, $level:expr, $tx_collection:expr, $text_with_format:expr, $($arg:expr),*) => {
for tx in $tx_collection {
tracing::event!(
$level,
target = $target,
tx_hash = format!("{:?}", tx),
$text_with_format,
$($arg),*
);
}
};
(data: tuple, target: $target:expr, $level:expr, $tx_collection:expr, $text_with_format:expr) => {
for tx in $tx_collection {
tracing::event!(
$level,
target = $target,
tx_hash = format!("{:?}", tx.0),
$text_with_format,
tx.1
);
}
};
}
macro_rules! log_xt_trace {
(data: $datatype:ident, target: $target:expr, $($arg:tt)+) => {
$crate::common::tracing_log_xt::log_xt!(data: $datatype, target: $target, tracing::Level::TRACE, $($arg)+);
};
(target: $target:expr, $tx_collection:expr, $text_with_format:expr) => {
$crate::common::tracing_log_xt::log_xt!(data: hash, target: $target, tracing::Level::TRACE, $tx_collection, $text_with_format);
};
(target: $target:expr, $tx_collection:expr, $text_with_format:expr, $($arg:expr)*) => {
$crate::common::tracing_log_xt::log_xt!(data: hash, target: $target, tracing::Level::TRACE, $tx_collection, $text_with_format, $($arg)*);
};
}

pub(crate) use log_xt;
pub(crate) use log_xt_trace;
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
//! by any view are detected and properly notified.

use crate::{
common::log_xt::log_xt_trace,
common::tracing_log_xt::log_xt_trace,
fork_aware_txpool::stream_map_util::next_event,
graph::{self, BlockHash, ExtrinsicHash},
LOG_TARGET,
};
use futures::stream::StreamExt;
use log::{debug, trace};
use sc_transaction_pool_api::TransactionStatus;
use sc_utils::mpsc;
use sp_runtime::traits::Block as BlockT;
Expand All @@ -41,6 +40,7 @@ use std::{
pin::Pin,
};
use tokio_stream::StreamMap;
use tracing::{debug, trace};

/// Represents a transaction that was removed from the transaction pool, including the reason of its
/// removal.
Expand Down Expand Up @@ -225,7 +225,7 @@ where
log_xt_trace!(
target: LOG_TARGET,
xts.clone(),
"[{:?}] dropped_watcher: finalized xt removed"
"dropped_watcher: finalized xt removed"
);
xts.iter().for_each(|xt| {
self.ready_transaction_views.remove(xt);
Expand Down Expand Up @@ -279,7 +279,7 @@ where
return Some(DroppedTransaction::new_enforced_by_limts(tx_hash))
}
} else {
debug!("[{:?}] dropped_watcher: removing (non-tracked) tx", tx_hash);
debug!(target: LOG_TARGET, ?tx_hash, "dropped_watcher: removing (non-tracked) tx");
return Some(DroppedTransaction::new_enforced_by_limts(tx_hash))
}
},
Expand Down
Loading
Loading