Skip to content

Commit

Permalink
feat: try-runtime support
Browse files Browse the repository at this point in the history
  • Loading branch information
sander2 committed Sep 19, 2022
1 parent 9b4acf6 commit 713e989
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions parachain/Cargo.toml
Expand Up @@ -79,6 +79,8 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "pol
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }

try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", optional = true }

# Cumulus dependencies
cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.26" }
cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.26" }
Expand All @@ -103,6 +105,15 @@ polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch =

[features]
default = []

try-runtime = [
"try-runtime-cli",
"interlay-runtime/try-runtime",
"kintsugi-runtime/try-runtime",
"testnet-interlay-runtime/try-runtime",
"testnet-kintsugi-runtime/try-runtime"
]

rococo-native = [ "polkadot-cli/rococo-native" ]
runtime-benchmarks = [
"interlay-runtime/runtime-benchmarks",
Expand Down
12 changes: 12 additions & 0 deletions parachain/runtime/interlay/Cargo.toml
Expand Up @@ -42,6 +42,7 @@ pallet-multisig = { git = "https://github.com/paritytech/substrate", branch = "p
pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
pallet-identity = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }

frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }

Expand Down Expand Up @@ -248,3 +249,14 @@ runtime-benchmarks = [
"vault-registry/runtime-benchmarks",
]
disable-runtime-api = []
try-runtime = [
"frame-try-runtime",
"frame-executive/try-runtime",
"frame-system/try-runtime",
"frame-support/try-runtime",
"pallet-aura/try-runtime",
"pallet-balances/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
]
11 changes: 11 additions & 0 deletions parachain/runtime/kintsugi/Cargo.toml
Expand Up @@ -42,6 +42,7 @@ pallet-multisig = { git = "https://github.com/paritytech/substrate", branch = "p
pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
pallet-identity = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }

frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }

Expand Down Expand Up @@ -252,3 +253,13 @@ runtime-benchmarks = [
"vault-registry/runtime-benchmarks",
]
disable-runtime-api = []
try-runtime = [
"frame-try-runtime",
"frame-executive/try-runtime",
"frame-system/try-runtime",
"frame-support/try-runtime",
"pallet-aura/try-runtime",
"pallet-balances/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
]
13 changes: 13 additions & 0 deletions parachain/runtime/testnet-interlay/Cargo.toml
Expand Up @@ -43,6 +43,7 @@ pallet-multisig = { git = "https://github.com/paritytech/substrate", branch = "p
pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
pallet-identity = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }

frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }

Expand Down Expand Up @@ -254,3 +255,15 @@ runtime-benchmarks = [
]
disable-runtime-api = []
dev-interlay = []
try-runtime = [
"frame-try-runtime",
"frame-executive/try-runtime",
"frame-system/try-runtime",
"frame-support/try-runtime",
"pallet-aura/try-runtime",
"pallet-balances/try-runtime",
"pallet-sudo/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
]
13 changes: 13 additions & 0 deletions parachain/runtime/testnet-kintsugi/Cargo.toml
Expand Up @@ -43,6 +43,7 @@ pallet-multisig = { git = "https://github.com/paritytech/substrate", branch = "p
pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
pallet-identity = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }

frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }

Expand Down Expand Up @@ -254,3 +255,15 @@ runtime-benchmarks = [
]
disable-runtime-api = []
dev-interlay = []
try-runtime = [
"frame-try-runtime",
"frame-executive/try-runtime",
"frame-system/try-runtime",
"frame-support/try-runtime",
"pallet-aura/try-runtime",
"pallet-balances/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-transaction-payment/try-runtime",
]
18 changes: 18 additions & 0 deletions parachain/runtime/testnet-kintsugi/src/lib.rs
Expand Up @@ -432,11 +432,13 @@ impl frame_support::traits::OnRuntimeUpgrade for SchedulerMigrationV3 {

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
log::error!("test");
Scheduler::pre_migrate_to_v3()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
log::error!("testq");
Scheduler::post_migrate_to_v3()
}
}
Expand Down Expand Up @@ -1455,6 +1457,22 @@ impl_runtime_apis! {
Replace::get_replace_requests_for_new_vault(vault_id)
}
}


#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade() -> (Weight, Weight) {
// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
// have a backtrace here. If any of the pre/post migration checks fail, we shall stop
// right here and right now.
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}

fn execute_block_no_check(block: Block) -> Weight {
Executive::execute_block_no_check(block)
}
}
}

struct CheckInherents;
Expand Down
8 changes: 8 additions & 0 deletions parachain/src/cli.rs
Expand Up @@ -42,6 +42,14 @@ pub enum Subcommand {
/// The custom benchmark subcommmand benchmarking runtime pallets.
#[clap(subcommand)]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),

/// Try some command against runtime state.
#[cfg(feature = "try-runtime")]
TryRuntime(try_runtime_cli::TryRuntimeCmd),

/// Try some command against runtime state. Note: `try-runtime` feature must be enabled.
#[cfg(not(feature = "try-runtime"))]
TryRuntime,
}

/// Command for exporting the metadata.
Expand Down
22 changes: 22 additions & 0 deletions parachain/src/command.rs
Expand Up @@ -458,6 +458,28 @@ pub fn run() -> Result<()> {

Ok(())
}
#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => {
let runner = cli.create_runner(cmd)?;
let chain_spec = &runner.config().chain_spec;

with_runtime_or_err!(chain_spec, {
return runner.async_run(|config| {
// we don't need any of the components of new_partial, just a runtime, or a task
// manager to do `async_run`.
let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager =
sc_service::TaskManager::new(config.tokio_handle.clone(), registry)
.map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?;
Ok((cmd.run::<Block, Executor>(config), task_manager))
});
})

},
#[cfg(not(feature = "try-runtime"))]
Some(Subcommand::TryRuntime) => Err("TryRuntime wasn't enabled when building the node. \
You can enable it with `--features try-runtime`."
.into()),
None => {
let runner = cli.create_runner(&cli.run.normalize())?;

Expand Down

0 comments on commit 713e989

Please sign in to comment.