-
Notifications
You must be signed in to change notification settings - Fork 10
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
Track additional composite enum metadata #55
Comments
To make sure that I understand the linked issue, I think the idea is that pallets can use some attribute like enum HoldReason { Foo, Bar }
enum FreezeReason { Wibble } Is that correct? Metadata represents similar things (eg calls) using a variant type, so I'd likely suggest that we add something like a Does that make sense? I might have misunderstood something fundamental :) |
Yes, this is similar to how events and errors get aggregated into RuntimeEvent and RuntimeError in construct_runtime, except that the syntax to do so isn't |
Actually maybe I misunderstood a little; the thing you want in the metadata is the concrete values picked for those enums rather than the description of the enums themselves (ie the (I guess I want to check; what will you be doing with this metadata?) |
Maybe we should start having the possibility to add random types to the metadata. |
Random values (I think that's what you mean, but maybe there's value in allowing random types to be added to the registry without associated values?) that were interesting could exist in a shape like: BTreeMap<String, { type_id: u32, value: Vec<u8> }> And that could exist both in individual pallets and at the global level in the metadata, where the (We could also use the Does this make sense? If so, we could add something like this to accomodate this |
It should either be a Moreover, and this is probably a bit too premature to say so, what we wanted to do eventually is to expand the functionality of the |
Ah to be clear, I didn't mean use this instead of a BTreeMap, but just instead of the value/tpye_id bit (but I prefer the value/type_id approach).
I'm not very familiar with these things; could you give an example of how that'd be used and what the outputs would be that we'd want to be saving to metadata? (does the |
Yes, the |
Let me try to elaborate in more detail: The #[pallet::composite_enum]
pub enum HoldReason {
Staking,
Governance,
} Where During pub enum RuntimeHoldReason {
PalletName(pallet::HoldReason),
} This entire mechanism here is similar to how However, all of |
Ooh I see, so it _is _ about arbitrary types and not values then? So the
and then in the type registry we have some type info which is sortof like And what you're saying is that In this case, we can't have concrete fields like So I guess we could have something in metadata like this (at the top level): BTreeMap<String, { type_id: u32 }> Where the string is eg Then we can also add arbitrary custom types behind some key if there is a need to expose other types in the metadata that may be useful. A question I still have about all of this is: assuming these are now in the metadata; how would people use these types? What value do they have to users? I mean, basically every other type we store in the type registry is either an argument to some call or storage entry or whatever (so we need it to encode data to make that call/query storage), or it's the result of some call or whatever (so we know how to decode the stuff we get back from the node). Where would this From the original issue:
So there must be a value corresponding to this enum somewhere? How does the user get hold of it? Is it stored behind a runtime API or some constant or something? If so then the type would end up being in the metadata anyway because we store info about all constants and runtime APIs and storage entries. Or is the idea that we do need some arbitrary value storage in the metadata that isn't any of those, to also store a value for (sorry for the longer than expected reply; just typing as I ponder this really) |
One example of where You can imagine that it will be very useful for the front-end UI to display just which pallet is putting the funds on hold, for what reason, and most importantly, the amount of funds that the pallet is holding. As an aside, do note that the concept of "holds" and "freezes" are new concepts -- they are designed to replace the concept of "reserves". I don't exactly recall the details, but this issue in Substrate explains it comprehensively. |
Isn't that just a constant though, which would be stored in the metadata with a corresponding type ID already? |
Is |
I started a Looking at the metadata it appears to be an enum with one variant:
I can't say whether that's expected offhand, but it exists already :)
Is there still some need to store types or values that aren't constants/storage types/tx types etc then? |
Wait, this is simply because the NIS pallet contains a config item called |
Following a private conversation with @jsdw, it's now clear to me that:
Given the above findings, it becomes apparent that there's no further need to create an extra field in |
Perfect!
I guess I'd expand this slightly to "the purpose of putting things into metadata is to provide all necessary information for things to make use of our APIs" (quite general I know), which is encoding/decoding but also eg providing documentation, allowing for codegen, or whatever. So I'd def understand if a future need to expose pallet config that is useful for UIs to present in some way (but not useful for encoding/decoding etc) comes up :) |
In paritytech/substrate#13722, we've added support to allow pallets to optionally specify and expose an enum which gets aggregated into a bigger enum with other pallets containing the same enum with the same name in
construct_runtime
. We'd like to expose this information as metadata for the pallet and the runtime.This is the same feature as requested in #48 (comment).
The text was updated successfully, but these errors were encountered: