diff --git a/frame/support/src/storage/generator/double_map.rs b/frame/support/src/storage/generator/double_map.rs index 7fdcac561c093..b60bb79566d51 100644 --- a/frame/support/src/storage/generator/double_map.rs +++ b/frame/support/src/storage/generator/double_map.rs @@ -237,7 +237,7 @@ where where KArg1: EncodeLike, { - unhashed::contains_prefix(Self::storage_double_map_final_key1(k1).as_ref()) + unhashed::contains_prefixed_key(Self::storage_double_map_final_key1(k1).as_ref()) } fn iter_prefix_values(k1: KArg1) -> storage::PrefixIterator diff --git a/frame/support/src/storage/generator/nmap.rs b/frame/support/src/storage/generator/nmap.rs index 7e763e22c2029..8cf1459431171 100755 --- a/frame/support/src/storage/generator/nmap.rs +++ b/frame/support/src/storage/generator/nmap.rs @@ -212,7 +212,7 @@ where where K: HasKeyPrefix, { - unhashed::contains_prefix(&Self::storage_n_map_partial_key(partial_key)) + unhashed::contains_prefixed_key(&Self::storage_n_map_partial_key(partial_key)) } fn iter_prefix_values(partial_key: KP) -> PrefixIterator diff --git a/frame/support/src/storage/unhashed.rs b/frame/support/src/storage/unhashed.rs index 086194d8473f8..8388c5f885c51 100644 --- a/frame/support/src/storage/unhashed.rs +++ b/frame/support/src/storage/unhashed.rs @@ -154,7 +154,10 @@ pub fn clear_prefix( MultiRemovalResults { maybe_cursor, backend: i, unique: i, loops: i } } -pub fn contains_prefix(prefix: &[u8]) -> bool { +/// Returns `true` if the storage contains any key, which starts with a certain prefix, +/// and is longer than said prefix. +/// This means that a key which equals the prefix will not be counted. +pub fn contains_prefixed_key(prefix: &[u8]) -> bool { match sp_io::storage::next_key(prefix) { Some(key) => key.starts_with(prefix), None => false,