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: Support iterating over NMaps with partial keys #1044

Closed
jsdw opened this issue Jun 30, 2023 · 0 comments · Fixed by #1079
Closed

Storage: Support iterating over NMaps with partial keys #1044

jsdw opened this issue Jun 30, 2023 · 0 comments · Fixed by #1079
Assignees

Comments

@jsdw
Copy link
Collaborator

jsdw commented Jun 30, 2023

Currently, when accessing storage maps (ie storage entries that require some key to be provided) we have two options:

// 1. provide _all_ of the keys to get a single value back:
runtime::storage().pallet().entry(key1, key2, ...);

// 2. provided no keys. This allows iterating over _everything_:
runtime::storage().pallet().entry_root();

When more than one key is needed, it'd be nice if people could provide any subset of the required keys to be able to iterate over all of the remaining values. In other words it'd be nice if the API looked something like:

// 1. provide _all_ of the keys to get a single value back:
runtime::storage().pallet().entry(key1, key2, key3);

// 2. provide some subset of keys. All of these allow iterating over results beneath them:
runtime::storage().pallet().entry_iter0();
runtime::storage().pallet().entry_iter1(key1);
runtime::storage().pallet().entry_iter2(key1, key2);

Here, entry would be Fetchable but not Iterable, and all of the _iter functions would be Iterable but not Fetchable.

Right now, one can call .to_root_key() on some entry to be able to iterate over the root things. Additionally, something like runtime::storage().pallet().entry(key1, key2, key3) is Iterable (iteration calls .to_root_key()). I'd propose scrapping both of these, ie:

  • Iterating over a key should never call .to_root_key(); it'll just iterate whatever was given.
  • If you provide every key eg runtime::storage().pallet().entry(key1, key2, key3);, you cannot iterate over this. Instead you'll have to construct a new entry with as many partial keys as you want to iterate, so it's explicit what you're actually iterating over.

See #1038 for the original inspiration.

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 a pull request may close this issue.

2 participants