From 04f9a1fa31ba3e8ee8b6e46d7be822fafcd5f6e8 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Wed, 11 Oct 2023 01:05:48 -0400 Subject: [PATCH] Correct handling of InSet's keys --- substrate/validator-sets/pallet/src/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/substrate/validator-sets/pallet/src/lib.rs b/substrate/validator-sets/pallet/src/lib.rs index 4427d653..d71859c1 100644 --- a/substrate/validator-sets/pallet/src/lib.rs +++ b/substrate/validator-sets/pallet/src/lib.rs @@ -83,8 +83,12 @@ pub mod pallet { ValueQuery, >; /// The validators selected to be in-set, yet with the ability to perform a check for presence. + // Uses Identity so we can call clear_prefix over network, manually inserting a Blake2 hash + // before the spammable key. + // TODO: Review child trees? #[pallet::storage] - pub type InSet = StorageMap<_, Blake2_128Concat, (NetworkId, Public), (), OptionQuery>; + pub type InSet = + StorageMap<_, Identity, (NetworkId, [u8; 16], Public), (), OptionQuery>; /// The current amount allocated to a validator set by a validator. #[pallet::storage] @@ -197,7 +201,10 @@ pub mod pallet { } let key = Public(next[(next.len() - 32) .. next.len()].try_into().unwrap()); - InSet::::set((network, key), Some(())); + InSet::::set( + (network, sp_io::hashing::blake2_128(&(network, key).encode()), key), + Some(()), + ); participants.push(key); last = next;