3

I have the following StorageMap defined in my pallet:

#[pallet::storage]
pub(super) type Signatures<T: Config> = StorageMap<
    _,
    Blake2_128Concat,
    T::Hash,
    BoundedBTreeMap<Public, BoundedVec<u8, T::SignatureLength>, T::MaxAuthorities>,
>;

and in the benchmarks:

benchmarks!{
test_add{
    type CustomMap= BoundedBTreeMap<sp_core::sr25519::Public, BoundedVec<u8, ConstU32<64>>, ConstU32<32>>;
        let mut custom : CustomMap= BoundedBTreeMap::new();
        let id = H256::default();// using a concrete type also wouldn't work
        let hash = T::Hash::default();
     }:{
 Signatures::<T>::insert(hash, custom);
}

} it gives me the following error:

 error[E0277]: the trait bound `frame_support::BoundedBTreeMap<sp_core::sr25519::Public, frame_support::BoundedVec<u8, ConstU32<64>>, ConstU32<32>>: EncodeL
ike<frame_support::BoundedBTreeMap<sp_core::sr25519::Public, frame_support::BoundedVec<u8, <T as pallet::Config>::SignatureLength>, <T as pallet::Config>::
MaxAuthorities>>` is not satisfied
     --> /home/test/projects/custom/pallet/src/benchmarking.rs:70:46
      |
  70  |             Signatures::<T>::insert(hash, custom);
      |             ----------------------           ^^^^^^ the trait `EncodeLike<frame_support::BoundedBTreeMap<sp_core::sr25519::Public, frame_support::Bou
ndedVec<u8, <T as pallet::Config>::SignatureLength>, <T as pallet::Config>::MaxAuthorities>>` is not implemented for `frame_support::BoundedBTreeMap<sp_cor
e::sr25519::Public, frame_support::BoundedVec<u8, ConstU32<64>>, ConstU32<32>>`

even though the same code is executed perfectly in the pallet with no errors.

1 Answer 1

2

I think the problem is that you are using ConstU32<64> instead of the config constant T::SignatureLength (same for the other parameter). It is not correct and lead to problems when benchmarking your pallet later on.
For the hash type: you need to require it to have a Default in the config trait and then do T::Hash::default(). You can obviously not use concrete types here, since benchmarks are generic over the pallet config trait. But you could additionally require them to be From<H256> for benchmarking only by putting a where_clause on the benchmark.

In your case you can probably let the Rust compiler guess the type like this:

benchmarks!{
test_add{
        let mut custom = BoundedBTreeMap::new();
        let id = H256::default();// using a concrete type also wouldn't work
        let hash = T::Hash::default();
     }:{
 Signatures::<T>::insert(hash, custom);
}

Or if you really want to type it, then create a type alias with something like SignatureOf<T> for example like in the Alliance pallet and use that.
If this does not answer your question the please provide source code. Otherwise it is not possible to debug.

1
  • 1
    it actually worked by removing the type though i remember it was complaining in the begining about the type not been know so i had to specify it, also using T::SignatureLength wont work, it says use of generic parameter from outer function
    – dadzerlaze
    Apr 27 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.