Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
paras: Prune upgrade cooldowns (#7470)
Browse files Browse the repository at this point in the history
After an upgrade cooldown triggered to remove a signal we also need to
prune it from the list.
  • Loading branch information
bkchr authored Jul 10, 2023
1 parent 5e42d24 commit 596d923
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
14 changes: 10 additions & 4 deletions runtime/parachains/src/paras/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ impl<T: Config> Pallet<T> {
// Persist parachains into the storage explicitly.
drop(parachains);

return outgoing
outgoing
}

// note replacement of the code of para with given `id`, which occured in the
Expand Down Expand Up @@ -1389,9 +1389,15 @@ impl<T: Config> Pallet<T> {
/// See `process_scheduled_upgrade_changes` for more details.
fn process_scheduled_upgrade_cooldowns(now: T::BlockNumber) {
UpgradeCooldowns::<T>::mutate(|upgrade_cooldowns: &mut Vec<(ParaId, T::BlockNumber)>| {
for &(para, _) in upgrade_cooldowns.iter().take_while(|&(_, at)| at <= &now) {
UpgradeRestrictionSignal::<T>::remove(&para);
}
// Remove all expired signals and also prune the cooldowns.
upgrade_cooldowns.retain(|(para, at)| {
if at <= &now {
UpgradeRestrictionSignal::<T>::remove(&para);
false
} else {
true
}
});
});
}

Expand Down
18 changes: 15 additions & 3 deletions runtime/parachains/src/paras/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ fn code_upgrade_applied_after_delay() {
run_to_block(2, Some(vec![1]));
assert_eq!(Paras::current_code(&para_id), Some(original_code.clone()));

let expected_at = {
let (expected_at, next_possible_upgrade_at) = {
// this parablock is in the context of block 1.
let expected_at = 1 + validation_upgrade_delay;
let next_possible_upgrade_at = 1 + validation_upgrade_cooldown;
Expand All @@ -460,7 +460,7 @@ fn code_upgrade_applied_after_delay() {
check_code_is_stored(&original_code);
check_code_is_stored(&new_code);

expected_at
(expected_at, next_possible_upgrade_at)
};

run_to_block(expected_at, None);
Expand Down Expand Up @@ -495,9 +495,21 @@ fn code_upgrade_applied_after_delay() {
assert!(FutureCodeHash::<Test>::get(&para_id).is_none());
assert!(UpgradeGoAheadSignal::<Test>::get(&para_id).is_none());
assert_eq!(Paras::current_code(&para_id), Some(new_code.clone()));
assert_eq!(
UpgradeRestrictionSignal::<Test>::get(&para_id),
Some(UpgradeRestriction::Present),
);
assert_eq!(UpgradeCooldowns::<Test>::get(), vec![(para_id, next_possible_upgrade_at)]);
check_code_is_stored(&original_code);
check_code_is_stored(&new_code);
}

run_to_block(next_possible_upgrade_at + 1, None);

{
assert!(UpgradeRestrictionSignal::<Test>::get(&para_id).is_none());
assert!(UpgradeCooldowns::<Test>::get().is_empty());
}
});
}

Expand Down Expand Up @@ -568,7 +580,7 @@ fn code_upgrade_applied_after_delay_even_when_late() {
// the upgrade.
{
// The signal should be set to go-ahead until the new head is actually processed.
assert_eq!(UpgradeGoAheadSignal::<Test>::get(&para_id), Some(UpgradeGoAhead::GoAhead),);
assert_eq!(UpgradeGoAheadSignal::<Test>::get(&para_id), Some(UpgradeGoAhead::GoAhead));

Paras::note_new_head(para_id, Default::default(), expected_at + 4);

Expand Down

0 comments on commit 596d923

Please sign in to comment.