From a823d18f057cdf1996d73d0c964122967df4a2e7 Mon Sep 17 00:00:00 2001
From: Branislav Kontur <bkontur@gmail.com>
Date: Thu, 23 May 2024 12:11:20 +0200
Subject: [PATCH] Fix bridges grandpa benchmarks (#2577) (#4548)

Cherry-picked fix from upcoming
https://github.com/paritytech/polkadot-sdk/pull/4494

---------

Co-authored-by: Svyatoslav Nikolsky <svyatonik@gmail.com>
Co-authored-by: command-bot <>
---
 bridges/modules/grandpa/src/benchmarking.rs   |  3 ++-
 .../src/weights/pallet_bridge_grandpa.rs      | 20 ++++++++--------
 .../src/weights/pallet_bridge_grandpa.rs      | 24 +++++++++----------
 3 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/bridges/modules/grandpa/src/benchmarking.rs b/bridges/modules/grandpa/src/benchmarking.rs
index a458abf524d..fb7354e05c0 100644
--- a/bridges/modules/grandpa/src/benchmarking.rs
+++ b/bridges/modules/grandpa/src/benchmarking.rs
@@ -70,11 +70,12 @@ const MAX_VOTE_ANCESTRIES_RANGE_END: u32 =
 // the same with validators - if there are too much validators, let's run benchmarks on subrange
 fn precommits_range_end<T: Config<I>, I: 'static>() -> u32 {
 	let max_bridged_authorities = T::BridgedChain::MAX_AUTHORITIES_COUNT;
-	if max_bridged_authorities > 128 {
+	let max_bridged_authorities = if max_bridged_authorities > 128 {
 		sp_std::cmp::max(128, max_bridged_authorities / 5)
 	} else {
 		max_bridged_authorities
 	};
+
 	required_justification_precommits(max_bridged_authorities)
 }
 
diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_grandpa.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_grandpa.rs
index 257e2dcac2f..11e1439a1f6 100644
--- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_grandpa.rs
+++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_grandpa.rs
@@ -17,9 +17,9 @@
 //! Autogenerated weights for `pallet_bridge_grandpa`
 //!
 //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
-//! DATE: 2024-05-17, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
+//! DATE: 2024-05-23, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
 //! WORST CASE MAP SIZE: `1000000`
-//! HOSTNAME: `runner-unxyhko3-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
+//! HOSTNAME: `runner-vicqj8em-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
 //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("bridge-hub-rococo-dev")`, DB CACHE: 1024
 
 // Executed Command:
@@ -62,17 +62,17 @@ impl<T: frame_system::Config> pallet_bridge_grandpa::WeightInfo for WeightInfo<T
 	/// Proof: `BridgeWestendGrandpa::ImportedHashes` (`max_values`: Some(1024), `max_size`: Some(36), added: 1521, mode: `MaxEncodedLen`)
 	/// Storage: `BridgeWestendGrandpa::ImportedHeaders` (r:0 w:2)
 	/// Proof: `BridgeWestendGrandpa::ImportedHeaders` (`max_values`: Some(1024), `max_size`: Some(68), added: 1553, mode: `MaxEncodedLen`)
-	/// The range of component `p` is `[1, 838]`.
+	/// The range of component `p` is `[1, 168]`.
 	/// The range of component `v` is `[50, 100]`.
 	fn submit_finality_proof(p: u32, _v: u32, ) -> Weight {
 		// Proof Size summary in bytes:
-		//  Measured:  `440 + p * (60 ±0)`
+		//  Measured:  `438 + p * (60 ±0)`
 		//  Estimated: `51735`
-		// Minimum execution time: 306_046_000 picoseconds.
-		Weight::from_parts(384_361_000, 0)
+		// Minimum execution time: 300_829_000 picoseconds.
+		Weight::from_parts(321_573_000, 0)
 			.saturating_add(Weight::from_parts(0, 51735))
-			// Standard Error: 14_298
-			.saturating_add(Weight::from_parts(49_045_748, 0).saturating_mul(p.into()))
+			// Standard Error: 25_917
+			.saturating_add(Weight::from_parts(48_613_160, 0).saturating_mul(p.into()))
 			.saturating_add(T::DbWeight::get().reads(6))
 			.saturating_add(T::DbWeight::get().writes(5))
 	}
@@ -90,8 +90,8 @@ impl<T: frame_system::Config> pallet_bridge_grandpa::WeightInfo for WeightInfo<T
 		// Proof Size summary in bytes:
 		//  Measured:  `452`
 		//  Estimated: `51735`
-		// Minimum execution time: 94_965_000 picoseconds.
-		Weight::from_parts(113_633_000, 0)
+		// Minimum execution time: 101_007_000 picoseconds.
+		Weight::from_parts(129_904_000, 0)
 			.saturating_add(Weight::from_parts(0, 51735))
 			.saturating_add(T::DbWeight::get().reads(3))
 			.saturating_add(T::DbWeight::get().writes(6))
diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_bridge_grandpa.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_bridge_grandpa.rs
index 348d651396c..e98be6ba39b 100644
--- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_bridge_grandpa.rs
+++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_bridge_grandpa.rs
@@ -17,9 +17,9 @@
 //! Autogenerated weights for `pallet_bridge_grandpa`
 //!
 //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
-//! DATE: 2024-05-17, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
+//! DATE: 2024-05-23, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
 //! WORST CASE MAP SIZE: `1000000`
-//! HOSTNAME: `runner-unxyhko3-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
+//! HOSTNAME: `runner-vicqj8em-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
 //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("bridge-hub-westend-dev")`, DB CACHE: 1024
 
 // Executed Command:
@@ -62,19 +62,19 @@ impl<T: frame_system::Config> pallet_bridge_grandpa::WeightInfo for WeightInfo<T
 	/// Proof: `BridgeRococoGrandpa::ImportedHashes` (`max_values`: Some(1024), `max_size`: Some(36), added: 1521, mode: `MaxEncodedLen`)
 	/// Storage: `BridgeRococoGrandpa::ImportedHeaders` (r:0 w:2)
 	/// Proof: `BridgeRococoGrandpa::ImportedHeaders` (`max_values`: Some(1024), `max_size`: Some(68), added: 1553, mode: `MaxEncodedLen`)
-	/// The range of component `p` is `[1, 838]`.
+	/// The range of component `p` is `[1, 168]`.
 	/// The range of component `v` is `[50, 100]`.
 	fn submit_finality_proof(p: u32, v: u32, ) -> Weight {
 		// Proof Size summary in bytes:
-		//  Measured:  `270 + p * (60 ±0)`
+		//  Measured:  `268 + p * (60 ±0)`
 		//  Estimated: `51735`
-		// Minimum execution time: 294_098_000 picoseconds.
-		Weight::from_parts(31_208_540, 0)
+		// Minimum execution time: 291_721_000 picoseconds.
+		Weight::from_parts(37_495_589, 0)
 			.saturating_add(Weight::from_parts(0, 51735))
-			// Standard Error: 8_832
-			.saturating_add(Weight::from_parts(40_930_987, 0).saturating_mul(p.into()))
-			// Standard Error: 147_319
-			.saturating_add(Weight::from_parts(2_663_839, 0).saturating_mul(v.into()))
+			// Standard Error: 22_170
+			.saturating_add(Weight::from_parts(45_403_072, 0).saturating_mul(p.into()))
+			// Standard Error: 73_977
+			.saturating_add(Weight::from_parts(2_130_216, 0).saturating_mul(v.into()))
 			.saturating_add(T::DbWeight::get().reads(6))
 			.saturating_add(T::DbWeight::get().writes(5))
 	}
@@ -92,8 +92,8 @@ impl<T: frame_system::Config> pallet_bridge_grandpa::WeightInfo for WeightInfo<T
 		// Proof Size summary in bytes:
 		//  Measured:  `282`
 		//  Estimated: `51735`
-		// Minimum execution time: 112_875_000 picoseconds.
-		Weight::from_parts(120_861_000, 0)
+		// Minimum execution time: 77_426_000 picoseconds.
+		Weight::from_parts(90_926_000, 0)
 			.saturating_add(Weight::from_parts(0, 51735))
 			.saturating_add(T::DbWeight::get().reads(3))
 			.saturating_add(T::DbWeight::get().writes(6))
-- 
GitLab