From 75b074174ffe81cb1cacbc612a8dda9a1e1ad8ba Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Wed, 4 May 2022 17:28:22 +0100 Subject: [PATCH 01/11] remove para lock check for now --- runtime/common/src/paras_registrar.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 59806e0cf639..4b34c414be96 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -255,7 +255,7 @@ pub mod pallet { /// The caller must be Root, the `para` owner, or the `para` itself. The para must be a parathread. #[pallet::weight(::WeightInfo::deregister())] pub fn deregister(origin: OriginFor, id: ParaId) -> DispatchResult { - Self::ensure_root_para_or_owner(origin, id)?; + Self::ensure_root_para_or_owner(origin, id, false)?; Self::do_deregister(id) } @@ -272,7 +272,7 @@ pub mod pallet { /// and the auction deposit are switched. #[pallet::weight(::WeightInfo::swap())] pub fn swap(origin: OriginFor, id: ParaId, other: ParaId) -> DispatchResult { - Self::ensure_root_para_or_owner(origin, id)?; + Self::ensure_root_para_or_owner(origin, id, false)?; // If `id` and `other` is the same id, we treat this as a "clear" function, and exit // early, since swapping the same id would otherwise be a noop. @@ -454,16 +454,17 @@ impl Registrar for Pallet { impl Pallet { /// Ensure the origin is one of Root, the `para` owner, or the `para` itself. - /// If the origin is the `para` owner, the `para` must be unlocked. + /// If the origin is the `para` owner, and `check_lock` is true, the `para` must be unlocked. fn ensure_root_para_or_owner( origin: ::Origin, id: ParaId, + check_lock: bool, ) -> DispatchResult { ensure_signed(origin.clone()) .map_err(|e| e.into()) .and_then(|who| -> DispatchResult { let para_info = Paras::::get(id).ok_or(Error::::NotRegistered)?; - ensure!(!para_info.locked, Error::::ParaLocked); + ensure!(!(check_lock && para_info.locked), Error::::ParaLocked); ensure!(para_info.manager == who, Error::::NotOwner); Ok(()) }) @@ -1084,9 +1085,6 @@ mod tests { vec![1, 2, 3].into(), )); - // Owner can call swap - assert_ok!(Registrar::swap(Origin::signed(1), para_id, para_id + 1)); - // 2 session changes to fully onboard. run_to_session(2); assert_eq!(Parachains::lifecycle(para_id), Some(ParaLifecycle::Parathread)); @@ -1094,8 +1092,8 @@ mod tests { // Once they begin onboarding, we lock them in. assert_ok!(Registrar::make_parachain(para_id)); - // Owner cannot call swap anymore - assert_noop!(Registrar::swap(Origin::signed(1), para_id, para_id + 2), BadOrigin); + // Owner cannot pass origin check when checking lock + assert_noop!(Registrar::ensure_root_para_or_owner(Origin::signed(1), para_id, true), BadOrigin); }); } From 634ec659f5e9931f111ed8545e19ff31b33c9394 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Wed, 4 May 2022 17:49:09 +0100 Subject: [PATCH 02/11] fmt --- runtime/common/src/paras_registrar.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 4b34c414be96..cb2a6c0b8bd0 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -1093,7 +1093,10 @@ mod tests { assert_ok!(Registrar::make_parachain(para_id)); // Owner cannot pass origin check when checking lock - assert_noop!(Registrar::ensure_root_para_or_owner(Origin::signed(1), para_id, true), BadOrigin); + assert_noop!( + Registrar::ensure_root_para_or_owner(Origin::signed(1), para_id, true), + BadOrigin + ); }); } From f494ab67c82c615bac8bd1e5d152c4f63b9a9bcc Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 5 May 2022 10:34:04 +0100 Subject: [PATCH 03/11] manual para lock --- runtime/common/src/crowdloan/mod.rs | 2 - runtime/common/src/paras_registrar.rs | 72 ++++++++++++++++----------- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/runtime/common/src/crowdloan/mod.rs b/runtime/common/src/crowdloan/mod.rs index ea4d3026bad3..99d505898037 100644 --- a/runtime/common/src/crowdloan/mod.rs +++ b/runtime/common/src/crowdloan/mod.rs @@ -434,8 +434,6 @@ pub mod pallet { ); NextFundIndex::::put(new_fund_index); - // Add a lock to the para so that the configuration cannot be changed. - T::Registrar::apply_lock(index); Self::deposit_event(Event::::Created(index)); Ok(()) diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index cb2a6c0b8bd0..246d74c688d8 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -255,7 +255,7 @@ pub mod pallet { /// The caller must be Root, the `para` owner, or the `para` itself. The para must be a parathread. #[pallet::weight(::WeightInfo::deregister())] pub fn deregister(origin: OriginFor, id: ParaId) -> DispatchResult { - Self::ensure_root_para_or_owner(origin, id, false)?; + Self::ensure_root_para_or_owner(origin, id)?; Self::do_deregister(id) } @@ -272,7 +272,7 @@ pub mod pallet { /// and the auction deposit are switched. #[pallet::weight(::WeightInfo::swap())] pub fn swap(origin: OriginFor, id: ParaId, other: ParaId) -> DispatchResult { - Self::ensure_root_para_or_owner(origin, id, false)?; + Self::ensure_root_para_or_owner(origin, id)?; // If `id` and `other` is the same id, we treat this as a "clear" function, and exit // early, since swapping the same id would otherwise be a noop. @@ -318,11 +318,11 @@ pub mod pallet { /// Remove a manager lock from a para. This will allow the manager of a /// previously locked para to deregister or swap a para without using governance. /// - /// Can only be called by the Root origin. + /// Can only be called by the Root origin or the parachain. #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] - pub fn force_remove_lock(origin: OriginFor, para: ParaId) -> DispatchResult { - ensure_root(origin)?; - Self::remove_lock(para); + pub fn remove_lock(origin: OriginFor, para: ParaId) -> DispatchResult { + Self::ensure_root_or_para(origin, para)?; + ::remove_lock(para); Ok(()) } @@ -348,6 +348,17 @@ pub mod pallet { NextFreeParaId::::set(id + 1); Ok(()) } + + /// Add a manager lock from a para. This will prevent the manager of a + /// para to deregister or swap a para. + /// + /// Can only be called by the owner, Root, or the parachain. + #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] + pub fn add_lock(origin: OriginFor, para: ParaId) -> DispatchResult { + Self::ensure_root_para_or_owner(origin, para)?; + ::apply_lock(para); + Ok(()) + } } } @@ -379,7 +390,7 @@ impl Registrar for Pallet { Paras::::mutate(id, |x| x.as_mut().map(|mut info| info.locked = true)); } - // Apply a lock to the parachain. + // Remove a lock from the parachain. fn remove_lock(id: ParaId) { Paras::::mutate(id, |x| x.as_mut().map(|mut info| info.locked = false)); } @@ -411,9 +422,6 @@ impl Registrar for Pallet { ); runtime_parachains::schedule_parathread_upgrade::(id) .map_err(|_| Error::::CannotUpgrade)?; - // Once a para has upgraded to a parachain, it can no longer be managed by the owner. - // Intentionally, the flag stays with the para even after downgrade. - Self::apply_lock(id); Ok(()) } @@ -458,26 +466,30 @@ impl Pallet { fn ensure_root_para_or_owner( origin: ::Origin, id: ParaId, - check_lock: bool, ) -> DispatchResult { ensure_signed(origin.clone()) .map_err(|e| e.into()) .and_then(|who| -> DispatchResult { let para_info = Paras::::get(id).ok_or(Error::::NotRegistered)?; - ensure!(!(check_lock && para_info.locked), Error::::ParaLocked); + ensure!(!para_info.locked, Error::::ParaLocked); ensure!(para_info.manager == who, Error::::NotOwner); Ok(()) }) - .or_else(|_| -> DispatchResult { - // Else check if para origin... - let caller_id = ensure_parachain(::Origin::from(origin.clone()))?; - ensure!(caller_id == id, Error::::NotOwner); - Ok(()) - }) - .or_else(|_| -> DispatchResult { - // Check if root... - ensure_root(origin.clone()).map_err(|e| e.into()) - }) + .or_else(|_| -> DispatchResult { Self::ensure_root_or_para(origin, id) }) + } + + fn ensure_root_or_para( + origin: ::Origin, + id: ParaId, + ) -> DispatchResult { + if let Ok(caller_id) = ensure_parachain(::Origin::from(origin.clone())) { + // Check if matching para id... + ensure!(caller_id == id, Error::::NotOwner); + } else { + // Check if root... + ensure_root(origin.clone())?; + } + Ok(()) } fn do_reserve( @@ -1085,18 +1097,20 @@ mod tests { vec![1, 2, 3].into(), )); - // 2 session changes to fully onboard. - run_to_session(2); - assert_eq!(Parachains::lifecycle(para_id), Some(ParaLifecycle::Parathread)); - + assert_noop!(Registrar::add_lock(Origin::signed(2), para_id), BadOrigin); // Once they begin onboarding, we lock them in. - assert_ok!(Registrar::make_parachain(para_id)); - + assert_ok!(Registrar::add_lock(Origin::signed(1), para_id)); // Owner cannot pass origin check when checking lock assert_noop!( - Registrar::ensure_root_para_or_owner(Origin::signed(1), para_id, true), + Registrar::ensure_root_para_or_owner(Origin::signed(1), para_id), BadOrigin ); + // Owner cannot remove lock. + assert_noop!(Registrar::remove_lock(Origin::signed(1), para_id), BadOrigin); + // Para can. + assert_ok!(Registrar::remove_lock(para_origin(para_id), para_id)); + // Owner can pass origin check again + assert_ok!(Registrar::ensure_root_para_or_owner(Origin::signed(1), para_id)); }); } From 229c6dcdb27a3ac97602adeca6210b4df40fd571 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 5 May 2022 11:31:51 +0100 Subject: [PATCH 04/11] expose schedule_code_upgrade and set_current_head --- runtime/parachains/src/lib.rs | 14 ++++++++++++- runtime/parachains/src/paras/mod.rs | 32 ++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/runtime/parachains/src/lib.rs b/runtime/parachains/src/lib.rs index 2005861a6c4b..b6dc024aab35 100644 --- a/runtime/parachains/src/lib.rs +++ b/runtime/parachains/src/lib.rs @@ -50,7 +50,8 @@ mod mock; pub use origin::{ensure_parachain, Origin}; pub use paras::ParaLifecycle; -use primitives::v2::Id as ParaId; +use primitives::v2::{HeadData, Id as ParaId, ValidationCode}; +use sp_runtime::DispatchResult; /// Schedule a para to be initialized at the start of the next session with the given genesis data. /// @@ -78,3 +79,14 @@ pub fn schedule_parathread_upgrade(id: ParaId) -> Result<(), ( pub fn schedule_parachain_downgrade(id: ParaId) -> Result<(), ()> { paras::Pallet::::schedule_parachain_downgrade(id).map_err(|_| ()) } + +pub fn schedule_code_upgrade( + id: ParaId, + new_code: ValidationCode, +) -> DispatchResult { + paras::Pallet::::schedule_code_upgrade_external(id, new_code) +} + +pub fn set_current_head(id: ParaId, new_head: HeadData) { + paras::Pallet::::set_current_head(id, new_head) +} diff --git a/runtime/parachains/src/paras/mod.rs b/runtime/parachains/src/paras/mod.rs index 3c5b82479395..d2dd00adf885 100644 --- a/runtime/parachains/src/paras/mod.rs +++ b/runtime/parachains/src/paras/mod.rs @@ -118,7 +118,7 @@ use primitives::v2::{ use scale_info::TypeInfo; use sp_core::RuntimeDebug; use sp_runtime::{ - traits::{AppVerify, One}, + traits::{AppVerify, One, Saturating}, DispatchResult, SaturatedConversion, }; use sp_std::{cmp, mem, prelude::*}; @@ -535,6 +535,8 @@ pub mod pallet { /// The PVF pre-checking statement cannot be included since the PVF pre-checking mechanism /// is disabled. PvfCheckDisabled, + /// Parachain cannot currently schedule a code upgrade. + CannotUpgradeCode, } /// All currently active PVF pre-checking votes. @@ -752,8 +754,7 @@ pub mod pallet { new_head: HeadData, ) -> DispatchResult { ensure_root(origin)?; - ::Heads::insert(¶, new_head); - Self::deposit_event(Event::CurrentHeadUpdated(para)); + Self::set_current_head(para, new_head); Ok(()) } @@ -1055,6 +1056,31 @@ const INVALID_TX_DOUBLE_VOTE: u8 = 3; const INVALID_TX_PVF_CHECK_DISABLED: u8 = 4; impl Pallet { + /// This is a call to schedule code upgrades for parachains which is safe to be called + /// outside of this module. That means this function does all checks necessary to ensure + /// that some external code is allowed to trigger a code upgrade. We do not do auth checks, + /// that should be handled by whomever calls this function. + pub(crate) fn schedule_code_upgrade_external( + id: ParaId, + new_code: ValidationCode, + ) -> DispatchResult { + // Check that we can schedule an upgrade at all. + ensure!(Self::can_upgrade_validation_code(id), Error::::CannotUpgradeCode); + let config = configuration::Pallet::::config(); + let current_block = frame_system::Pallet::::block_number(); + // Schedule the upgrade with a delay just like if a parachain triggered the upgrade. + let upgrade_block = current_block.saturating_add(config.validation_upgrade_delay); + Self::schedule_code_upgrade(id, new_code, upgrade_block, &config); + Self::deposit_event(Event::CodeUpgradeScheduled(id)); + Ok(()) + } + + /// Set the current head of a parachain. + pub(crate) fn set_current_head(para: ParaId, new_head: HeadData) { + ::Heads::insert(¶, new_head); + Self::deposit_event(Event::CurrentHeadUpdated(para)); + } + /// Called by the initializer to initialize the paras pallet. pub(crate) fn initializer_initialize(now: T::BlockNumber) -> Weight { let weight = Self::prune_old_code(now); From 4f223110388bd03700555915c43c2abbb12d0133 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 5 May 2022 11:53:01 +0100 Subject: [PATCH 05/11] extrinsics and benchmarks --- runtime/common/src/paras_registrar.rs | 51 ++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 246d74c688d8..5e72c792bead 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -60,6 +60,8 @@ pub trait WeightInfo { fn force_register() -> Weight; fn deregister() -> Weight; fn swap() -> Weight; + fn schedule_code_upgrade(b: u32) -> Weight; + fn set_current_head(b: u32) -> Weight; } pub struct TestWeightInfo; @@ -79,6 +81,12 @@ impl WeightInfo for TestWeightInfo { fn swap() -> Weight { 0 } + fn schedule_code_upgrade(_b: u32) -> Weight { + 0 + } + fn set_current_head(_b: u32) -> Weight { + 0 + } } #[frame_support::pallet] @@ -352,13 +360,41 @@ pub mod pallet { /// Add a manager lock from a para. This will prevent the manager of a /// para to deregister or swap a para. /// - /// Can only be called by the owner, Root, or the parachain. + /// Can be called by Root, the parachain, or the parachain manager if the parachain is unlocked. #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] pub fn add_lock(origin: OriginFor, para: ParaId) -> DispatchResult { Self::ensure_root_para_or_owner(origin, para)?; ::apply_lock(para); Ok(()) } + + /// Schedule a parachain upgrade. + /// + /// Can be called by Root, the parachain, or the parachain manager if the parachain is unlocked. + #[pallet::weight(::WeightInfo::schedule_code_upgrade(new_code.0.len() as u32))] + pub fn schedule_code_upgrade( + origin: OriginFor, + para: ParaId, + new_code: ValidationCode, + ) -> DispatchResult { + Self::ensure_root_para_or_owner(origin, para)?; + runtime_parachains::schedule_code_upgrade::(para, new_code)?; + Ok(()) + } + + /// Set the parachain's current head. + /// + /// Can be called by Root, the parachain, or the parachain manager if the parachain is unlocked. + #[pallet::weight(::WeightInfo::set_current_head(new_head.0.len() as u32))] + pub fn set_current_head( + origin: OriginFor, + para: ParaId, + new_head: HeadData, + ) -> DispatchResult { + Self::ensure_root_para_or_owner(origin, para)?; + runtime_parachains::set_current_head::(para, new_head); + Ok(()) + } } } @@ -1236,6 +1272,7 @@ mod benchmarking { use crate::traits::Registrar as RegistrarT; use frame_support::assert_ok; use frame_system::RawOrigin; + use primitives::v2::{MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE}; use runtime_parachains::{paras, shared, Origin as ParaOrigin}; use sp_runtime::traits::Bounded; @@ -1352,6 +1389,18 @@ mod benchmarking { assert_eq!(paras::Pallet::::lifecycle(parathread), Some(ParaLifecycle::Parachain)); } + schedule_code_upgrade { + let b in 1 .. MAX_CODE_SIZE; + 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; + let new_head = HeadData(vec![0; b as usize]); + let para_id = ParaId::from(1000); + }: _(RawOrigin::Root, para_id, new_head) + impl_benchmark_test_suite!( Registrar, crate::integration_tests::new_test_ext(), From d4743edf40d7984dd11b9ea58ccca657d4042a1a Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 5 May 2022 11:54:05 +0100 Subject: [PATCH 06/11] use zero --- runtime/common/src/paras_registrar.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 5e72c792bead..672e99ac3db9 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -37,7 +37,7 @@ pub use pallet::*; use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; use sp_runtime::{ - traits::{CheckedSub, Saturating}, + traits::{CheckedSub, Saturating, Zero}, RuntimeDebug, }; @@ -67,25 +67,25 @@ pub trait WeightInfo { pub struct TestWeightInfo; impl WeightInfo for TestWeightInfo { fn reserve() -> Weight { - 0 + Weight::zero() } fn register() -> Weight { - 0 + Weight::zero() } fn force_register() -> Weight { - 0 + Weight::zero() } fn deregister() -> Weight { - 0 + Weight::zero() } fn swap() -> Weight { - 0 + Weight::zero() } fn schedule_code_upgrade(_b: u32) -> Weight { - 0 + Weight::zero() } fn set_current_head(_b: u32) -> Weight { - 0 + Weight::zero() } } From 95bcb3e27a4b1f7d9b982e9bcde8fb3193f2ffc0 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 5 May 2022 11:57:43 +0100 Subject: [PATCH 07/11] add weights --- bridges/bin/rialto/runtime/src/parachains.rs | 18 +++++++++----- .../weights/runtime_common_paras_registrar.rs | 24 +++++++++++++++++++ .../weights/runtime_common_paras_registrar.rs | 24 +++++++++++++++++++ .../weights/runtime_common_paras_registrar.rs | 24 +++++++++++++++++++ .../weights/runtime_common_paras_registrar.rs | 24 +++++++++++++++++++ 5 files changed, 108 insertions(+), 6 deletions(-) diff --git a/bridges/bin/rialto/runtime/src/parachains.rs b/bridges/bin/rialto/runtime/src/parachains.rs index 20a9aeb28c0d..93503111de63 100644 --- a/bridges/bin/rialto/runtime/src/parachains.rs +++ b/bridges/bin/rialto/runtime/src/parachains.rs @@ -32,7 +32,7 @@ use polkadot_runtime_parachains::{ paras_inherent as parachains_paras_inherent, scheduler as parachains_scheduler, session_info as parachains_session_info, shared as parachains_shared, ump as parachains_ump, }; -use sp_runtime::transaction_validity::TransactionPriority; +use sp_runtime::{transaction_validity::TransactionPriority, traits::Zero}; impl frame_system::offchain::SendTransactionTypes for Runtime where @@ -148,19 +148,25 @@ pub struct ZeroWeights; impl polkadot_runtime_common::paras_registrar::WeightInfo for ZeroWeights { fn reserve() -> Weight { - 0 + Weight::zero() } fn register() -> Weight { - 0 + Weight::zero() } fn force_register() -> Weight { - 0 + Weight::zero() } fn deregister() -> Weight { - 0 + Weight::zero() } fn swap() -> Weight { - 0 + Weight::zero() + } + fn schedule_code_upgrade(_b: u32) -> Weight { + Weight::zero() + } + fn set_current_head(_b: u32) -> Weight { + Weight::zero() } } diff --git a/runtime/kusama/src/weights/runtime_common_paras_registrar.rs b/runtime/kusama/src/weights/runtime_common_paras_registrar.rs index 7e1afed03669..f82c776c1c0c 100644 --- a/runtime/kusama/src/weights/runtime_common_paras_registrar.rs +++ b/runtime/kusama/src/weights/runtime_common_paras_registrar.rs @@ -103,4 +103,28 @@ impl runtime_common::paras_registrar::WeightInfo for We .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } + // Storage: Paras FutureCodeHash (r:1 w:1) + // Storage: Paras CurrentCodeHash (r:1 w:0) + // Storage: Paras UpgradeCooldowns (r:1 w:1) + // Storage: Paras PvfActiveVoteMap (r:1 w:0) + // Storage: Paras CodeByHash (r:1 w:1) + // Storage: Paras UpcomingUpgrades (r:1 w:1) + // Storage: System Digest (r:1 w:1) + // Storage: Paras CodeByHashRefs (r:1 w:1) + // Storage: Paras FutureCodeUpgrades (r:0 w:1) + // Storage: Paras UpgradeRestrictionSignal (r:0 w:1) + fn schedule_code_upgrade(b: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 0 + .saturating_add((3_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + } + // Storage: Paras Heads (r:0 w:1) + fn set_current_head(b: u32, ) -> Weight { + (5_494_000 as Weight) + // Standard Error: 0 + .saturating_add((1_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } } diff --git a/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs b/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs index 0d2fe1c5a34e..d942c2a3b8d4 100644 --- a/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs +++ b/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs @@ -105,4 +105,28 @@ impl runtime_common::paras_registrar::WeightInfo for We .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } + // Storage: Paras FutureCodeHash (r:1 w:1) + // Storage: Paras CurrentCodeHash (r:1 w:0) + // Storage: Paras UpgradeCooldowns (r:1 w:1) + // Storage: Paras PvfActiveVoteMap (r:1 w:0) + // Storage: Paras CodeByHash (r:1 w:1) + // Storage: Paras UpcomingUpgrades (r:1 w:1) + // Storage: System Digest (r:1 w:1) + // Storage: Paras CodeByHashRefs (r:1 w:1) + // Storage: Paras FutureCodeUpgrades (r:0 w:1) + // Storage: Paras UpgradeRestrictionSignal (r:0 w:1) + fn schedule_code_upgrade(b: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 0 + .saturating_add((3_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + } + // Storage: Paras Heads (r:0 w:1) + fn set_current_head(b: u32, ) -> Weight { + (5_494_000 as Weight) + // Standard Error: 0 + .saturating_add((1_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } } diff --git a/runtime/rococo/src/weights/runtime_common_paras_registrar.rs b/runtime/rococo/src/weights/runtime_common_paras_registrar.rs index 3a726f6f403b..b7689cd32976 100644 --- a/runtime/rococo/src/weights/runtime_common_paras_registrar.rs +++ b/runtime/rococo/src/weights/runtime_common_paras_registrar.rs @@ -105,4 +105,28 @@ impl runtime_common::paras_registrar::WeightInfo for We .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } + // Storage: Paras FutureCodeHash (r:1 w:1) + // Storage: Paras CurrentCodeHash (r:1 w:0) + // Storage: Paras UpgradeCooldowns (r:1 w:1) + // Storage: Paras PvfActiveVoteMap (r:1 w:0) + // Storage: Paras CodeByHash (r:1 w:1) + // Storage: Paras UpcomingUpgrades (r:1 w:1) + // Storage: System Digest (r:1 w:1) + // Storage: Paras CodeByHashRefs (r:1 w:1) + // Storage: Paras FutureCodeUpgrades (r:0 w:1) + // Storage: Paras UpgradeRestrictionSignal (r:0 w:1) + fn schedule_code_upgrade(b: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 0 + .saturating_add((3_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + } + // Storage: Paras Heads (r:0 w:1) + fn set_current_head(b: u32, ) -> Weight { + (5_494_000 as Weight) + // Standard Error: 0 + .saturating_add((1_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } } diff --git a/runtime/westend/src/weights/runtime_common_paras_registrar.rs b/runtime/westend/src/weights/runtime_common_paras_registrar.rs index 04e159856c27..e5004d1dd1d1 100644 --- a/runtime/westend/src/weights/runtime_common_paras_registrar.rs +++ b/runtime/westend/src/weights/runtime_common_paras_registrar.rs @@ -103,4 +103,28 @@ impl runtime_common::paras_registrar::WeightInfo for We .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } + // Storage: Paras FutureCodeHash (r:1 w:1) + // Storage: Paras CurrentCodeHash (r:1 w:0) + // Storage: Paras UpgradeCooldowns (r:1 w:1) + // Storage: Paras PvfActiveVoteMap (r:1 w:0) + // Storage: Paras CodeByHash (r:1 w:1) + // Storage: Paras UpcomingUpgrades (r:1 w:1) + // Storage: System Digest (r:1 w:1) + // Storage: Paras CodeByHashRefs (r:1 w:1) + // Storage: Paras FutureCodeUpgrades (r:0 w:1) + // Storage: Paras UpgradeRestrictionSignal (r:0 w:1) + fn schedule_code_upgrade(b: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 0 + .saturating_add((3_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + } + // Storage: Paras Heads (r:0 w:1) + fn set_current_head(b: u32, ) -> Weight { + (5_494_000 as Weight) + // Standard Error: 0 + .saturating_add((1_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } } From e76ff03bab6f8173fd197d08ac3351d486d08426 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 5 May 2022 12:08:43 +0100 Subject: [PATCH 08/11] fix variable name --- runtime/kusama/src/weights/runtime_common_paras_registrar.rs | 4 ++-- .../polkadot/src/weights/runtime_common_paras_registrar.rs | 4 ++-- runtime/rococo/src/weights/runtime_common_paras_registrar.rs | 4 ++-- runtime/westend/src/weights/runtime_common_paras_registrar.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime/kusama/src/weights/runtime_common_paras_registrar.rs b/runtime/kusama/src/weights/runtime_common_paras_registrar.rs index f82c776c1c0c..ccff94caa210 100644 --- a/runtime/kusama/src/weights/runtime_common_paras_registrar.rs +++ b/runtime/kusama/src/weights/runtime_common_paras_registrar.rs @@ -116,7 +116,7 @@ impl runtime_common::paras_registrar::WeightInfo for We fn schedule_code_upgrade(b: u32, ) -> Weight { (0 as Weight) // Standard Error: 0 - .saturating_add((3_000 as Weight).saturating_mul(c as Weight)) + .saturating_add((3_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } @@ -124,7 +124,7 @@ impl runtime_common::paras_registrar::WeightInfo for We fn set_current_head(b: u32, ) -> Weight { (5_494_000 as Weight) // Standard Error: 0 - .saturating_add((1_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } diff --git a/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs b/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs index d942c2a3b8d4..ebedea371fa5 100644 --- a/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs +++ b/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs @@ -118,7 +118,7 @@ impl runtime_common::paras_registrar::WeightInfo for We fn schedule_code_upgrade(b: u32, ) -> Weight { (0 as Weight) // Standard Error: 0 - .saturating_add((3_000 as Weight).saturating_mul(c as Weight)) + .saturating_add((3_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } @@ -126,7 +126,7 @@ impl runtime_common::paras_registrar::WeightInfo for We fn set_current_head(b: u32, ) -> Weight { (5_494_000 as Weight) // Standard Error: 0 - .saturating_add((1_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } diff --git a/runtime/rococo/src/weights/runtime_common_paras_registrar.rs b/runtime/rococo/src/weights/runtime_common_paras_registrar.rs index b7689cd32976..672bda385ad1 100644 --- a/runtime/rococo/src/weights/runtime_common_paras_registrar.rs +++ b/runtime/rococo/src/weights/runtime_common_paras_registrar.rs @@ -118,7 +118,7 @@ impl runtime_common::paras_registrar::WeightInfo for We fn schedule_code_upgrade(b: u32, ) -> Weight { (0 as Weight) // Standard Error: 0 - .saturating_add((3_000 as Weight).saturating_mul(c as Weight)) + .saturating_add((3_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } @@ -126,7 +126,7 @@ impl runtime_common::paras_registrar::WeightInfo for We fn set_current_head(b: u32, ) -> Weight { (5_494_000 as Weight) // Standard Error: 0 - .saturating_add((1_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } diff --git a/runtime/westend/src/weights/runtime_common_paras_registrar.rs b/runtime/westend/src/weights/runtime_common_paras_registrar.rs index e5004d1dd1d1..a747fd15d34e 100644 --- a/runtime/westend/src/weights/runtime_common_paras_registrar.rs +++ b/runtime/westend/src/weights/runtime_common_paras_registrar.rs @@ -116,7 +116,7 @@ impl runtime_common::paras_registrar::WeightInfo for We fn schedule_code_upgrade(b: u32, ) -> Weight { (0 as Weight) // Standard Error: 0 - .saturating_add((3_000 as Weight).saturating_mul(c as Weight)) + .saturating_add((3_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } @@ -124,7 +124,7 @@ impl runtime_common::paras_registrar::WeightInfo for We fn set_current_head(b: u32, ) -> Weight { (5_494_000 as Weight) // Standard Error: 0 - .saturating_add((1_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } From 1ca7b21df5b35d17de08dd0420fac8011a69c077 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Sat, 8 Oct 2022 01:25:53 -0400 Subject: [PATCH 09/11] add and fix comments --- runtime/common/src/paras_registrar.rs | 3 ++- runtime/parachains/src/lib.rs | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index c5860aa5a196..d522c6bc086e 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -498,7 +498,7 @@ impl Registrar for Pallet { impl Pallet { /// Ensure the origin is one of Root, the `para` owner, or the `para` itself. - /// If the origin is the `para` owner, and `check_lock` is true, the `para` must be unlocked. + /// If the origin is the `para` owner, the `para` must be unlocked. fn ensure_root_para_or_owner( origin: ::RuntimeOrigin, id: ParaId, @@ -514,6 +514,7 @@ impl Pallet { .or_else(|_| -> DispatchResult { Self::ensure_root_or_para(origin, id) }) } + /// Ensure the origin is one of Root or the `para` itself. fn ensure_root_or_para( origin: ::RuntimeOrigin, id: ParaId, diff --git a/runtime/parachains/src/lib.rs b/runtime/parachains/src/lib.rs index b6dc024aab35..3d73a4049ed4 100644 --- a/runtime/parachains/src/lib.rs +++ b/runtime/parachains/src/lib.rs @@ -80,6 +80,9 @@ pub fn schedule_parachain_downgrade(id: ParaId) -> Result<(), paras::Pallet::::schedule_parachain_downgrade(id).map_err(|_| ()) } +/// Schedules a validation code upgrade to a parachain with the given id. +/// +/// This simply calls [`crate::paras::Pallet::schedule_code_upgrade_external`]. pub fn schedule_code_upgrade( id: ParaId, new_code: ValidationCode, @@ -87,6 +90,9 @@ pub fn schedule_code_upgrade( paras::Pallet::::schedule_code_upgrade_external(id, new_code) } +/// Sets the current parachain head with the given id. +/// +/// This simply calls [`crate::paras::Pallet::set_current_head`]. pub fn set_current_head(id: ParaId, new_head: HeadData) { paras::Pallet::::set_current_head(id, new_head) } From 53e047c5db855785d76ac7c4029720bb2f4a9623 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Sat, 8 Oct 2022 02:37:11 -0400 Subject: [PATCH 10/11] fix weights --- .../src/weights/runtime_common_paras_registrar.rs | 14 +++++++------- .../src/weights/runtime_common_paras_registrar.rs | 14 +++++++------- .../src/weights/runtime_common_paras_registrar.rs | 14 +++++++------- .../src/weights/runtime_common_paras_registrar.rs | 14 +++++++------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/runtime/kusama/src/weights/runtime_common_paras_registrar.rs b/runtime/kusama/src/weights/runtime_common_paras_registrar.rs index 651e80e54ae1..8b9f554fe3e6 100644 --- a/runtime/kusama/src/weights/runtime_common_paras_registrar.rs +++ b/runtime/kusama/src/weights/runtime_common_paras_registrar.rs @@ -114,17 +114,17 @@ impl runtime_common::paras_registrar::WeightInfo for We // Storage: Paras FutureCodeUpgrades (r:0 w:1) // Storage: Paras UpgradeRestrictionSignal (r:0 w:1) fn schedule_code_upgrade(b: u32, ) -> Weight { - (0 as Weight) + Weight::from_ref_time(0 as u64) // Standard Error: 0 - .saturating_add((3_000 as Weight).saturating_mul(b as Weight)) - .saturating_add(T::DbWeight::get().reads(8 as Weight)) - .saturating_add(T::DbWeight::get().writes(8 as Weight)) + .saturating_add(Weight::from_ref_time(3_000 as u64).saturating_mul(b as u64)) + .saturating_add(T::DbWeight::get().reads(8 as u64)) + .saturating_add(T::DbWeight::get().writes(8 as u64)) } // Storage: Paras Heads (r:0 w:1) fn set_current_head(b: u32, ) -> Weight { - (5_494_000 as Weight) + Weight::from_ref_time(5_494_000 as u64) // Standard Error: 0 - .saturating_add((1_000 as Weight).saturating_mul(b as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(Weight::from_ref_time(1_000 as u64).saturating_mul(b as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) } } diff --git a/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs b/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs index addf7d90351b..89a1c628c503 100644 --- a/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs +++ b/runtime/polkadot/src/weights/runtime_common_paras_registrar.rs @@ -116,17 +116,17 @@ impl runtime_common::paras_registrar::WeightInfo for We // Storage: Paras FutureCodeUpgrades (r:0 w:1) // Storage: Paras UpgradeRestrictionSignal (r:0 w:1) fn schedule_code_upgrade(b: u32, ) -> Weight { - (0 as Weight) + Weight::from_ref_time(0 as u64) // Standard Error: 0 - .saturating_add((3_000 as Weight).saturating_mul(b as Weight)) - .saturating_add(T::DbWeight::get().reads(8 as Weight)) - .saturating_add(T::DbWeight::get().writes(8 as Weight)) + .saturating_add(Weight::from_ref_time(3_000 as u64).saturating_mul(b as u64)) + .saturating_add(T::DbWeight::get().reads(8 as u64)) + .saturating_add(T::DbWeight::get().writes(8 as u64)) } // Storage: Paras Heads (r:0 w:1) fn set_current_head(b: u32, ) -> Weight { - (5_494_000 as Weight) + Weight::from_ref_time(5_494_000 as u64) // Standard Error: 0 - .saturating_add((1_000 as Weight).saturating_mul(b as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(Weight::from_ref_time(1_000 as u64).saturating_mul(b as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) } } diff --git a/runtime/rococo/src/weights/runtime_common_paras_registrar.rs b/runtime/rococo/src/weights/runtime_common_paras_registrar.rs index 4a9023a2e7db..5afe490ae1ff 100644 --- a/runtime/rococo/src/weights/runtime_common_paras_registrar.rs +++ b/runtime/rococo/src/weights/runtime_common_paras_registrar.rs @@ -116,17 +116,17 @@ impl runtime_common::paras_registrar::WeightInfo for We // Storage: Paras FutureCodeUpgrades (r:0 w:1) // Storage: Paras UpgradeRestrictionSignal (r:0 w:1) fn schedule_code_upgrade(b: u32, ) -> Weight { - (0 as Weight) + Weight::from_ref_time(0 as u64) // Standard Error: 0 - .saturating_add((3_000 as Weight).saturating_mul(b as Weight)) - .saturating_add(T::DbWeight::get().reads(8 as Weight)) - .saturating_add(T::DbWeight::get().writes(8 as Weight)) + .saturating_add(Weight::from_ref_time(3_000 as u64).saturating_mul(b as u64)) + .saturating_add(T::DbWeight::get().reads(8 as u64)) + .saturating_add(T::DbWeight::get().writes(8 as u64)) } // Storage: Paras Heads (r:0 w:1) fn set_current_head(b: u32, ) -> Weight { - (5_494_000 as Weight) + Weight::from_ref_time(5_494_000 as u64) // Standard Error: 0 - .saturating_add((1_000 as Weight).saturating_mul(b as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(Weight::from_ref_time(1_000 as u64).saturating_mul(b as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) } } diff --git a/runtime/westend/src/weights/runtime_common_paras_registrar.rs b/runtime/westend/src/weights/runtime_common_paras_registrar.rs index f9050b6c4680..e52924381cd7 100644 --- a/runtime/westend/src/weights/runtime_common_paras_registrar.rs +++ b/runtime/westend/src/weights/runtime_common_paras_registrar.rs @@ -114,17 +114,17 @@ impl runtime_common::paras_registrar::WeightInfo for We // Storage: Paras FutureCodeUpgrades (r:0 w:1) // Storage: Paras UpgradeRestrictionSignal (r:0 w:1) fn schedule_code_upgrade(b: u32, ) -> Weight { - (0 as Weight) + Weight::from_ref_time(0 as u64) // Standard Error: 0 - .saturating_add((3_000 as Weight).saturating_mul(b as Weight)) - .saturating_add(T::DbWeight::get().reads(8 as Weight)) - .saturating_add(T::DbWeight::get().writes(8 as Weight)) + .saturating_add(Weight::from_ref_time(3_000 as u64).saturating_mul(b as u64)) + .saturating_add(T::DbWeight::get().reads(8 as u64)) + .saturating_add(T::DbWeight::get().writes(8 as u64)) } // Storage: Paras Heads (r:0 w:1) fn set_current_head(b: u32, ) -> Weight { - (5_494_000 as Weight) + Weight::from_ref_time(5_494_000 as u64) // Standard Error: 0 - .saturating_add((1_000 as Weight).saturating_mul(b as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(Weight::from_ref_time(1_000 as u64).saturating_mul(b as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) } } From ded84e9a047274939f53e30aea971584ab796822 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 10 Oct 2022 13:19:58 -0400 Subject: [PATCH 11/11] add back default lock --- runtime/common/src/crowdloan/mod.rs | 2 ++ runtime/common/src/paras_registrar.rs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/runtime/common/src/crowdloan/mod.rs b/runtime/common/src/crowdloan/mod.rs index f28f2de90af2..1f84af3f2ee9 100644 --- a/runtime/common/src/crowdloan/mod.rs +++ b/runtime/common/src/crowdloan/mod.rs @@ -434,6 +434,8 @@ pub mod pallet { ); NextFundIndex::::put(new_fund_index); + // Add a lock to the para so that the configuration cannot be changed. + T::Registrar::apply_lock(index); Self::deposit_event(Event::::Created { para_id: index }); Ok(()) diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index d522c6bc086e..7245cd92d304 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -458,6 +458,9 @@ impl Registrar for Pallet { ); runtime_parachains::schedule_parathread_upgrade::(id) .map_err(|_| Error::::CannotUpgrade)?; + // Once a para has upgraded to a parachain, it can no longer be managed by the owner. + // Intentionally, the flag stays with the para even after downgrade. + Self::apply_lock(id); Ok(()) }