Skip to content

Commit 110e940

Browse files
committed
freeze on initialize per new session
1 parent 4ada34b commit 110e940

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

polkadot/runtime/parachains/src/assigner_coretime/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<N> From<Schedule<N>> for WorkState<N> {
207207
#[frame_support::pallet]
208208
pub mod pallet {
209209
use super::*;
210-
210+
211211
#[pallet::pallet]
212212
#[pallet::without_storage_info]
213213
pub struct Pallet<T>(_);

polkadot/runtime/parachains/src/paras/mod.rs

+32
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ use sp_runtime::{
129129
traits::{AppVerify, One, Saturating},
130130
DispatchResult, SaturatedConversion,
131131
};
132+
use crate::scheduler::common::Assignment;
132133

133134
use serde::{Deserialize, Serialize};
134135

@@ -244,6 +245,7 @@ impl ParaLifecycle {
244245
pub fn is_transitioning(&self) -> bool {
245246
!Self::is_stable(self)
246247
}
248+
247249
}
248250

249251
impl<N: Ord + Copy + PartialEq> ParaPastCodeMeta<N> {
@@ -677,6 +679,8 @@ pub mod pallet {
677679
/// The given validation code was rejected by the PVF pre-checking vote.
678680
/// `code_hash` `para_id`
679681
PvfCheckRejected(ValidationCodeHash, ParaId),
682+
/// A paraId has been frozen
683+
ParaIdFrozen(ParaId)
680684
}
681685

682686
#[pallet::error]
@@ -871,6 +875,10 @@ pub mod pallet {
871875
#[pallet::storage]
872876
pub type CodeByHash<T: Config> = StorageMap<_, Identity, ValidationCodeHash, ValidationCode>;
873877

878+
/// Frozen parachain list
879+
#[pallet::storage]
880+
pub type FrozenParas<T: Config> = StorageValue<_,Vec<ParaId>,ValueQuery>;
881+
874882
#[pallet::genesis_config]
875883
#[derive(DefaultNoBound)]
876884
pub struct GenesisConfig<T: Config> {
@@ -1160,6 +1168,30 @@ pub mod pallet {
11601168
MostRecentContext::<T>::insert(&para, context);
11611169
Ok(())
11621170
}
1171+
1172+
#[pallet::call_index(9)]
1173+
#[pallet::weight(Weight::zero())]
1174+
pub fn freeze_parachain(origin: OriginFor<T>, para_id: ParaId) -> DispatchResult {
1175+
ensure_root(origin)?;
1176+
// clean any ongoing activies on the parablock
1177+
crate::scheduler::ClaimQueue::<T>::mutate(|cq|{
1178+
for assignments in cq.values_mut() {
1179+
assignments.retain(|&assignment| {
1180+
let assigned_para_id = match assignment {
1181+
Assignment::Bulk(id) => id,
1182+
Assignment::Pool { para_id, ..} => para_id
1183+
};
1184+
para_id != assigned_para_id
1185+
})
1186+
}
1187+
});
1188+
// TODO
1189+
FrozenParas::<T>::mutate(|paras|{
1190+
paras.push(para_id)
1191+
});
1192+
Self::deposit_event(Event::ParaIdFrozen(para_id));
1193+
Ok(())
1194+
}
11631195
}
11641196

11651197
#[pallet::validate_unsigned]

polkadot/runtime/parachains/src/scheduler.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,10 @@ impl<T: Config> Pallet<T> {
398398
}
399399

400400
fn fill_claim_queue(core_idx: CoreIndex, n_lookahead: u32) {
401+
401402
ClaimQueue::<T>::mutate(|la| {
402403
let cq = la.entry(core_idx).or_default();
403-
404+
let frozen_paras = crate::paras::FrozenParas::<T>::get();
404405
let mut n_lookahead_used = cq.len() as u32;
405406

406407
// If the claim queue used to be empty, we need to double the first assignment.
@@ -411,15 +412,31 @@ impl<T: Config> Pallet<T> {
411412
if n_lookahead_used == 0 && n_lookahead > 1 {
412413
if let Some(assignment) = T::AssignmentProvider::pop_assignment_for_core(core_idx) {
413414
T::AssignmentProvider::assignment_duplicated(&assignment);
414-
cq.push_back(assignment.clone());
415-
cq.push_back(assignment);
416-
n_lookahead_used += 2;
415+
// check if the paraId is frozen
416+
let para_id = match assignment {
417+
Assignment::Bulk(id) => id,
418+
Assignment::Pool { para_id, ..} => para_id
419+
};
420+
421+
if !frozen_paras.contains(&para_id) {
422+
cq.push_back(assignment.clone());
423+
cq.push_back(assignment);
424+
n_lookahead_used += 2;
425+
}
426+
417427
}
418428
}
419429

420430
for _ in n_lookahead_used..n_lookahead {
421431
if let Some(assignment) = T::AssignmentProvider::pop_assignment_for_core(core_idx) {
422-
cq.push_back(assignment);
432+
433+
let para_id = match assignment {
434+
Assignment::Bulk(id) => id,
435+
Assignment::Pool { para_id, ..} => para_id
436+
};
437+
if !frozen_paras.contains(&para_id) {
438+
cq.push_back(assignment);
439+
}
423440
} else {
424441
break
425442
}

0 commit comments

Comments
 (0)