Skip to content

Commit bd8d7ed

Browse files
bkchrdharjeezy
authored andcommitted
Fix parachain upgrade scheduling when done by the owner/root (paritytech#3341)
When using `schedule_code_upgrade` to change the code of a parachain in the relay chain runtime, we had already fixed to not set the `GoAhead` signal. This was done to not brick any parachain after the upgrade, because they were seeing the signal without having any upgrade prepared. The remaining problem is that the parachain code is only upgraded after a parachain header was enacted, aka the parachain made some progress. However, this is quite complicated if the parachain is bricked (which is the most common scenario why to manually schedule a code upgrade). Thus, this pull request replaces `SetGoAhead` with `UpgradeStrategy` to signal to the logic kind of strategy want to use. The strategies are either `SetGoAheadSignal` or `ApplyAtExpectedBlock`. `SetGoAheadSignal` sets the go ahead signal as before and awaits a parachain block. `ApplyAtExpectedBlock` schedules the upgrade and applies it directly at the `expected_block` without waiting for the parachain to make any kind of progress.
1 parent 1ff0a07 commit bd8d7ed

9 files changed

Lines changed: 237 additions & 169 deletions

File tree

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use frame_system::{self, ensure_root, ensure_signed};
2929
use primitives::{HeadData, Id as ParaId, ValidationCode, LOWEST_PUBLIC_ID, MIN_CODE_SIZE};
3030
use runtime_parachains::{
3131
configuration, ensure_parachain,
32-
paras::{self, ParaGenesisArgs, SetGoAhead},
32+
paras::{self, ParaGenesisArgs, UpgradeStrategy},
3333
Origin, ParaLifecycle,
3434
};
3535
use sp_std::{prelude::*, result};
@@ -408,6 +408,13 @@ pub mod pallet {
408408

409409
/// Schedule a parachain upgrade.
410410
///
411+
/// This will kick off a check of `new_code` by all validators. After the majority of the
412+
/// validators have reported on the validity of the code, the code will either be enacted
413+
/// or the upgrade will be rejected. If the code will be enacted, the current code of the
414+
/// parachain will be overwritten directly. This means that any PoV will be checked by this
415+
/// new code. The parachain itself will not be informed explictely that the validation code
416+
/// has changed.
417+
///
411418
/// Can be called by Root, the parachain, or the parachain manager if the parachain is
412419
/// unlocked.
413420
#[pallet::call_index(7)]
@@ -418,7 +425,11 @@ pub mod pallet {
418425
new_code: ValidationCode,
419426
) -> DispatchResult {
420427
Self::ensure_root_para_or_owner(origin, para)?;
421-
runtime_parachains::schedule_code_upgrade::<T>(para, new_code, SetGoAhead::No)?;
428+
runtime_parachains::schedule_code_upgrade::<T>(
429+
para,
430+
new_code,
431+
UpgradeStrategy::ApplyAtExpectedBlock,
432+
)?;
422433
Ok(())
423434
}
424435

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use crate::{
2323
configuration::{self, HostConfiguration},
2424
disputes, dmp, hrmp,
25-
paras::{self, SetGoAhead},
25+
paras::{self, UpgradeStrategy},
2626
scheduler,
2727
shared::{self, AllowedRelayParentsTracker},
2828
util::make_persisted_validation_data_with_parent,
@@ -839,7 +839,7 @@ impl<T: Config> Pallet<T> {
839839
new_code,
840840
now,
841841
&config,
842-
SetGoAhead::Yes,
842+
UpgradeStrategy::SetGoAheadSignal,
843843
));
844844
}
845845

polkadot/runtime/parachains/src/inclusion/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ fn candidate_checks() {
15901590
vec![9, 8, 7, 6, 5, 4, 3, 2, 1].into(),
15911591
expected_at,
15921592
&cfg,
1593-
SetGoAhead::Yes,
1593+
UpgradeStrategy::SetGoAheadSignal,
15941594
);
15951595
}
15961596

@@ -2857,7 +2857,7 @@ fn para_upgrade_delay_scheduled_from_inclusion() {
28572857
let cause = &active_vote_state.causes()[0];
28582858
// Upgrade block is the block of inclusion, not candidate's parent.
28592859
assert_matches!(cause,
2860-
paras::PvfCheckCause::Upgrade { id, included_at, set_go_ahead: SetGoAhead::Yes }
2860+
paras::PvfCheckCause::Upgrade { id, included_at, upgrade_strategy: UpgradeStrategy::SetGoAheadSignal }
28612861
if id == &chain_a && included_at == &7
28622862
);
28632863
});

polkadot/runtime/parachains/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ mod mock;
5454
mod ump_tests;
5555

5656
pub use origin::{ensure_parachain, Origin};
57-
pub use paras::{ParaLifecycle, SetGoAhead};
57+
pub use paras::{ParaLifecycle, UpgradeStrategy};
5858
use primitives::{HeadData, Id as ParaId, ValidationCode};
5959
use sp_runtime::{DispatchResult, FixedU128};
6060

@@ -104,7 +104,7 @@ pub fn schedule_parachain_downgrade<T: paras::Config>(id: ParaId) -> Result<(),
104104
pub fn schedule_code_upgrade<T: paras::Config>(
105105
id: ParaId,
106106
new_code: ValidationCode,
107-
set_go_ahead: SetGoAhead,
107+
set_go_ahead: UpgradeStrategy,
108108
) -> DispatchResult {
109109
paras::Pallet::<T>::schedule_code_upgrade_external(id, new_code, set_go_ahead)
110110
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ benchmarks! {
129129
ValidationCode(vec![0]),
130130
expired,
131131
&config,
132-
SetGoAhead::Yes,
132+
UpgradeStrategy::SetGoAheadSignal,
133133
);
134134
}: _(RawOrigin::Root, para_id, new_head)
135135
verify {

polkadot/runtime/parachains/src/paras/benchmarking/pvf_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ where
177177
validation_code,
178178
/* relay_parent_number */ 1u32.into(),
179179
&configuration::Pallet::<T>::config(),
180-
SetGoAhead::Yes,
180+
UpgradeStrategy::SetGoAheadSignal,
181181
);
182182
} else {
183183
let r = Pallet::<T>::schedule_para_initialize(

0 commit comments

Comments
 (0)