RFC 14: Improve locking mechanism for parachains (#1290)

* rfc14

* Update polkadot/runtime/common/src/paras_registrar/mod.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update polkadot/runtime/common/src/paras_registrar/mod.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update polkadot/runtime/common/src/paras_registrar/mod.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* fmt

* fix

* Update polkadot/runtime/common/src/paras_registrar/migration.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

* 2224 is unlocked

* update migration list

* update comment

* use VersionedMigration

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Xiliang Chen
2023-09-06 21:09:07 +12:00
committed by GitHub
parent eaf380aaf5
commit cd71f7e9b1
18 changed files with 191 additions and 24 deletions
+1
View File
@@ -6,6 +6,7 @@ edition.workspace = true
license.workspace = true
[dependencies]
impl-trait-for-tuples = "0.2.2"
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] }
log = { version = "0.4.17", default-features = false }
+1
View File
@@ -214,6 +214,7 @@ impl crate::paras::Config for Test {
type UnsignedPriority = ParasUnsignedPriority;
type QueueFootprinter = ParaInclusion;
type NextSessionRotation = TestNextSessionRotation;
type OnNewHead = ();
}
impl crate::dmp::Config for Test {}
+24 -3
View File
@@ -481,6 +481,22 @@ impl<BlockNumber> PvfCheckActiveVoteState<BlockNumber> {
}
}
/// Runtime hook for when a parachain head is updated.
pub trait OnNewHead {
/// Called when a parachain head is updated.
/// Returns the weight consumed by this function.
fn on_new_head(id: ParaId, head: &HeadData) -> Weight;
}
#[impl_trait_for_tuples::impl_for_tuples(30)]
impl OnNewHead for Tuple {
fn on_new_head(id: ParaId, head: &HeadData) -> Weight {
let mut weight: Weight = Default::default();
for_tuples!( #( weight.saturating_accrue(Tuple::on_new_head(id, head)); )* );
weight
}
}
pub trait WeightInfo {
fn force_set_current_code(c: u32) -> Weight;
fn force_set_current_head(s: u32) -> Weight;
@@ -575,6 +591,9 @@ pub mod pallet {
/// be set to the `ParaInclusion` pallet.
type QueueFootprinter: QueueFootprinter<Origin = UmpQueueId>;
/// Runtime hook for when a parachain head is updated.
type OnNewHead: OnNewHead;
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}
@@ -1962,10 +1981,10 @@ impl<T: Config> Pallet<T> {
new_head: HeadData,
execution_context: BlockNumberFor<T>,
) -> Weight {
Heads::<T>::insert(&id, new_head);
Heads::<T>::insert(&id, &new_head);
MostRecentContext::<T>::insert(&id, execution_context);
if let Some(expected_at) = FutureCodeUpgrades::<T>::get(&id) {
let weight = if let Some(expected_at) = FutureCodeUpgrades::<T>::get(&id) {
if expected_at <= execution_context {
FutureCodeUpgrades::<T>::remove(&id);
UpgradeGoAheadSignal::<T>::remove(&id);
@@ -2005,7 +2024,9 @@ impl<T: Config> Pallet<T> {
// the `Abort` signal.
UpgradeGoAheadSignal::<T>::remove(&id);
T::DbWeight::get().reads_writes(1, 2)
}
};
weight.saturating_add(T::OnNewHead::on_new_head(id, &new_head))
}
/// Returns the list of PVFs (aka validation code) that require casting a vote by a validator in