Hey Substrate community,

there are two different methods to remove multiple items for one specific first key from a StorageDoubleMap. There is clear_prefix and drain_prefix. clear_prefix provides additional information with a cursor, that needs to be used for the case, that the map is not fully cleaned. But isn't drain_prefix the same functionality with less information as clear_prefix?

So I mean I can check with drain_prefix, if there are items left to delete. I could query if <StorageItem<T>>::drain_prefix(first_key).take(1).next().is_none(). Sure, this requires one additional read. Is this the reason why clear_prefix exists too?

1 Answer 1


The main difference to me is if it returns a closure.

When you just want to remove it:


Note: these are pseudo code

When you want to interact with the removed item:

Foo::darin_prefix().iter().for_each(|removed_item| {
    Bar::insert(removed_item.hash(), removed_item);

Note: these are pseudo code

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.