Weights and Benchmarks

There are a few points to note for weights and benchmarks, because substrate requires statically defined weights, we have provided some traits that should be implemented by module callbacks and Consensus clients.


The WeightProvider trait allows us return weights for different ConsensusClient and IsmpModule implementations.
Consensus client operations should be benchmarked and the result of this benchmark should be used in implementing ConsensusClientWeight .


This trait provides a means to return reasonable weights for execution of IsmpModule callbacks. It is recommended to write separate benchmarks for the on_accept , on_response, and on_timeout functions of the IsmpModule implementation.
For the Contract handler a reasonable gas limit for execution of IsmpModule callbacks should be returned as the weight when implementing the IsmpModuleWeight, this weight would be used as a global value for all contract callbacks.
// A sample using the IsmpDemo pallet described above pub struct IsmpDemoModuleBenchmark; impl IsmpModuleWeight for IsmpDemoModuleBenchmark { fn on_accept(&self, request: &Post) -> Weight { // Return the weight derived from actual benchmarks of the IsmpDemo // -- snip -- } // -- snip -- } // This portion would go into the runtime lib.rs file pub struct IsmpWeightProvider; impl WeightProvider for IsmpWeightProvider { fn consensus_client(_id: ConsensusClientId) -> Option<Box<dyn ConsensusClientWeight>> { // --snip-- } fn module_callback(dest_module: ModuleId) -> Option<Box<dyn IsmpModuleWeight>> { match dest_module { ismp_demo::PALLET_ID => Some(Box::new(IsmpDemoModuleBenchmark)) _ => None } } }