Currently across the substrate code base, there are a lot of PRs updating storage items to bounded forms, example: https://github.com/paritytech/substrate/pull/11591/

I am wondering what is the behavior if say a we are changing storage of Vec<T> that has 11 items into a BoundedVec<T, I> that only allows ten items? Does BoundedVec<T,I> truncate the value leaving the last value inaccessible via the high level storage abstraction? Does there need to be a runtime migration for cases such as this?

1 Answer 1


In short, if the bounds being introduced are all known to be respected, they don't.

BoundedVec encodes exactly the same as a normal Vec (namely based on being derived). TO go a bit deeper, the bound is encoded in the type, as an associated Get type, which only a compile-time matter.

That being said, if any of the values that already exist in storage violate the bound, then bound, then the Decode implementation of BoundedVec fails, and the storage item cannot be accessed. In these cases, None or Default::default() are returned. For these values, a migration is needed.

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.