@@ -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