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

Follow up for: Use the umbrella crate for the parachain template #5993 #7464

Open
wants to merge 45 commits into
base: master
Choose a base branch
from

Conversation

seemantaggarwal
Copy link
Contributor

@seemantaggarwal seemantaggarwal commented Feb 5, 2025

Resolving sc-tracing not being resolved when imported through the polkadot sdk

@seemantaggarwal seemantaggarwal changed the title removing unused imports Follow up for: Use the umbrella crate for the parachain template #5993 Feb 5, 2025
@serban300 serban300 added the R0-silent Changes should not be mentioned in any release notes label Feb 6, 2025
serban300
serban300 previously approved these changes Feb 6, 2025
@serban300 serban300 dismissed their stale review February 6, 2025 11:31

Will take another look when the PR is ready for review

]
runtime-full = ["assets-common", "binary-merkle-tree", "bp-header-chain", "bp-messages", "bp-parachains", "bp-polkadot", "bp-polkadot-core", "bp-relayers", "bp-runtime", "bp-test-utils", "bp-xcm-bridge-hub", "bp-xcm-bridge-hub-router", "bridge-hub-common", "bridge-runtime-common", "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", "cumulus-pallet-parachain-system-proc-macro", "cumulus-pallet-session-benchmarking", "cumulus-pallet-solo-to-para", "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", "cumulus-ping", "cumulus-primitives-aura", "cumulus-primitives-core", "cumulus-primitives-parachain-inherent", "cumulus-primitives-proof-size-hostfunction", "cumulus-primitives-storage-weight-reclaim", "cumulus-primitives-timestamp", "cumulus-primitives-utility", "frame-benchmarking", "frame-benchmarking-pallet-pov", "frame-election-provider-solution-type", "frame-election-provider-support", "frame-executive", "frame-metadata-hash-extension", "frame-support", "frame-support-procedural", "frame-support-procedural-tools-derive", "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", "pallet-alliance", "pallet-asset-conversion", "pallet-asset-conversion-ops", "pallet-asset-conversion-tx-payment", "pallet-asset-rate", "pallet-asset-rewards", "pallet-asset-tx-payment", "pallet-assets", "pallet-assets-freezer", "pallet-atomic-swap", "pallet-aura", "pallet-authority-discovery", "pallet-authorship", "pallet-babe", "pallet-bags-list", "pallet-balances", "pallet-beefy", "pallet-beefy-mmr", "pallet-bounties", "pallet-bridge-grandpa", "pallet-bridge-messages", "pallet-bridge-parachains", "pallet-bridge-relayers", "pallet-broker", "pallet-child-bounties", "pallet-collator-selection", "pallet-collective", "pallet-collective-content", "pallet-contracts", "pallet-contracts-proc-macro", "pallet-contracts-uapi", "pallet-conviction-voting", "pallet-core-fellowship", "pallet-delegated-staking", "pallet-democracy", "pallet-dev-mode", "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", "pallet-elections-phragmen", "pallet-fast-unstake", "pallet-glutton", "pallet-grandpa", "pallet-identity", "pallet-im-online", "pallet-indices", "pallet-insecure-randomness-collective-flip", "pallet-lottery", "pallet-membership", "pallet-message-queue", "pallet-migrations", "pallet-mixnet", "pallet-mmr", "pallet-multisig", "pallet-nft-fractionalization", "pallet-nfts", "pallet-nfts-runtime-api", "pallet-nis", "pallet-node-authorization", "pallet-nomination-pools", "pallet-nomination-pools-benchmarking", "pallet-nomination-pools-runtime-api", "pallet-offences", "pallet-offences-benchmarking", "pallet-paged-list", "pallet-parameters", "pallet-preimage", "pallet-proxy", "pallet-ranked-collective", "pallet-recovery", "pallet-referenda", "pallet-remark", "pallet-revive", "pallet-revive-proc-macro", "pallet-revive-uapi", "pallet-root-offences", "pallet-root-testing", "pallet-safe-mode", "pallet-salary", "pallet-scheduler", "pallet-scored-pool", "pallet-session", "pallet-session-benchmarking", "pallet-skip-feeless-payment", "pallet-society", "pallet-staking", "pallet-staking-reward-curve", "pallet-staking-reward-fn", "pallet-staking-runtime-api", "pallet-state-trie-migration", "pallet-statement", "pallet-sudo", "pallet-timestamp", "pallet-tips", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "pallet-transaction-storage", "pallet-treasury", "pallet-tx-pause", "pallet-uniques", "pallet-utility", "pallet-verify-signature", "pallet-vesting", "pallet-whitelist", "pallet-xcm", "pallet-xcm-benchmarks", "pallet-xcm-bridge-hub", "pallet-xcm-bridge-hub-router", "parachains-common", "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-primitives", "polkadot-runtime-common", "polkadot-runtime-metrics", "polkadot-runtime-parachains", "polkadot-sdk-frame", "sc-chain-spec-derive", "sc-tracing-proc-macro", "slot-range-helper", "snowbridge-beacon-primitives", "snowbridge-core", "snowbridge-ethereum", "snowbridge-outbound-queue-merkle-tree", "snowbridge-outbound-queue-runtime-api", "snowbridge-pallet-ethereum-client", "snowbridge-pallet-ethereum-client-fixtures", "snowbridge-pallet-inbound-queue", "snowbridge-pallet-inbound-queue-fixtures", "snowbridge-pallet-outbound-queue", "snowbridge-pallet-system", "snowbridge-router-primitives", "snowbridge-runtime-common", "snowbridge-system-runtime-api", "sp-api", "sp-api-proc-macro", "sp-application-crypto", "sp-arithmetic", "sp-authority-discovery", "sp-block-builder", "sp-consensus-aura", "sp-consensus-babe", "sp-consensus-beefy", "sp-consensus-grandpa", "sp-consensus-pow", "sp-consensus-slots", "sp-core", "sp-crypto-ec-utils", "sp-crypto-hashing", "sp-crypto-hashing-proc-macro", "sp-debug-derive", "sp-externalities", "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", "sp-keystore", "sp-metadata-ir", "sp-mixnet", "sp-mmr-primitives", "sp-npos-elections", "sp-offchain", "sp-runtime", "sp-runtime-interface", "sp-runtime-interface-proc-macro", "sp-session", "sp-staking", "sp-state-machine", "sp-statement-store", "sp-std", "sp-storage", "sp-timestamp", "sp-tracing", "sp-transaction-pool", "sp-transaction-storage-proof", "sp-trie", "sp-version", "sp-version-proc-macro", "sp-wasm-interface", "sp-weights", "staging-parachain-info", "staging-xcm", "staging-xcm-builder", "staging-xcm-executor", "substrate-bip39", "testnet-parachains-constants", "tracing-gum-proc-macro", "xcm-procedural", "xcm-runtime-apis"]
runtime-full = ["assets-common", "binary-merkle-tree", "bp-header-chain", "bp-messages", "bp-parachains", "bp-polkadot", "bp-polkadot-core", "bp-relayers", "bp-runtime", "bp-test-utils", "bp-xcm-bridge-hub", "bp-xcm-bridge-hub-router", "bridge-hub-common", "bridge-runtime-common", "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", "cumulus-pallet-parachain-system-proc-macro", "cumulus-pallet-session-benchmarking", "cumulus-pallet-solo-to-para", "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", "cumulus-ping", "cumulus-primitives-aura", "cumulus-primitives-core", "cumulus-primitives-parachain-inherent", "cumulus-primitives-proof-size-hostfunction", "cumulus-primitives-storage-weight-reclaim", "cumulus-primitives-timestamp", "cumulus-primitives-utility", "frame-benchmarking", "frame-benchmarking-pallet-pov", "frame-election-provider-solution-type", "frame-election-provider-support", "frame-executive", "frame-metadata-hash-extension", "frame-support", "frame-support-procedural", "frame-support-procedural-tools-derive", "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", "pallet-alliance", "pallet-asset-conversion", "pallet-asset-conversion-ops", "pallet-asset-conversion-tx-payment", "pallet-asset-rate", "pallet-asset-rewards", "pallet-asset-tx-payment", "pallet-assets", "pallet-assets-freezer", "pallet-atomic-swap", "pallet-aura", "pallet-authority-discovery", "pallet-authorship", "pallet-babe", "pallet-bags-list", "pallet-balances", "pallet-beefy", "pallet-beefy-mmr", "pallet-bounties", "pallet-bridge-grandpa", "pallet-bridge-messages", "pallet-bridge-parachains", "pallet-bridge-relayers", "pallet-broker", "pallet-child-bounties", "pallet-collator-selection", "pallet-collective", "pallet-collective-content", "pallet-contracts", "pallet-contracts-proc-macro", "pallet-contracts-uapi", "pallet-conviction-voting", "pallet-core-fellowship", "pallet-delegated-staking", "pallet-democracy", "pallet-dev-mode", "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", "pallet-elections-phragmen", "pallet-fast-unstake", "pallet-glutton", "pallet-grandpa", "pallet-identity", "pallet-im-online", "pallet-indices", "pallet-insecure-randomness-collective-flip", "pallet-lottery", "pallet-membership", "pallet-message-queue", "pallet-migrations", "pallet-mixnet", "pallet-mmr", "pallet-multisig", "pallet-nft-fractionalization", "pallet-nfts", "pallet-nfts-runtime-api", "pallet-nis", "pallet-node-authorization", "pallet-nomination-pools", "pallet-nomination-pools-benchmarking", "pallet-nomination-pools-runtime-api", "pallet-offences", "pallet-offences-benchmarking", "pallet-paged-list", "pallet-parameters", "pallet-preimage", "pallet-proxy", "pallet-ranked-collective", "pallet-recovery", "pallet-referenda", "pallet-remark", "pallet-revive", "pallet-revive-proc-macro", "pallet-revive-uapi", "pallet-root-offences", "pallet-root-testing", "pallet-safe-mode", "pallet-salary", "pallet-scheduler", "pallet-scored-pool", "pallet-session", "pallet-session-benchmarking", "pallet-skip-feeless-payment", "pallet-society", "pallet-staking", "pallet-staking-reward-curve", "pallet-staking-reward-fn", "pallet-staking-runtime-api", "pallet-state-trie-migration", "pallet-statement", "pallet-sudo", "pallet-timestamp", "pallet-tips", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "pallet-transaction-storage", "pallet-treasury", "pallet-tx-pause", "pallet-uniques", "pallet-utility", "pallet-verify-signature", "pallet-vesting", "pallet-whitelist", "pallet-xcm", "pallet-xcm-benchmarks", "pallet-xcm-bridge-hub", "pallet-xcm-bridge-hub-router", "parachains-common", "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-primitives", "polkadot-runtime-common", "polkadot-runtime-metrics", "polkadot-runtime-parachains", "polkadot-sdk-frame", "sc-chain-spec-derive", "sc-tracing", "sc-tracing-proc-macro", "slot-range-helper", "snowbridge-beacon-primitives", "snowbridge-core", "snowbridge-ethereum", "snowbridge-outbound-queue-merkle-tree", "snowbridge-outbound-queue-runtime-api", "snowbridge-pallet-ethereum-client", "snowbridge-pallet-ethereum-client-fixtures", "snowbridge-pallet-inbound-queue", "snowbridge-pallet-inbound-queue-fixtures", "snowbridge-pallet-outbound-queue", "snowbridge-pallet-system", "snowbridge-router-primitives", "snowbridge-runtime-common", "snowbridge-system-runtime-api", "sp-api", "sp-api-proc-macro", "sp-application-crypto", "sp-arithmetic", "sp-authority-discovery", "sp-block-builder", "sp-consensus-aura", "sp-consensus-babe", "sp-consensus-beefy", "sp-consensus-grandpa", "sp-consensus-pow", "sp-consensus-slots", "sp-core", "sp-crypto-ec-utils", "sp-crypto-hashing", "sp-crypto-hashing-proc-macro", "sp-debug-derive", "sp-externalities", "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", "sp-keystore", "sp-metadata-ir", "sp-mixnet", "sp-mmr-primitives", "sp-npos-elections", "sp-offchain", "sp-runtime", "sp-runtime-interface", "sp-runtime-interface-proc-macro", "sp-session", "sp-staking", "sp-state-machine", "sp-statement-store", "sp-std", "sp-storage", "sp-timestamp", "sp-tracing", "sp-transaction-pool", "sp-transaction-storage-proof", "sp-trie", "sp-version", "sp-version-proc-macro", "sp-wasm-interface", "sp-weights", "staging-parachain-info", "staging-xcm", "staging-xcm-builder", "staging-xcm-executor", "substrate-bip39", "testnet-parachains-constants", "tracing-gum-proc-macro", "xcm-procedural", "xcm-runtime-apis"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sc-* crates are Substrate Client libraries, they should not be in the runtime feature.
Please use the generate-umbrella.py script if you want to update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok makes sense, was just trying an experiment, i will keep that in mind, thanks

@iulianbarbu
Copy link
Contributor

iulianbarbu commented Feb 12, 2025

The node crate still fails to build because an error is raised here during the compilation, when the macro is expanded: https://github.com/paritytech/polkadot-sdk/blob/master/substrate/client/tracing/proc-macro/src/lib.rs#L123. crate_name function searches through the node's Cargo.toml for the sc-tracing dependency, or for the renamed version of the same crate (https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml), but it can not find it, since we rely on polkadot-sdk with its node feature, which pulls the sc-tracing crate and re-exports it, and the compilation fails as a result.

I would attempt a fix in sc-tracing-proc-macro crate, maybe based on cargo-metadata (https://docs.rs/cargo_metadata/latest/cargo_metadata/), where we parse through the dependency graph. Not sure how easy it is, but I would check for our current crate dependencies, search for polkadot-sdk, and then iterate through its dependencies (and here check if sc-tracing exists ). I am not sure if sc-tracing will show up no matter what polkadot-sdk features we enable, because if this is the case, then we might report sc-tracing can be used in the crate that uses polkadot-sdk, but in practice this would fail, because no enabled features pulls it in. However, this is already better since for the cases where sc-tracing is pulled in because of an enabled feature that pulls it in, the compilation wouldn't fail (assuming use polkadot-sdk::* is used in the file where sc_tracing is used).

@seemantaggarwal
Copy link
Contributor Author

Maybe I can try it out instead, we can discuss of what and how, that way, we try it out, and I learn something, 2 birds one stone ;)

@iulianbarbu
Copy link
Contributor

iulianbarbu commented Feb 13, 2025

Just posting the code change and the file. It successfully builds now.

	let crate_name = match crate_name("sc-tracing") {
		Ok(FoundCrate::Itself) => Ident::new("sc_tracing", Span::call_site()),
		Ok(FoundCrate::Name(crate_name)) => Ident::new(&crate_name, Span::call_site()),
		Err(_) => match crate_name("polkadot-sdk") {
			Ok(FoundCrate::Itself) | Ok(FoundCrate::Name(_)) =>
				Ident::new("sc_tracing", Span::call_site()),
			Err(_) => return Error::new(Span::call_site(), "Neither one of `sc-tracing` or `polkadot-sdk` hasn't been found in your dependencies, or no `polkadot-sdk`'s enabled feature pulls in `sc-tracing`.").to_compile_error().into(),
		},
	};

Copy link
Contributor

@serban300 serban300 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment.

Also as a high level suggestion, personally sometimes I find it hard to review PRs with a lot of commits. As long as the PR is not ready for review, I would just squash all the commits in a single one and force push.

Later edit: Also I think you need to update Cargo.lock. Some of the CI errors seem to be caused by this.

@seemantaggarwal
Copy link
Contributor Author

seemantaggarwal commented Feb 17, 2025

What I have tried, outside of the current commit:

cargo tree | grep sc-tracing                             

│   │   │   │   │   │   ├── sc-tracing v28.0.0 (/Users/seemantaggarwal/RustroverProjects/polkadot-sdk/substrate/client/tracing)
│   │   │   │   │   │   │   ├── sc-tracing-proc-macro v11.0.0 (proc-macro) (/Users/seemantaggarwal/RustroverProjects/polkadot-sdk/substrate/client/tracing/proc-macro)
│   │   │   │   │   ├── sc-tracing v28.0.0 (/Users/seemantaggarwal/RustroverProjects/polkadot-sdk/substrate/client/tracing) (*)
│   │   │   │   ├── sc-tracing v28.0.0 (/Users/seemantaggarwal/RustroverProjects/polkadot-sdk/substrate/client/tracing) (*)
│   │   │   │   │   │   │   │   ├── sc-tracing v28.0.0 (/Users/seemantaggarwal/RustroverProjects/polkadot-sdk/substrate/client/tracing) (*)
│   │   │   │   │   │   │   │   ├── sc-tracing v28.0.0 (/Users/seemantaggarwal/RustroverProjects/polkadot-sdk/substrate/client/tracing) (*)
│   │   │   │   │   ├── sc-tracing v28.0.0 (/Users/seemantaggarwal/RustroverProjects/polkadot-sdk/substrate/client/tracing) (*)
│   │   │   │   ├── sc-tracing v28.0.0 (/Users/seemantaggarwal/RustroverProjects/polkadot-sdk/substrate/client/tracing) (*)
│   │   │   │   ├── sc-tracing v28.0.0 (/Users/seemantaggarwal/RustroverProjects/polkadot-sdk/substrate/client/tracing) (*)
│   │   │   ├── sc-tracing v28.0.0 (/Users/seemantaggarwal/RustroverProjects/polkadot-sdk/substrate/client/tracing) (*)
│   │   ├── sc-tracing v28.0.0 (/Users/seemantaggarwal/RustroverProjects/polkadot-sdk/substrate/client/tracing) (*)
    ├── sc-tracing v28.0.0 (/Users/seemantaggarwal/RustroverProjects/polkadot-sdk/substrate/client/tracing) (*)

Tried using explicit import for use polkadot_sdk::sc_tracing; in service.rs

Created a separate feature for tracing:
in umbrella/Cargo.toml
[features] default = ["sc-tracing"]

also as:

[features]
sc-tracing = ["dep:sc-tracing"]

and modifying the umbrella/src/lib.rs

#[cfg(feature = "sc-tracing")]
pub use sc_tracing::*;

and then importing in node/src/service.rs

#[cfg(feature = "sc-tracing")]
use polkadot_sdk::sc_tracing;

The output from:

cargo tree --features sc-tracing | grep sc-tracing

error: the package 'parachain-template-node' does not contain this feature: sc-tracing
help: packages with the missing feature: polkadot-sdk, polkadot-cli

also ran:

cargo metadata --format-version 1 | jq '.packages[] | select(.name=="polkadot-sdk") | .features'

to get

`output of cargo metadata --format-version 1 | jq '.packages[] | select(.name=="polkadot-sdk") | .features'

"sc-tracing": [
   "dep:sc-tracing"
 ],
 "sc-tracing-proc-macro": [
   "dep:sc-tracing-proc-macro"
 ],
"node":[
 "sc-tracing",
]
"sc-tracing": [
   "dep:sc-tracing"
 ],

"sc-tracing-proc-macro": [
   "dep:sc-tracing-proc-macro"
 ],`

@seemantaggarwal seemantaggarwal force-pushed the seemant-parachain-umbrella-crate-mig branch from 9c31997 to 2f95de5 Compare February 17, 2025 19:02
@seemantaggarwal
Copy link
Contributor Author

seemantaggarwal commented Feb 18, 2025

Tagging @iulianbarbu @kianenigma @serban300
For an eye/help:

As seen above in the comment, #7464 (comment)

The cargo tree suggests tracing to be under polkadot-sdk

However, in the service.rs under the parachain it is not being resolved, I have also added, what my investigation involves so far, and some further experimentation in the following commits:

ad6e74a
e2f570d

5166954

I am not sure why it is not being resolved and could use some insights into debugging

@serban300
Copy link
Contributor

and then importing in node/src/service.rs

#[cfg(feature = "sc-tracing")]
use polkadot_sdk::sc_tracing;

The output from:

cargo tree --features sc-tracing | grep sc-tracing

error: the package 'parachain-template-node' does not contain this feature: sc-tracing
help: packages with the missing feature: polkadot-sdk, polkadot-cli

If you do

#[cfg(feature = "sc-tracing")]
use polkadot_sdk::sc_tracing;

than I think you also need to define a sc-tracing feature in the Cargo.toml of the parachain template node. Maybe that's the problem.

But I wouldn't do this. I wouldn't guard use polkadot_sdk::sc_tracing; with #[cfg(feature = "sc-tracing")] and I wouldn't add a sc-tracing feature in the Cargo.toml of the parachain template node. I would add the sc-tracing as a dependency of the node feature in the umbrella Cargo.toml. And then in the parachain template node, we already use this feature: polkadot-sdk = { workspace = true, features = ["node"] };

@seemantaggarwal
Copy link
Contributor Author

seemantaggarwal commented Feb 19, 2025

Hi @serban300 I agree with . I wouldn't guard use polkadot_sdk::sc_tracing;
it was just an explicit trial

sc-tracing already exists under node btw, so I am not sure why it is unabl to resolve that

ahh reading it again:

I would add the sc-tracing as a dependency of the node feature in the umbrella Cargo.toml

Let me try this

@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/13485865048
Failed job name: cargo-clippy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes T17-Templates This PR/Issue is related to templates
Projects
Status: Milestone 1
Development

Successfully merging this pull request may close these issues.

5 participants