From 117c417e679c90d4589231cb73d9544036d0430e Mon Sep 17 00:00:00 2001
From: "paritytech-cmd-bot-polkadot-sdk[bot]"
 <179002856+paritytech-cmd-bot-polkadot-sdk[bot]@users.noreply.github.com>
Date: Tue, 14 Jan 2025 13:24:32 +0100
Subject: [PATCH] [stable2409] Backport #5526 (#7145)

Backport #5526 into `stable2409` from ordian.

See the
[documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md)
on how to use this bot.

<!--
  # To be used by other automation, do not modify:
  original-pr-number: #${pull_number}
-->

Co-authored-by: ordian <write@reusable.software>
---
 .../parachains/src/inclusion/benchmarking.rs  |  4 +-
 .../polkadot_runtime_parachains_inclusion.rs  | 45 ++++++++--------
 .../polkadot_runtime_parachains_inclusion.rs  | 54 ++++++++++---------
 prdoc/pr_5526.prdoc                           | 13 +++++
 4 files changed, 68 insertions(+), 48 deletions(-)
 create mode 100644 prdoc/pr_5526.prdoc

diff --git a/polkadot/runtime/parachains/src/inclusion/benchmarking.rs b/polkadot/runtime/parachains/src/inclusion/benchmarking.rs
index 978ef718ea4..d5d0716870a 100644
--- a/polkadot/runtime/parachains/src/inclusion/benchmarking.rs
+++ b/polkadot/runtime/parachains/src/inclusion/benchmarking.rs
@@ -95,8 +95,8 @@ benchmarks! {
 	}
 
 	enact_candidate {
-		let u in 1 .. 32;
-		let h in 1 .. 32;
+		let u in 0 .. 2;
+		let h in 0 .. 2;
 		let c in 0 .. 1;
 
 		let para = 42_u32.into();	// not especially important.
diff --git a/polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_inclusion.rs b/polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_inclusion.rs
index 4c6ce883557..5824658383b 100644
--- a/polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_inclusion.rs
+++ b/polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_inclusion.rs
@@ -17,9 +17,9 @@
 //! Autogenerated weights for `polkadot_runtime_parachains::inclusion`
 //!
 //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
-//! DATE: 2024-08-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
+//! DATE: 2024-08-29, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
 //! WORST CASE MAP SIZE: `1000000`
-//! HOSTNAME: `runner-696hpswk-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
+//! HOSTNAME: `runner-svzsllib-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
 //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("rococo-dev")`, DB CACHE: 1024
 
 // Executed Command:
@@ -70,13 +70,13 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::inclusion::WeightInfo
 	/// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`)
 	/// Storage: `MessageQueue::BookStateFor` (r:1 w:1)
 	/// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(55), added: 2530, mode: `MaxEncodedLen`)
-	/// Storage: `MessageQueue::Pages` (r:1 w:32)
+	/// Storage: `MessageQueue::Pages` (r:1 w:10)
 	/// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(32818), added: 35293, mode: `MaxEncodedLen`)
-	/// Storage: `Hrmp::HrmpChannelDigests` (r:33 w:33)
+	/// Storage: `Hrmp::HrmpChannelDigests` (r:11 w:11)
 	/// Proof: `Hrmp::HrmpChannelDigests` (`max_values`: None, `max_size`: None, mode: `Measured`)
-	/// Storage: `Hrmp::HrmpChannels` (r:32 w:32)
+	/// Storage: `Hrmp::HrmpChannels` (r:10 w:10)
 	/// Proof: `Hrmp::HrmpChannels` (`max_values`: None, `max_size`: None, mode: `Measured`)
-	/// Storage: `Hrmp::HrmpChannelContents` (r:32 w:32)
+	/// Storage: `Hrmp::HrmpChannelContents` (r:10 w:10)
 	/// Proof: `Hrmp::HrmpChannelContents` (`max_values`: None, `max_size`: None, mode: `Measured`)
 	/// Storage: `Paras::FutureCodeUpgrades` (r:1 w:0)
 	/// Proof: `Paras::FutureCodeUpgrades` (`max_values`: None, `max_size`: None, mode: `Measured`)
@@ -96,28 +96,31 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::inclusion::WeightInfo
 	/// Proof: `Paras::UpgradeRestrictionSignal` (`max_values`: None, `max_size`: None, mode: `Measured`)
 	/// Storage: UNKNOWN KEY `0xf5207f03cfdce586301014700e2c2593fad157e461d71fd4c1f936839a5f1f3e` (r:0 w:1)
 	/// Proof: UNKNOWN KEY `0xf5207f03cfdce586301014700e2c2593fad157e461d71fd4c1f936839a5f1f3e` (r:0 w:1)
-	/// The range of component `u` is `[1, 32]`.
-	/// The range of component `h` is `[1, 32]`.
+	/// The range of component `u` is `[0, 10]`.
+	/// The range of component `h` is `[0, 10]`.
 	/// The range of component `c` is `[0, 1]`.
 	fn enact_candidate(u: u32, h: u32, c: u32, ) -> Weight {
 		// Proof Size summary in bytes:
-		//  Measured:  `33353 + c * (16114 ±0) + h * (75 ±0)`
-		//  Estimated: `36818 + c * (26467 ±0) + h * (2551 ±0)`
-		// Minimum execution time: 4_829_551_000 picoseconds.
-		Weight::from_parts(1_892_697_027, 0)
-			.saturating_add(Weight::from_parts(0, 36818))
-			// Standard Error: 793_993
-			.saturating_add(Weight::from_parts(126_698_671, 0).saturating_mul(u.into()))
-			// Standard Error: 793_993
-			.saturating_add(Weight::from_parts(144_116_038, 0).saturating_mul(h.into()))
-			.saturating_add(T::DbWeight::get().reads(7))
+		//  Measured:  `33352 + c * (16115 ±0) + h * (76 ±0)`
+		//  Estimated: `36283 + c * (19327 ±403) + h * (3057 ±59) + u * (1314 ±59)`
+		// Minimum execution time: 1_334_017_000 picoseconds.
+		Weight::from_parts(5_805_317, 0)
+			.saturating_add(Weight::from_parts(0, 36283))
+			// Standard Error: 282_194
+			.saturating_add(Weight::from_parts(128_332_196, 0).saturating_mul(u.into()))
+			// Standard Error: 282_194
+			.saturating_add(Weight::from_parts(146_910_684, 0).saturating_mul(h.into()))
+			// Standard Error: 1_905_330
+			.saturating_add(Weight::from_parts(91_514_854, 0).saturating_mul(c.into()))
+			.saturating_add(T::DbWeight::get().reads(6))
 			.saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(h.into())))
 			.saturating_add(T::DbWeight::get().reads((8_u64).saturating_mul(c.into())))
-			.saturating_add(T::DbWeight::get().writes(10))
+			.saturating_add(T::DbWeight::get().writes(8))
 			.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(u.into())))
 			.saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(h.into())))
 			.saturating_add(T::DbWeight::get().writes((7_u64).saturating_mul(c.into())))
-			.saturating_add(Weight::from_parts(0, 26467).saturating_mul(c.into()))
-			.saturating_add(Weight::from_parts(0, 2551).saturating_mul(h.into()))
+			.saturating_add(Weight::from_parts(0, 19327).saturating_mul(c.into()))
+			.saturating_add(Weight::from_parts(0, 3057).saturating_mul(h.into()))
+			.saturating_add(Weight::from_parts(0, 1314).saturating_mul(u.into()))
 	}
 }
diff --git a/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_inclusion.rs b/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_inclusion.rs
index 36a4c5c24c9..28d8aa8ea32 100644
--- a/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_inclusion.rs
+++ b/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_inclusion.rs
@@ -17,9 +17,9 @@
 //! Autogenerated weights for `polkadot_runtime_parachains::inclusion`
 //!
 //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
-//! DATE: 2024-08-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
+//! DATE: 2024-08-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
 //! WORST CASE MAP SIZE: `1000000`
-//! HOSTNAME: `runner-696hpswk-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
+//! HOSTNAME: `runner-svzsllib-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
 //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("westend-dev")`, DB CACHE: 1024
 
 // Executed Command:
@@ -80,13 +80,13 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::inclusion::WeightInfo
 	/// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`)
 	/// Storage: `MessageQueue::BookStateFor` (r:1 w:1)
 	/// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(55), added: 2530, mode: `MaxEncodedLen`)
-	/// Storage: `MessageQueue::Pages` (r:1 w:32)
+	/// Storage: `MessageQueue::Pages` (r:1 w:2)
 	/// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(131122), added: 133597, mode: `MaxEncodedLen`)
-	/// Storage: `Hrmp::HrmpChannelDigests` (r:33 w:33)
+	/// Storage: `Hrmp::HrmpChannelDigests` (r:3 w:3)
 	/// Proof: `Hrmp::HrmpChannelDigests` (`max_values`: None, `max_size`: None, mode: `Measured`)
-	/// Storage: `Hrmp::HrmpChannels` (r:32 w:32)
+	/// Storage: `Hrmp::HrmpChannels` (r:2 w:2)
 	/// Proof: `Hrmp::HrmpChannels` (`max_values`: None, `max_size`: None, mode: `Measured`)
-	/// Storage: `Hrmp::HrmpChannelContents` (r:32 w:32)
+	/// Storage: `Hrmp::HrmpChannelContents` (r:2 w:2)
 	/// Proof: `Hrmp::HrmpChannelContents` (`max_values`: None, `max_size`: None, mode: `Measured`)
 	/// Storage: `Paras::FutureCodeUpgrades` (r:1 w:0)
 	/// Proof: `Paras::FutureCodeUpgrades` (`max_values`: None, `max_size`: None, mode: `Measured`)
@@ -104,28 +104,32 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::inclusion::WeightInfo
 	/// Proof: `Paras::UpgradeRestrictionSignal` (`max_values`: None, `max_size`: None, mode: `Measured`)
 	/// Storage: UNKNOWN KEY `0xf5207f03cfdce586301014700e2c2593fad157e461d71fd4c1f936839a5f1f3e` (r:0 w:1)
 	/// Proof: UNKNOWN KEY `0xf5207f03cfdce586301014700e2c2593fad157e461d71fd4c1f936839a5f1f3e` (r:0 w:1)
-	/// The range of component `u` is `[1, 32]`.
-	/// The range of component `h` is `[1, 32]`.
+	/// The range of component `u` is `[0, 2]`.
+	/// The range of component `h` is `[0, 2]`.
 	/// The range of component `c` is `[0, 1]`.
 	fn enact_candidate(u: u32, h: u32, c: u32, ) -> Weight {
 		// Proof Size summary in bytes:
-		//  Measured:  `132737 + c * (15992 ±0) + h * (75 ±0)`
-		//  Estimated: `136202 + c * (76098 ±0) + h * (2551 ±0)`
-		// Minimum execution time: 18_868_930_000 picoseconds.
-		Weight::from_parts(6_899_601_016, 0)
-			.saturating_add(Weight::from_parts(0, 136202))
-			// Standard Error: 1_952_665
-			.saturating_add(Weight::from_parts(467_810_135, 0).saturating_mul(u.into()))
-			// Standard Error: 1_952_665
-			.saturating_add(Weight::from_parts(551_226_340, 0).saturating_mul(h.into()))
-			.saturating_add(T::DbWeight::get().reads(11))
+		//  Measured:  `1447 + c * (15992 ±0) + h * (92 ±0) + u * (131259 ±0)`
+		//  Estimated: `134587 + c * (25419 ±939) + h * (29985 ±511) + u * (82828 ±511)`
+		// Minimum execution time: 1_065_780_000 picoseconds.
+		Weight::from_parts(192_328_221, 0)
+			.saturating_add(Weight::from_parts(0, 134587))
+			// Standard Error: 1_263_527
+			.saturating_add(Weight::from_parts(454_948_671, 0).saturating_mul(u.into()))
+			// Standard Error: 1_263_527
+			.saturating_add(Weight::from_parts(527_131_211, 0).saturating_mul(h.into()))
+			// Standard Error: 2_093_815
+			.saturating_add(Weight::from_parts(11_112_489, 0).saturating_mul(c.into()))
+			.saturating_add(T::DbWeight::get().reads(8))
+			.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(u.into())))
 			.saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(h.into())))
-			.saturating_add(T::DbWeight::get().reads((8_u64).saturating_mul(c.into())))
-			.saturating_add(T::DbWeight::get().writes(11))
-			.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(u.into())))
-			.saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(h.into())))
-			.saturating_add(T::DbWeight::get().writes((7_u64).saturating_mul(c.into())))
-			.saturating_add(Weight::from_parts(0, 76098).saturating_mul(c.into()))
-			.saturating_add(Weight::from_parts(0, 2551).saturating_mul(h.into()))
+			.saturating_add(T::DbWeight::get().reads((9_u64).saturating_mul(c.into())))
+			.saturating_add(T::DbWeight::get().writes(6))
+			.saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(u.into())))
+			.saturating_add(T::DbWeight::get().writes((4_u64).saturating_mul(h.into())))
+			.saturating_add(T::DbWeight::get().writes((8_u64).saturating_mul(c.into())))
+			.saturating_add(Weight::from_parts(0, 25419).saturating_mul(c.into()))
+			.saturating_add(Weight::from_parts(0, 29985).saturating_mul(h.into()))
+			.saturating_add(Weight::from_parts(0, 82828).saturating_mul(u.into()))
 	}
 }
diff --git a/prdoc/pr_5526.prdoc b/prdoc/pr_5526.prdoc
new file mode 100644
index 00000000000..0c0a4b055f6
--- /dev/null
+++ b/prdoc/pr_5526.prdoc
@@ -0,0 +1,13 @@
+title: "Fix enact_candidate weight generation"
+doc:
+  - audience: Runtime Dev
+    description: |
+      This PR works around an issue in multivariate linear regression of weight generation.
+
+crates:
+  - name: polkadot-runtime-parachains
+    bump: patch
+  - name: rococo-runtime
+    bump: patch
+  - name: westend-runtime
+    bump: patch
-- 
GitLab