polkadot-sdk icon indicating copy to clipboard operation
polkadot-sdk copied to clipboard

Have all the special storage keys in a single place

Open xlc opened this issue 2 years ago • 6 comments

I am working on a feature of Chopsticks to decode all the storage keys. There are some keys requires special handling as they are not included in metadata.

Currently we have

https://github.com/paritytech/polkadot-sdk/blob/86228fa45e4c64642f7210cf44c40cc84ae17537/substrate/primitives/storage/src/lib.rs#L192-L216

https://github.com/paritytech/polkadot-sdk/blob/86228fa45e4c64642f7210cf44c40cc84ae17537/substrate/frame/support/src/traits/metadata.rs#L163-L167

https://github.com/paritytech/polkadot-sdk/blob/86228fa45e4c64642f7210cf44c40cc84ae17537/substrate/frame/support/src/storage/transactional.rs#L34-L37

https://github.com/paritytech/polkadot-sdk/blob/86228fa45e4c64642f7210cf44c40cc84ae17537/substrate/primitives/consensus/grandpa/src/lib.rs#L65-L67

https://github.com/paritytech/polkadot-sdk/blob/86228fa45e4c64642f7210cf44c40cc84ae17537/polkadot/primitives/src/v6/mod.rs#L242-L251

Please let me know if I missed anything

This makes it really hard to implement a generic and all-catching storage decoder. Can we move all the Substrate well known keys to sp_core::storage::well_known_keys? The polkadot one are all in a single place so that's good.

xlc avatar Nov 01 '23 22:11 xlc

The key format is also inconsistent. Some of them are :xxx and some of them are :xxx: but I guess we are already too late to change them.

We should also update the docs to include encoded hex and the expected value type.

xlc avatar Nov 01 '23 22:11 xlc

The polkadot one are all in a single place so that's good.

The Polkadot ones are not special keys, these are just the normal FRAME storage keys.

bkchr avatar Nov 02 '23 07:11 bkchr

:relay_dispatch_queue_remaining_capacity is definitely a special key but yeah everything else seems just storage keys encoded. Maybe we could refactor them in such why we code the string and have macro to convert them to hex in compile time? So it is more obvious where the hex is coming from.

xlc avatar Nov 02 '23 07:11 xlc

:relay_dispatch_queue_remaining_capacity

Ahh you got me :P

Maybe we could refactor them in such why we code the string and have macro to convert them to hex in compile time?

In a perfect way we would not need them at all. Or better abstracted. But we already have the hash macros, so it should actually work.

bkchr avatar Nov 02 '23 07:11 bkchr

I think we should use storage_alias to have type safety.

ggwpez avatar Mar 13 '24 12:03 ggwpez

is this issue just all about creating a cratewell_known_keys in sp_storage and moving the keys specified into it and then refractoring? is there anything else to be done asides that? @ggwpez

dharjeezy avatar Sep 02 '24 17:09 dharjeezy

It seems a bit odd to me that the keys for runtime specific things are specified in sp_storage and not a frame crate.
But since sp-storage cannot depend on frame, we could re-export all well known keys somewhere in frame-support.

Not sure if that is ideal, better ideas?

and then refractoring

Please first add a deprecation warning. If you want to remove something.

ggwpez avatar Oct 07 '24 11:10 ggwpez

@ggwpez can we then put all these keys in the frame support storage crate?

dharjeezy avatar Oct 26 '24 12:10 dharjeezy

We can re-export them there yes, but they are also needed in lower level crates, so they need to stay in there as well.

I guess a common re-export module is the best we can do now.

ggwpez avatar Oct 28 '24 17:10 ggwpez

We can re-export them there yes, but they are also needed in lower level crates, so they need to stay in there as well.

I guess a common re-export module is the best we can do now.

i don't seem to quite get what you mean by a common re-export module? what do you mean? @ggwpez

dharjeezy avatar Oct 28 '24 17:10 dharjeezy

mod well_known_keye {
    pub use sp_storage::...
    pub use sp_consensus_grandpa::...
}

and so on. Although it would probably not cover the ones from polkadot primitives, since what would create a dependency cycle again.

Not sure what @bkchr was thinking.

ggwpez avatar Oct 28 '24 20:10 ggwpez

It seems a bit odd to me that the keys for runtime specific things are specified in sp_storage and not a frame crate.

Because these keys are not FRAME specific. These are Substrate well known keys for communicating data to the node. Things like the code should not require to first call into the runtime.

bkchr avatar Oct 28 '24 21:10 bkchr

Generally, maybe just adding a page in the polkadot sdk docs is a better idea. I don't see any reason for adding them somewhere to re-export them, while this ticket is just about being able to find these keys/having a place to look them up.

bkchr avatar Oct 28 '24 21:10 bkchr

so, no need to get this done anymore? @bkchr

dharjeezy avatar Nov 01 '24 23:11 dharjeezy

As I said above, I think there should be a guide/reference doc added to the sdk docs.

bkchr avatar Nov 05 '24 23:11 bkchr

Recently, I create this ~~removed~~.

I'm interesting to add the well know storage keys there. It might be an option.

And also #324. Subscan team is struggling with the custom pallet account across different chains. 🤷🏻‍♂️

aurexav avatar Jan 11 '25 18:01 aurexav

And also #324. Subscan team is struggling with the custom pallet account across different chains. 🤷🏻‍♂️

But can they not read the PalletId from the constants?

bkchr avatar Jan 12 '25 22:01 bkchr

But can they not read the PalletId from the constants?

Yep, that would be the plan B. But a static registry is better.

aurexav avatar Jan 13 '25 01:01 aurexav

But a static registry is better.

But why?

bkchr avatar Jan 14 '25 20:01 bkchr