Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d1bce56
inherent overhaul
liamaharon May 7, 2024
20878ee
bump version
liamaharon May 7, 2024
d58941c
clean up custom idps
liamaharon May 8, 2024
ff30415
smart inherent provider
liamaharon May 8, 2024
5883f46
licence and basic docs
liamaharon May 9, 2024
b27fd10
clippy
liamaharon May 9, 2024
62d9696
remove node-executor node-primitive deps
liamaharon May 9, 2024
9c5fcbe
fmt
liamaharon May 9, 2024
ac898c2
update cargo.lock
liamaharon May 9, 2024
36a8cf1
move shared params to common
liamaharon May 10, 2024
4424f61
move misc logging to common
liamaharon May 10, 2024
a0a5485
move parse to common
liamaharon May 10, 2024
16c5b39
move state to common
liamaharon May 10, 2024
9632a14
move inherents to empty block production dir
liamaharon May 10, 2024
4f7e04e
move block creation out of fast forward
liamaharon May 10, 2024
b728086
improve log
liamaharon May 10, 2024
039cdaf
clippy
liamaharon May 10, 2024
bcdd083
cargo fmt
liamaharon May 13, 2024
4a406c6
update test runtimes and snapshots
liamaharon May 14, 2024
fd0092e
use stable for clippy
liamaharon May 14, 2024
4b4648b
fix typos
liamaharon May 14, 2024
527c857
Update core/src/common/empty_block/inherents/pre_apply.rs
liamaharon May 15, 2024
c7dbbfe
address comments
liamaharon May 16, 2024
8b465e2
doc comment
liamaharon May 16, 2024
828a357
doc
liamaharon May 16, 2024
5980993
use valueenum
liamaharon May 16, 2024
aee8086
rename execute_next_block to mine_block
liamaharon May 16, 2024
2254202
bump relay_offset +1
liamaharon May 17, 2024
00e2962
blocktime arg
liamaharon May 20, 2024
e80f524
make blocktime a required value
liamaharon May 20, 2024
47a76ca
hardcode relaychain blocktime
liamaharon May 20, 2024
c6a143b
clippy
liamaharon May 26, 2024
5fdd6d5
free disk space on test runner
liamaharon May 26, 2024
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
Next Next commit
inherent overhaul
  • Loading branch information
liamaharon committed May 7, 2024
commit d1bce56a2088a87054cd3cf3197fb48d157e421e
4,019 changes: 2,778 additions & 1,241 deletions Cargo.lock

Large diffs are not rendered by default.

61 changes: 33 additions & 28 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ homepage = "https://github.com/paritytech/try-runtime-cli"
repository = "https://github.com/paritytech/try-runtime-cli/"

[workspace.dependencies]
array-bytes = { version = "6.2.2" }
assert_cmd = { version = "2.0.10" }
async-trait = { version = "0.1.57" }
bytesize = { version = "1.2.0" }
Expand All @@ -28,41 +29,45 @@ serde_json = { version = "1.0.85" }
strum = "0.25"
strum_macros = "0.25"
tempfile = { version = "3.1.0" }
tokio = { version = "1.27.0" }
tokio = { version = "1.37.0" }
zstd = { version = "0.11.2", default-features = false }

# Polkadot SDK
frame-remote-externalities = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
frame-remote-externalities = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }

sc-cli = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sc-executor = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sc-service = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sc-cli = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sc-executor = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sc-service = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }

sp-api = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-externalities = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-inherents = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-rpc = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-state-machine = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-storage = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-transaction-storage-proof = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-version = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-weights = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-externalities = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-inherents = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-rpc = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-state-machine = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-storage = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-transaction-storage-proof = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-version = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
sp-weights = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }

substrate-cli-test-utils = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
substrate-rpc-client = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
substrate-cli-test-utils = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
substrate-rpc-client = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }

node-executor = { package = "staging-node-executor", git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
node-primitives = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1d5d4a484021ede73152bf71af37718fa38bb72b" }
node-executor = { package = "staging-node-executor", git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
node-primitives = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }
cumulus-client-parachain-inherent = { git = "https://github.com/paritytech/polkadot-sdk", branch = "liam-remote-ext-snapshot-header" }

# Local
try-runtime-core = { path = "core" }
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ parity-scale-codec = { workspace = true, features = ["derive"] }
tokio = { workspace = true, features = ["full"] }

sp-io = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-state-machine = { workspace = true }
sp-storage = { workspace = true }
Expand Down
8 changes: 6 additions & 2 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@
use std::env;

use clap::Parser;
use node_primitives::Block;
use sp_runtime::{
generic::{Block, Header},
traits::BlakeTwo256,
OpaqueExtrinsic,
};
use try_runtime_core::commands::TryRuntime;

fn init_env() {
Expand All @@ -315,7 +319,7 @@ async fn main() {
init_env();

let cmd = TryRuntime::parse();
cmd.run::<Block, sp_io::SubstrateHostFunctions>()
cmd.run::<Block<Header<u32, BlakeTwo256>, OpaqueExtrinsic>, sp_io::SubstrateHostFunctions>()
.await
.unwrap();
}
8 changes: 7 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
# Crates.io
async-trait = { workspace = true }
array-bytes = { workspace = true }
polkadot-primitives = { workspace = true }
bytesize = { workspace = true, features = ["serde"] }
clap = { workspace = true, features = ["derive"] }
hex = { workspace = true }
Expand Down Expand Up @@ -51,6 +53,10 @@ sp-transaction-storage-proof = { workspace = true }
sp-version = { workspace = true }
sp-weights = { workspace = true }

cumulus-primitives-parachain-inherent = { workspace = true }
cumulus-primitives-core = { workspace = true }
cumulus-client-parachain-inherent = { workspace = true }

substrate-rpc-client = { workspace = true }
paris = "1.5.15"
similar-asserts = "1.5.0"
Expand All @@ -61,6 +67,6 @@ regex = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true }

node-executor = { workspace = true }
sc-service = { workspace = true }
substrate-cli-test-utils = { workspace = true, features = ["try-runtime"] }

110 changes: 44 additions & 66 deletions core/src/commands/fast_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ use serde::de::DeserializeOwned;
use sp_core::H256;
use sp_inherents::InherentData;
use sp_runtime::{
traits::{HashingFor, Header, NumberFor, One, Saturating},
traits::{HashingFor, Header, NumberFor, One},
Digest,
};
use sp_state_machine::TestExternalities;
use substrate_rpc_client::{ws_client, ChainApi};

use crate::{
build_executor, full_extensions,
inherent_provider::{Chain, InherentProvider},
rpc_err_handler,
state::{LiveState, RuntimeChecks, State},
inherents::providers::{pre_apply_inherents, ChainVariant, InherentProvider},
state::{RuntimeChecks, State},
state_machine_call, state_machine_call_with_proof, BlockT, SharedParams,
};

Expand All @@ -45,15 +43,9 @@ pub struct Command {
#[arg(long)]
pub n_blocks: u64,

/// Chain
/// ChainVariant
#[arg(long)]
pub chain: Chain,

/// The ws uri from which to fetch the block.
///
/// If `state` is `Live`, this is ignored. Otherwise, it must not be empty.
#[arg(long, value_parser = crate::parse::url)]
pub block_ws_uri: Option<String>,
pub chain: ChainVariant,

/// Which try-state targets to execute when running this command.
///
Expand All @@ -76,35 +68,6 @@ pub struct Command {
pub state: State,
}

impl Command {
fn block_ws_uri(&self) -> &str {
match self.state {
State::Live(LiveState { ref uri, .. }) => uri,
_ => self
.block_ws_uri
.as_ref()
.expect("Either `--block-uri` must be provided, or state must be `live`"),
}
}
}

/// Read the block number corresponding to `hash` with an RPC call to `ws_uri`.
async fn get_block_number<Block: BlockT>(
hash: Block::Hash,
ws_uri: &str,
) -> Result<NumberFor<Block>>
where
Block::Header: DeserializeOwned,
{
let rpc = ws_client(ws_uri).await?;
Ok(
ChainApi::<(), Block::Hash, Block::Header, ()>::header(&rpc, Some(hash))
.await
.map_err(rpc_err_handler)
.and_then(|maybe_header| maybe_header.ok_or("header_not_found").map(|h| *h.number()))?,
)
}

/// Call `method` with `data` and return the result. `externalities` will not change.
fn dry_call<T: Decode, Block: BlockT, HostFns: HostFunctions>(
externalities: &TestExternalities<HashingFor<Block>>,
Expand Down Expand Up @@ -153,25 +116,37 @@ async fn call<Block: BlockT, HostFns: HostFunctions>(
async fn produce_next_block<Block: BlockT, HostFns: HostFunctions>(
externalities: &mut TestExternalities<HashingFor<Block>>,
executor: &WasmExecutor<HostFns>,
parent_height: NumberFor<Block>,
parent_hash: Block::Hash,
inherent_provider: &dyn InherentProvider<Err = String>,
parent_header: Block::Header,
chain: ChainVariant,
previous_block_building_info: Option<(InherentData, Digest)>,
) -> Result<(Block, Option<(InherentData, Digest)>)> {
) -> Result<(Block, Option<(InherentData, Digest)>)>
where
Block: BlockT<Hash = H256> + DeserializeOwned,
Block::Header: DeserializeOwned,
<Block::Hash as FromStr>::Err: Debug,
NumberFor<Block>: FromStr,
<NumberFor<Block> as FromStr>::Err: Debug,
{
let (inherent_data_provider, pre_digest) =
inherent_provider.get_inherent_providers_and_pre_digest(previous_block_building_info)?;
<ChainVariant as InherentProvider<Block>>::get_inherent_providers_and_pre_digest(
&chain,
previous_block_building_info,
parent_header.clone(),
externalities,
)?;

pre_apply_inherents::<Block>(chain, externalities);
let inherent_data = inherent_data_provider
.create_inherent_data()
.await
.map_err(|s| sc_cli::Error::Input(s.to_string()))?;
let digest = Digest { logs: pre_digest };

let header = Block::Header::new(
parent_height + One::one(),
*parent_header.number() + One::one(),
Default::default(),
Default::default(),
parent_hash,
parent_header.hash(),
digest.clone(),
);

Expand Down Expand Up @@ -255,37 +230,35 @@ where
}

log::info!("Fast forwarding {} blocks...", command.n_blocks);
let mut last_block_hash = ext.block_hash;
let mut last_block_number =
get_block_number::<Block>(last_block_hash, command.block_ws_uri()).await?;
let mut prev_block_building_info = None;

let mut ext = ext.inner_ext;
let mut inner_ext = ext.inner_ext;
let mut parent_header = ext.header.clone();
let mut parent_block_building_info = None;

for _ in 1..=command.n_blocks {
// We are saving state before we overwrite it while producing new block.
let backend = ext.as_backend();
let backend = inner_ext.as_backend();

log::info!(
"Producing new empty block at height {:?}",
last_block_number + One::one()
*parent_header.number() + One::one()
);

let (next_block, new_block_building_info) = produce_next_block::<Block, HostFns>(
&mut ext,
&mut inner_ext,
&executor,
last_block_number,
last_block_hash,
&command.chain,
prev_block_building_info,
parent_header.clone(),
command.chain,
parent_block_building_info,
)
.await?;

log::info!("Produced a new block: {:?}", next_block.header());

// And now we restore previous state.
ext.backend = backend;
inner_ext.backend = backend;

pre_apply_inherents::<Block>(command.chain, &mut inner_ext);
let state_root_check = true;
let signature_check = true;
let payload = (
Expand All @@ -295,13 +268,18 @@ where
command.try_state.clone(),
)
.encode();
call::<Block, _>(&mut ext, &executor, "TryRuntime_execute_block", &payload).await?;
call::<Block, _>(
&mut inner_ext,
&executor,
"TryRuntime_execute_block",
&payload,
)
.await?;

log::info!("Executed the new block");

prev_block_building_info = new_block_building_info;
last_block_hash = next_block.hash();
last_block_number.saturating_inc();
parent_block_building_info = new_block_building_info;
parent_header = next_block.header().clone();
}

Ok(())
Expand Down
Loading