5

I am currently writing a migration to remove a pallet and all its memory from our runtime. Unfortunately, I cannot manage to check for the existence of the pallet's prefix in the pre- and post upgrade try-runtime hooks as all of my tried check function return false, even if the storage exists, e.g. frame_support::storage::unhashed::kill_prefix(&prefix, None) returns AllRemoved(5).

I have tried the following functions which internally use sp_io::storage API:

frame_support::storage::unhashed::exists(&prefix);
frame_support::storage::get_raw::exists(&prefix);
frame_support::storage::migration::have_storage_value(&prefix, &[]);
frame_support::storage::migration::have_storage_value(&prefix, &some_storage_entry);

Moreover, after removing all entries with kill_prefix in the on_runtime_upgrade_hook, the same call results in SomeRemaining(1) when checking in post_upgrade hook. Does this happen because one storage entry persists in the in-memory overlay of the try-runtime execution?

1 Answer 1

2

Using the frame support iterators on pallet maps when available could be the better approach.

If not using frame support (or storage structure do not allow iteration), one can use sp_io primitives (similar to support raw api). First check existence of prefix key, then call sp_io::storage::next_key(prefix) until the resulting key does no start with the prefix. That's pretty low level but does not need to assume anything from the pallet (just its prefix and that it never did write outside of it).

kill_prefix always apply from the prefix (there is no persistence of previous calls progress), so it only make sense to call it multiple time if the limit of removed items is increased (generally calling it only once per block is better).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.