referrerpolicy=no-referrer-when-downgrade

Function sp_io::storage::clear_prefix

source ·
pub fn clear_prefix(prefix: &[u8], limit: Option<u32>) -> KillStorageResult
Expand description

Clear the storage of each key-value pair where the key starts with the given prefix.

§Limit

Deletes all keys from the overlay and up to limit keys from the backend if it is set to Some. No limit is applied when limit is set to None.

The limit can be used to partially delete a prefix storage in case it is too large to delete in one go (block).

Returns KillStorageResult to inform about the result.

§Note

Please note that keys that are residing in the overlay for that prefix when issuing this call are all deleted without counting towards the limit. Only keys written during the current block are part of the overlay. Deleting with a limit mostly makes sense with an empty overlay for that prefix.

Calling this function multiple times per block for the same prefix does not make much sense because it is not cumulative when called inside the same block. The deletion would always start from prefix resulting in the same keys being deleted every time this function is called with the exact same arguments per block. This happens because the keys in the overlay are not taken into account when deleting keys in the backend.