allow to write pre and post runtime upgrade in pallet macro (#8194)

This commit is contained in:
Guillaume Thiolliere
2021-02-25 11:43:48 +01:00
committed by GitHub
parent f0c3656489
commit 5232e8ad5c
48 changed files with 136 additions and 6 deletions
@@ -51,3 +51,4 @@ std = [
'frame-support/std',
'frame-system/std'
]
try-runtime = ["frame-support/try-runtime"]
+36
View File
@@ -154,6 +154,7 @@ std = [
"pallet-society/std",
"pallet-recovery/std",
"pallet-vesting/std",
"frame-try-runtime/std",
]
runtime-benchmarks = [
"frame-benchmarking",
@@ -193,4 +194,39 @@ runtime-benchmarks = [
try-runtime = [
"frame-executive/try-runtime",
"frame-try-runtime",
"frame-system/try-runtime",
"pallet-assets/try-runtime",
"pallet-authority-discovery/try-runtime",
"pallet-authorship/try-runtime",
"pallet-babe/try-runtime",
"pallet-balances/try-runtime",
"pallet-bounties/try-runtime",
"pallet-collective/try-runtime",
"pallet-contracts/try-runtime",
"pallet-democracy/try-runtime",
"pallet-elections-phragmen/try-runtime",
"pallet-grandpa/try-runtime",
"pallet-im-online/try-runtime",
"pallet-indices/try-runtime",
"pallet-lottery/try-runtime",
"pallet-membership/try-runtime",
"pallet-mmr/try-runtime",
"pallet-multisig/try-runtime",
"pallet-identity/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-offences/try-runtime",
"pallet-proxy/try-runtime",
"pallet-randomness-collective-flip/try-runtime",
"pallet-session/try-runtime",
"pallet-staking/try-runtime",
"pallet-sudo/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-tips/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-utility/try-runtime",
"pallet-society/try-runtime",
"pallet-recovery/try-runtime",
"pallet-vesting/try-runtime",
]
+1
View File
@@ -46,3 +46,4 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -37,3 +37,4 @@ std = [
"sp-io/std",
"sp-core/std",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -45,3 +45,4 @@ std = [
"sp-timestamp/std",
"pallet-timestamp/std",
]
try-runtime = ["frame-support/try-runtime"]
@@ -41,3 +41,4 @@ std = [
"frame-support/std",
"frame-system/std",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -38,3 +38,4 @@ std = [
"frame-system/std",
"sp-authorship/std",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -61,3 +61,4 @@ std = [
"sp-timestamp/std",
]
runtime-benchmarks = ["frame-benchmarking"]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -38,3 +38,4 @@ std = [
"frame-system/std",
]
runtime-benchmarks = ["frame-benchmarking"]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -45,3 +45,4 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -44,3 +44,4 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -69,3 +69,4 @@ runtime-benchmarks = [
"rand",
"rand_pcg",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -48,3 +48,4 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
@@ -64,3 +64,4 @@ runtime-benchmarks = [
"frame-benchmarking",
"rand",
]
try-runtime = ["frame-support/try-runtime"]
@@ -45,3 +45,4 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -38,3 +38,4 @@ std = [
"sp-runtime/std",
"frame-system/std",
]
try-runtime = ["frame-support/try-runtime"]
@@ -38,3 +38,4 @@ std = [
"sp-runtime/std",
"sp-std/std",
]
try-runtime = ["frame-support/try-runtime"]
@@ -36,3 +36,4 @@ std = [
"sp-std/std",
"sp-tasks/std",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -59,3 +59,4 @@ std = [
"pallet-session/std",
]
runtime-benchmarks = ["frame-benchmarking"]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -40,3 +40,4 @@ std = [
"frame-system/std",
]
runtime-benchmarks = ["frame-benchmarking"]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -46,3 +46,4 @@ std = [
"frame-system/std",
]
runtime-benchmarks = ["frame-benchmarking"]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -45,3 +45,4 @@ runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -41,3 +41,4 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -35,3 +35,4 @@ std = [
"frame-support/std",
"frame-system/std",
]
try-runtime = ["frame-support/try-runtime"]
@@ -44,3 +44,4 @@ std = [
"sp-std/std",
]
runtime-benchmarks = ["frame-benchmarking"]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -43,3 +43,4 @@ runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -36,3 +36,4 @@ std = [
"frame-support/std",
"frame-system/std",
]
try-runtime = ["frame-support/try-runtime"]
@@ -33,3 +33,4 @@ std = [
"sp-runtime/std",
"sp-std/std",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -39,3 +39,4 @@ std = [
"frame-system/std",
]
runtime-benchmarks = []
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -44,3 +44,4 @@ runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
@@ -35,3 +35,4 @@ std = [
"sp-runtime/std",
"sp-std/std",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -37,3 +37,4 @@ std = [
"frame-support/std",
"frame-system/std",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -41,3 +41,4 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -36,3 +36,4 @@ std = [
"frame-support/std",
"frame-system/std",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -47,3 +47,4 @@ std = [
"pallet-timestamp/std",
"sp-trie/std",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -41,3 +41,4 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -69,3 +69,4 @@ runtime-benchmarks = [
"sp-election-providers/runtime-benchmarks",
"rand_chacha",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -35,3 +35,4 @@ std = [
"frame-support/std",
"frame-system/std",
]
try-runtime = ["frame-support/try-runtime"]
@@ -75,6 +75,24 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
result.saturating_add(additional_write)
}
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
<
Self
as
#frame_support::traits::Hooks<<T as #frame_system::Config>::BlockNumber>
>::pre_upgrade()
}
#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
<
Self
as
#frame_support::traits::Hooks<<T as #frame_system::Config>::BlockNumber>
>::post_upgrade()
}
}
impl<#type_impl_gen>
+20
View File
@@ -1334,6 +1334,16 @@ macro_rules! decl_module {
result.saturating_add(additional_write)
}
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
Ok(())
}
#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
Ok(())
}
}
};
@@ -1356,6 +1366,16 @@ macro_rules! decl_module {
<$trait_instance as $system::Config>::DbWeight as $crate::traits::Get<_>
>::get().writes(1)
}
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
Ok(())
}
#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
Ok(())
}
}
};
+18 -6
View File
@@ -1575,17 +1575,13 @@ pub trait OnRuntimeUpgrade {
///
/// This hook is never meant to be executed on-chain but is meant to be used by testing tools.
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
Ok(())
}
fn pre_upgrade() -> Result<(), &'static str>;
/// Execute some post-checks after a runtime upgrade.
///
/// This hook is never meant to be executed on-chain but is meant to be used by testing tools.
#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
Ok(())
}
fn post_upgrade() -> Result<(), &'static str>;
}
#[impl_for_tuples(30)]
@@ -2012,6 +2008,22 @@ pub trait Hooks<BlockNumber> {
/// Return the non-negotiable weight consumed for runtime upgrade.
fn on_runtime_upgrade() -> crate::weights::Weight { 0 }
/// Execute some pre-checks prior to a runtime upgrade.
///
/// This hook is never meant to be executed on-chain but is meant to be used by testing tools.
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
Ok(())
}
/// Execute some post-checks after a runtime upgrade.
///
/// This hook is never meant to be executed on-chain but is meant to be used by testing tools.
#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
Ok(())
}
/// Implementing this function on a module allows you to perform long-running tasks
/// that make (by default) validators generate transactions that feed results
/// of those long-running computations back on chain.
+1
View File
@@ -44,6 +44,7 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"frame-support/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
[[bench]]
name = "bench"
+1
View File
@@ -45,3 +45,4 @@ std = [
"sp-timestamp/std"
]
runtime-benchmarks = ["frame-benchmarking", "sp-io"]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -45,3 +45,4 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
@@ -40,3 +40,4 @@ std = [
"sp-io/std",
"sp-core/std",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -45,3 +45,4 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -43,3 +43,4 @@ runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
+1
View File
@@ -40,3 +40,4 @@ std = [
"frame-system/std",
]
runtime-benchmarks = ["frame-benchmarking"]
try-runtime = ["frame-support/try-runtime"]