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 Oct 11, 2022
1 parent 9b4acf6 commit 6f08921
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 65 deletions.
9 changes: 7 additions & 2 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
13 changes: 13 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,15 @@ 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",
"issue/try-runtime",
]
15 changes: 15 additions & 0 deletions parachain/runtime/interlay/src/lib.rs
Expand Up @@ -1483,6 +1483,21 @@ 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
12 changes: 12 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,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-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"issue/try-runtime",
]
15 changes: 15 additions & 0 deletions parachain/runtime/kintsugi/src/lib.rs
Expand Up @@ -1484,6 +1484,21 @@ 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
14 changes: 14 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,16 @@ 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",
"issue/try-runtime",
]
15 changes: 15 additions & 0 deletions parachain/runtime/testnet-interlay/src/lib.rs
Expand Up @@ -1456,6 +1456,21 @@ 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
14 changes: 14 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,16 @@ 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",
"issue/try-runtime",
]
16 changes: 16 additions & 0 deletions parachain/runtime/testnet-kintsugi/src/lib.rs
Expand Up @@ -1455,6 +1455,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

0 comments on commit 6f08921

Please sign in to comment.