Skip to content

Commit

Permalink
Warn if user runs on-runtime-upgrade with a spec version not gt on-ch…
Browse files Browse the repository at this point in the history
…ain spec version (#37)
  • Loading branch information
liamaharon authored Sep 26, 2023
1 parent 22c7571 commit eb5c6ae
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/src/commands/create_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where

let executor = build_executor::<HostFns>(&shared);
let _ = State::Live(command.from)
.to_ext::<Block, HostFns>(&shared, &executor, Some(path.into()), false)
.to_ext::<Block, HostFns>(&shared, &executor, Some(path.into()), false, false)
.await?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion core/src/commands/execute_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ where
let executor = build_executor::<HostFns>(&shared);
let ext = command
.state
.to_ext::<Block, HostFns>(&shared, &executor, None, true)
.to_ext::<Block, HostFns>(&shared, &executor, None, true, false)
.await?;

// get the block number associated with this block.
Expand Down
2 changes: 1 addition & 1 deletion core/src/commands/fast_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ where
let executor = build_executor::<HostFns>(&shared);
let ext = command
.state
.to_ext::<Block, HostFns>(&shared, &executor, None, true)
.to_ext::<Block, HostFns>(&shared, &executor, None, true, false)
.await?;

if command.run_migrations {
Expand Down
2 changes: 1 addition & 1 deletion core/src/commands/follow_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ where
hashed_prefixes: vec![],
});
let ext = state
.to_ext::<Block, HostFns>(&shared, &executor, None, true)
.to_ext::<Block, HostFns>(&shared, &executor, None, true, false)
.await?;
maybe_state_ext = Some(ext);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/commands/offchain_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ where
// we first build the externalities with the remote code.
let ext = command
.state
.to_ext::<Block, HostFns>(&shared, &executor, None, true)
.to_ext::<Block, HostFns>(&shared, &executor, None, true, false)
.await?;

let header_ws_uri = command.header_ws_uri();
Expand Down
2 changes: 1 addition & 1 deletion core/src/commands/on_runtime_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where
let executor = build_executor(&shared);
let ext = command
.state
.to_ext::<Block, HostFns>(&shared, &executor, None, true)
.to_ext::<Block, HostFns>(&shared, &executor, None, true, true)
.await?;

if let State::Live(_) = command.state {
Expand Down
11 changes: 10 additions & 1 deletion core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ pub struct LiveState {
#[arg(short, long, num_args = 1..)]
pub pallet: Vec<String>,

/// Storage entry key prefixes to scrape and inject into the test externalities. Pass as 0x prefixed hex strings. By default, all keys are scraped and included.
/// Storage entry key prefixes to scrape and inject into the test externalities. Pass as 0x
/// prefixed hex strings. By default, all keys are scraped and included.
#[arg(long = "prefix", value_parser = parse::hash, num_args = 1..)]
pub hashed_prefixes: Vec<String>,

Expand Down Expand Up @@ -107,6 +108,7 @@ impl State {
executor: &WasmExecutor<HostFns>,
state_snapshot: Option<SnapshotConfig>,
try_runtime_check: bool,
spec_version_check: bool,
) -> sc_cli::Result<RemoteExternalities<Block>>
where
Block::Header: DeserializeOwned,
Expand Down Expand Up @@ -253,6 +255,13 @@ impl State {
if new_version.spec_name != old_version.spec_name {
return Err("Spec names must match.".into());
}

if spec_version_check && new_version.spec_version <= old_version.spec_version {
log::warn!(
target: LOG_TARGET,
"New runtime spec version is not greater than the on-chain runtime spec version. Don't forget to increment the spec version if you intend to use the new code in a runtime upgrade."
);
}
}

// whatever runtime we have in store now must have been compiled with try-runtime feature.
Expand Down

0 comments on commit eb5c6ae

Please sign in to comment.