Skip to content

Commit

Permalink
reapply changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Daanvdplas committed Sep 11, 2023
1 parent a414ea7 commit 21570c6
Show file tree
Hide file tree
Showing 6 changed files with 341 additions and 5 deletions.
4 changes: 2 additions & 2 deletions polkadot/runtime/common/src/paras_registrar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use frame_system::{self, ensure_root, ensure_signed};
use primitives::{HeadData, Id as ParaId, ValidationCode, LOWEST_PUBLIC_ID};
use runtime_parachains::{
configuration, ensure_parachain,
paras::{self, ParaGenesisArgs},
paras::{self, ParaGenesisArgs, SetGoAhead},
Origin, ParaLifecycle,
};
use sp_std::{prelude::*, result};
Expand Down Expand Up @@ -412,7 +412,7 @@ pub mod pallet {
new_code: ValidationCode,
) -> DispatchResult {
Self::ensure_root_para_or_owner(origin, para)?;
runtime_parachains::schedule_code_upgrade::<T>(para, new_code)?;
runtime_parachains::schedule_code_upgrade::<T>(para, new_code, SetGoAhead::No)?;
Ok(())
}

Expand Down
13 changes: 12 additions & 1 deletion polkadot/runtime/parachains/src/inclusion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

use crate::{
configuration::{self, HostConfiguration},
disputes, dmp, hrmp, paras,
disputes, dmp, hrmp,
paras::{self, SetGoAhead},
scheduler::{self, AvailabilityTimeoutStatus},
shared::{self, AllowedRelayParentsTracker},
};
Expand Down Expand Up @@ -448,8 +449,14 @@ impl fmt::Debug for UmpAcceptanceCheckErr {
"the ump queue would have grown past the max size permitted by config ({} > {})",
total_size, limit,
),
<<<<<<< Updated upstream
UmpAcceptanceCheckErr::IsOffboarding =>
write!(fmt, "upward message rejected because the para is off-boarding",),
=======
UmpAcceptanceCheckErr::IsOffboarding => {
write!(fmt, "upward message rejected because the para is off-boarding")
},
>>>>>>> Stashed changes
}
}
}
Expand Down Expand Up @@ -885,6 +892,10 @@ impl<T: Config> Pallet<T> {
new_code,
now,
&config,
<<<<<<< Updated upstream
=======
SetGoAhead::Yes,
>>>>>>> Stashed changes
));
}

Expand Down
14 changes: 14 additions & 0 deletions polkadot/runtime/parachains/src/inclusion/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,17 @@ fn candidate_checks() {
let cfg = Configuration::config();
let expected_at = 10 + cfg.validation_upgrade_delay;
assert_eq!(expected_at, 12);
<<<<<<< Updated upstream
Paras::schedule_code_upgrade(chain_a, vec![1, 2, 3, 4].into(), expected_at, &cfg);
=======
Paras::schedule_code_upgrade(
chain_a,
vec![1, 2, 3, 4].into(),
expected_at,
&cfg,
SetGoAhead::Yes,
);
>>>>>>> Stashed changes
}

assert_noop!(
Expand Down Expand Up @@ -2235,7 +2245,11 @@ fn para_upgrade_delay_scheduled_from_inclusion() {
let cause = &active_vote_state.causes()[0];
// Upgrade block is the block of inclusion, not candidate's parent.
assert_matches!(cause,
<<<<<<< Updated upstream
paras::PvfCheckCause::Upgrade { id, included_at }
=======
paras::PvfCheckCause::Upgrade { id, included_at, set_go_ahead: SetGoAhead::Yes }
>>>>>>> Stashed changes
if id == &chain_a && included_at == &7
);
});
Expand Down
5 changes: 3 additions & 2 deletions polkadot/runtime/parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mod mock;
mod ump_tests;

pub use origin::{ensure_parachain, Origin};
pub use paras::ParaLifecycle;
pub use paras::{ParaLifecycle, SetGoAhead};
use primitives::{HeadData, Id as ParaId, ValidationCode};
use sp_runtime::{DispatchResult, FixedU128};

Expand Down Expand Up @@ -89,8 +89,9 @@ pub fn schedule_parachain_downgrade<T: paras::Config>(id: ParaId) -> Result<(),
pub fn schedule_code_upgrade<T: paras::Config>(
id: ParaId,
new_code: ValidationCode,
set_go_ahead: SetGoAhead,
) -> DispatchResult {
paras::Pallet::<T>::schedule_code_upgrade_external(id, new_code)
paras::Pallet::<T>::schedule_code_upgrade_external(id, new_code, set_go_ahead)
}

/// Sets the current parachain head with the given id.
Expand Down
47 changes: 47 additions & 0 deletions polkadot/runtime/parachains/src/paras/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,21 @@ pub(crate) enum PvfCheckCause<BlockNumber> {
///
/// See https://github.com/paritytech/polkadot/issues/4601 for detailed explanation.
included_at: BlockNumber,
<<<<<<< Updated upstream
=======
/// Whether or not the given para should be sent the `GoAhead` signal.
set_go_ahead: SetGoAhead,
>>>>>>> Stashed changes
},
}

/// Should the `GoAhead` signal be set after a successful check of the new wasm binary?
#[derive(Debug, Copy, Clone, PartialEq, TypeInfo, Decode, Encode)]
pub enum SetGoAhead {
Yes,
No,
}

impl<BlockNumber> PvfCheckCause<BlockNumber> {
/// Returns the ID of the para that initiated or subscribed to the pre-checking vote.
fn para_id(&self) -> ParaId {
Expand Down Expand Up @@ -888,7 +900,17 @@ pub mod pallet {
) -> DispatchResult {
ensure_root(origin)?;
let config = configuration::Pallet::<T>::config();
<<<<<<< Updated upstream
Self::schedule_code_upgrade(para, new_code, relay_parent_number, &config);
=======
Self::schedule_code_upgrade(
para,
new_code,
relay_parent_number,
&config,
SetGoAhead::No,
);
>>>>>>> Stashed changes
Self::deposit_event(Event::CodeUpgradeScheduled(para));
Ok(())
}
Expand Down Expand Up @@ -1186,14 +1208,19 @@ impl<T: Config> Pallet<T> {
pub(crate) fn schedule_code_upgrade_external(
id: ParaId,
new_code: ValidationCode,
set_go_ahead: SetGoAhead,
) -> DispatchResult {
// Check that we can schedule an upgrade at all.
ensure!(Self::can_upgrade_validation_code(id), Error::<T>::CannotUpgradeCode);
let config = configuration::Pallet::<T>::config();
let current_block = frame_system::Pallet::<T>::block_number();
// Schedule the upgrade with a delay just like if a parachain triggered the upgrade.
let upgrade_block = current_block.saturating_add(config.validation_upgrade_delay);
<<<<<<< Updated upstream
Self::schedule_code_upgrade(id, new_code, upgrade_block, &config);
=======
Self::schedule_code_upgrade(id, new_code, upgrade_block, &config, set_go_ahead);
>>>>>>> Stashed changes
Self::deposit_event(Event::CodeUpgradeScheduled(id));
Ok(())
}
Expand Down Expand Up @@ -1568,6 +1595,10 @@ impl<T: Config> Pallet<T> {
now: BlockNumberFor<T>,
relay_parent_number: BlockNumberFor<T>,
cfg: &configuration::HostConfiguration<BlockNumberFor<T>>,
<<<<<<< Updated upstream
=======
set_go_ahead: SetGoAhead,
>>>>>>> Stashed changes
) -> Weight {
let mut weight = Weight::zero();

Expand All @@ -1591,12 +1622,24 @@ impl<T: Config> Pallet<T> {
weight += T::DbWeight::get().reads_writes(1, 4);
FutureCodeUpgrades::<T>::insert(&id, expected_at);

<<<<<<< Updated upstream
UpcomingUpgrades::<T>::mutate(|upcoming_upgrades| {
let insert_idx = upcoming_upgrades
.binary_search_by_key(&expected_at, |&(_, b)| b)
.unwrap_or_else(|idx| idx);
upcoming_upgrades.insert(insert_idx, (id, expected_at));
});
=======
// Only set an upcoming upgrade if `GoAhead` signal should be set for the respective para.
if set_go_ahead == SetGoAhead::Yes {
UpcomingUpgrades::<T>::mutate(|upcoming_upgrades| {
let insert_idx = upcoming_upgrades
.binary_search_by_key(&expected_at, |&(_, b)| b)
.unwrap_or_else(|idx| idx);
upcoming_upgrades.insert(insert_idx, (id, expected_at));
});
}
>>>>>>> Stashed changes

let expected_at = expected_at.saturated_into();
let log = ConsensusLog::ParaScheduleUpgradeCode(id, *code_hash, expected_at);
Expand Down Expand Up @@ -1835,6 +1878,10 @@ impl<T: Config> Pallet<T> {
new_code: ValidationCode,
inclusion_block_number: BlockNumberFor<T>,
cfg: &configuration::HostConfiguration<BlockNumberFor<T>>,
<<<<<<< Updated upstream
=======
set_go_ahead: SetGoAhead,
>>>>>>> Stashed changes
) -> Weight {
let mut weight = T::DbWeight::get().reads(1);

Expand Down
Loading

0 comments on commit 21570c6

Please sign in to comment.