Skip to content

Commit f0128f5

Browse files
committed
fixes
1 parent 00c3bfa commit f0128f5

File tree

6 files changed

+21
-19
lines changed

6 files changed

+21
-19
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_7464.prdoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
title: 'Fix sc-tracing to be derived from umbrella crate in parachain template'
1+
title: 'Enable importing sc-tracing macros through polkadot-sdk'
22
doc:
3-
- audience: Runtime Dev
3+
- audience: Node Dev
44
description: |-
5-
Resolving sc-tracing not being resolved when imported through the polkadot sdk
5+
This PR makes it possible to use the sc-tracing macros when they are imported through the umbrella crate.
66

77
crates:
88
- name: parachain-template-node

substrate/client/tracing/proc-macro/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ targets = ["x86_64-unknown-linux-gnu"]
1818
proc-macro = true
1919

2020
[dependencies]
21+
frame-support-procedural-tools = { workspace = true, default-features = true }
2122
proc-macro-crate = { workspace = true }
2223
proc-macro2 = { workspace = true }
2324
quote = { features = ["proc-macro"], workspace = true }

substrate/client/tracing/proc-macro/src/lib.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
1717

18+
use frame_support_procedural_tools::generate_access_from_frame_or_crate;
1819
use proc_macro::TokenStream;
1920
use proc_macro2::Span;
20-
use proc_macro_crate::{crate_name, FoundCrate};
2121
use quote::quote;
22-
use syn::{Error, Expr, Ident, ItemFn};
22+
use syn::{Error, Expr, ItemFn};
2323

2424
/// Add a log prefix to the function.
2525
///
@@ -109,22 +109,17 @@ pub fn prefix_logs_with(arg: TokenStream, item: TokenStream) -> TokenStream {
109109
if arg.is_empty() {
110110
return Error::new(
111111
Span::call_site(),
112-
"missing argument: name of the node. Example: #[prefix_logs_with(\"MyNode\")]",
112+
"missing argument: prefix. Example: sc_cli::prefix_logs_with(<expr>)",
113113
)
114114
.to_compile_error()
115115
.into();
116116
}
117117

118118
let name = syn::parse_macro_input!(arg as Expr);
119119

120-
let crate_name = match crate_name("polkadot-sdk") {
121-
Ok(FoundCrate::Name(sdk_name)) => Ident::new(sdk_name.as_str(), Span::call_site()),
122-
_ => match crate_name("sc-tracing") {
123-
Ok(FoundCrate::Itself) => Ident::new("sc_tracing", Span::call_site()),
124-
Ok(FoundCrate::Name(tracing_name)) =>
125-
Ident::new(tracing_name.as_str(), Span::call_site()),
126-
Err(e) => return Error::new(Span::call_site(), e).to_compile_error().into(),
127-
},
120+
let crate_name = match generate_access_from_frame_or_crate("sc-tracing") {
121+
Ok(ident) => ident,
122+
Err(err) => return err.to_compile_error().into(),
128123
};
129124

130125
let ItemFn { attrs, vis, sig, block } = item_fn;

templates/parachain/node/Cargo.toml

+8-3
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,25 @@ docify = { workspace = true }
1717
futures = { workspace = true }
1818
jsonrpsee = { features = ["server"], workspace = true }
1919
log = { workspace = true, default-features = true }
20-
polkadot-sdk = { workspace = true, features = ["node"] }
2120
serde = { features = ["derive"], workspace = true, default-features = true }
2221

22+
polkadot-sdk = { workspace = true, features = ["node"] }
23+
2324
parachain-template-runtime = { workspace = true }
2425

2526
# Substrate
2627
prometheus-endpoint = { workspace = true, default-features = true }
2728

2829
[build-dependencies]
29-
polkadot-sdk = { workspace = true, features = ["node", "substrate-build-script-utils"] }
30+
polkadot-sdk = { workspace = true, features = ["substrate-build-script-utils"] }
3031

3132
[features]
3233
default = ["std"]
33-
std = ["log/std", "parachain-template-runtime/std", "polkadot-sdk/std"]
34+
std = [
35+
"log/std",
36+
"parachain-template-runtime/std",
37+
"polkadot-sdk/std",
38+
]
3439
runtime-benchmarks = [
3540
"parachain-template-runtime/runtime-benchmarks",
3641
"polkadot-sdk/runtime-benchmarks",

templates/parachain/node/src/service.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use parachain_template_runtime::{
1010
};
1111

1212
use polkadot_sdk::*;
13+
1314
// Cumulus Imports
1415
use cumulus_client_cli::CollatorOptions;
1516
use cumulus_client_collator::service::CollatorService;
@@ -31,7 +32,6 @@ use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};
3132

3233
// Substrate Imports
3334
use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE;
34-
use polkadot_sdk::sc_tracing::logging;
3535
use prometheus_endpoint::Registry;
3636
use sc_client_api::Backend;
3737
use sc_consensus::ImportQueue;
@@ -229,7 +229,7 @@ fn start_consensus(
229229
}
230230

231231
/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.
232-
#[logging::prefix_logs_with("Parachain")]
232+
#[sc_tracing::logging::prefix_logs_with("Parachain")]
233233
pub async fn start_parachain_node(
234234
parachain_config: Configuration,
235235
polkadot_config: Configuration,

0 commit comments

Comments
 (0)