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

Commit 1629aaa

Browse files
committed
pvf-precheck: update configuration module
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.
1 parent 7e91fa0 commit 1629aaa

2 files changed

Lines changed: 381 additions & 4 deletions

File tree

runtime/parachains/src/configuration.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,31 @@ pub struct HostConfiguration<BlockNumber> {
177177
/// The maximum amount of weight any individual upward message may consume. Messages above this
178178
/// weight go into the overweight queue and may only be serviced explicitly.
179179
pub ump_max_individual_weight: Weight,
180+
/// This flag controls whether PVF pre-checking is enabled.
181+
///
182+
/// If the flag is false, the behavior should be exactly the same as prior. Specifically, the
183+
/// upgrade procedure is time-based and parachains that do not look at the go-ahead signal
184+
/// should still work.
185+
pub pvf_checking_enabled: bool,
186+
/// If the PVF pre-checking voting observes this many number of sessions it gets automatically
187+
/// rejected.
188+
///
189+
/// 0 means PVF pre-checking will be rejected on the first observed session unless the voting
190+
/// gained supermajority before that the session change.
191+
pub pvf_voting_ttl: SessionIndex,
192+
/// The lower bound number of blocks an upgrade can be scheduled.
193+
///
194+
/// Typically, upgrade gets scheduled [`validation_upgrade_delay`] relay-chain blocks after
195+
/// the relay-parent of the parablock that signalled the validation code upgrade. However,
196+
/// in the case a pre-checking voting was concluded in a longer duration the upgrade will be
197+
/// scheduled to the next block.
198+
///
199+
/// That can disrupt parachain inclusion. Specifically, it will make the blocks that were
200+
/// already backed invalid.
201+
///
202+
/// To prevent that, we introduce the minimum number of blocks after which the upgrade can be
203+
/// scheduled. This number is controlled by this field.
204+
pub minimum_validation_upgrade_delay: BlockNumber,
180205
}
181206

182207
impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber> {
@@ -222,6 +247,9 @@ impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber
222247
hrmp_max_parathread_outbound_channels: Default::default(),
223248
hrmp_max_message_num_per_candidate: Default::default(),
224249
ump_max_individual_weight: 20 * WEIGHT_PER_MILLIS,
250+
pvf_checking_enabled: false,
251+
pvf_voting_ttl: 2u32.into(),
252+
minimum_validation_upgrade_delay: 0.into(),
225253
}
226254
}
227255
}
@@ -947,6 +975,50 @@ pub mod pallet {
947975
});
948976
Ok(())
949977
}
978+
979+
/// Enable or disable PVF pre-checking. Consult the field documentation prior executing.
980+
#[pallet::weight((
981+
// Using u32 here is a little bit of cheating, but that should be fine.
982+
T::WeightInfo::set_config_with_u32(),
983+
DispatchClass::Operational,
984+
))]
985+
pub fn set_pvf_checking_enabled(origin: OriginFor<T>, new: bool) -> DispatchResult {
986+
ensure_root(origin)?;
987+
Self::update_config_member(|config| {
988+
sp_std::mem::replace(&mut config.pvf_checking_enabled, new) != new
989+
});
990+
Ok(())
991+
}
992+
993+
/// Set the number of session changes after which a PVF pre-checking voting is rejected.
994+
#[pallet::weight((
995+
T::WeightInfo::set_config_with_u32(),
996+
DispatchClass::Operational,
997+
))]
998+
pub fn set_pvf_voting_ttl(origin: OriginFor<T>, new: SessionIndex) -> DispatchResult {
999+
ensure_root(origin)?;
1000+
Self::update_config_member(|config| {
1001+
sp_std::mem::replace(&mut config.pvf_voting_ttl, new) != new
1002+
});
1003+
Ok(())
1004+
}
1005+
1006+
/// Sets the minimum delay between announcing the upgrade block for a parachain until the
1007+
/// upgrade taking place.
1008+
#[pallet::weight((
1009+
T::WeightInfo::set_config_with_block_number(),
1010+
DispatchClass::Operational,
1011+
))]
1012+
pub fn set_minimum_validation_upgrade_delay(
1013+
origin: OriginFor<T>,
1014+
new: T::BlockNumber,
1015+
) -> DispatchResult {
1016+
ensure_root(origin)?;
1017+
Self::update_config_member(|config| {
1018+
sp_std::mem::replace(&mut config.minimum_validation_upgrade_delay, new) != new
1019+
});
1020+
Ok(())
1021+
}
9501022
}
9511023

9521024
#[pallet::hooks]
@@ -1086,6 +1158,9 @@ mod tests {
10861158
hrmp_max_parathread_outbound_channels: 200,
10871159
hrmp_max_message_num_per_candidate: 20,
10881160
ump_max_individual_weight: 909,
1161+
pvf_checking_enabled: true,
1162+
pvf_voting_ttl: 3,
1163+
minimum_validation_upgrade_delay: 20,
10891164
};
10901165

10911166
assert!(<Configuration as Store>::PendingConfig::get(shared::SESSION_DELAY).is_none());
@@ -1252,6 +1327,17 @@ mod tests {
12521327
new_config.ump_max_individual_weight,
12531328
)
12541329
.unwrap();
1330+
Configuration::set_pvf_checking_enabled(
1331+
Origin::root(),
1332+
new_config.pvf_checking_enabled,
1333+
)
1334+
.unwrap();
1335+
Configuration::set_pvf_voting_ttl(Origin::root(), new_config.pvf_voting_ttl).unwrap();
1336+
Configuration::set_minimum_validation_upgrade_delay(
1337+
Origin::root(),
1338+
new_config.minimum_validation_upgrade_delay,
1339+
)
1340+
.unwrap();
12551341

12561342
assert_eq!(
12571343
<Configuration as Store>::PendingConfig::get(shared::SESSION_DELAY),

0 commit comments

Comments
 (0)