2

I have been looking into the hrmp pallets where some of the extrinsics needs to have a witness data variable provided as a parameter.

Example:

/// Total number of opening channels must be provided as witness data.
#[pallet::weight(<T as Config>::WeightInfo::force_process_hrmp_open(*_channels))]
pub fn force_process_hrmp_open(origin: OriginFor<T>, _channels: u32)` 

I found on this previous StackExchange answer that using a length witness as argument is a solution to calculate the weights of a extrinsic where the complexity is dictated by the number of items held in storage. And another example of another pallet with this approach (Alliance).

My question here is if this is only for benchmarking? and is there an alternative for this approach?

1 Answer 1

1

Yes this is done solely for benchmarking purposes. And AFAIK there is no alternative.
The reason is that we cannot just read the number of elements in the storage without opening up a DoS vector.
Imagine the weight function would read the number of channels from the storage; now that storage element would need to be loaded from disk and accessed - for free!
Instead; we use witness data and have a benchmark in case that it is wrong to still deduce the worst-case weight.

Thank you for pointing out this example; I think it is a bug that the number of channels is not verified. Witness data always needs to be verified.

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.