diff --git a/frame/support/src/storage/mod.rs b/frame/support/src/storage/mod.rs index 0fb7b44939533..9b07190d25c02 100644 --- a/frame/support/src/storage/mod.rs +++ b/frame/support/src/storage/mod.rs @@ -1160,7 +1160,7 @@ pub trait StoragePrefixedMap { /// removed and the same result being returned. This happens because the keys to delete in the /// overlay are not taken into account when deleting keys in the backend. fn clear(limit: Option) -> sp_io::ClearPrefixResult { - sp_io::storage::clear_prefix(&Self::final_prefix(), limit) + unhashed::clear_prefix(&Self::final_prefix(), limit) } /// Iter over all value of the storage. diff --git a/frame/support/src/storage/unhashed.rs b/frame/support/src/storage/unhashed.rs index 65f5f268a1ca7..c3d5d0e13cd50 100644 --- a/frame/support/src/storage/unhashed.rs +++ b/frame/support/src/storage/unhashed.rs @@ -98,12 +98,22 @@ pub fn kill(key: &[u8]) { /// Ensure keys with the given `prefix` have no entries in storage. #[deprecated = "Use `clear_prefix` instead"] pub fn kill_prefix(prefix: &[u8], limit: Option) -> sp_io::KillStorageResult { - clear_prefix(prefix, limit).into() + // TODO: Once the network has upgraded to include the new host functions, this code can be + // enabled. + // clear_prefix(prefix, limit).into() + sp_io::storage::clear_prefix(prefix, limit) } /// Ensure keys with the given `prefix` have no entries in storage. pub fn clear_prefix(prefix: &[u8], limit: Option) -> sp_io::ClearPrefixResult { - sp_io::storage::clear_prefix(prefix, limit) + // TODO: Once the network has upgraded to include the new host functions, this code can be + // enabled. + // sp_io::storage::clear_prefix(prefix, limit) + use sp_io::{KillStorageResult::*, ClearPrefixResult::*}; + match kill_prefix(prefix, limit) { + AllRemoved(db) => NoneLeft { db, total: db }, + SomeRemaining(db) => SomeLeft { db, total: db }, + } } /// Get a Vec of bytes from storage. diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index faf5f906bd8bc..7c61eae1f5c3f 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -236,7 +236,7 @@ pub trait Storage { /// 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. - #[version(3)] + #[version(3, register_only)] fn clear_prefix(&mut self, prefix: &[u8], limit: Option) -> ClearPrefixResult { let (all_removed, db, total) = Externalities::clear_prefix(*self, prefix, limit); match all_removed {