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

Commit

Permalink
pvf-precheck: update configuration module
Browse files Browse the repository at this point in the history
This PR is a part of #3211.

This PR adds three new fields into the `HostConfiguration` structure.
The fields are going to be used in PRs down the stack.

This change requires migration, so this PR performs runtime storage
migration for configuration module from version 1 to version 2.

This PR closes #4010 and subsumes #4177.

There are several TODOs:

- [ ] Fill in the PR number for the reference in migration code
- [ ] Decide what weight use for `set_pvf_checking_enabled`. It seems
  that u32 will be close enough, but maybe we still want to add weight
  for boolean parameters
- [ ] Test the upgrade.
  • Loading branch information
pepyakin committed Nov 30, 2021
1 parent c856b7b commit 2be5ed0
Show file tree
Hide file tree
Showing 2 changed files with 380 additions and 4 deletions.
85 changes: 85 additions & 0 deletions runtime/parachains/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,31 @@ pub struct HostConfiguration<BlockNumber> {
/// The maximum amount of weight any individual upward message may consume. Messages above this
/// weight go into the overweight queue and may only be serviced explicitly.
pub ump_max_individual_weight: Weight,
/// This flag controls whether PVF pre-checking is enabled.
///
/// If the flag is false, the behavior should be exactly the same as prior. Specifically, the
/// upgrade procedure is time-based and parachains that do not look at the go-ahead signal
/// should still work.
pub pvf_checking_enabled: bool,
/// If the PVF pre-checking voting observes this many number of sessions it gets automatically
/// rejected.
///
/// 0 means PVF pre-checking will be rejected on the first observed session unless the voting
/// gained supermajority before that the session change.
pub pvf_voting_ttl: SessionIndex,
/// The lower bound number of blocks an upgrade can be scheduled.
///
/// Typically, upgrade gets scheduled [`validation_upgrade_delay`] relay-chain blocks after
/// the relay-parent of the parablock that signalled the validation code upgrade. However,
/// in the case a pre-checking voting was concluded in a longer duration the upgrade will be
/// scheduled to the next block.
///
/// That can disrupt parachain inclusion. Specifically, it will make the blocks that were
/// already backed invalid.
///
/// To prevent that, we introduce the minimum number of blocks after which the upgrade can be
/// scheduled. This number is controlled by this field.
pub minimum_validation_upgrade_delay: BlockNumber,
}

impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber> {
Expand Down Expand Up @@ -222,6 +247,9 @@ impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber
hrmp_max_parathread_outbound_channels: Default::default(),
hrmp_max_message_num_per_candidate: Default::default(),
ump_max_individual_weight: 20 * WEIGHT_PER_MILLIS,
pvf_checking_enabled: false,
pvf_voting_ttl: 2u32.into(),
minimum_validation_upgrade_delay: 0.into(),
}
}
}
Expand Down Expand Up @@ -947,6 +975,49 @@ pub mod pallet {
});
Ok(())
}

/// Enable or disable PVF pre-checking. Consult the field documentation prior executing.
#[pallet::weight((
T::WeightInfo::set_config_with_u32(), // TODO: should we change that to bool?
DispatchClass::Operational,
))]
pub fn set_pvf_checking_enabled(origin: OriginFor<T>, new: bool) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
sp_std::mem::replace(&mut config.pvf_checking_enabled, new) != new
});
Ok(())
}

/// Set the number of session changes after which a PVF pre-checking voting is rejected.
#[pallet::weight((
T::WeightInfo::set_config_with_u32(),
DispatchClass::Operational,
))]
pub fn set_pvf_voting_ttl(origin: OriginFor<T>, new: SessionIndex) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
sp_std::mem::replace(&mut config.pvf_voting_ttl, new) != new
});
Ok(())
}

/// Sets the minimum delay between announcing the upgrade block for a parachain until the
/// upgrade taking place.
#[pallet::weight((
T::WeightInfo::set_config_with_block_number(),
DispatchClass::Operational,
))]
pub fn set_minimum_validation_upgrade_delay(
origin: OriginFor<T>,
new: T::BlockNumber,
) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
sp_std::mem::replace(&mut config.minimum_validation_upgrade_delay, new) != new
});
Ok(())
}
}

#[pallet::hooks]
Expand Down Expand Up @@ -1086,6 +1157,9 @@ mod tests {
hrmp_max_parathread_outbound_channels: 200,
hrmp_max_message_num_per_candidate: 20,
ump_max_individual_weight: 909,
pvf_checking_enabled: true,
pvf_voting_ttl: 3,
minimum_validation_upgrade_delay: 20,
};

assert!(<Configuration as Store>::PendingConfig::get(shared::SESSION_DELAY).is_none());
Expand Down Expand Up @@ -1252,6 +1326,17 @@ mod tests {
new_config.ump_max_individual_weight,
)
.unwrap();
Configuration::set_pvf_checking_enabled(
Origin::root(),
new_config.pvf_checking_enabled,
)
.unwrap();
Configuration::set_pvf_voting_ttl(Origin::root(), new_config.pvf_voting_ttl).unwrap();
Configuration::set_minimum_validation_upgrade_delay(
Origin::root(),
new_config.minimum_validation_upgrade_delay,
)
.unwrap();

assert_eq!(
<Configuration as Store>::PendingConfig::get(shared::SESSION_DELAY),
Expand Down
Loading

0 comments on commit 2be5ed0

Please sign in to comment.