0

New substrate version requires derive MaxEncodedLen

I have a following storage:

#[derive(PartialEq, Eq, PartialOrd, Ord, Default, Clone, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct SortitionSumTree<AccountId> {
    pub k: u64,
    pub stack: Vec<u64>,
    pub nodes: Vec<u64>,
    pub ids_to_node_indexes: BTreeMap<AccountId, u64>, // citizen id, node index
    pub node_indexes_to_ids: BTreeMap<u64, AccountId>, // node index, citizen id
}

But it gives error:

no function or associated item named `max_encoded_len` found for struct `std::vec::Vec<u64>` in the current scope

no function or associated item named `max_encoded_len` found for struct `std::collections::BTreeMap` in the current scope

1 Answer 1

4

The point here is that BTreeMap by default isn't bounded. Meaning you could store an unlimited amount of data in these maps. For this case there exists the BoundedBTreeMap type in Substrate. There you statically need to define the upper number of data that will be stored inside the BTreeMap.

You can also disable the requirement for MaxEncodedLength by setting the without_storage_info attribute. If your pallet should not be used in Parachain, that is completely fine, because there you don't have the requirement to produce a storage proof which needs to be predictable.

Your Answer

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

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