Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Extend PalletInfoAccess with module_name and crate_version method #9690

Merged
merged 20 commits into from
Sep 28, 2021

Conversation

KiChjang
Copy link
Contributor

@KiChjang KiChjang commented Sep 4, 2021

Per request from @gavofyork via Element, this PR adds module names and crate versions to the PalletInfoAccess struct as public fields.

@KiChjang KiChjang added A0-please_review Pull request needs code review. B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Sep 4, 2021
@KiChjang KiChjang changed the title Extend CallMetadata with pallet index and crate version information Extend PalletInfoAccess with crate_version method Sep 4, 2021
Copy link
Contributor

@thiolliere thiolliere left a comment

Choose a reason for hiding this comment

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

Code is good to me (top message should be updated to reflect the current state of the PR)

I don't know if this will fix Gav request. Because contrary to method CallMetadata which list all the modules, this PR only allow to get the crate version for a specific module, it is not possible to list all modules index and crate versions as far as I can see.

(But we should be able to do so by introducing a new trait similar to CallMetadata. The easiest would be to implement this trait on Tuple of type which implements PalletInfoAccess, and then we can simply use the type alias AllPalletsWithSystem. (or we can implement manually like CallMetadata))

@gavofyork
Copy link
Member

Yeah this doesn't actually do what I need (yet). But the PR description does describe what I need. @KiChjang do you intend to get this to the point where it'a in line with the PR description?

@bkchr
Copy link
Member

bkchr commented Sep 6, 2021

@gavofyork do you have an actual instance of a call on which you want to get this metadata?

@gavofyork
Copy link
Member

gavofyork commented Sep 6, 2021

@bkchr No - I only have a string which is meant to be the pallet's name. With this string I need to be able to get all pallet instances of that name together with their index and crate version.

Since a pallet instance has two associated names - the module/crate name (e.g. "pallet_balances", "crowdloan") and the instance name (e.g. "Balances", "Crowdloan"), ideally I would get both, though the module/crate name is the most important.

@bkchr
Copy link
Member

bkchr commented Sep 6, 2021

Yeah, so CallMetadata wouldn't work here anyway.

@KiChjang the only thing that is missing is the module/crate_name which could be added to PalletInfo as well. Then we should be able in Polkadot to create a trait that will be implemented for tuples of PalletInfo types aka AllPalletsWithSystem and then we should be able to collect all the data that @gavofyork needs for XCM.

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

For the name the idea was more to take the input to construct_runtime. Because stuff like crowdloan, claims etc all come from the same crate.

frame/support/src/lib.rs Outdated Show resolved Hide resolved
@KiChjang
Copy link
Contributor Author

KiChjang commented Sep 7, 2021

For the name the idea was more to take the input to construct_runtime. Because stuff like crowdloan, claims etc all come from the same crate.

The issue here is that whatever was provided to construct_runtime!, i.e. this identifier here...

	pub enum Runtime where
		Block = Block,
		NodeBlock = Block,
		UncheckedExtrinsic = UncheckedExtrinsic
	{
		System: system::{Pallet, Call, Event<T>, Origin<T>} = 30,
		NestedModule3: nested::module3::{Pallet, Call, Config, Storage, Event, Origin},
		               ^^^^^^^^^^^^^^^
	}

... is not necessarily a single identifier, and so grabbing the crate name directly from the pallet is the easiest way to disambiguate. I suppose I could also make a naming scheme where the double colons get converted to underscores, so we'd have nested_module3 as the identifier for such a crate.

@KiChjang KiChjang changed the title Extend PalletInfoAccess with crate_version method Extend PalletInfoAccess with module_name and crate_version method Sep 7, 2021
@gavofyork
Copy link
Member

I suppose I could also make a naming scheme where the double colons get converted to underscores, so we'd have nested_module3 as the identifier for such a crate.

If it's just going into a string, then you can keep the ::s.

@gavofyork
Copy link
Member

It's not such a huge issue that naming is a bit idiosyncratic when dealing with pallets that are one of several in a crate local to the project. The primary use-case for this is for standardised pallets anyway, so if they have necessarily non-standard paths then they're unlikely to be the target of this code.

@thiolliere
Copy link
Contributor

thiolliere commented Sep 8, 2021

I think the pallet path given to construct_runtime shouldn't really identify anything other than the path to access this pallet. People can do renaming, or reexport etc...

Instead if xcm want to check if a pallet is made from some specific pallet "blueprint" like council is made from the "blueprint" pallet-collective. Maybe we need to allow the pallet to declare what is his "blueprint". The crate name as said above is not precise enough, and it is a bit weird to me to rely on the path which should just give some regular rust path to some crate.

Instead pallet could be able to declare their "blueprint" name maybe ? we can do that with an optional new attribute #[pallet::blueprint = "foo"] and so we would have for each pallet an Option<Blueprint>.

@KiChjang
Copy link
Contributor Author

This needs another approval before it can be merged, anything else I need to add here?

Copy link
Contributor

@thiolliere thiolliere left a comment

Choose a reason for hiding this comment

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

looks good to me, identifying a pallet kind using its rust module may be fine. Note that this doesn't include the specification of the instance, so 2 pallets can have the same module name.

frame/support/src/traits/metadata.rs Outdated Show resolved Hide resolved
@kianenigma kianenigma self-requested a review September 23, 2021 14:17
@gavofyork
Copy link
Member

Needs resolving and CI failing @KiChjang

@gavofyork
Copy link
Member

A test would have been nice.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants