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

storage_type: Strip key proper hash and entry bytes (32 instead of 16) #1522

Merged
merged 4 commits into from
Apr 9, 2024

Conversation

lexnv
Copy link
Collaborator

@lexnv lexnv commented Apr 8, 2024

This PR ensures that we can properly decode storage key addresses.

There was an issue confirmed by #1517, where the decoding of keys for dynamic storage queries would always fail at:

let keys = <Address::Keys as StorageKey>::decode_storage_key(
cursor,
&mut hashers.iter(),
metadata.types(),
)?;

After investigating the code path, the error is coming from the following lines:

// We've consumed all of the hashers, so we expect to also consume all of the bytes:
if !bytes.is_empty() {
return Err(StorageAddressError::TooManyBytes.into());
}

The check appeared to be correct, as well as consuming hasher keys via consume_hash_returning_key_bytes.

After inspecting the key address bytes, we wrongly assumed the storage prefix bytes length.

Our storage keys start with the following:

twox_128(storage prefix) ++ twox_128(storage entry name)

In the issue, it is twox_128(System) ++ twox_128(Accounts).

The output of the twox is: 16 bytes, not 8 as stated and assumed in our code base.

Testing Done

  • reproduced the issue via storage_iter_dynamic example
  • Compared addr bytes with expected prefix:
    • twox_128("System"): 26aa394eea5630e07c48ae0c9558cef7
    • twox_128("Account"): b99d880ec681799c0cf30e8886371da9

Closes: #1517

@lexnv lexnv requested a review from a team as a code owner April 8, 2024 21:18
Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

A test for iterating over storage keys would be nice :)

@jsdw
Copy link
Collaborator

jsdw commented Apr 9, 2024

Awesome; thanks for digging into this!

@lexnv lexnv merged commit c07ee0c into master Apr 9, 2024
13 checks passed
@lexnv lexnv deleted the lexnv/dyn-storage-iter branch April 9, 2024 11:08
lexnv added a commit that referenced this pull request Apr 9, 2024
#1522)

* storage_type: Strip key proper hash and entry bytes (32 instead of 16)

Signed-off-by: Alexandru Vasile <[email protected]>

* storage_type: Fix typo

Signed-off-by: Alexandru Vasile <[email protected]>

* storage/tests: Check keys decode properly and don't cause errors

Signed-off-by: Alexandru Vasile <[email protected]>

* Update testing/integration-tests/src/full_client/storage/mod.rs

Co-authored-by: James Wilson <[email protected]>

---------

Signed-off-by: Alexandru Vasile <[email protected]>
Co-authored-by: James Wilson <[email protected]>
@jsdw jsdw mentioned this pull request May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic storage iter example no longer works
3 participants