Skip to content

Commit 0ecf484

Browse files
committed
fix: GoAhead signal from schedule_code_upgrade
1 parent 1a38d6d commit 0ecf484

File tree

4 files changed

+237
-29
lines changed

4 files changed

+237
-29
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,9 @@ impl fmt::Debug for UmpAcceptanceCheckErr {
456456
"the ump queue would have grown past the max size permitted by config ({} > {})",
457457
total_size, limit,
458458
),
459-
UmpAcceptanceCheckErr::IsOffboarding =>
460-
write!(fmt, "upward message rejected because the para is off-boarding",),
459+
UmpAcceptanceCheckErr::IsOffboarding => {
460+
write!(fmt, "upward message rejected because the para is off-boarding",)
461+
},
461462
}
462463
}
463464
}
@@ -911,6 +912,7 @@ impl<T: Config> Pallet<T> {
911912
new_code,
912913
now,
913914
&config,
915+
true,
914916
));
915917
}
916918

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,13 @@ fn candidate_checks() {
12591259
let cfg = Configuration::config();
12601260
let expected_at = 10 + cfg.validation_upgrade_delay;
12611261
assert_eq!(expected_at, 12);
1262-
Paras::schedule_code_upgrade(chain_a, vec![1, 2, 3, 4].into(), expected_at, &cfg);
1262+
Paras::schedule_code_upgrade(
1263+
chain_a,
1264+
vec![1, 2, 3, 4].into(),
1265+
expected_at,
1266+
&cfg,
1267+
true,
1268+
);
12631269
}
12641270

12651271
assert_noop!(
@@ -2277,7 +2283,7 @@ fn para_upgrade_delay_scheduled_from_inclusion() {
22772283
let cause = &active_vote_state.causes()[0];
22782284
// Upgrade block is the block of inclusion, not candidate's parent.
22792285
assert_matches!(cause,
2280-
paras::PvfCheckCause::Upgrade { id, included_at }
2286+
paras::PvfCheckCause::Upgrade { id, included_at, set_go_ahead: true }
22812287
if id == &chain_a && included_at == &7
22822288
);
22832289
});

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ pub(crate) enum PvfCheckCause<BlockNumber> {
386386
///
387387
/// See https://github.com/paritytech/polkadot/issues/4601 for detailed explanation.
388388
included_at: BlockNumber,
389+
/// Whether or not the given para should be sent the `GoAhead` signal.
390+
set_go_ahead: bool,
389391
},
390392
}
391393

@@ -723,7 +725,9 @@ pub mod pallet {
723725
StorageMap<_, Twox64Concat, ParaId, ValidationCodeHash>;
724726

725727
/// This is used by the relay-chain to communicate to a parachain a go-ahead with in the upgrade
726-
/// procedure.
728+
/// procedure. The `GoAhead` is only set when it is assured the parachain is ready for the
729+
/// upgrade, i.e. when the upgrade is enacted on the parachain side
730+
/// (`enact_authorized_upgrade`).
727731
///
728732
/// This value is absent when there are no upgrades scheduled or during the time the relay chain
729733
/// performs the checks. It is set at the first relay-chain block when the corresponding
@@ -869,7 +873,7 @@ pub mod pallet {
869873
) -> DispatchResult {
870874
ensure_root(origin)?;
871875
let config = configuration::Pallet::<T>::config();
872-
Self::schedule_code_upgrade(para, new_code, relay_parent_number, &config);
876+
Self::schedule_code_upgrade(para, new_code, relay_parent_number, &config, false);
873877
Self::deposit_event(Event::CodeUpgradeScheduled(para));
874878
Ok(())
875879
}
@@ -1174,7 +1178,7 @@ impl<T: Config> Pallet<T> {
11741178
let current_block = frame_system::Pallet::<T>::block_number();
11751179
// Schedule the upgrade with a delay just like if a parachain triggered the upgrade.
11761180
let upgrade_block = current_block.saturating_add(config.validation_upgrade_delay);
1177-
Self::schedule_code_upgrade(id, new_code, upgrade_block, &config);
1181+
Self::schedule_code_upgrade(id, new_code, upgrade_block, &config, false);
11781182
Self::deposit_event(Event::CodeUpgradeScheduled(id));
11791183
Ok(())
11801184
}
@@ -1515,8 +1519,15 @@ impl<T: Config> Pallet<T> {
15151519
PvfCheckCause::Onboarding(id) => {
15161520
weight += Self::proceed_with_onboarding(*id, sessions_observed);
15171521
},
1518-
PvfCheckCause::Upgrade { id, included_at } => {
1519-
weight += Self::proceed_with_upgrade(*id, code_hash, now, *included_at, cfg);
1522+
PvfCheckCause::Upgrade { id, included_at, set_go_ahead } => {
1523+
weight += Self::proceed_with_upgrade(
1524+
*id,
1525+
code_hash,
1526+
now,
1527+
*included_at,
1528+
cfg,
1529+
*set_go_ahead,
1530+
);
15201531
},
15211532
}
15221533
}
@@ -1549,6 +1560,7 @@ impl<T: Config> Pallet<T> {
15491560
now: BlockNumberFor<T>,
15501561
relay_parent_number: BlockNumberFor<T>,
15511562
cfg: &configuration::HostConfiguration<BlockNumberFor<T>>,
1563+
set_go_ahead: bool,
15521564
) -> Weight {
15531565
let mut weight = Weight::zero();
15541566

@@ -1572,12 +1584,15 @@ impl<T: Config> Pallet<T> {
15721584
weight += T::DbWeight::get().reads_writes(1, 4);
15731585
FutureCodeUpgrades::<T>::insert(&id, expected_at);
15741586

1575-
UpcomingUpgrades::<T>::mutate(|upcoming_upgrades| {
1576-
let insert_idx = upcoming_upgrades
1577-
.binary_search_by_key(&expected_at, |&(_, b)| b)
1578-
.unwrap_or_else(|idx| idx);
1579-
upcoming_upgrades.insert(insert_idx, (id, expected_at));
1580-
});
1587+
// Only set an upcoming upgrade if `GoAhead` signal should be set for the respective para.
1588+
if set_go_ahead {
1589+
UpcomingUpgrades::<T>::mutate(|upcoming_upgrades| {
1590+
let insert_idx = upcoming_upgrades
1591+
.binary_search_by_key(&expected_at, |&(_, b)| b)
1592+
.unwrap_or_else(|idx| idx);
1593+
upcoming_upgrades.insert(insert_idx, (id, expected_at));
1594+
});
1595+
}
15811596

15821597
let expected_at = expected_at.saturated_into();
15831598
let log = ConsensusLog::ParaScheduleUpgradeCode(id, *code_hash, expected_at);
@@ -1816,6 +1831,7 @@ impl<T: Config> Pallet<T> {
18161831
new_code: ValidationCode,
18171832
inclusion_block_number: BlockNumberFor<T>,
18181833
cfg: &configuration::HostConfiguration<BlockNumberFor<T>>,
1834+
set_go_ahead: bool,
18191835
) -> Weight {
18201836
let mut weight = T::DbWeight::get().reads(1);
18211837

@@ -1865,7 +1881,7 @@ impl<T: Config> Pallet<T> {
18651881
});
18661882

18671883
weight += Self::kick_off_pvf_check(
1868-
PvfCheckCause::Upgrade { id, included_at: inclusion_block_number },
1884+
PvfCheckCause::Upgrade { id, included_at: inclusion_block_number, set_go_ahead },
18691885
code_hash,
18701886
new_code,
18711887
cfg,

0 commit comments

Comments
 (0)