There is very little information to be found on static
parameter types. All I could find is a docstring that says: In testing, StaticArgument
can be altered later: StaticArgument::set(8)
.
I need to alter a parameter in benchmarking code to be able to benchmark a specific path Pallet config:
#[pallet::config]
pub trait Config: frame_system::Config {
type HeadersToKeep: Get<u32>;
}
In the runtime code the parameter is declared as static
:
parameter_types! {
pub static HeadersToKeepArgument: u32 = 1000;
}
Passed to the config:
impl my_pallet::Config for Runtime {
type HeadersToKeep = HeadersToKeepArgument;
}
Now when I want to set it's value to execute a benchmark code:
benchmarks! {
benchmark_with_pruning {
let _ = T::HeadersToKeep::set(3);
...
}: foo(RawOrigin::Signed(caller.clone()))
verify {
...
}
}
75 | let _ = T::HeadersToKeep::set(3);
| ^^^ function or associated item cannot be called on `<T as pallet::Config>::HeadersToKeep` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`<T as pallet::Config>::HeadersToKeep: frame_support::storage::generator::StorageValue<_>`
which is required by `<T as pallet::Config>::HeadersToKeep: frame_support::StorageValue<_>`
`&<T as pallet::Config>::HeadersToKeep: frame_support::storage::generator::StorageValue<_>`
which is required by `&<T as pallet::Config>::HeadersToKeep: frame_support::StorageValue<_>`
`&mut <T as pallet::Config>::HeadersToKeep: frame_support::storage::generator::StorageValue<_>`
which is required by `&mut <T as pallet::Config>::HeadersToKeep: frame_support::StorageValue<_>`
Get
implementation needs to be dynamically changed? The value should be constant when implemented in your runtime, and thus, when you run benchmarks, you will get exactly the results for the value that put. In summary, I think you might be doing something wrong here.Get
parameter (1K here). It's a convoluted setup to get it over 1k and trigger that other logic, and the number of elements won't impact the compute complexity. It does not need to be dynamically changed though, conditional compilation is also a possibility, so I might just go with that.