Weights for pallet-bridge-grandpa (#815)

* Add benchmarking skeleton

* Allow runtime to indicate concrete header type for benches

* Set up skeleton for benchmark tests

* Play around with mutating bench header

* Create a working test for benchmarking

* Add benches related to enacting authority set changes

* Add bench for checking effect of prec-commits/vote ancestries

* Use new `no_std` test utils in benchmarks

* Support pallet instances in benchmarking

* Use correct benchmarking instance macro

* Add instance to runtime benchmark helper impl

* Start using new justification creation API

* Allow mock header's number to be specified

* Set up benches with correct fork/depth parameters

* Use new pallet name during runtime bench setup

* Use correct `set_id` in tests

* Limit number of forks as workaround to get tests passing

* Use number of authorities which matches number of forks

* Make sure test post-conditions are checked properly

* Only read `CurrentAuthoritySet` from storage once

* Add combined benchmark for `submit_finality_proof`

* Add bench test

* Introduce config bounds related to justification verification

* Use config consts from pallet in benchmarking

* Return data relevant to benchmarks from helper functions

* Annotate `submit_finality_proof` with autogenerated weights

* Return actual weight after call execution

* Ignore Clippy warnings in bench template

* Update benchmark template

* Use `test-utils` to create test headers

* Clarify that helper is only for messages benches

* Add more documentation to benches

* Update TODOs

* Clarify return types in comment

* Fix pallet name post-merge

* Update NOTE to a TODO item

* Indicate that Config params are max values, not actual values

* Change Config validator count type to be `u32`

* Return decoded justification instead of fields

* Add missing trait bounds for tests

* Correctly issue weight refund

Thanks for spotting this Tomek!

* Update comment

* Add note about SESSION_LENGTH

* Fix benchmarking code
This commit is contained in:
Hernando Castano
2021-04-01 12:51:43 -04:00
committed by Bastian Köcher
parent 67cdca8aa4
commit 025a9cad59
12 changed files with 544 additions and 15 deletions
+10 -1
View File
@@ -417,11 +417,18 @@ parameter_types! {
// Note that once this is hit the pallet will essentially throttle incoming requests down to one
// call per block.
pub const MaxRequests: u32 = 50;
pub const MillauSessionLength: bp_millau::BlockNumber = bp_millau::SESSION_LENGTH;
// TODO [#846]: Right now this will break benchmarking if it is greater than `u8::MAX`
pub const MillauValidatorCount: u32 = 255;
}
impl pallet_bridge_grandpa::Config for Runtime {
type BridgedChain = bp_millau::Millau;
type MaxRequests = MaxRequests;
type MaxBridgedSessionLength = MillauSessionLength;
type MaxBridgedValidatorCount = MillauValidatorCount;
type WeightInfo = pallet_bridge_grandpa::weights::RialtoWeight<Runtime>;
}
impl pallet_shift_session_manager::Config for Runtime {}
@@ -799,6 +806,7 @@ impl_runtime_apis! {
config: frame_benchmarking::BenchmarkConfig,
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey, add_benchmark};
let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
@@ -945,6 +953,7 @@ impl_runtime_apis! {
>(
&lane_id,
).0;
let make_millau_header = |state_root| bp_millau::Header::new(
0,
Default::default(),
@@ -1005,7 +1014,6 @@ impl_runtime_apis! {
}
}
add_benchmark!(params, batches, pallet_bridge_eth_poa, BridgeKovan);
add_benchmark!(
params,
batches,
@@ -1018,6 +1026,7 @@ impl_runtime_apis! {
pallet_bridge_messages,
MessagesBench::<Runtime, WithMillauMessagesInstance>
);
add_benchmark!(params, batches, pallet_bridge_grandpa, BridgeMillauGrandpa);
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)