Selectable on-runtime-upgrade checks (#13045)

* Make try-runtime checks selectable

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/support/src/traits/try_runtime.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Add Clap wrapper for enum UpgradeCheckSelect

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "Add Clap wrapper for enum UpgradeCheckSelect"

This reverts commit e29538c1a79d1711b43addc9400d871f6aa32844.

* fix pools sanity check

* Set default for --checks to None

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make --checks backwards comp

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add clap attr comment

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: kianenigma <kian@parity.io>
This commit is contained in:
Oliver Tale-Yazdi
2023-01-04 13:44:41 +01:00
committed by GitHub
parent 7ead16802e
commit d0bbec32ad
8 changed files with 79 additions and 21 deletions
@@ -21,7 +21,7 @@ use impl_trait_for_tuples::impl_for_tuples;
use sp_arithmetic::traits::AtLeast32BitUnsigned;
use sp_std::prelude::*;
// Which state tests to execute.
/// Which state tests to execute.
#[derive(codec::Encode, codec::Decode, Clone)]
pub enum Select {
/// None of them.
@@ -81,6 +81,46 @@ impl sp_std::str::FromStr for Select {
}
}
/// Select which checks should be run when trying a runtime upgrade upgrade.
#[derive(codec::Encode, codec::Decode, Clone, Debug, Copy)]
pub enum UpgradeCheckSelect {
/// Run no checks.
None,
/// Run the `try_state`, `pre_upgrade` and `post_upgrade` checks.
All,
/// Run the `pre_upgrade` and `post_upgrade` checks.
PreAndPost,
/// Run the `try_state` checks.
TryState,
}
impl UpgradeCheckSelect {
/// Whether the pre- and post-upgrade checks are selected.
pub fn pre_and_post(&self) -> bool {
matches!(self, Self::All | Self::PreAndPost)
}
/// Whether the try-state checks are selected.
pub fn try_state(&self) -> bool {
matches!(self, Self::All | Self::TryState)
}
}
#[cfg(feature = "std")]
impl core::str::FromStr for UpgradeCheckSelect {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"none" => Ok(Self::None),
"all" => Ok(Self::All),
"pre-and-post" => Ok(Self::PreAndPost),
"try-state" => Ok(Self::TryState),
_ => Err("Invalid CheckSelector"),
}
}
}
/// Execute some checks to ensure the internal state of a pallet is consistent.
///
/// Usually, these checks should check all of the invariants that are expected to be held on all of