Unverified Commit b583753a authored by ferrell-code's avatar ferrell-code Committed by GitHub
Browse files

paras.rs to FRAME V2 (#3403)

* to v2 macro

* line width

* fix mock

* actually compile moxk

* compile tests

* add hooks

* origin back in mocks

* assimilate_storage

* add generic

* maybe mock compiles now

* origin between parachain and system causing problem

* change origin

* type alias as origin

* keep origin

* add aliases to tests

* remove unnecessary imports

* Parachain -> Paras

* paras test

* nvm

* use genesis build in mock
parent a78434a6
Pipeline #145608 passed with stages
in 35 minutes and 5 seconds
......@@ -975,7 +975,6 @@ fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::
},
paras: rococo_runtime::ParasConfig {
paras: vec![],
_phdata: Default::default(),
},
hrmp: Default::default(),
parachains_configuration: rococo_runtime::ParachainsConfigurationConfig {
......@@ -1516,7 +1515,6 @@ pub fn rococo_testnet_genesis(
hrmp: Default::default(),
paras: rococo_runtime::ParasConfig {
paras: vec![],
_phdata: Default::default(),
},
bridge_rococo_grandpa: rococo_runtime::BridgeRococoGrandpaConfig {
owner: Some(root_key.clone()),
......
......@@ -65,7 +65,7 @@ frame_support::construct_runtime!(
// Parachains Runtime
Configuration: configuration::{Pallet, Call, Storage, Config<T>},
Paras: paras::{Pallet, Origin, Call, Storage, Event, Config<T>},
Paras: paras::{Pallet, Origin, Call, Storage, Event, Config},
// Para Onboarding Pallets
Registrar: paras_registrar::{Pallet, Call, Storage, Event<T>},
......
......@@ -572,7 +572,7 @@ mod tests {
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
ParachainsConfiguration: configuration::{Pallet, Call, Storage, Config<T>},
Parachains: paras::{Pallet, Origin, Call, Storage, Config<T>, Event},
Parachains: paras::{Pallet, Origin, Call, Storage, Config, Event},
Registrar: paras_registrar::{Pallet, Call, Storage, Event<T>},
}
);
......
......@@ -1486,7 +1486,7 @@ construct_runtime! {
ParasInclusion: parachains_inclusion::{Pallet, Call, Storage, Event<T>} = 53,
ParasInherent: parachains_paras_inherent::{Pallet, Call, Storage, Inherent} = 54,
ParasScheduler: parachains_scheduler::{Pallet, Call, Storage} = 55,
Paras: parachains_paras::{Pallet, Call, Storage, Event, Config<T>} = 56,
Paras: parachains_paras::{Pallet, Call, Storage, Event, Config} = 56,
ParasInitializer: parachains_initializer::{Pallet, Call, Storage} = 57,
ParasDmp: parachains_dmp::{Pallet, Call, Storage} = 58,
ParasUmp: parachains_ump::{Pallet, Call, Storage, Event} = 59,
......
......@@ -573,8 +573,8 @@ impl<T: Config> Module<T> {
);
if request.confirmed {
if <paras::Module<T>>::is_valid_para(channel_id.sender)
&& <paras::Module<T>>::is_valid_para(channel_id.recipient)
if <paras::Pallet<T>>::is_valid_para(channel_id.sender)
&& <paras::Pallet<T>>::is_valid_para(channel_id.recipient)
{
<Self as Store>::HrmpChannels::insert(
&channel_id,
......@@ -972,7 +972,7 @@ impl<T: Config> Module<T> {
) -> DispatchResult {
ensure!(origin != recipient, Error::<T>::OpenHrmpChannelToSelf);
ensure!(
<paras::Module<T>>::is_valid_para(recipient),
<paras::Pallet<T>>::is_valid_para(recipient),
Error::<T>::OpenHrmpChannelInvalidRecipient,
);
......@@ -1010,7 +1010,7 @@ impl<T: Config> Module<T> {
let egress_cnt =
<Self as Store>::HrmpEgressChannelsIndex::decode_len(&origin).unwrap_or(0) as u32;
let open_req_cnt = <Self as Store>::HrmpOpenChannelRequestCount::get(&origin);
let channel_num_limit = if <paras::Module<T>>::is_parathread(origin) {
let channel_num_limit = if <paras::Pallet<T>>::is_parathread(origin) {
config.hrmp_max_parathread_outbound_channels
} else {
config.hrmp_max_parachain_outbound_channels
......@@ -1080,7 +1080,7 @@ impl<T: Config> Module<T> {
// check if by accepting this open channel request, this parachain would exceed the
// number of inbound channels.
let config = <configuration::Module<T>>::config();
let channel_num_limit = if <paras::Module<T>>::is_parathread(origin) {
let channel_num_limit = if <paras::Pallet<T>>::is_parathread(origin) {
config.hrmp_max_parathread_inbound_channels
} else {
config.hrmp_max_parachain_inbound_channels
......
......@@ -453,7 +453,7 @@ impl<T: Config> Module<T> {
);
let validation_code_hash =
<paras::Module<T>>::validation_code_hash_at(para_id, now, None)
<paras::Pallet<T>>::validation_code_hash_at(para_id, now, None)
// A candidate for a parachain without current validation code is not scheduled.
.ok_or_else(|| Error::<T>::UnscheduledCandidate)?;
ensure!(
......@@ -679,7 +679,7 @@ impl<T: Config> Module<T> {
// initial weight is config read.
let mut weight = T::DbWeight::get().reads_writes(1, 0);
if let Some(new_code) = commitments.new_validation_code {
weight += <paras::Module<T>>::schedule_code_upgrade(
weight += <paras::Pallet<T>>::schedule_code_upgrade(
receipt.descriptor.para_id,
new_code,
relay_parent_number + config.validation_upgrade_delay,
......@@ -708,7 +708,7 @@ impl<T: Config> Module<T> {
Event::<T>::CandidateIncluded(plain, commitments.head_data.clone(), core_index, backing_group)
);
weight + <paras::Module<T>>::note_new_head(
weight + <paras::Pallet<T>>::note_new_head(
receipt.descriptor.para_id,
commitments.head_data,
relay_parent_number,
......@@ -869,7 +869,7 @@ impl<T: Config> CandidateCheckContext<T> {
// if any, the code upgrade attempt is allowed.
if let Some(new_validation_code) = new_validation_code {
let valid_upgrade_attempt = <paras::Module<T>>::last_code_upgrade(para_id, true)
let valid_upgrade_attempt = <paras::Pallet<T>>::last_code_upgrade(para_id, true)
.map_or(true, |last| {
last <= self.relay_parent_number
&& self.relay_parent_number.saturating_sub(last)
......
......@@ -131,7 +131,7 @@ decl_module! {
// - HRMP
let total_weight = configuration::Module::<T>::initializer_initialize(now) +
shared::Module::<T>::initializer_initialize(now) +
paras::Module::<T>::initializer_initialize(now) +
paras::Pallet::<T>::initializer_initialize(now) +
scheduler::Module::<T>::initializer_initialize(now) +
inclusion::Module::<T>::initializer_initialize(now) +
session_info::Module::<T>::initializer_initialize(now) +
......@@ -152,7 +152,7 @@ decl_module! {
session_info::Module::<T>::initializer_finalize();
inclusion::Module::<T>::initializer_finalize();
scheduler::Module::<T>::initializer_finalize();
paras::Module::<T>::initializer_finalize();
paras::Pallet::<T>::initializer_finalize();
shared::Module::<T>::initializer_finalize();
configuration::Module::<T>::initializer_finalize();
......@@ -224,7 +224,7 @@ impl<T: Config> Module<T> {
session_index,
};
let outgoing_paras = paras::Module::<T>::initializer_on_new_session(&notification);
let outgoing_paras = paras::Pallet::<T>::initializer_on_new_session(&notification);
scheduler::Module::<T>::initializer_on_new_session(&notification);
inclusion::Module::<T>::initializer_on_new_session(&notification);
session_info::Module::<T>::initializer_on_new_session(&notification);
......
......@@ -52,20 +52,20 @@ pub fn schedule_para_initialize<T: paras::Config>(
id: ParaId,
genesis: paras::ParaGenesisArgs,
) -> Result<(), ()> {
<paras::Module<T>>::schedule_para_initialize(id, genesis).map_err(|_| ())
<paras::Pallet<T>>::schedule_para_initialize(id, genesis).map_err(|_| ())
}
/// Schedule a para to be cleaned up at the start of the next session.
pub fn schedule_para_cleanup<T: paras::Config>(id: primitives::v1::Id) -> Result<(), ()> {
<paras::Module<T>>::schedule_para_cleanup(id).map_err(|_| ())
<paras::Pallet<T>>::schedule_para_cleanup(id).map_err(|_| ())
}
/// Schedule a parathread to be upgraded to a parachain.
pub fn schedule_parathread_upgrade<T: paras::Config>(id: ParaId) -> Result<(), ()> {
paras::Module::<T>::schedule_parathread_upgrade(id).map_err(|_| ())
paras::Pallet::<T>::schedule_parathread_upgrade(id).map_err(|_| ())
}
/// Schedule a parachain to be downgraded to a parathread.
pub fn schedule_parachain_downgrade<T: paras::Config>(id: ParaId) -> Result<(), ()> {
paras::Module::<T>::schedule_parachain_downgrade(id).map_err(|_| ())
paras::Pallet::<T>::schedule_parachain_downgrade(id).map_err(|_| ())
}
......@@ -23,6 +23,7 @@ use sp_runtime::traits::{
};
use primitives::v1::{AuthorityDiscoveryId, Balance, BlockNumber, Header, ValidatorIndex};
use frame_support::parameter_types;
use frame_support::traits::GenesisBuild;
use frame_support_test::TestRandomness;
use std::cell::RefCell;
use std::collections::HashMap;
......@@ -42,7 +43,7 @@ frame_support::construct_runtime!(
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Paras: paras::{Pallet, Origin, Call, Storage, Event, Config<T>},
Paras: paras::{Pallet, Origin, Call, Storage, Event, Config},
Configuration: configuration::{Pallet, Call, Storage, Config<T>},
Shared: shared::{Pallet, Call, Storage},
Inclusion: inclusion::{Pallet, Call, Storage, Event<T>},
......@@ -208,7 +209,7 @@ pub fn new_test_ext(state: MockGenesisConfig) -> TestExternalities {
let mut t = state.system.build_storage::<Test>().unwrap();
state.configuration.assimilate_storage(&mut t).unwrap();
state.paras.assimilate_storage(&mut t).unwrap();
GenesisBuild::<Test>::assimilate_storage(&state.paras, &mut t).unwrap();
t.into()
}
......@@ -217,5 +218,5 @@ pub fn new_test_ext(state: MockGenesisConfig) -> TestExternalities {
pub struct MockGenesisConfig {
pub system: frame_system::GenesisConfig,
pub configuration: crate::configuration::GenesisConfig<Test>,
pub paras: crate::paras::GenesisConfig<Test>,
pub paras: crate::paras::GenesisConfig,
}
......@@ -14,29 +14,23 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! The paras module is responsible for storing data on parachains and parathreads.
//! The paras pallet is responsible for storing data on parachains and parathreads.
//!
//! It tracks which paras are parachains, what their current head data is in
//! this fork of the relay chain, what their validation code is, and what their past and upcoming
//! validation code is.
//!
//! A para is not considered live until it is registered and activated in this module. Activation can
//! A para is not considered live until it is registered and activated in this pallet. Activation can
//! only occur at session boundaries.
use sp_std::prelude::*;
use sp_std::result;
#[cfg(feature = "std")]
use sp_std::marker::PhantomData;
use primitives::v1::{
Id as ParaId, ValidationCode, ValidationCodeHash, HeadData, SessionIndex, ConsensusLog,
};
use sp_runtime::{traits::One, DispatchResult, SaturatedConversion};
use frame_system::ensure_root;
use frame_support::{
decl_storage, decl_module, decl_error, decl_event, ensure,
traits::Get,
weights::Weight,
};
use frame_system::pallet_prelude::*;
use frame_support::pallet_prelude::*;
use parity_scale_codec::{Encode, Decode};
use crate::{configuration, shared, initializer::SessionChangeNotification};
use sp_core::RuntimeDebug;
......@@ -44,20 +38,9 @@ use sp_core::RuntimeDebug;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
pub use crate::Origin;
pub use crate::Origin as ParachainOrigin;
pub trait Config:
frame_system::Config +
configuration::Config +
shared::Config
{
/// The outer origin type.
type Origin: From<Origin>
+ From<<Self as frame_system::Config>::Origin>
+ Into<result::Result<Origin, <Self as Config>::Origin>>;
type Event: From<Event> + Into<<Self as frame_system::Config>::Event>;
}
pub use pallet::*;
// the two key times necessary to track for every code replacement.
#[derive(Default, Encode, Decode)]
......@@ -279,91 +262,45 @@ pub struct ParaGenesisArgs {
pub parachain: bool,
}
decl_storage! {
trait Store for Module<T: Config> as Paras {
/// All parachains. Ordered ascending by ParaId. Parathreads are not included.
Parachains get(fn parachains): Vec<ParaId>;
/// The current lifecycle of a all known Para IDs.
ParaLifecycles: map hasher(twox_64_concat) ParaId => Option<ParaLifecycle>;
/// The head-data of every registered para.
Heads get(fn para_head): map hasher(twox_64_concat) ParaId => Option<HeadData>;
/// The validation code hash of every live para.
///
/// Corresponding code can be retrieved with [`CodeByHash`].
CurrentCodeHash: map hasher(twox_64_concat) ParaId => Option<ValidationCodeHash>;
/// Actual past code hash, indicated by the para id as well as the block number at which it
/// became outdated.
///
/// Corresponding code can be retrieved with [`CodeByHash`].
PastCodeHash: map hasher(twox_64_concat) (ParaId, T::BlockNumber) => Option<ValidationCodeHash>;
/// Past code of parachains. The parachains themselves may not be registered anymore,
/// but we also keep their code on-chain for the same amount of time as outdated code
/// to keep it available for secondary checkers.
PastCodeMeta get(fn past_code_meta):
map hasher(twox_64_concat) ParaId => ParaPastCodeMeta<T::BlockNumber>;
/// Which paras have past code that needs pruning and the relay-chain block at which the code was replaced.
/// Note that this is the actual height of the included block, not the expected height at which the
/// code upgrade would be applied, although they may be equal.
/// This is to ensure the entire acceptance period is covered, not an offset acceptance period starting
/// from the time at which the parachain perceives a code upgrade as having occurred.
/// Multiple entries for a single para are permitted. Ordered ascending by block number.
PastCodePruning: Vec<(ParaId, T::BlockNumber)>;
/// The block number at which the planned code change is expected for a para.
/// The change will be applied after the first parablock for this ID included which executes
/// in the context of a relay chain block with a number >= `expected_at`.
FutureCodeUpgrades get(fn future_code_upgrade_at): map hasher(twox_64_concat) ParaId => Option<T::BlockNumber>;
/// The actual future code hash of a para.
///
/// Corresponding code can be retrieved with [`CodeByHash`].
FutureCodeHash: map hasher(twox_64_concat) ParaId => Option<ValidationCodeHash>;
/// The actions to perform during the start of a specific session index.
ActionsQueue get(fn actions_queue): map hasher(twox_64_concat) SessionIndex => Vec<ParaId>;
/// Upcoming paras instantiation arguments.
UpcomingParasGenesis: map hasher(twox_64_concat) ParaId => Option<ParaGenesisArgs>;
/// The number of reference on the validation code in [`CodeByHash`] storage.
CodeByHashRefs: map hasher(identity) ValidationCodeHash => u32;
/// Validation code stored by its hash.
///
/// This storage is consistent with [`FutureCodeHash`], [`CurrentCodeHash`] and
/// [`PastCodeHash`].
CodeByHash get(fn code_by_hash): map hasher(identity) ValidationCodeHash => Option<ValidationCode>;
}
add_extra_genesis {
config(paras): Vec<(ParaId, ParaGenesisArgs)>;
config(_phdata): PhantomData<T>;
build(build::<T>);
#[frame_support::pallet]
pub mod pallet {
use super::*;
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config:
frame_system::Config +
configuration::Config +
shared::Config
{
/// The outer origin type.
type Origin: From<Origin>
+ From<<Self as frame_system::Config>::Origin>
+ Into<result::Result<Origin, <Self as Config>::Origin>>;
type Event: From<Event> + IsType<<Self as frame_system::Config>::Event>;
}
}
#[cfg(feature = "std")]
fn build<T: Config>(config: &GenesisConfig<T>) {
let mut parachains: Vec<_> = config.paras
.iter()
.filter(|(_, args)| args.parachain)
.map(|&(ref id, _)| id)
.cloned()
.collect();
parachains.sort();
parachains.dedup();
Parachains::put(&parachains);
for (id, genesis_args) in &config.paras {
let code_hash = genesis_args.validation_code.hash();
<Module<T>>::increase_code_ref(&code_hash, &genesis_args.validation_code);
<Module<T> as Store>::CurrentCodeHash::insert(&id, &code_hash);
<Module<T> as Store>::Heads::insert(&id, &genesis_args.genesis_head);
if genesis_args.parachain {
ParaLifecycles::insert(&id, ParaLifecycle::Parachain);
} else {
ParaLifecycles::insert(&id, ParaLifecycle::Parathread);
}
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event {
/// Current code has been updated for a Para. \[para_id\]
CurrentCodeUpdated(ParaId),
/// Current head has been updated for a Para. \[para_id\]
CurrentHeadUpdated(ParaId),
/// A code upgrade has been scheduled for a Para. \[para_id\]
CodeUpgradeScheduled(ParaId),
/// A new head has been noted for a Para. \[para_id\]
NewHeadNoted(ParaId),
/// A para has been queued to execute pending actions. \[para_id\]
ActionQueued(ParaId, SessionIndex),
}
}
decl_error! {
pub enum Error for Module<T: Config> {
#[pallet::error]
pub enum Error<T> {
/// Para is not registered in our system.
NotRegistered,
/// Para cannot be onboarded because it is already tracked by our system.
......@@ -375,33 +312,146 @@ decl_error! {
/// Para cannot be downgraded to a parathread.
CannotDowngrade,
}
}
decl_event! {
pub enum Event {
/// Current code has been updated for a Para. \[para_id\]
CurrentCodeUpdated(ParaId),
/// Current head has been updated for a Para. \[para_id\]
CurrentHeadUpdated(ParaId),
/// A code upgrade has been scheduled for a Para. \[para_id\]
CodeUpgradeScheduled(ParaId),
/// A new head has been noted for a Para. \[para_id\]
NewHeadNoted(ParaId),
/// A para has been queued to execute pending actions. \[para_id\]
ActionQueued(ParaId, SessionIndex),
/// All parachains. Ordered ascending by ParaId. Parathreads are not included.
#[pallet::storage]
#[pallet::getter(fn parachains)]
pub(super) type Parachains<T: Config> = StorageValue<_, Vec<ParaId>, ValueQuery>;
/// The current lifecycle of a all known Para IDs.
#[pallet::storage]
pub(super) type ParaLifecycles<T: Config> = StorageMap<_, Twox64Concat, ParaId, ParaLifecycle>;
/// The head-data of every registered para.
#[pallet::storage]
#[pallet::getter(fn para_head)]
pub(super) type Heads<T: Config> = StorageMap<_, Twox64Concat, ParaId, HeadData>;
/// The validation code hash of every live para.
///
/// Corresponding code can be retrieved with [`CodeByHash`].
#[pallet::storage]
pub(super) type CurrentCodeHash<T: Config> = StorageMap<_, Twox64Concat, ParaId, ValidationCodeHash>;
/// Actual past code hash, indicated by the para id as well as the block number at which it
/// became outdated.
///
/// Corresponding code can be retrieved with [`CodeByHash`].
#[pallet::storage]
pub(super) type PastCodeHash<T: Config> = StorageMap<
_,
Twox64Concat,
(ParaId, T::BlockNumber),
ValidationCodeHash
>;
/// Past code of parachains. The parachains themselves may not be registered anymore,
/// but we also keep their code on-chain for the same amount of time as outdated code
/// to keep it available for secondary checkers.
#[pallet::storage]
#[pallet::getter(fn past_code_meta)]
pub(super) type PastCodeMeta<T: Config> = StorageMap<
_,
Twox64Concat,
ParaId,
ParaPastCodeMeta<T::BlockNumber>,
ValueQuery
>;
/// Which paras have past code that needs pruning and the relay-chain block at which the code was replaced.
/// Note that this is the actual height of the included block, not the expected height at which the
/// code upgrade would be applied, although they may be equal.
/// This is to ensure the entire acceptance period is covered, not an offset acceptance period starting
/// from the time at which the parachain perceives a code upgrade as having occurred.
/// Multiple entries for a single para are permitted. Ordered ascending by block number.
#[pallet::storage]
pub(super) type PastCodePruning<T: Config> = StorageValue<_, Vec<(ParaId, T::BlockNumber)>, ValueQuery>;
/// The block number at which the planned code change is expected for a para.
/// The change will be applied after the first parablock for this ID included which executes
/// in the context of a relay chain block with a number >= `expected_at`.
#[pallet::storage]
#[pallet::getter(fn future_code_upgrade_at)]
pub(super) type FutureCodeUpgrades<T: Config> = StorageMap<_, Twox64Concat, ParaId, T::BlockNumber>;
/// The actual future code hash of a para.
///
/// Corresponding code can be retrieved with [`CodeByHash`].
#[pallet::storage]
pub(super) type FutureCodeHash<T: Config> = StorageMap<_, Twox64Concat, ParaId, ValidationCodeHash>;
/// The actions to perform during the start of a specific session index.
#[pallet::storage]
#[pallet::getter(fn actions_queue)]
pub(super) type ActionsQueue<T: Config> = StorageMap<_, Twox64Concat, SessionIndex, Vec<ParaId>, ValueQuery>;
/// Upcoming paras instantiation arguments.
#[pallet::storage]
pub(super) type UpcomingParasGenesis<T: Config> = StorageMap<_, Twox64Concat, ParaId, ParaGenesisArgs>;
/// The number of reference on the validation code in [`CodeByHash`] storage.
#[pallet::storage]
pub(super) type CodeByHashRefs<T: Config> = StorageMap<_, Identity, ValidationCodeHash, u32, ValueQuery>;
/// Validation code stored by its hash.
///
/// This storage is consistent with [`FutureCodeHash`], [`CurrentCodeHash`] and
/// [`PastCodeHash`].
#[pallet::storage]
#[pallet::getter(fn code_by_hash)]
pub(super) type CodeByHash<T: Config> = StorageMap<_, Identity, ValidationCodeHash, ValidationCode>;
#[pallet::genesis_config]
pub struct GenesisConfig {
pub paras: Vec<(ParaId, ParaGenesisArgs)>,
}
#[cfg(feature = "std")]
impl Default for GenesisConfig {
fn default() -> Self {
GenesisConfig {
paras: Default::default(),
}
}
}
}
decl_module! {
/// The parachains configuration module.
pub struct Module<T: Config> for enum Call where origin: <T as frame_system::Config>::Origin {
type Error = Error<T>;
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {
let mut parachains: Vec<_> = self.paras
.iter()
.filter(|(_, args)| args.parachain)
.map(|&(ref id, _)| id)
.cloned()
.collect();
parachains.sort();
parachains.dedup();
Parachains::<T>::put(&parachains);
for (id, genesis_args) in &self.paras {
let code_hash = genesis_args.validation_code.hash();
<Pallet<T>>::increase_code_ref(&code_hash, &genesis_args.validation_code);
<Pallet<T> as Store>::CurrentCodeHash::insert(&id, &code_hash);
<Pallet<T> as Store>::Heads::insert(&id, &genesis_args.genesis_head);
if genesis_args.parachain {
ParaLifecycles::<T>::insert(&id, ParaLifecycle::Parachain);
} else {
ParaLifecycles::<T>::insert(&id, ParaLifecycle::Parathread);
}
}
}
}
fn deposit_event() = default;
#[pallet::origin]
pub type Origin = ParachainOrigin;
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Set the storage for the parachain validation code immediately.
#[weight = 0]
fn force_set_current_code(origin, para: ParaId, new_code: ValidationCode) {
#[pallet::weight(0)]
pub fn force_set_current_code(origin: OriginFor<T>, para: ParaId, new_code: ValidationCode) -> DispatchResult {
ensure_root(origin)?;
let prior_code_hash = <Self as Store>::CurrentCodeHash::get(&para).unwrap_or_default();
let new_code_hash = new_code.hash();
......@@ -411,57 +461,67 @@ decl_module! {
let now = frame_system::Pallet::<T>::block_number();
Self::note_past_code(para, now, now, prior_code_hash);
Self::deposit_event(Event::CurrentCodeUpdated(para));
Ok(())
}
/// Set the storage for the current parachain head data immediately.
#[weight = 0]
fn force_set_current_head(origin, para: ParaId, new_head: HeadData) {
#[pallet::weight(0)]
pub fn force_set_current_head(origin: OriginFor<T>, para: ParaId, new_head: HeadData) -> DispatchResult {
ensure_root(origin)?;
<Self as Store>::Heads::insert(&para, new_head);
Self::deposit_event(Event::CurrentHeadUpdated(para));
Ok(())
}
/// Schedule a code upgrade for block `expected_at`.
#[weight = 0]
fn force_schedule_code_upgrade(origin, para: ParaId, new_code: ValidationCode, expected_at: T::BlockNumber) {
#[pallet::weight(0)]
pub fn force_schedule_code_upgrade(
origin: OriginFor<T>,
para: ParaId,
new_code: ValidationCode,
expected_at: T::BlockNumber
) -> DispatchResult {
ensure_root(origin)?;
Self::schedule_code_upgrade(para, new_code, expected_at);
Self::deposit_event(Event::CodeUpgradeScheduled(para));
Ok(())
}