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

Have all the special storage keys in a single place #2126

Open
xlc opened this issue Nov 1, 2023 · 5 comments
Open

Have all the special storage keys in a single place #2126

xlc opened this issue Nov 1, 2023 · 5 comments
Labels
C1-mentor A task where a mentor is available. Please indicate in the issue who the mentor could be. D1-medium Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase. I4-refactor Code needs refactoring.

Comments

@xlc
Copy link
Contributor

xlc commented Nov 1, 2023

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

/// Wasm code of the runtime.
///
/// Stored as a raw byte vector. Required by substrate.
pub const CODE: &[u8] = b":code";
/// Number of wasm linear memory pages required for execution of the runtime.
///
/// The type of this value is encoded `u64`.
pub const HEAP_PAGES: &[u8] = b":heappages";
/// Current extrinsic index (u32) is stored under this key.
///
/// Encodes to `0x3a65787472696e7369635f696e646578`.
pub const EXTRINSIC_INDEX: &[u8] = b":extrinsic_index";
/// Current intra-block entropy (a universally unique `[u8; 32]` value) is stored here.
///
/// Encodes to `0x3a696e747261626c6f636b5f656e74726f7079`.
pub const INTRABLOCK_ENTROPY: &[u8] = b":intrablock_entropy";
/// Prefix of child storage keys.
pub const CHILD_STORAGE_KEY_PREFIX: &[u8] = b":child_storage:";
/// Prefix of the default child storage keys in the top trie.
pub const DEFAULT_CHILD_STORAGE_KEY_PREFIX: &[u8] = b":child_storage:default:";

/// The storage key postfix that is used to store the [`StorageVersion`] per pallet.
///
/// The full storage key is built by using:
/// Twox128([`PalletInfo::name`]) ++ Twox128([`STORAGE_VERSION_STORAGE_KEY_POSTFIX`])
pub const STORAGE_VERSION_STORAGE_KEY_POSTFIX: &[u8] = b":__STORAGE_VERSION__:";

/// The key that is holds the current number of active layers.
///
/// Encodes to `0x3a7472616e73616374696f6e5f6c6576656c3a`.
pub const TRANSACTION_LEVEL_KEY: &[u8] = b":transaction_level:";

/// The storage key for the current set of weighted Grandpa authorities.
/// The value stored is an encoded VersionedAuthorityList.
pub const GRANDPA_AUTHORITIES_KEY: &[u8] = b":grandpa_authorities";

/// The upward message dispatch queue remaining capacity for the given para id.
///
/// The storage entry stores a tuple of two values:
///
/// - `count: u32`, the number of additional messages which may be enqueued for the given para,
/// - `total_size: u32`, the total size of additional messages which may be enqueued for the
/// given para.
pub fn relay_dispatch_queue_remaining_capacity(para_id: Id) -> WellKnownKey<(u32, u32)> {
(b":relay_dispatch_queue_remaining_capacity", para_id).encode().into()
}

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
Copy link
Contributor Author

xlc commented Nov 1, 2023

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.

@bkchr
Copy link
Member

bkchr commented Nov 2, 2023

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.

@xlc
Copy link
Contributor Author

xlc commented Nov 2, 2023

: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.

@bkchr
Copy link
Member

bkchr commented Nov 2, 2023

: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.

@ggwpez
Copy link
Member

ggwpez commented Mar 13, 2024

I think we should use storage_alias to have type safety.

@ggwpez ggwpez added C1-mentor A task where a mentor is available. Please indicate in the issue who the mentor could be. I4-refactor Code needs refactoring. D1-medium Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase. labels Mar 13, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Mar 26, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Mar 27, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Apr 8, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Apr 8, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Apr 8, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Apr 8, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Apr 8, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Apr 10, 2024
serban300 added a commit to serban300/polkadot-sdk that referenced this issue Apr 10, 2024
bkchr pushed a commit that referenced this issue Apr 10, 2024
TomaszWaszczyk pushed a commit to TomaszWaszczyk/polkadot-sdk that referenced this issue May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C1-mentor A task where a mentor is available. Please indicate in the issue who the mentor could be. D1-medium Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase. I4-refactor Code needs refactoring.
Projects
None yet
Development

No branches or pull requests

3 participants