Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4c0abc5
A clean new attempt
kianenigma Feb 3, 2021
7f9b5b8
Checkpoint to move remote.
kianenigma Feb 10, 2021
4883812
A lot of dependency wiring to make it feature gated.
kianenigma Feb 10, 2021
be549b4
bad macro, bad macro.
kianenigma Feb 10, 2021
8e97733
Master.into()
kianenigma Feb 11, 2021
d84dad4
Undo the DB mess.
kianenigma Feb 11, 2021
aeb7a0e
Update frame/support/src/traits.rs
kianenigma Feb 11, 2021
d968f58
Apply suggestions from code review
kianenigma Feb 11, 2021
ce4128b
unbreak the build
kianenigma Feb 13, 2021
ee8ae08
Merge branch 'kiz-finally-finally-finally-finally-migration-testing-2…
kianenigma Feb 13, 2021
62be119
Master.into()
kianenigma Feb 16, 2021
712c240
Update frame/try-runtime/src/lib.rs
kianenigma Feb 18, 2021
9a23940
Update utils/frame/try-runtime/cli/Cargo.toml
kianenigma Feb 18, 2021
93f299a
Update frame/try-runtime/Cargo.toml
kianenigma Feb 18, 2021
3cea840
Address most review grumbles.
kianenigma Feb 18, 2021
ab9d4a3
Upstream.into()
kianenigma Feb 18, 2021
b13ea31
Fix build
kianenigma Feb 18, 2021
d3a2368
Add some comments
kianenigma Feb 18, 2021
c8ba546
Remove allowing one pallet at a time.
kianenigma Feb 18, 2021
2f9ad0e
More grumbles.
kianenigma Feb 18, 2021
6db195c
Merge branch 'master' of github.com:paritytech/substrate into kiz-fin…
kianenigma Feb 18, 2021
b8ab620
relocate remote-ext
kianenigma Feb 19, 2021
be5210d
Merge branch 'master' of github.com:paritytech/substrate into kiz-fin…
kianenigma Feb 19, 2021
b5e394b
Fix build
kianenigma Feb 19, 2021
deb03d4
Merge branch 'master' of github.com:paritytech/substrate into kiz-fin…
kianenigma Feb 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove allowing one pallet at a time.
  • Loading branch information
kianenigma committed Feb 18, 2021
commit c8ba546b87b9d8c7ff01633723a74e36d8e5b9e0
24 changes: 2 additions & 22 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,29 +1334,9 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(target: frame_try_runtime::Target) -> Result<(Weight, Weight), sp_runtime::RuntimeString> {
fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> {
frame_support::debug::RuntimeLogger::init();

let weight = match target {
frame_try_runtime::Target::All => {
frame_support::debug::info!("Dry-running all on-runtime-upgrades.");
Executive::try_runtime_upgrade()?
},
frame_try_runtime::Target::Pallet(name) => {
let name = sp_std::str::from_utf8(&name).expect("pallet name is utf8-decodable; qed");
frame_support::debug::info!("Dry-running on-runtime-upgrade of {}.", name);

frame_try_runtime::match_pallet_on_runtime_upgrade!(name,
System, Utility, Babe, Timestamp, Authorship, Indices, Balances,
TransactionPayment, Staking, Session, Democracy, Council,
TechnicalCommittee, Elections, TechnicalMembership, Grandpa, Treasury,
Contracts, Sudo, ImOnline, AuthorityDiscovery, Offences, Historical,
RandomnessCollectiveFlip, Identity, Society, Recovery, Vesting, Scheduler,
Proxy, Multisig, Bounties, Tips, Assets, Mmr, Lottery,
)
}
};

let weight = Executive::try_runtime_upgrade()?;
Ok((weight, RuntimeBlockWeights::get().max_block))
}
}
Expand Down
49 changes: 4 additions & 45 deletions frame/try-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,19 @@

#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Decode, Encode};
use sp_std::prelude::*;
use frame_support::weights::Weight;

#[doc(hidden)]
pub use frame_support as _support;

/// Helper macro to generate the match expression needed to match a pallet name to
/// its `on_runtime_upgrade()` implementation.
#[macro_export]
macro_rules! match_pallet_on_runtime_upgrade {
($name:ident, $($pallet:ty),* $(,)*) => {
match $name {
$(
stringify!($pallet) => {
<$pallet as $crate::_support::traits::OnRuntimeUpgrade>::pre_upgrade()?;
let weight = <$pallet as $crate::_support::traits::OnRuntimeUpgrade>::on_runtime_upgrade();
<$pallet as $crate::_support::traits::OnRuntimeUpgrade>::post_upgrade()?;
weight
},
)*
_ => panic!("Unknown pallet name provided"),
}
};
}

/// Possible targets for try-runtime testing.
#[derive(Debug, Encode, Decode)]
pub enum Target {
/// All pallets.
All,
/// A single pallet. Inner value is the encoded pallet name.
Pallet(Vec<u8>),
}

#[cfg(feature = "std")]
impl sp_std::str::FromStr for Target {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(if s.to_lowercase() == "all" {
Target::All
} else {
Target::Pallet(s.as_bytes().to_vec())
})
}
}

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(target: Target) -> Result<(Weight, Weight), sp_runtime::RuntimeString>;
fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString>;
}
}
9 changes: 2 additions & 7 deletions utils/frame/try-runtime/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

//! `Structopt`-ready struct for `try-runtime`.

use parity_scale_codec::{Decode, Encode};
use parity_scale_codec::Decode;
use std::{fmt::Debug, str::FromStr};
use sc_service::Configuration;
use sc_cli::{CliConfiguration, ExecutionStrategy, WasmExecutionMethod};
Expand All @@ -26,7 +26,6 @@ use sc_service::NativeExecutionDispatch;
use sp_state_machine::StateMachine;
use sp_runtime::traits::{Block as BlockT, NumberFor};
use sp_core::storage::{StorageData, StorageKey, well_known_keys};
use frame_try_runtime::Target;

/// Various commands to try out the new runtime, over configurable states.
///
Expand All @@ -38,10 +37,6 @@ pub struct TryRuntimeCmd {
#[structopt(flatten)]
pub shared_params: sc_cli::SharedParams,

/// The target pallet to run the migration against.
#[structopt(short, long, default_value = "All")]
pub target: Target,

/// The state to use to run the migration. Should be a valid FILE or HTTP URI.
#[structopt(short, long, default_value = "http://localhost:9933")]
pub state: State,
Expand Down Expand Up @@ -147,7 +142,7 @@ impl TryRuntimeCmd {
&mut changes,
&executor,
"TryRuntime_on_runtime_upgrade",
&self.target.encode(),
&[],
ext.extensions,
&sp_state_machine::backend::BackendRuntimeCode::new(&ext.backend)
.runtime_code()?,
Expand Down