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

Introduce prechecking into the configuration runtime #4177

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,7 @@ impl<T: frame_system::Config> runtime_parachains::configuration::WeightInfo for
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn set_config_with_bool() -> Weight {
todo!()
}
}
89 changes: 89 additions & 0 deletions runtime/parachains/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ pub struct HostConfiguration<BlockNumber> {
/// The delay, in blocks, before a validation upgrade is applied.
pub validation_upgrade_delay: BlockNumber,

// TODO: Which section do these belong to?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do not need to expose those to the parachains, at least not yet.

The closest is the pvf_upgrade_delay, but the idea is that parachains will look at the go-ahead signal anyway for synchronizing of the upgrades, so it is not needed as well.

/// Additional delay applied for parachains when they upgrade their runtime (see `pvf_upgrade_delay`).
pub min_upgrade_delay: BlockNumber,
/// Disables PVF prechecking.
pub pvf_prechecking_bypass: bool,

// TODO: Is this additional field needed? Could simply keep validation_upgrade_delay.
// Also the naming is questionable.
/// The delay, in blocks, before the stored PVF becomes usable.
pub pvf_upgrade_delay: BlockNumber,
/// The number of session changes a PVF pre-checking voting can observe, exclusive,
/// i.e. observing at least this many would cause a PVF to get rejected.
pub pvf_voting_ttl: SessionIndex,

/**
* The parameters that are not essential, but still may be of interest for parachains.
*/
Expand Down Expand Up @@ -188,6 +202,11 @@ impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber
no_show_slots: 1u32.into(),
validation_upgrade_frequency: Default::default(),
validation_upgrade_delay: Default::default(),
// TODO: defaults for migration.
min_upgrade_delay: Default::default(),
pvf_prechecking_bypass: Default::default(),
pvf_upgrade_delay: Default::default(),
pvf_voting_ttl: Default::default(),
code_retention_period: Default::default(),
max_code_size: Default::default(),
max_pov_size: Default::default(),
Expand Down Expand Up @@ -276,6 +295,7 @@ pub trait WeightInfo {
fn set_config_with_weight() -> Weight;
fn set_config_with_balance() -> Weight;
fn set_hrmp_open_request_ttl() -> Weight;
fn set_config_with_bool() -> Weight;
}

pub struct TestWeightInfo;
Expand All @@ -298,6 +318,9 @@ impl WeightInfo for TestWeightInfo {
fn set_hrmp_open_request_ttl() -> Weight {
Weight::MAX
}
fn set_config_with_bool() -> Weight {
Weight::MAX
}
}

#[frame_support::pallet]
Expand Down Expand Up @@ -947,6 +970,58 @@ pub mod pallet {
});
Ok(())
}

/// Set the minimum upgrade delay.
#[pallet::weight((
T::WeightInfo::set_config_with_block_number(),
DispatchClass::Operational,
))]
pub fn set_min_upgrade_delay(origin: OriginFor<T>, new: T::BlockNumber) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
sp_std::mem::replace(&mut config.min_upgrade_delay, new) != new
});
Ok(())
}

/// Enable or disable PVF prechecking.
#[pallet::weight((
T::WeightInfo::set_config_with_bool(),
DispatchClass::Operational,
))]
pub fn set_pvf_prechecking_bypass(origin: OriginFor<T>, new: bool) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
sp_std::mem::replace(&mut config.pvf_prechecking_bypass, new) != new
});
Ok(())
}

/// Set the minimum delay in blocks for PVF upgrades.
#[pallet::weight((
T::WeightInfo::set_config_with_block_number(),
DispatchClass::Operational,
))]
pub fn set_pvf_upgrade_delay(origin: OriginFor<T>, new: T::BlockNumber) -> DispatchResult {
ensure_root(origin)?;
Self::update_config_member(|config| {
sp_std::mem::replace(&mut config.pvf_upgrade_delay, new) != new
});
Ok(())
}

/// Set the number of session changes a PVF pre-checking voting can observe.
#[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(())
}
}

#[pallet::hooks]
Expand Down Expand Up @@ -1048,6 +1123,10 @@ mod tests {
let new_config = HostConfiguration {
validation_upgrade_frequency: 100,
validation_upgrade_delay: 10,
min_upgrade_delay: 15,
pvf_prechecking_bypass: false,
pvf_upgrade_delay: 10,
pvf_voting_ttl: 100,
code_retention_period: 5,
max_code_size: 100_000,
max_pov_size: 1024,
Expand Down Expand Up @@ -1100,6 +1179,16 @@ mod tests {
new_config.validation_upgrade_delay,
)
.unwrap();
Configuration::set_min_upgrade_delay(Origin::root(), new_config.min_upgrade_delay)
.unwrap();
Configuration::set_pvf_prechecking_bypass(
Origin::root(),
new_config.pvf_prechecking_bypass,
)
.unwrap();
Configuration::set_pvf_upgrade_delay(Origin::root(), new_config.pvf_upgrade_delay)
.unwrap();
Configuration::set_pvf_voting_ttl(Origin::root(), new_config.pvf_voting_ttl).unwrap();
Configuration::set_code_retention_period(
Origin::root(),
new_config.code_retention_period,
Expand Down
2 changes: 2 additions & 0 deletions runtime/parachains/src/configuration/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ benchmarks! {

set_config_with_balance {}: set_hrmp_sender_deposit(RawOrigin::Root, 100_000_000_000)

set_config_with_bool {}: set_pvf_prechecking_bypass(RawOrigin::Root, true)

impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(Default::default()),
Expand Down
Loading