From 5232e8ad5c61ff28c480e9217d5c3b64560a6385 Mon Sep 17 00:00:00 2001 From: Guillaume Thiolliere <gui.thiolliere@gmail.com> Date: Thu, 25 Feb 2021 11:43:48 +0100 Subject: [PATCH] allow to write pre and post runtime upgrade in pallet macro (#8194) --- .../node-template/pallets/template/Cargo.toml | 1 + substrate/bin/node/runtime/Cargo.toml | 36 +++++++++++++++++++ substrate/frame/assets/Cargo.toml | 1 + substrate/frame/atomic-swap/Cargo.toml | 1 + substrate/frame/aura/Cargo.toml | 1 + .../frame/authority-discovery/Cargo.toml | 1 + substrate/frame/authorship/Cargo.toml | 1 + substrate/frame/babe/Cargo.toml | 1 + substrate/frame/balances/Cargo.toml | 1 + substrate/frame/bounties/Cargo.toml | 1 + substrate/frame/collective/Cargo.toml | 1 + substrate/frame/contracts/Cargo.toml | 1 + substrate/frame/democracy/Cargo.toml | 1 + .../election-provider-multi-phase/Cargo.toml | 1 + substrate/frame/elections-phragmen/Cargo.toml | 1 + substrate/frame/elections/Cargo.toml | 1 + .../frame/example-offchain-worker/Cargo.toml | 1 + substrate/frame/example-parallel/Cargo.toml | 1 + substrate/frame/grandpa/Cargo.toml | 1 + substrate/frame/identity/Cargo.toml | 1 + substrate/frame/im-online/Cargo.toml | 1 + substrate/frame/indices/Cargo.toml | 1 + substrate/frame/lottery/Cargo.toml | 1 + substrate/frame/membership/Cargo.toml | 1 + .../frame/merkle-mountain-range/Cargo.toml | 1 + substrate/frame/multisig/Cargo.toml | 1 + substrate/frame/nicks/Cargo.toml | 1 + substrate/frame/node-authorization/Cargo.toml | 1 + substrate/frame/offences/Cargo.toml | 1 + substrate/frame/proxy/Cargo.toml | 1 + .../randomness-collective-flip/Cargo.toml | 1 + substrate/frame/recovery/Cargo.toml | 1 + substrate/frame/scheduler/Cargo.toml | 1 + substrate/frame/scored-pool/Cargo.toml | 1 + substrate/frame/session/Cargo.toml | 1 + substrate/frame/society/Cargo.toml | 1 + substrate/frame/staking/Cargo.toml | 1 + substrate/frame/sudo/Cargo.toml | 1 + .../procedural/src/pallet/expand/hooks.rs | 18 ++++++++++ substrate/frame/support/src/dispatch.rs | 20 +++++++++++ substrate/frame/support/src/traits.rs | 24 +++++++++---- substrate/frame/system/Cargo.toml | 1 + substrate/frame/timestamp/Cargo.toml | 1 + substrate/frame/tips/Cargo.toml | 1 + .../frame/transaction-payment/Cargo.toml | 1 + substrate/frame/treasury/Cargo.toml | 1 + substrate/frame/utility/Cargo.toml | 1 + substrate/frame/vesting/Cargo.toml | 1 + 48 files changed, 136 insertions(+), 6 deletions(-) diff --git a/substrate/bin/node-template/pallets/template/Cargo.toml b/substrate/bin/node-template/pallets/template/Cargo.toml index a13d05082b0..e6c0c5ac062 100644 --- a/substrate/bin/node-template/pallets/template/Cargo.toml +++ b/substrate/bin/node-template/pallets/template/Cargo.toml @@ -51,3 +51,4 @@ std = [ 'frame-support/std', 'frame-system/std' ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index a803d141c9e..6e615759db3 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -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", ] diff --git a/substrate/frame/assets/Cargo.toml b/substrate/frame/assets/Cargo.toml index 67fa0af3d63..9be2d6d0910 100644 --- a/substrate/frame/assets/Cargo.toml +++ b/substrate/frame/assets/Cargo.toml @@ -46,3 +46,4 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "frame-system/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/atomic-swap/Cargo.toml b/substrate/frame/atomic-swap/Cargo.toml index 99ce41f3993..a3b62d65e56 100644 --- a/substrate/frame/atomic-swap/Cargo.toml +++ b/substrate/frame/atomic-swap/Cargo.toml @@ -37,3 +37,4 @@ std = [ "sp-io/std", "sp-core/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/aura/Cargo.toml b/substrate/frame/aura/Cargo.toml index 80ea164cf0f..5f299cfbe09 100644 --- a/substrate/frame/aura/Cargo.toml +++ b/substrate/frame/aura/Cargo.toml @@ -45,3 +45,4 @@ std = [ "sp-timestamp/std", "pallet-timestamp/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/authority-discovery/Cargo.toml b/substrate/frame/authority-discovery/Cargo.toml index 43a09b01fd4..85844cf716f 100644 --- a/substrate/frame/authority-discovery/Cargo.toml +++ b/substrate/frame/authority-discovery/Cargo.toml @@ -41,3 +41,4 @@ std = [ "frame-support/std", "frame-system/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/authorship/Cargo.toml b/substrate/frame/authorship/Cargo.toml index ab48fbec8f5..3bbbe9749c6 100644 --- a/substrate/frame/authorship/Cargo.toml +++ b/substrate/frame/authorship/Cargo.toml @@ -38,3 +38,4 @@ std = [ "frame-system/std", "sp-authorship/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/babe/Cargo.toml b/substrate/frame/babe/Cargo.toml index f0d90214263..3b9b16d294e 100644 --- a/substrate/frame/babe/Cargo.toml +++ b/substrate/frame/babe/Cargo.toml @@ -61,3 +61,4 @@ std = [ "sp-timestamp/std", ] runtime-benchmarks = ["frame-benchmarking"] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/balances/Cargo.toml b/substrate/frame/balances/Cargo.toml index 39b7fda77fe..2b1cde70d3d 100644 --- a/substrate/frame/balances/Cargo.toml +++ b/substrate/frame/balances/Cargo.toml @@ -38,3 +38,4 @@ std = [ "frame-system/std", ] runtime-benchmarks = ["frame-benchmarking"] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/bounties/Cargo.toml b/substrate/frame/bounties/Cargo.toml index ec4f1b94cd6..090458c0162 100644 --- a/substrate/frame/bounties/Cargo.toml +++ b/substrate/frame/bounties/Cargo.toml @@ -45,3 +45,4 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/collective/Cargo.toml b/substrate/frame/collective/Cargo.toml index 0c58f416401..0bddb400e60 100644 --- a/substrate/frame/collective/Cargo.toml +++ b/substrate/frame/collective/Cargo.toml @@ -44,3 +44,4 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "frame-system/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/contracts/Cargo.toml b/substrate/frame/contracts/Cargo.toml index c5ba615504c..3cff8dbfa9b 100644 --- a/substrate/frame/contracts/Cargo.toml +++ b/substrate/frame/contracts/Cargo.toml @@ -69,3 +69,4 @@ runtime-benchmarks = [ "rand", "rand_pcg", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/democracy/Cargo.toml b/substrate/frame/democracy/Cargo.toml index 2e675dd2518..3cd859a9b67 100644 --- a/substrate/frame/democracy/Cargo.toml +++ b/substrate/frame/democracy/Cargo.toml @@ -48,3 +48,4 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/election-provider-multi-phase/Cargo.toml b/substrate/frame/election-provider-multi-phase/Cargo.toml index e52093ce135..851db01bfa3 100644 --- a/substrate/frame/election-provider-multi-phase/Cargo.toml +++ b/substrate/frame/election-provider-multi-phase/Cargo.toml @@ -64,3 +64,4 @@ runtime-benchmarks = [ "frame-benchmarking", "rand", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/elections-phragmen/Cargo.toml b/substrate/frame/elections-phragmen/Cargo.toml index bdb301c73ec..ce568d1d8ea 100644 --- a/substrate/frame/elections-phragmen/Cargo.toml +++ b/substrate/frame/elections-phragmen/Cargo.toml @@ -45,3 +45,4 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/elections/Cargo.toml b/substrate/frame/elections/Cargo.toml index a13c6d7567f..ac3c709300f 100644 --- a/substrate/frame/elections/Cargo.toml +++ b/substrate/frame/elections/Cargo.toml @@ -38,3 +38,4 @@ std = [ "sp-runtime/std", "frame-system/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/example-offchain-worker/Cargo.toml b/substrate/frame/example-offchain-worker/Cargo.toml index 5a2db258f8a..cf4b3beaa90 100644 --- a/substrate/frame/example-offchain-worker/Cargo.toml +++ b/substrate/frame/example-offchain-worker/Cargo.toml @@ -38,3 +38,4 @@ std = [ "sp-runtime/std", "sp-std/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/example-parallel/Cargo.toml b/substrate/frame/example-parallel/Cargo.toml index b2f28887cec..2c593db7ec9 100644 --- a/substrate/frame/example-parallel/Cargo.toml +++ b/substrate/frame/example-parallel/Cargo.toml @@ -36,3 +36,4 @@ std = [ "sp-std/std", "sp-tasks/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/grandpa/Cargo.toml b/substrate/frame/grandpa/Cargo.toml index 39207e10f8f..692674155c1 100644 --- a/substrate/frame/grandpa/Cargo.toml +++ b/substrate/frame/grandpa/Cargo.toml @@ -59,3 +59,4 @@ std = [ "pallet-session/std", ] runtime-benchmarks = ["frame-benchmarking"] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/identity/Cargo.toml b/substrate/frame/identity/Cargo.toml index 3fd0c30a0f8..1db480ecb94 100644 --- a/substrate/frame/identity/Cargo.toml +++ b/substrate/frame/identity/Cargo.toml @@ -40,3 +40,4 @@ std = [ "frame-system/std", ] runtime-benchmarks = ["frame-benchmarking"] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/im-online/Cargo.toml b/substrate/frame/im-online/Cargo.toml index bde041c4376..6e7f4b03abb 100644 --- a/substrate/frame/im-online/Cargo.toml +++ b/substrate/frame/im-online/Cargo.toml @@ -46,3 +46,4 @@ std = [ "frame-system/std", ] runtime-benchmarks = ["frame-benchmarking"] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/indices/Cargo.toml b/substrate/frame/indices/Cargo.toml index cde3cdeeecb..0d99fbb1348 100644 --- a/substrate/frame/indices/Cargo.toml +++ b/substrate/frame/indices/Cargo.toml @@ -45,3 +45,4 @@ runtime-benchmarks = [ "frame-benchmarking", "frame-support/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/lottery/Cargo.toml b/substrate/frame/lottery/Cargo.toml index 05bb7e385f5..94cd6d2325e 100644 --- a/substrate/frame/lottery/Cargo.toml +++ b/substrate/frame/lottery/Cargo.toml @@ -41,3 +41,4 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "frame-support/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/membership/Cargo.toml b/substrate/frame/membership/Cargo.toml index 98987e6fe90..37e7aa2cb82 100644 --- a/substrate/frame/membership/Cargo.toml +++ b/substrate/frame/membership/Cargo.toml @@ -35,3 +35,4 @@ std = [ "frame-support/std", "frame-system/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/merkle-mountain-range/Cargo.toml b/substrate/frame/merkle-mountain-range/Cargo.toml index eea3845ae16..c1fe0aca848 100644 --- a/substrate/frame/merkle-mountain-range/Cargo.toml +++ b/substrate/frame/merkle-mountain-range/Cargo.toml @@ -44,3 +44,4 @@ std = [ "sp-std/std", ] runtime-benchmarks = ["frame-benchmarking"] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/multisig/Cargo.toml b/substrate/frame/multisig/Cargo.toml index e8d62513837..451cc1033b9 100644 --- a/substrate/frame/multisig/Cargo.toml +++ b/substrate/frame/multisig/Cargo.toml @@ -43,3 +43,4 @@ runtime-benchmarks = [ "frame-benchmarking", "frame-support/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/nicks/Cargo.toml b/substrate/frame/nicks/Cargo.toml index 611f492b81f..6c8b609b401 100644 --- a/substrate/frame/nicks/Cargo.toml +++ b/substrate/frame/nicks/Cargo.toml @@ -36,3 +36,4 @@ std = [ "frame-support/std", "frame-system/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/node-authorization/Cargo.toml b/substrate/frame/node-authorization/Cargo.toml index db77f25c188..b76976d831c 100644 --- a/substrate/frame/node-authorization/Cargo.toml +++ b/substrate/frame/node-authorization/Cargo.toml @@ -33,3 +33,4 @@ std = [ "sp-runtime/std", "sp-std/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/offences/Cargo.toml b/substrate/frame/offences/Cargo.toml index 3232d5f3ae5..cbf779df847 100644 --- a/substrate/frame/offences/Cargo.toml +++ b/substrate/frame/offences/Cargo.toml @@ -39,3 +39,4 @@ std = [ "frame-system/std", ] runtime-benchmarks = [] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/proxy/Cargo.toml b/substrate/frame/proxy/Cargo.toml index 9490364abd8..d297d324aa1 100644 --- a/substrate/frame/proxy/Cargo.toml +++ b/substrate/frame/proxy/Cargo.toml @@ -44,3 +44,4 @@ runtime-benchmarks = [ "frame-benchmarking", "frame-support/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/randomness-collective-flip/Cargo.toml b/substrate/frame/randomness-collective-flip/Cargo.toml index 285326ef1e9..ad9bcb97837 100644 --- a/substrate/frame/randomness-collective-flip/Cargo.toml +++ b/substrate/frame/randomness-collective-flip/Cargo.toml @@ -35,3 +35,4 @@ std = [ "sp-runtime/std", "sp-std/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/recovery/Cargo.toml b/substrate/frame/recovery/Cargo.toml index 80450db0bd3..1f8003bd4d0 100644 --- a/substrate/frame/recovery/Cargo.toml +++ b/substrate/frame/recovery/Cargo.toml @@ -37,3 +37,4 @@ std = [ "frame-support/std", "frame-system/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/scheduler/Cargo.toml b/substrate/frame/scheduler/Cargo.toml index eef287d8677..a0624247f5c 100644 --- a/substrate/frame/scheduler/Cargo.toml +++ b/substrate/frame/scheduler/Cargo.toml @@ -41,3 +41,4 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/scored-pool/Cargo.toml b/substrate/frame/scored-pool/Cargo.toml index e5e71dba688..97e3a954d7e 100644 --- a/substrate/frame/scored-pool/Cargo.toml +++ b/substrate/frame/scored-pool/Cargo.toml @@ -36,3 +36,4 @@ std = [ "frame-support/std", "frame-system/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/session/Cargo.toml b/substrate/frame/session/Cargo.toml index 5b8fe6e2d13..52b8ebbdf47 100644 --- a/substrate/frame/session/Cargo.toml +++ b/substrate/frame/session/Cargo.toml @@ -47,3 +47,4 @@ std = [ "pallet-timestamp/std", "sp-trie/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/society/Cargo.toml b/substrate/frame/society/Cargo.toml index 5ddebeb9f57..913e40e0301 100644 --- a/substrate/frame/society/Cargo.toml +++ b/substrate/frame/society/Cargo.toml @@ -41,3 +41,4 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "frame-system/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/staking/Cargo.toml b/substrate/frame/staking/Cargo.toml index 11de7e63ea9..21e5b4a5648 100644 --- a/substrate/frame/staking/Cargo.toml +++ b/substrate/frame/staking/Cargo.toml @@ -69,3 +69,4 @@ runtime-benchmarks = [ "sp-election-providers/runtime-benchmarks", "rand_chacha", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/sudo/Cargo.toml b/substrate/frame/sudo/Cargo.toml index ed19d2e1653..c1b841c30c6 100644 --- a/substrate/frame/sudo/Cargo.toml +++ b/substrate/frame/sudo/Cargo.toml @@ -35,3 +35,4 @@ std = [ "frame-support/std", "frame-system/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/support/procedural/src/pallet/expand/hooks.rs b/substrate/frame/support/procedural/src/pallet/expand/hooks.rs index 2e4fddebb7b..b1eee507fdf 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/hooks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/hooks.rs @@ -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> diff --git a/substrate/frame/support/src/dispatch.rs b/substrate/frame/support/src/dispatch.rs index 7927ccd014b..f5c8f017e34 100644 --- a/substrate/frame/support/src/dispatch.rs +++ b/substrate/frame/support/src/dispatch.rs @@ -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(()) + } } }; diff --git a/substrate/frame/support/src/traits.rs b/substrate/frame/support/src/traits.rs index 4114afa973c..f0ab3be642c 100644 --- a/substrate/frame/support/src/traits.rs +++ b/substrate/frame/support/src/traits.rs @@ -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. diff --git a/substrate/frame/system/Cargo.toml b/substrate/frame/system/Cargo.toml index c4530e9dfd0..4789f9b8add 100644 --- a/substrate/frame/system/Cargo.toml +++ b/substrate/frame/system/Cargo.toml @@ -44,6 +44,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "frame-support/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] [[bench]] name = "bench" diff --git a/substrate/frame/timestamp/Cargo.toml b/substrate/frame/timestamp/Cargo.toml index f4f7bbda0f8..843517049ad 100644 --- a/substrate/frame/timestamp/Cargo.toml +++ b/substrate/frame/timestamp/Cargo.toml @@ -45,3 +45,4 @@ std = [ "sp-timestamp/std" ] runtime-benchmarks = ["frame-benchmarking", "sp-io"] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/tips/Cargo.toml b/substrate/frame/tips/Cargo.toml index 92af65ce076..aa776ffaaf0 100644 --- a/substrate/frame/tips/Cargo.toml +++ b/substrate/frame/tips/Cargo.toml @@ -45,3 +45,4 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/transaction-payment/Cargo.toml b/substrate/frame/transaction-payment/Cargo.toml index 7a713ab1cfb..2a7fbe503ef 100644 --- a/substrate/frame/transaction-payment/Cargo.toml +++ b/substrate/frame/transaction-payment/Cargo.toml @@ -40,3 +40,4 @@ std = [ "sp-io/std", "sp-core/std", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/treasury/Cargo.toml b/substrate/frame/treasury/Cargo.toml index 461dc912239..186a5900cf0 100644 --- a/substrate/frame/treasury/Cargo.toml +++ b/substrate/frame/treasury/Cargo.toml @@ -45,3 +45,4 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/utility/Cargo.toml b/substrate/frame/utility/Cargo.toml index edb930231e1..b4f8b4943df 100644 --- a/substrate/frame/utility/Cargo.toml +++ b/substrate/frame/utility/Cargo.toml @@ -43,3 +43,4 @@ runtime-benchmarks = [ "frame-benchmarking", "frame-support/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/vesting/Cargo.toml b/substrate/frame/vesting/Cargo.toml index dc42fbcbab1..31d1f72869b 100644 --- a/substrate/frame/vesting/Cargo.toml +++ b/substrate/frame/vesting/Cargo.toml @@ -40,3 +40,4 @@ std = [ "frame-system/std", ] runtime-benchmarks = ["frame-benchmarking"] +try-runtime = ["frame-support/try-runtime"] -- GitLab