diff --git a/polkadot/runtime/parachains/src/paras/mod.rs b/polkadot/runtime/parachains/src/paras/mod.rs index 95bab14651d8a389cd8dddb34eb88f2a30f1ee86..7b64cc09027f4004cf6dc45e081f138a01138920 100644 --- a/polkadot/runtime/parachains/src/paras/mod.rs +++ b/polkadot/runtime/parachains/src/paras/mod.rs @@ -720,8 +720,10 @@ pub mod pallet { CannotUpgradeCode, /// Invalid validation code size. InvalidCode, - /// The given code is not authorized. - NotAuthorizedCode, + /// No upgrade authorized. + NothingAuthorized, + /// The submitted code is not authorized. + Unauthorized, } /// All currently active PVF pre-checking votes. @@ -1214,13 +1216,9 @@ pub mod pallet { // no need to ensure, anybody can do this // Ensure `new_code` is authorized - if let Some(authorized_code_hash) = AuthorizedCodeHash::<T>::take(¶) { - if new_code.hash() != authorized_code_hash { - return Err(Error::<T>::NotAuthorizedCode.into()); - } - } else { - return Err(Error::<T>::NotAuthorizedCode.into()); - } + let authorized_code_hash = + AuthorizedCodeHash::<T>::take(¶).ok_or(Error::<T>::NothingAuthorized)?; + ensure!(authorized_code_hash == new_code.hash(), Error::<T>::Unauthorized); // TODO: FAIL-CI - more validations? diff --git a/polkadot/runtime/parachains/src/paras/tests.rs b/polkadot/runtime/parachains/src/paras/tests.rs index 2eb1bf593b28fc7f9e45a9b1b98758ff8097fe3f..fbdefaac3469be55bcc0d01b3ac0a658c230f8fb 100644 --- a/polkadot/runtime/parachains/src/paras/tests.rs +++ b/polkadot/runtime/parachains/src/paras/tests.rs @@ -2041,7 +2041,7 @@ fn authorize_and_apply_set_current_code_works() { para_a, code_1.clone() ), - Error::<Test>::NotAuthorizedCode, + Error::<Test>::NothingAuthorized, ); // non-root user cannot authorize @@ -2066,7 +2066,7 @@ fn authorize_and_apply_set_current_code_works() { para_a, code_2.clone() ), - Error::<Test>::NotAuthorizedCode, + Error::<Test>::Unauthorized, ); assert_eq!(AuthorizedCodeHash::<Test>::get(para_a), Some(code_1_hash)); assert!(CurrentCodeHash::<Test>::get(para_a).is_none()); @@ -2111,7 +2111,7 @@ fn authorize_and_apply_set_current_code_works() { para_a, code_1.clone() ), - Error::<Test>::NotAuthorizedCode, + Error::<Test>::Unauthorized, ); assert_err!( Paras::apply_authorized_force_set_current_code( @@ -2119,7 +2119,7 @@ fn authorize_and_apply_set_current_code_works() { para_a, code_2.clone() ), - Error::<Test>::NotAuthorizedCode, + Error::<Test>::Unauthorized, ); // apply just authorized