diff --git a/polkadot/runtime/common/src/paras_registrar/mod.rs b/polkadot/runtime/common/src/paras_registrar/mod.rs index 2ead621dedf0..e653716b59db 100644 --- a/polkadot/runtime/common/src/paras_registrar/mod.rs +++ b/polkadot/runtime/common/src/paras_registrar/mod.rs @@ -318,7 +318,7 @@ pub mod pallet { // early, since swapping the same id would otherwise be a noop. if id == other { PendingSwap::::remove(id); - return Ok(()) + return Ok(()); } // Sanity check that `id` is even a para. @@ -330,23 +330,23 @@ pub mod pallet { paras::Pallet::::lifecycle(other).ok_or(Error::::NotRegistered)?; // identify which is a lease holding parachain and which is a parathread (on-demand // parachain) - if id_lifecycle == ParaLifecycle::Parachain && - other_lifecycle == ParaLifecycle::Parathread + if id_lifecycle == ParaLifecycle::Parachain + && other_lifecycle == ParaLifecycle::Parathread { Self::do_thread_and_chain_swap(id, other); - } else if id_lifecycle == ParaLifecycle::Parathread && - other_lifecycle == ParaLifecycle::Parachain + } else if id_lifecycle == ParaLifecycle::Parathread + && other_lifecycle == ParaLifecycle::Parachain { Self::do_thread_and_chain_swap(other, id); - } else if id_lifecycle == ParaLifecycle::Parachain && - other_lifecycle == ParaLifecycle::Parachain + } else if id_lifecycle == ParaLifecycle::Parachain + && other_lifecycle == ParaLifecycle::Parachain { // If both chains are currently parachains, there is nothing funny we // need to do for their lifecycle management, just swap the underlying // data. T::OnSwap::on_swap(id, other); } else { - return Err(Error::::CannotSwap.into()) + return Err(Error::::CannotSwap.into()); } Self::deposit_event(Event::::Swapped { para_id: id, other_id: other }); PendingSwap::::remove(other); @@ -1532,7 +1532,7 @@ mod benchmarking { use polkadot_runtime_parachains::{paras, shared, Origin as ParaOrigin}; use sp_runtime::traits::Bounded; - use frame_benchmarking::{account, benchmarks, whitelisted_caller}; + use frame_benchmarking::v2::*; fn assert_last_event(generic_event: ::RuntimeEvent) { let events = frame_system::Pallet::::events(); @@ -1559,7 +1559,7 @@ mod benchmarking { frame_system::Origin::::Root.into(), validation_code, )); - return para + return para; } fn para_origin(id: u32) -> ParaOrigin { @@ -1572,66 +1572,105 @@ mod benchmarking { paras::Pallet::::test_on_new_session(); } - benchmarks! { - where_clause { where ParaOrigin: Into<::RuntimeOrigin> } + #[benchmarks( + where ParaOrigin: Into<::RuntimeOrigin>, + )] + mod benchmarks { + use super::*; - reserve { + #[benchmark] + fn reserve() -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - }: _(RawOrigin::Signed(caller.clone())) - verify { - assert_last_event::(Event::::Reserved { para_id: LOWEST_PUBLIC_ID, who: caller }.into()); + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone())); + + assert_last_event::( + Event::::Reserved { para_id: LOWEST_PUBLIC_ID, who: caller }.into(), + ); assert!(Paras::::get(LOWEST_PUBLIC_ID).is_some()); assert_eq!(paras::Pallet::::lifecycle(LOWEST_PUBLIC_ID), None); + + Ok(()) } - register { + #[benchmark] + fn register() -> Result<(), BenchmarkError> { let para = LOWEST_PUBLIC_ID; let genesis_head = Registrar::::worst_head_data(); let validation_code = Registrar::::worst_validation_code(); let caller: T::AccountId = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); assert_ok!(Registrar::::reserve(RawOrigin::Signed(caller.clone()).into())); - }: _(RawOrigin::Signed(caller.clone()), para, genesis_head, validation_code.clone()) - verify { - assert_last_event::(Event::::Registered{ para_id: para, manager: caller }.into()); + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), para, genesis_head, validation_code.clone()); + + assert_last_event::( + Event::::Registered { para_id: para, manager: caller }.into(), + ); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Onboarding)); - assert_ok!(polkadot_runtime_parachains::paras::Pallet::::add_trusted_validation_code( - frame_system::Origin::::Root.into(), - validation_code, - )); + assert_ok!( + polkadot_runtime_parachains::paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + ) + ); next_scheduled_session::(); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Parathread)); + + Ok(()) } - force_register { + #[benchmark] + fn force_register() -> Result<(), BenchmarkError> { let manager: T::AccountId = account("manager", 0, 0); let deposit = 0u32.into(); let para = ParaId::from(69); let genesis_head = Registrar::::worst_head_data(); let validation_code = Registrar::::worst_validation_code(); - }: _(RawOrigin::Root, manager.clone(), deposit, para, genesis_head, validation_code.clone()) - verify { + + #[extrinsic_call] + _( + RawOrigin::Root, + manager.clone(), + deposit, + para, + genesis_head, + validation_code.clone(), + ); + assert_last_event::(Event::::Registered { para_id: para, manager }.into()); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Onboarding)); - assert_ok!(polkadot_runtime_parachains::paras::Pallet::::add_trusted_validation_code( - frame_system::Origin::::Root.into(), - validation_code, - )); + assert_ok!( + polkadot_runtime_parachains::paras::Pallet::::add_trusted_validation_code( + frame_system::Origin::::Root.into(), + validation_code, + ) + ); next_scheduled_session::(); assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Parathread)); + + Ok(()) } - deregister { + #[benchmark] + fn deregister() -> Result<(), BenchmarkError> { let para = register_para::(LOWEST_PUBLIC_ID.into()); next_scheduled_session::(); let caller: T::AccountId = whitelisted_caller(); - }: _(RawOrigin::Signed(caller), para) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller), para); + assert_last_event::(Event::::Deregistered { para_id: para }.into()); + + Ok(()) } - swap { + #[benchmark] + fn swap() -> Result<(), BenchmarkError> { // On demand parachain let parathread = register_para::(LOWEST_PUBLIC_ID.into()); let parachain = register_para::((LOWEST_PUBLIC_ID + 1).into()); @@ -1650,25 +1689,41 @@ mod benchmarking { let caller: T::AccountId = whitelisted_caller(); Registrar::::swap(parachain_origin.into(), parachain, parathread)?; - }: _(RawOrigin::Signed(caller.clone()), parathread, parachain) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), parathread, parachain); + next_scheduled_session::(); // Swapped! assert_eq!(paras::Pallet::::lifecycle(parachain), Some(ParaLifecycle::Parathread)); assert_eq!(paras::Pallet::::lifecycle(parathread), Some(ParaLifecycle::Parachain)); + + Ok(()) } - schedule_code_upgrade { - let b in MIN_CODE_SIZE .. MAX_CODE_SIZE; + #[benchmark] + fn schedule_code_upgrade( + b: Linear, + ) -> Result<(), BenchmarkError> { let new_code = ValidationCode(vec![0; b as usize]); let para_id = ParaId::from(1000); - }: _(RawOrigin::Root, para_id, new_code) - set_current_head { - let b in 1 .. MAX_HEAD_DATA_SIZE; + #[extrinsic_call] + _(RawOrigin::Root, para_id, new_code); + + Ok(()) + } + + #[benchmark] + fn set_current_head(b: Linear<1, MAX_HEAD_DATA_SIZE>) -> Result<(), BenchmarkError> { let new_head = HeadData(vec![0; b as usize]); let para_id = ParaId::from(1000); - }: _(RawOrigin::Root, para_id, new_head) + + #[extrinsic_call] + _(RawOrigin::Root, para_id, new_head); + + Ok(()) + } impl_benchmark_test_suite!( Registrar,