2

I'm currently working on a custom Substrate pallet and am trying to understand the best practices surrounding the Config trait. I've come across a design decision and would appreciate some guidance.

In my pallet, I have the following:

/// Base URI limit
const BASE_URI_LIMIT_U32: u32 = u8::MAX as u32;
/// Base URI limit type
type BaseURILimit = ConstU32<BASE_URI_LIMIT_U32>;
/// Base URI type
pub type BaseURI = BoundedVec<u8, BaseURILimit>;

Given that BaseURILimit is supposed to be non-configurable and constant across different runtimes using this pallet, is there any reason or advantage to moving it into the pallet's Config trait?

I'm trying to adhere to best practices and ensure maintainability. Any insights or recommendations would be invaluable.

3 Answers 3

2

If you are sure that it should never change, then that approach is fine.

Given that BaseURILimit is supposed to be non-configurable and constant across different runtimes using this pallet, is there any reason or advantage to moving it into the pallet's Config trait?

Its fine to have some things non-configurable if there is a good reason to. Personally i would make BASE_URI_LIMIT_U32 and the other type public as well to make downstream usage a bit easier.

0
-1

Usually it's not best practice store unlimited size of BoundedVec into runtime, and better to add the upper limit const into runtime rather than pallet.

2
  • 1
    I hold some concerns: 1. Inherently, a BoundedVec cannot possess an unlimited capacity. 2. The ability to define a limit at runtime suggests its adaptability. This means pallets with varied limits can be created, which contradicts the non-configurable requirement. Could you provide some clarity regarding these doubts?
    – ALeSD
    Aug 17, 2023 at 9:54
  • "unlimited size of BoundedVec" this makes no sense. The code is clearly using u8::MAX as limit. Aug 17, 2023 at 11:20
-1

As Ron suggested, we should store it as a constant in runtime like here and then use it in the pallet config like here

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.