mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 18:31:05 +00:00
Migration testing runtime API/Bot (#8038)
* A clean new attempt * Checkpoint to move remote. * A lot of dependency wiring to make it feature gated. * bad macro, bad macro. * Undo the DB mess. * Update frame/support/src/traits.rs Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> * Apply suggestions from code review Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> * unbreak the build * Update frame/try-runtime/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/frame/try-runtime/cli/Cargo.toml Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Update frame/try-runtime/Cargo.toml Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Address most review grumbles. * Fix build * Add some comments * Remove allowing one pallet at a time. * More grumbles. * relocate remote-ext * Fix build Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -47,3 +47,6 @@ std = [
|
||||
"sp-tracing/std",
|
||||
"sp-std/std",
|
||||
]
|
||||
try-runtime = [
|
||||
"frame-support/try-runtime"
|
||||
]
|
||||
|
||||
@@ -44,7 +44,8 @@
|
||||
//!
|
||||
//! ## Usage
|
||||
//!
|
||||
//! The default Substrate node template declares the [`Executive`](./struct.Executive.html) type in its library.
|
||||
//! The default Substrate node template declares the [`Executive`](./struct.Executive.html) type in
|
||||
//! its library.
|
||||
//!
|
||||
//! ### Example
|
||||
//!
|
||||
@@ -185,26 +186,58 @@ where
|
||||
}
|
||||
|
||||
impl<
|
||||
System: frame_system::Config,
|
||||
Block: traits::Block<Header=System::Header, Hash=System::Hash>,
|
||||
Context: Default,
|
||||
UnsignedValidator,
|
||||
AllModules:
|
||||
OnRuntimeUpgrade +
|
||||
OnInitialize<System::BlockNumber> +
|
||||
OnFinalize<System::BlockNumber> +
|
||||
OffchainWorker<System::BlockNumber>,
|
||||
COnRuntimeUpgrade: OnRuntimeUpgrade,
|
||||
> Executive<System, Block, Context, UnsignedValidator, AllModules, COnRuntimeUpgrade>
|
||||
System: frame_system::Config,
|
||||
Block: traits::Block<Header = System::Header, Hash = System::Hash>,
|
||||
Context: Default,
|
||||
UnsignedValidator,
|
||||
AllModules: OnRuntimeUpgrade
|
||||
+ OnInitialize<System::BlockNumber>
|
||||
+ OnFinalize<System::BlockNumber>
|
||||
+ OffchainWorker<System::BlockNumber>,
|
||||
COnRuntimeUpgrade: OnRuntimeUpgrade,
|
||||
> Executive<System, Block, Context, UnsignedValidator, AllModules, COnRuntimeUpgrade>
|
||||
where
|
||||
Block::Extrinsic: Checkable<Context> + Codec,
|
||||
CheckedOf<Block::Extrinsic, Context>:
|
||||
Applyable +
|
||||
GetDispatchInfo,
|
||||
CallOf<Block::Extrinsic, Context>: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo>,
|
||||
CheckedOf<Block::Extrinsic, Context>: Applyable + GetDispatchInfo,
|
||||
CallOf<Block::Extrinsic, Context>:
|
||||
Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
|
||||
OriginOf<Block::Extrinsic, Context>: From<Option<System::AccountId>>,
|
||||
UnsignedValidator: ValidateUnsigned<Call=CallOf<Block::Extrinsic, Context>>,
|
||||
UnsignedValidator: ValidateUnsigned<Call = CallOf<Block::Extrinsic, Context>>,
|
||||
{
|
||||
/// Execute all `OnRuntimeUpgrade` of this runtime, and return the aggregate weight.
|
||||
pub fn execute_on_runtime_upgrade() -> frame_support::weights::Weight {
|
||||
let mut weight = 0;
|
||||
weight = weight.saturating_add(
|
||||
<frame_system::Module<System> as OnRuntimeUpgrade>::on_runtime_upgrade(),
|
||||
);
|
||||
weight = weight.saturating_add(COnRuntimeUpgrade::on_runtime_upgrade());
|
||||
weight = weight.saturating_add(<AllModules as OnRuntimeUpgrade>::on_runtime_upgrade());
|
||||
|
||||
weight
|
||||
}
|
||||
|
||||
/// Execute all `OnRuntimeUpgrade` of this runtime, including the pre and post migration checks.
|
||||
///
|
||||
/// This should only be used for testing.
|
||||
#[cfg(feature = "try-runtime")]
|
||||
pub fn try_runtime_upgrade() -> Result<frame_support::weights::Weight, &'static str> {
|
||||
<
|
||||
(frame_system::Module::<System>, COnRuntimeUpgrade, AllModules)
|
||||
as
|
||||
OnRuntimeUpgrade
|
||||
>::pre_upgrade()?;
|
||||
|
||||
let weight = Self::execute_on_runtime_upgrade();
|
||||
|
||||
<
|
||||
(frame_system::Module::<System>, COnRuntimeUpgrade, AllModules)
|
||||
as
|
||||
OnRuntimeUpgrade
|
||||
>::post_upgrade()?;
|
||||
|
||||
Ok(weight)
|
||||
}
|
||||
|
||||
/// Start the execution of a particular block.
|
||||
pub fn initialize_block(header: &System::Header) {
|
||||
sp_io::init_tracing();
|
||||
@@ -234,10 +267,7 @@ where
|
||||
) {
|
||||
let mut weight = 0;
|
||||
if Self::runtime_upgraded() {
|
||||
// System is not part of `AllModules`, so we need to call this manually.
|
||||
weight = weight.saturating_add(<frame_system::Module::<System> as OnRuntimeUpgrade>::on_runtime_upgrade());
|
||||
weight = weight.saturating_add(COnRuntimeUpgrade::on_runtime_upgrade());
|
||||
weight = weight.saturating_add(<AllModules as OnRuntimeUpgrade>::on_runtime_upgrade());
|
||||
weight = weight.saturating_add(Self::execute_on_runtime_upgrade());
|
||||
}
|
||||
<frame_system::Module<System>>::initialize(
|
||||
block_number,
|
||||
|
||||
@@ -60,3 +60,4 @@ std = [
|
||||
nightly = []
|
||||
strict = []
|
||||
runtime-benchmarks = []
|
||||
try-runtime = []
|
||||
|
||||
@@ -1547,7 +1547,25 @@ pub trait OnRuntimeUpgrade {
|
||||
/// block local data are not accessible.
|
||||
///
|
||||
/// Return the non-negotiable weight consumed for runtime upgrade.
|
||||
fn on_runtime_upgrade() -> crate::weights::Weight { 0 }
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
||||
#[impl_for_tuples(30)]
|
||||
@@ -1557,6 +1575,20 @@ impl OnRuntimeUpgrade for Tuple {
|
||||
for_tuples!( #( weight = weight.saturating_add(Tuple::on_runtime_upgrade()); )* );
|
||||
weight
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<(), &'static str> {
|
||||
let mut result = Ok(());
|
||||
for_tuples!( #( result = result.and(Tuple::pre_upgrade()); )* );
|
||||
result
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn post_upgrade() -> Result<(), &'static str> {
|
||||
let mut result = Ok(());
|
||||
for_tuples!( #( result = result.and(Tuple::post_upgrade()); )* );
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
/// Off-chain computation trait.
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
[package]
|
||||
name = "frame-try-runtime"
|
||||
version = "0.9.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://substrate.dev"
|
||||
repository = "https://github.com/paritytech/substrate/"
|
||||
description = "FRAME pallet for democracy"
|
||||
readme = "README.md"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false }
|
||||
|
||||
sp-api = { version = "3.0.0", path = "../../primitives/api", default-features = false }
|
||||
sp-std = { version = "3.0.0", path = "../../primitives/std" , default-features = false }
|
||||
sp-runtime = { version = "3.0.0", path = "../../primitives/runtime" , default-features = false }
|
||||
|
||||
frame-support = { version = "3.0.0", path = "../support", default-features = false }
|
||||
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
std = [
|
||||
"sp-api/std",
|
||||
"sp-std/std",
|
||||
"sp-runtime/std",
|
||||
"frame-support/std",
|
||||
]
|
||||
@@ -0,0 +1,37 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2021 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Supporting types for try-runtime, testing and dry-running commands.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use frame_support::weights::Weight;
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
/// Runtime api for testing the execution of a runtime upgrade.
|
||||
pub trait TryRuntime {
|
||||
/// dry-run runtime upgrades, returning the total weight consumed.
|
||||
///
|
||||
/// This should do EXACTLY the same operations as the runtime would have done in the case of
|
||||
/// a runtime upgrade (e.g. pallet ordering must be the same)
|
||||
///
|
||||
/// Returns the consumed weight of the migration in case of a successful one, combined with
|
||||
/// the total allowed block weight of the runtime.
|
||||
fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user