Skip to main content
6 votes
Accepted

How to implement BoundedVec inside an extrinsic?

A more elegant way: Make your max value part of your pallet's configuration trait so you can keep it generic in your pallet: #[pallet::constant] type StringLimit: Get<u32>; Define some alias ...
Sacha Lansky's user avatar
  • 2,640
5 votes
Accepted

Issue with #[pallet::generate_storage_info]

generate_storage_info is now the default. So, you don't need to specify it anymore. For your error here it means, just remove this attribute. For reference, it means that if you are just developing a ...
bkchr's user avatar
  • 11.6k
5 votes

How to create a bounded vec from a normal vec?

You cannot just "type cast" a Vec into a BoundedVec because of the guarantees that a BoundedVec provides. Although there are some ways to create a BoundedVec from a Vec: Try Into / Try From ...
Oliver Tale-Yazdi's user avatar
4 votes
Accepted

What should be the maximum size of a `BoundedVec`?

Is that too much for a block to handle if I iterate through this for example three times? The answer to this question is benchmarking, the result of running such benchmarks will give a value that you ...
Alejandro Martínez's user avatar
4 votes

Prepare pallets for Weights v2

Great questions! Where can I find documentation on what exactly has to be done in terms of bounded types? The docs are quite sparse. Ideally the compiler should be able to lead the path. You "...
Oliver Tale-Yazdi's user avatar
3 votes

What should be the maximum size of a `BoundedVec`?

Just to add one thing into Alejandro's answer, the new Weights V2 has added a field into Weights: proof_size: pub struct Weight { /// The weight of computational time used based on ///...
Alex Bean's user avatar
  • 5,757
3 votes
Accepted

Substrate BoundedVec Error Cannot Borrow as mutable

The idea behind BoundedVec is to have a vector that is ensuring that the maximum size is not exceeded. Basically it is just a wrapper around Vec, but most of the methods are prefixed with try_. The ...
bkchr's user avatar
  • 11.6k
3 votes
Accepted

Use BoundedVec in benchmark

You could use BoundedVec anywhere. What is the value of MaxAccountsPerTransaction you used in the mock runtime? If z + 3 > MaxAccountsPerTransaction, then you got this error.
AurevoirXavier's user avatar
  • 10.8k
3 votes
Accepted

BoundedVec on ink!

You can store Vec in contract's storage which can grow over time. storage_deposit_limit specifies the max amount of storage your contract can use. If you want to explicitly limit the size of the Vec, ...
German Nikolishin's user avatar
3 votes
Accepted

How to create a bounded vec from a normal vec?

BoundedVec implements TryFrom, so you can use that in cases where you want an error if the BoundedVec can't be created given the length of the input vec. IE BoundedVec::try_from(endowed_accounts); You ...
Justin Frevert's user avatar
3 votes
Accepted

What happens when a bounded vec in storage is fully populated and then its bound is reduced?

Good question! Just reducing the bound will indeed result in a decoding error. It will behave like any other decode error; not panic but either return None or Default depending on whether you are ...
Oliver Tale-Yazdi's user avatar
3 votes
Accepted

Error defining BoundedVec as a Pallet Storage the trait `Decode` is not implemented for `sp_runtime::BoundedVec

Please check the impl. https://paritytech.github.io/substrate/master/src/sp_core/bounded/bounded_vec.rs.html#45 It requires Get<u32>. Try: #[pallet::constant] type MaxStudents: Get<u32>;
AurevoirXavier's user avatar
  • 10.8k
2 votes

Why BoundedVec does not implement a Decode trait

What? It is definetly decodable. Code from here: impl<T: Decode, S: Get<u32>> Decode for BoundedVec<T, S> { fn decode<I: codec::Input>(input: &mut I) -> Result<...
Oliver Tale-Yazdi's user avatar
2 votes

Update the way to limit a boundedvec

Yes this is fine. Just note that any reduction of that constant would incur a migration. This may or may not be obvious to runtime developers that use your pallet, and should be documented.
Oliver Tale-Yazdi's user avatar
1 vote
Accepted

How to construct the data structure with correct values for their attributes within a Pallet for data submitted by a polkadotJS app

JS encode: const registry = new TypeRegistry(); const someNameInstance = registry.createType('{"current_fraction":"u32"}', { current_fraction: 123 }); const encoded = ...
AurevoirXavier's user avatar
  • 10.8k
1 vote
Accepted

Data structure to choose for ordered items?

The performance is the most important aspect here. Storage::get(i) reads/decodes only the ith item from DB. Stgorage::get().iter().nth(i) reads/decodes the entire storage item from DB and then indexes ...
AurevoirXavier's user avatar
  • 10.8k
1 vote
Accepted

How to convert a u32 into a BoundedVec compatible format?

You can use the SCALE codec to encode types into Vec. Then the Vec can be converted into a BoundedVec. For example a u32 (but it works the same for any other encodable type): use codec::Encode; use ...
Oliver Tale-Yazdi's user avatar
1 vote
Accepted

Update the way to limit a boundedvec

You don't need a migration for this. In low-level, it's just a Vec. Tips: But if your MaximunCID is less than 100 and you have a "full" BoundedVec, that might be an issue. So, please check ...
AurevoirXavier's user avatar
  • 10.8k
1 vote

How to store a bounded map inside `StorageValue`?

If i have understood your question correctly you are asking if you can store a BoundedBTreeMap inside a storage value and what is the complexity of iterating over values in the BTree or getting a ...
gatsey's user avatar
  • 183
1 vote

frame_benchmarking convert Vec to BoundedVec

Okay after all of that, I managed to figure it out... Since frame_benchmarking::Vec<u8> wasn't working I decided to focus on converting a BoundedVec to the custom type. Firstly I needed to add ...
DJJ's user avatar
  • 63
1 vote
Accepted

How to benchmark huge bounded vectors?

10M entries of u32 in a vector? Sure this will not fit in the memory of the runtime, which is capped at 32 MiB. Three things to consider: It looks like your data structure is rather a map. Then ...
Oliver Tale-Yazdi's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible