Skip to content

Storage requirements using BoundedVec by default #782

@sacha-l

Description

@sacha-l

We need to document the change in Substrate that's just been merged: paritytech/substrate#10662

Pallets require that all vectors in runtime storage are bounded, meaning that they must use the BoundedVec type and specify a max value constant. For example:

	/// The description of each child-bounty.
	#[pallet::storage]
	#[pallet::getter(fn child_bounty_descriptions)]
	pub type ChildBountyDescriptions<T: Config> =
		StorageMap<_, Twox64Concat, BountyIndex, BoundedVec<u8, T::MaximumReasonLength>>;

To override this default behaviour, developers must add the without_storage_info attribute to their pallets:

	#[pallet::pallet]
	#[pallet::generate_store(pub(super) trait Store)]
	#[pallet::without_storage_info] 
	pub struct Pallet<T>(_);

Bounded storage items is important because if any Vec gets too big it can lead to:

  • Running out of wasm memory loading that vec for a solo chain / relay chain (which happened with staking on Polkadot a while back)
  • Running out of PoV space for a parachain validation block (only 5mb available per block)

Just like computation, memory / storage space is also a bottleneck for blockchains. For relay chains, bounded vectors are used to compute the PoV proof size and to ensure that the size of a proof-of-membership set in a vector doesn't grow unbounded. Users can still opt out of writing things bounded using the without_storage_info attribute. However they are encouraged by the compiler to ensure their storage is bounded.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions