From 83abc82d47cb783c8a40505e6a8e172967b503f1 Mon Sep 17 00:00:00 2001
From: "cmd[bot]" <41898282+github-actions[bot]@users.noreply.github.com>
Date: Thu, 27 Feb 2025 02:30:11 +0000
Subject: [PATCH] Update from bkontur running command 'fmt'

---
 .../parachains/src/paras/benchmarking.rs      | 12 ++-
 polkadot/runtime/parachains/src/paras/mod.rs  | 60 +++++++++----
 .../runtime/parachains/src/paras/tests.rs     | 90 ++++++++++++-------
 3 files changed, 106 insertions(+), 56 deletions(-)

diff --git a/polkadot/runtime/parachains/src/paras/benchmarking.rs b/polkadot/runtime/parachains/src/paras/benchmarking.rs
index 3d30c3efa35..ff322d3ea59 100644
--- a/polkadot/runtime/parachains/src/paras/benchmarking.rs
+++ b/polkadot/runtime/parachains/src/paras/benchmarking.rs
@@ -252,8 +252,10 @@ mod benchmarks {
 	#[benchmark]
 	fn authorize_code_hash() {
 		let para_id = ParaId::from(1000);
-		let authorization = CodeHashAuthorization::ForceSetCurrentCode {para_id, code_hash: [0; 32].into() };
-		let expire_at = frame_system::Pallet::<T>::block_number().saturating_add(BlockNumberFor::<T>::from(1_000_000_u32));
+		let authorization =
+			CodeHashAuthorization::ForceSetCurrentCode { para_id, code_hash: [0; 32].into() };
+		let expire_at = frame_system::Pallet::<T>::block_number()
+			.saturating_add(BlockNumberFor::<T>::from(1_000_000_u32));
 
 		#[extrinsic_call]
 		_(RawOrigin::Root, authorization.clone(), expire_at);
@@ -265,8 +267,10 @@ mod benchmarks {
 	fn apply_authorized_code(c: Linear<MIN_CODE_SIZE, MAX_CODE_SIZE>) {
 		let code = ValidationCode(vec![0; c as usize]);
 		let para_id = ParaId::from(1000);
-		let authorization = CodeHashAuthorization::ForceSetCurrentCode {para_id, code_hash: code.hash() };
-		let expire_at = frame_system::Pallet::<T>::block_number().saturating_add(BlockNumberFor::<T>::from(c));
+		let authorization =
+			CodeHashAuthorization::ForceSetCurrentCode { para_id, code_hash: code.hash() };
+		let expire_at =
+			frame_system::Pallet::<T>::block_number().saturating_add(BlockNumberFor::<T>::from(c));
 		AuthorizedCodeHash::<T>::set(vec![(authorization.clone(), expire_at)]);
 		generate_disordered_pruning::<T>();
 
diff --git a/polkadot/runtime/parachains/src/paras/mod.rs b/polkadot/runtime/parachains/src/paras/mod.rs
index 59732a69fe7..191c6d9ff33 100644
--- a/polkadot/runtime/parachains/src/paras/mod.rs
+++ b/polkadot/runtime/parachains/src/paras/mod.rs
@@ -590,12 +590,16 @@ impl<N> CodeHashAuthorization<N> {
 		use CodeHashAuthorization::*;
 
 		match (self, other) {
-			(ForceSetCurrentCode { para_id: a, .. }, ForceSetCurrentCode { para_id: b, .. })
-			| (ForceScheduleCodeUpgrade { para_id: a, .. }, ForceScheduleCodeUpgrade { para_id: b, .. })
-			if a == b => true,
+			(ForceSetCurrentCode { para_id: a, .. }, ForceSetCurrentCode { para_id: b, .. }) |
+			(
+				ForceScheduleCodeUpgrade { para_id: a, .. },
+				ForceScheduleCodeUpgrade { para_id: b, .. },
+			) if a == b => true,
 
-			(AddTrustedValidationCode { code_hash: a }, AddTrustedValidationCode { code_hash: b })
-			if a == b => true,
+			(
+				AddTrustedValidationCode { code_hash: a },
+				AddTrustedValidationCode { code_hash: b },
+			) if a == b => true,
 
 			_ => false,
 		}
@@ -604,9 +608,9 @@ impl<N> CodeHashAuthorization<N> {
 	/// Compares the stored `code_hash` with the hash of the provided validation code.
 	fn code_matches(&self, code: &ValidationCode) -> bool {
 		let code_hash = match self {
-			CodeHashAuthorization::ForceSetCurrentCode { code_hash, .. }
-			| CodeHashAuthorization::ForceScheduleCodeUpgrade { code_hash, .. }
-			| CodeHashAuthorization::AddTrustedValidationCode { code_hash } => code_hash,
+			CodeHashAuthorization::ForceSetCurrentCode { code_hash, .. } |
+			CodeHashAuthorization::ForceScheduleCodeUpgrade { code_hash, .. } |
+			CodeHashAuthorization::AddTrustedValidationCode { code_hash } => code_hash,
 		};
 
 		code_hash == &code.hash()
@@ -891,8 +895,11 @@ pub mod pallet {
 
 	/// The code hash authorizations which will expire `expire_at` `BlockNumberFor<T>`.
 	#[pallet::storage]
-	pub(super) type AuthorizedCodeHash<T: Config> =
-		StorageValue<_, Vec<(CodeHashAuthorization<BlockNumberFor<T>>, BlockNumberFor<T>)>, ValueQuery>;
+	pub(super) type AuthorizedCodeHash<T: Config> = StorageValue<
+		_,
+		Vec<(CodeHashAuthorization<BlockNumberFor<T>>, BlockNumberFor<T>)>,
+		ValueQuery,
+	>;
 
 	/// This is used by the relay-chain to communicate to a parachain a go-ahead with in the upgrade
 	/// procedure.
@@ -1212,8 +1219,8 @@ pub mod pallet {
 		/// Sets the storage for the authorized current code hash of the parachain.
 		/// If not applied, it will be removed at the `expire_at` block.
 		///
-		/// This can be useful, for example, when triggering `Paras::force_set_current_code(para, code)`
-		/// from a different chain than the one where the `Paras` pallet is deployed.
+		/// This can be useful, for example, when triggering `Paras::force_set_current_code(para,
+		/// code)` from a different chain than the one where the `Paras` pallet is deployed.
 		///
 		/// The main purpose is to avoid transferring the entire `code` Wasm blob between chains.
 		/// Instead, we authorize `code_hash` with `root`, which can later be applied by
@@ -1229,14 +1236,23 @@ pub mod pallet {
 			expire_at: BlockNumberFor<T>,
 		) -> DispatchResult {
 			ensure_root(origin)?;
-			ensure!(expire_at > frame_system::Pallet::<T>::block_number(), Error::<T>::InvalidBlockNumber);
+			ensure!(
+				expire_at > frame_system::Pallet::<T>::block_number(),
+				Error::<T>::InvalidBlockNumber
+			);
 
-			// insert authorized code hash and make sure to overwrite existing variant `CodeHashAuthorization` for `para_id`.
+			// insert authorized code hash and make sure to overwrite existing variant
+			// `CodeHashAuthorization` for `para_id`.
 			AuthorizedCodeHash::<T>::mutate(|authorizations| {
-				authorizations.retain(|(authorization, _)| !authorization.should_be_replaced_by(&new_authorization));
+				authorizations.retain(|(authorization, _)| {
+					!authorization.should_be_replaced_by(&new_authorization)
+				});
 				authorizations.push((new_authorization.clone(), expire_at));
 			});
-			Self::deposit_event(Event::CodeAuthorized { authorization: new_authorization, expire_at });
+			Self::deposit_event(Event::CodeAuthorized {
+				authorization: new_authorization,
+				expire_at,
+			});
 
 			Ok(())
 		}
@@ -1264,9 +1280,15 @@ pub mod pallet {
 
 			// apply/dispatch
 			match authorized_code_hash {
-				CodeHashAuthorization::ForceSetCurrentCode { para_id, .. } => Self::do_force_set_current_code_update(para_id, code),
-				CodeHashAuthorization::AddTrustedValidationCode { .. } => Self::do_add_trusted_validation_code(code),
-				CodeHashAuthorization::ForceScheduleCodeUpgrade { para_id, relay_parent_number, .. } => Self::do_force_schedule_code_upgrade(para_id, code, relay_parent_number),
+				CodeHashAuthorization::ForceSetCurrentCode { para_id, .. } =>
+					Self::do_force_set_current_code_update(para_id, code),
+				CodeHashAuthorization::AddTrustedValidationCode { .. } =>
+					Self::do_add_trusted_validation_code(code),
+				CodeHashAuthorization::ForceScheduleCodeUpgrade {
+					para_id,
+					relay_parent_number,
+					..
+				} => Self::do_force_schedule_code_upgrade(para_id, code, relay_parent_number),
 			}
 
 			// if ok, then allows "for free"
diff --git a/polkadot/runtime/parachains/src/paras/tests.rs b/polkadot/runtime/parachains/src/paras/tests.rs
index 9a4ab59542c..83b1f2fa5ee 100644
--- a/polkadot/runtime/parachains/src/paras/tests.rs
+++ b/polkadot/runtime/parachains/src/paras/tests.rs
@@ -2048,10 +2048,14 @@ fn authorize_code_hash_works() {
 		let code_2 = ValidationCode(vec![2]);
 		let code_1_hash = code_1.hash();
 		let code_2_hash = code_2.hash();
-		let authorize_force_set_current_code_1_for_para_a = CodeHashAuthorization::ForceSetCurrentCode {para_id: para_a, code_hash: code_1_hash };
-		let authorize_force_set_current_code_1_for_para_b = CodeHashAuthorization::ForceSetCurrentCode {para_id: para_b, code_hash: code_1_hash };
-		let authorize_force_set_current_code_2_for_para_a = CodeHashAuthorization::ForceSetCurrentCode {para_id: para_a, code_hash: code_2_hash };
-		let add_trusted_validation_code_1 = CodeHashAuthorization::AddTrustedValidationCode {code_hash: code_1_hash};
+		let authorize_force_set_current_code_1_for_para_a =
+			CodeHashAuthorization::ForceSetCurrentCode { para_id: para_a, code_hash: code_1_hash };
+		let authorize_force_set_current_code_1_for_para_b =
+			CodeHashAuthorization::ForceSetCurrentCode { para_id: para_b, code_hash: code_1_hash };
+		let authorize_force_set_current_code_2_for_para_a =
+			CodeHashAuthorization::ForceSetCurrentCode { para_id: para_a, code_hash: code_2_hash };
+		let add_trusted_validation_code_1 =
+			CodeHashAuthorization::AddTrustedValidationCode { code_hash: code_1_hash };
 		let expire_at = 143;
 
 		// check before
@@ -2070,15 +2074,31 @@ fn authorize_code_hash_works() {
 		// cannot authorize when `expire_at` is in the past
 		System::set_block_number(expire_at + 1);
 		assert_err!(
-			Paras::authorize_code_hash(RuntimeOrigin::root(), authorize_force_set_current_code_1_for_para_a.clone(), expire_at),
+			Paras::authorize_code_hash(
+				RuntimeOrigin::root(),
+				authorize_force_set_current_code_1_for_para_a.clone(),
+				expire_at
+			),
 			Error::<Test>::InvalidBlockNumber,
 		);
 		let expire_at = expire_at + 2;
 
 		// root can authorize
-		assert_ok!(Paras::authorize_code_hash(RuntimeOrigin::root(), authorize_force_set_current_code_1_for_para_a.clone(), expire_at));
-		assert_ok!(Paras::authorize_code_hash(RuntimeOrigin::root(), authorize_force_set_current_code_1_for_para_b.clone(), expire_at));
-		assert_ok!(Paras::authorize_code_hash(RuntimeOrigin::root(), add_trusted_validation_code_1.clone(), expire_at));
+		assert_ok!(Paras::authorize_code_hash(
+			RuntimeOrigin::root(),
+			authorize_force_set_current_code_1_for_para_a.clone(),
+			expire_at
+		));
+		assert_ok!(Paras::authorize_code_hash(
+			RuntimeOrigin::root(),
+			authorize_force_set_current_code_1_for_para_b.clone(),
+			expire_at
+		));
+		assert_ok!(Paras::authorize_code_hash(
+			RuntimeOrigin::root(),
+			add_trusted_validation_code_1.clone(),
+			expire_at
+		));
 		assert_eq!(
 			AuthorizedCodeHash::<Test>::get(),
 			vec![
@@ -2089,8 +2109,16 @@ fn authorize_code_hash_works() {
 		);
 
 		// the same authorization variant is overwritten
-		assert_ok!(Paras::authorize_code_hash(RuntimeOrigin::root(), authorize_force_set_current_code_2_for_para_a.clone(), expire_at));
-		assert_ok!(Paras::authorize_code_hash(RuntimeOrigin::root(), add_trusted_validation_code_1.clone(), expire_at + 5));
+		assert_ok!(Paras::authorize_code_hash(
+			RuntimeOrigin::root(),
+			authorize_force_set_current_code_2_for_para_a.clone(),
+			expire_at
+		));
+		assert_ok!(Paras::authorize_code_hash(
+			RuntimeOrigin::root(),
+			add_trusted_validation_code_1.clone(),
+			expire_at + 5
+		));
 		assert_eq!(
 			{
 				let mut sorted = AuthorizedCodeHash::<Test>::get();
@@ -2101,7 +2129,7 @@ fn authorize_code_hash_works() {
 				let mut sorted = vec![
 					(authorize_force_set_current_code_2_for_para_a, expire_at), // changed code
 					(authorize_force_set_current_code_1_for_para_b, expire_at), // no change
-					(add_trusted_validation_code_1, expire_at + 5), // changed expire_at
+					(add_trusted_validation_code_1, expire_at + 5),             /* changed expire_at */
 				];
 				sorted.sort();
 				sorted
@@ -2118,8 +2146,10 @@ fn apply_authorized_code_works() {
 		let code_2 = ValidationCode(vec![2]);
 		let code_1_hash = code_1.hash();
 		let code_2_hash = code_2.hash();
-		let authorize_force_set_current_code_1_for_para_a = CodeHashAuthorization::ForceSetCurrentCode {para_id: para_a, code_hash: code_1_hash };
-		let add_trusted_validation_code_2 = CodeHashAuthorization::AddTrustedValidationCode {code_hash: code_2_hash};
+		let authorize_force_set_current_code_1_for_para_a =
+			CodeHashAuthorization::ForceSetCurrentCode { para_id: para_a, code_hash: code_1_hash };
+		let add_trusted_validation_code_2 =
+			CodeHashAuthorization::AddTrustedValidationCode { code_hash: code_2_hash };
 		let expire_at = 143;
 
 		// check before
@@ -2144,12 +2174,10 @@ fn apply_authorized_code_works() {
 		);
 
 		// authorize
-		AuthorizedCodeHash::<Test>::set(
-			vec![
-				(authorize_force_set_current_code_1_for_para_a.clone(), expire_at),
-				(add_trusted_validation_code_2.clone(), expire_at),
-			]
-		);
+		AuthorizedCodeHash::<Test>::set(vec![
+			(authorize_force_set_current_code_1_for_para_a.clone(), expire_at),
+			(add_trusted_validation_code_2.clone(), expire_at),
+		]);
 
 		// cannot apply unauthorized code_2
 		assert_err!(
@@ -2169,9 +2197,7 @@ fn apply_authorized_code_works() {
 		));
 		assert_eq!(
 			AuthorizedCodeHash::<Test>::get(),
-			vec![
-				(add_trusted_validation_code_2.clone(), expire_at),
-			]
+			vec![(add_trusted_validation_code_2.clone(), expire_at),]
 		);
 
 		// cannot apply previously authorized code again
@@ -2192,16 +2218,16 @@ fn prune_expired_authorizations_works() {
 		let para_a = ParaId::from(111);
 		let code_1 = ValidationCode(vec![1]);
 		let code_1_hash = code_1.hash();
-		let authorize_force_set_current_code_1_for_para_a = CodeHashAuthorization::ForceSetCurrentCode {para_id: para_a, code_hash: code_1_hash };
-		let add_trusted_validation_code_1 = CodeHashAuthorization::AddTrustedValidationCode {code_hash: code_1_hash};
+		let authorize_force_set_current_code_1_for_para_a =
+			CodeHashAuthorization::ForceSetCurrentCode { para_id: para_a, code_hash: code_1_hash };
+		let add_trusted_validation_code_1 =
+			CodeHashAuthorization::AddTrustedValidationCode { code_hash: code_1_hash };
 
 		// add authorizations
-		AuthorizedCodeHash::<Test>::set(
-			vec![
-				(authorize_force_set_current_code_1_for_para_a.clone(), 201),
-				(add_trusted_validation_code_1.clone(), 202),
-			]
-		);
+		AuthorizedCodeHash::<Test>::set(vec![
+			(authorize_force_set_current_code_1_for_para_a.clone(), 201),
+			(add_trusted_validation_code_1.clone(), 202),
+		]);
 
 		// nothing
 		let _ = Paras::prune_expired_authorizations(200);
@@ -2217,9 +2243,7 @@ fn prune_expired_authorizations_works() {
 		let _ = Paras::prune_expired_authorizations(201);
 		assert_eq!(
 			AuthorizedCodeHash::<Test>::get(),
-			vec![
-				(add_trusted_validation_code_1.clone(), 202),
-			]
+			vec![(add_trusted_validation_code_1.clone(), 202),]
 		);
 
 		// pruned 202
-- 
GitLab