From 63ea95bd1e5666f2c680e6809bd94803f12bec07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 15 Dec 2022 10:09:53 +0100 Subject: [PATCH 01/13] try-runtime::fast-forward --- Cargo.lock | 2 + bin/node-template/node/src/command.rs | 28 +- utils/frame/try-runtime/cli/Cargo.toml | 2 + .../cli/src/commands/fast_forward.rs | 292 ++++++++++++++++++ .../frame/try-runtime/cli/src/commands/mod.rs | 1 + utils/frame/try-runtime/cli/src/lib.rs | 32 +- 6 files changed, 351 insertions(+), 6 deletions(-) create mode 100644 utils/frame/try-runtime/cli/src/commands/fast_forward.rs diff --git a/Cargo.lock b/Cargo.lock index b840cadce3e5c..b6657bd9bae36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10649,6 +10649,7 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" name = "try-runtime-cli" version = "0.10.0-dev" dependencies = [ + "async-trait", "clap 4.0.11", "frame-remote-externalities", "frame-try-runtime", @@ -10664,6 +10665,7 @@ dependencies = [ "sp-core", "sp-debug-derive", "sp-externalities", + "sp-inherents", "sp-io", "sp-keystore", "sp-rpc", diff --git a/bin/node-template/node/src/command.rs b/bin/node-template/node/src/command.rs index 15cd69b34b5b2..aeb579643b049 100644 --- a/bin/node-template/node/src/command.rs +++ b/bin/node-template/node/src/command.rs @@ -8,7 +8,12 @@ use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE use node_template_runtime::{Block, EXISTENTIAL_DEPOSIT}; use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli}; use sc_service::PartialComponents; +use sp_consensus_aura::{Slot, SlotDuration, AURA_ENGINE_ID}; +use sp_core::Encode; +use sp_inherents::InherentData; use sp_keyring::Sr25519Keyring; +use sp_runtime::{Digest, DigestItem}; +use sp_timestamp::TimestampInherentData; impl SubstrateCli for Cli { fn impl_name() -> String { @@ -184,11 +189,32 @@ pub fn run() -> sc_cli::Result<()> { let task_manager = sc_service::TaskManager::new(config.tokio_handle.clone(), registry) .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?; + + let info_provider = |_, maybe_prev_info: Option<(InherentData, Digest)>| async { + const BLOCKTIME_MILLIS: u64 = 2 * 3_000; + + let timestamp_idp = match maybe_prev_info { + Some((inherent_data, _)) => sp_timestamp::InherentDataProvider::new( + inherent_data.timestamp_inherent_data().unwrap().unwrap() + + BLOCKTIME_MILLIS, + ), + None => sp_timestamp::InherentDataProvider::from_system_time(), + }; + + let slot = Slot::from_timestamp( + *timestamp_idp, + SlotDuration::from_millis(BLOCKTIME_MILLIS), + ); + let digest = vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())]; + + Ok((timestamp_idp, digest)) + }; + Ok(( cmd.run::::ExtendHostFunctions, - >>(), + >, _>(Some(info_provider)), task_manager, )) }) diff --git a/utils/frame/try-runtime/cli/Cargo.toml b/utils/frame/try-runtime/cli/Cargo.toml index d6f211392c6cf..b16dbaea26723 100644 --- a/utils/frame/try-runtime/cli/Cargo.toml +++ b/utils/frame/try-runtime/cli/Cargo.toml @@ -19,6 +19,7 @@ sc-executor = { version = "0.10.0-dev", path = "../../../../client/executor" } sc-service = { version = "0.10.0-dev", default-features = false, path = "../../../../client/service" } sp-core = { version = "7.0.0", path = "../../../../primitives/core" } sp-externalities = { version = "0.13.0", path = "../../../../primitives/externalities" } +sp-inherents = { path = "../../../../primitives/inherents" } sp-io = { version = "7.0.0", path = "../../../../primitives/io" } sp-keystore = { version = "0.13.0", path = "../../../../primitives/keystore" } sp-runtime = { version = "7.0.0", path = "../../../../primitives/runtime" } @@ -31,6 +32,7 @@ sp-weights = { version = "4.0.0", path = "../../../../primitives/weights" } frame-try-runtime = { optional = true, path = "../../../../frame/try-runtime" } substrate-rpc-client = { path = "../../rpc/client" } +async-trait = "0.1.57" parity-scale-codec = "3.0.0" hex = "0.4.3" clap = { version = "4.0.9", features = ["derive"] } diff --git a/utils/frame/try-runtime/cli/src/commands/fast_forward.rs b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs new file mode 100644 index 0000000000000..b706fb1e9df06 --- /dev/null +++ b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs @@ -0,0 +1,292 @@ +use crate::{ + build_executor, full_extensions, rpc_err_handler, state_machine_call, BlockT, LiveState, + SharedParams, State, +}; +use parity_scale_codec::{Decode, Encode}; +use sc_cli::Result; +use sc_executor::{sp_wasm_interface::HostFunctions, WasmExecutor}; +use serde::de::DeserializeOwned; +use sp_core::H256; +use sp_inherents::{InherentData, InherentDataProvider}; +use sp_io::TestExternalities; +use sp_runtime::{ + traits::{Header, NumberFor, One}, + Digest, DigestItem, +}; +use std::{fmt::Debug, str::FromStr}; +use substrate_rpc_client::{ws_client, ChainApi}; + +/// Configurations of the [`Command::FastForward`]. +#[derive(Debug, Clone, clap::Parser)] +pub struct FastForwardCmd { + /// How many blocks should be processed. If `None`, then blocks will be produced and processed + /// in a loop. + #[arg(long)] + n_blocks: Option, + + /// The state type to use. + #[command(subcommand)] + state: State, + + /// The ws uri from which to fetch the block. + /// + /// If `state` is `Live`, this is ignored. Otherwise, it must not be empty. + // todo: make use of clap's arg groups + #[arg(long, value_parser = crate::parse::url)] + block_ws_uri: Option, + + /// Which try-state targets to execute when running this command. + /// + /// Expected values: + /// - `all` + /// - `none` + /// - A comma separated list of pallets, as per pallet names in `construct_runtime!()` (e.g. + /// `Staking, System`). + /// - `rr-[x]` where `[x]` is a number. Then, the given number of pallets are checked in a + /// round-robin fashion. + #[arg(long, default_value = "all")] + try_state: frame_try_runtime::TryStateSelect, +} + +impl FastForwardCmd { + 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`"), + } + } +} + +/// Something that can create inherent data providers and pre-runtime digest. +/// +/// It is possible for the caller to provide custom arguments to the callee by setting the +/// `ExtraArgs` generic parameter. +/// +/// This module already provides some convenience implementation of this trait for closures. So, it +/// should not be required to implement +#[async_trait::async_trait] +pub trait BlockBuildingInfoProvider { + type InherentDataProviders: InherentDataProvider; + + async fn get_inherent_providers_and_pre_digest( + &self, + parent_hash: Block::Hash, + extra_args: ExtraArgs, + ) -> Result<(Self::InherentDataProviders, Vec)>; +} + +#[async_trait::async_trait] +impl BlockBuildingInfoProvider for F +where + Block: BlockT, + F: Fn(Block::Hash, ExtraArgs) -> Fut + Sync + Send, + Fut: std::future::Future)>> + Send + 'static, + IDP: InherentDataProvider + 'static, + ExtraArgs: Send + 'static, +{ + type InherentDataProviders = IDP; + + async fn get_inherent_providers_and_pre_digest( + &self, + parent: Block::Hash, + extra_args: ExtraArgs, + ) -> Result<(Self::InherentDataProviders, Vec)> { + (*self)(parent, extra_args).await + } +} + +/// Read the block number corresponding to `hash` with an RPC call to `ws_uri`. +async fn get_block_number( + hash: Block::Hash, + ws_uri: &str, +) -> Result> +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. +async fn dry_run( + externalities: &TestExternalities, + executor: &WasmExecutor, + method: &'static str, + data: &[u8], +) -> Result { + let (_, result) = state_machine_call::( + externalities, + executor, + method, + data, + full_extensions(), + )?; + + Ok(::decode(&mut &*result)?) +} + +/// Call `method` with `data` and actually save storage changes to `externalities`. +async fn run( + externalities: &mut TestExternalities, + executor: &WasmExecutor, + method: &'static str, + data: &[u8], +) -> Result<()> { + let (mut changes, _) = state_machine_call::( + externalities, + executor, + method, + data, + full_extensions(), + )?; + + let storage_changes = changes + .drain_storage_changes( + &externalities.backend, + &mut Default::default(), + externalities.state_version, + ) + .unwrap(); + + externalities + .backend + .apply_transaction(storage_changes.transaction_storage_root, storage_changes.transaction); + + Ok(()) +} + +/// Produce next empty block. +async fn next_empty_block< + Block: BlockT, + HostFns: HostFunctions, + BBIP: BlockBuildingInfoProvider>, +>( + externalities: &mut TestExternalities, + executor: &WasmExecutor, + parent_height: NumberFor, + parent_hash: Block::Hash, + block_building_info_provider: &Option, + previous_block_building_info: Option<(InherentData, Digest)>, +) -> Result<(Block, Option<(InherentData, Digest)>)> { + let (maybe_inherent_data, pre_digest) = match &block_building_info_provider { + None => (None, Default::default()), + Some(bbip) => { + let (inherent_data_provider, pre_digest) = bbip + .get_inherent_providers_and_pre_digest(parent_hash, previous_block_building_info) + .await?; + let inherent_data = inherent_data_provider + .create_inherent_data() + .await + .map_err(|e| sc_cli::Error::Input(format!("I don't know how to convert {e:?}")))?; + + (Some(inherent_data), Digest { logs: pre_digest }) + }, + }; + + let header = Block::Header::new( + parent_height + One::one(), + Default::default(), + Default::default(), + parent_hash, + pre_digest.clone(), + ); + let mut extrinsics = >::new(); + + run::(externalities, executor, "Core_initialize_block", &header.encode()).await?; + + if let Some(ref inherent_data) = maybe_inherent_data { + extrinsics = dry_run::, Block, _>( + externalities, + executor, + "BlockBuilder_inherent_extrinsics", + &inherent_data.encode(), + ) + .await?; + } + + for xt in &extrinsics { + run::(externalities, executor, "BlockBuilder_apply_extrinsic", &xt.encode()) + .await?; + } + + let header = dry_run::( + externalities, + executor, + "BlockBuilder_finalize_block", + &[0u8; 0], + ) + .await?; + + run::(externalities, executor, "BlockBuilder_finalize_block", &[0u8; 0]).await?; + + Ok((Block::new(header, extrinsics), (maybe_inherent_data.map(|id| (id, pre_digest))))) +} + +pub(crate) async fn fast_forward( + shared: SharedParams, + command: FastForwardCmd, + block_building_info_provider: Option, +) -> Result<()> +where + Block: BlockT + DeserializeOwned, + Block::Hash: FromStr, + Block::Header: DeserializeOwned, + ::Err: Debug, + NumberFor: FromStr, + as FromStr>::Err: Debug, + HostFns: HostFunctions, + BBIP: BlockBuildingInfoProvider>, +{ + let executor = build_executor::(&shared); + let ext = command.state.into_ext::(&shared, &executor, None).await?; + + let mut last_block_hash = ext.block_hash; + let mut last_block_number = + get_block_number::(last_block_hash, command.block_ws_uri()).await?; + let mut prev_block_building_info = None; + + let mut ext = ext.inner_ext; + + for _ in 1..=command.n_blocks.unwrap_or(u64::MAX) { + // We are saving state before we overwrite it while producing new block. + let backend = ext.as_backend(); + + log::info!("Producing new empty block at height {:?}", last_block_number + One::one()); + + let (next_block, new_block_building_info) = next_empty_block::( + &mut ext, + &executor, + last_block_number, + last_block_hash, + &block_building_info_provider, + prev_block_building_info, + ) + .await?; + + log::info!("Produced a new block: {:?}", next_block.header()); + + // And now we restore previous state. + ext.backend = backend; + + let state_root_check = true; + let signature_check = true; + let payload = + (next_block.clone(), state_root_check, signature_check, command.try_state.clone()) + .encode(); + run::(&mut 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 += One::one(); + } + + Ok(()) +} diff --git a/utils/frame/try-runtime/cli/src/commands/mod.rs b/utils/frame/try-runtime/cli/src/commands/mod.rs index ab0a066585f6a..81deb263163b0 100644 --- a/utils/frame/try-runtime/cli/src/commands/mod.rs +++ b/utils/frame/try-runtime/cli/src/commands/mod.rs @@ -17,6 +17,7 @@ pub mod create_snapshot; pub mod execute_block; +pub mod fast_forward; pub mod follow_chain; pub mod offchain_worker; pub mod on_runtime_upgrade; diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index 47a9dfa3f6544..69da6a30f0e43 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -358,6 +358,7 @@ #![cfg(feature = "try-runtime")] +use crate::commands::fast_forward::BlockBuildingInfoProvider; use parity_scale_codec::Decode; use remote_externalities::{ Builder, Mode, OfflineConfig, OnlineConfig, RemoteExternalities, SnapshotConfig, @@ -381,10 +382,11 @@ use sp_core::{ twox_128, H256, }; use sp_externalities::Extensions; +use sp_inherents::InherentData; use sp_keystore::{testing::KeyStore, KeystoreExt}; use sp_runtime::{ traits::{BlakeTwo256, Block as BlockT, NumberFor}, - DeserializeOwned, + DeserializeOwned, Digest, }; use sp_state_machine::{CompactProof, OverlayedChanges, StateMachine, TrieBackendBuilder}; use sp_version::StateVersion; @@ -445,6 +447,15 @@ pub enum Command { /// tested has remained the same, otherwise block decoding might fail. FollowChain(commands::follow_chain::FollowChainCmd), + /// Produce a series of empty, consecutive blocks and execute them one-by-one. + /// + /// To compare it with [`Command::FollowChain`]: + /// - we don't have the delay of the original blocktime (for Polkadot 6s), but instead, we + /// execute every block immediately + /// - the only data that will be put into blocks are pre-runtime digest items and inherent + /// extrinsics; both things should be defined in your node CLI handling level + FastForward(commands::fast_forward::FastForwardCmd), + /// Create a new snapshot file. CreateSnapshot(commands::create_snapshot::CreateSnapshotCmd), } @@ -484,7 +495,7 @@ pub struct SharedParams { /// go away. #[allow(missing_docs)] #[clap(flatten)] - pub shared_params: sc_cli::SharedParams, + shared_params: sc_cli::SharedParams, /// The runtime to use. /// @@ -505,7 +516,7 @@ pub struct SharedParams { ignore_case = true, default_value_t = DEFAULT_WASM_EXECUTION_METHOD, )] - pub wasm_method: WasmExecutionMethod, + wasm_method: WasmExecutionMethod, /// The WASM instantiation method to use. /// @@ -516,7 +527,7 @@ pub struct SharedParams { default_value_t = DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, value_enum, )] - pub wasmtime_instantiation_strategy: WasmtimeInstantiationStrategy, + wasmtime_instantiation_strategy: WasmtimeInstantiationStrategy, /// The number of 64KB pages to allocate for Wasm execution. Defaults to /// [`sc_service::Configuration.default_heap_pages`]. @@ -710,7 +721,10 @@ impl State { } impl TryRuntimeCmd { - pub async fn run(&self) -> sc_cli::Result<()> + pub async fn run( + &self, + block_building_info_provider: Option, + ) -> sc_cli::Result<()> where Block: BlockT + DeserializeOwned, Block::Header: DeserializeOwned, @@ -720,6 +734,7 @@ impl TryRuntimeCmd { as TryInto>::Error: Debug, NumberFor: FromStr, HostFns: HostFunctions, + BBIP: BlockBuildingInfoProvider>, { match &self.command { Command::OnRuntimeUpgrade(ref cmd) => @@ -746,6 +761,13 @@ impl TryRuntimeCmd { cmd.clone(), ) .await, + Command::FastForward(cmd) => + commands::fast_forward::fast_forward::( + self.shared.clone(), + cmd.clone(), + block_building_info_provider, + ) + .await, Command::CreateSnapshot(cmd) => commands::create_snapshot::create_snapshot::( self.shared.clone(), From 6cdf5e0718b88c7ee88820b9d527c561f5092fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 15 Dec 2022 12:25:13 +0100 Subject: [PATCH 02/13] Revert un`pub`ing command's fields --- utils/frame/try-runtime/cli/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index 69da6a30f0e43..2bdbafa52df66 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -495,7 +495,7 @@ pub struct SharedParams { /// go away. #[allow(missing_docs)] #[clap(flatten)] - shared_params: sc_cli::SharedParams, + pub shared_params: sc_cli::SharedParams, /// The runtime to use. /// @@ -516,7 +516,7 @@ pub struct SharedParams { ignore_case = true, default_value_t = DEFAULT_WASM_EXECUTION_METHOD, )] - wasm_method: WasmExecutionMethod, + pub wasm_method: WasmExecutionMethod, /// The WASM instantiation method to use. /// @@ -527,7 +527,7 @@ pub struct SharedParams { default_value_t = DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, value_enum, )] - wasmtime_instantiation_strategy: WasmtimeInstantiationStrategy, + pub wasmtime_instantiation_strategy: WasmtimeInstantiationStrategy, /// The number of 64KB pages to allocate for Wasm execution. Defaults to /// [`sc_service::Configuration.default_heap_pages`]. From 4641e1fd1543dea3d64bd886c7462232995b8ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Mon, 9 Jan 2023 10:54:57 +0100 Subject: [PATCH 03/13] Handle storage change failure --- .../try-runtime/cli/src/commands/fast_forward.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/utils/frame/try-runtime/cli/src/commands/fast_forward.rs b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs index b706fb1e9df06..c1bca61a6ea6b 100644 --- a/utils/frame/try-runtime/cli/src/commands/fast_forward.rs +++ b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs @@ -146,13 +146,11 @@ async fn run( full_extensions(), )?; - let storage_changes = changes - .drain_storage_changes( - &externalities.backend, - &mut Default::default(), - externalities.state_version, - ) - .unwrap(); + let storage_changes = changes.drain_storage_changes( + &externalities.backend, + &mut Default::default(), + externalities.state_version, + )?; externalities .backend From f8e4e284a27ec8a4d4aa1362cacb76ffe0820153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Tue, 10 Jan 2023 13:18:59 +0100 Subject: [PATCH 04/13] Adjust Substrate node --- bin/node/cli/src/command.rs | 44 +++++++++++++++++-- .../cli/src/commands/fast_forward.rs | 3 +- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index fd464bbc914a5..752f2e9722f44 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -22,14 +22,20 @@ use crate::{ service::{new_partial, FullClient}, Cli, Subcommand, }; +use codec::Encode; use frame_benchmarking_cli::*; -use kitchensink_runtime::{ExistentialDeposit, RuntimeApi}; +use kitchensink_runtime::{constants::time::SLOT_DURATION, ExistentialDeposit, RuntimeApi}; use node_executor::ExecutorDispatch; -use node_primitives::Block; +use node_primitives::{Block, Header}; use sc_cli::{ChainSpec, Result, RuntimeVersion, SubstrateCli}; use sc_service::PartialComponents; +use sp_consensus_babe::{Slot, SlotDuration, BABE_ENGINE_ID}; use sp_keyring::Sr25519Keyring; +use sc_consensus_babe::{PreDigest, SecondaryPlainPreDigest}; +use sp_inherents::InherentData; +use sp_runtime::{Digest, DigestItem}; +use sp_timestamp::TimestampInherentData; use std::sync::Arc; impl SubstrateCli for Cli { @@ -237,11 +243,43 @@ pub fn run() -> Result<()> { sc_service::TaskManager::new(config.tokio_handle.clone(), registry) .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?; + let info_provider = |_, maybe_prev_info: Option<(InherentData, Digest)>| async { + let uncles_idp = sp_authorship::InherentDataProvider::
::new(vec![]); + + let timestamp_idp = match maybe_prev_info { + Some((inherent_data, _)) => sp_timestamp::InherentDataProvider::new( + inherent_data.timestamp_inherent_data().unwrap().unwrap() + + SLOT_DURATION, + ), + None => sp_timestamp::InherentDataProvider::from_system_time(), + }; + + let slot = Slot::from_timestamp( + *timestamp_idp, + SlotDuration::from_millis(SLOT_DURATION), + ); + let slot_idp = sp_consensus_babe::inherents::InherentDataProvider::new(slot); + + let storage_proof_idp = + sp_transaction_storage_proof::InherentDataProvider::new(None); + + let digest = vec![DigestItem::PreRuntime( + BABE_ENGINE_ID, + PreDigest::SecondaryPlain(SecondaryPlainPreDigest { + slot, + authority_index: 0, + }) + .encode(), + )]; + + Ok(((slot_idp, timestamp_idp, uncles_idp, storage_proof_idp), digest)) + }; + Ok(( cmd.run::::ExtendHostFunctions, - >>(), + >, _>(Some(info_provider)), task_manager, )) }) diff --git a/utils/frame/try-runtime/cli/src/commands/fast_forward.rs b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs index c1bca61a6ea6b..ada2eb5fc6f94 100644 --- a/utils/frame/try-runtime/cli/src/commands/fast_forward.rs +++ b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs @@ -31,7 +31,6 @@ pub struct FastForwardCmd { /// The ws uri from which to fetch the block. /// /// If `state` is `Live`, this is ignored. Otherwise, it must not be empty. - // todo: make use of clap's arg groups #[arg(long, value_parser = crate::parse::url)] block_ws_uri: Option, @@ -66,7 +65,7 @@ impl FastForwardCmd { /// `ExtraArgs` generic parameter. /// /// This module already provides some convenience implementation of this trait for closures. So, it -/// should not be required to implement +/// should not be required to implement it directly. #[async_trait::async_trait] pub trait BlockBuildingInfoProvider { type InherentDataProviders: InherentDataProvider; From 576204dff1c641e3e601079a696bc619a1ba1ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Tue, 10 Jan 2023 15:12:52 +0100 Subject: [PATCH 05/13] Feature-gated imports --- bin/node/cli/src/command.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index 752f2e9722f44..8468e7af7fa86 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -22,22 +22,28 @@ use crate::{ service::{new_partial, FullClient}, Cli, Subcommand, }; -use codec::Encode; use frame_benchmarking_cli::*; -use kitchensink_runtime::{constants::time::SLOT_DURATION, ExistentialDeposit, RuntimeApi}; +use kitchensink_runtime::{ExistentialDeposit, RuntimeApi}; use node_executor::ExecutorDispatch; -use node_primitives::{Block, Header}; +use node_primitives::Block; use sc_cli::{ChainSpec, Result, RuntimeVersion, SubstrateCli}; use sc_service::PartialComponents; -use sp_consensus_babe::{Slot, SlotDuration, BABE_ENGINE_ID}; use sp_keyring::Sr25519Keyring; -use sc_consensus_babe::{PreDigest, SecondaryPlainPreDigest}; -use sp_inherents::InherentData; -use sp_runtime::{Digest, DigestItem}; -use sp_timestamp::TimestampInherentData; use std::sync::Arc; +#[cfg(feature = "try-runtime")] +use { + codec::Encode, + kitchensink_runtime::constants::time::SLOT_DURATION, + node_primitives::Header, + sc_consensus_babe::{PreDigest, SecondaryPlainPreDigest}, + sp_consensus_babe::{Slot, SlotDuration, BABE_ENGINE_ID}, + sp_inherents::InherentData, + sp_runtime::{Digest, DigestItem}, + sp_timestamp::TimestampInherentData, +}; + impl SubstrateCli for Cli { fn impl_name() -> String { "Substrate Node".into() From 80e35f94a203d8dc4a72336c3b065a10f859d669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Tue, 10 Jan 2023 15:17:21 +0100 Subject: [PATCH 06/13] doc link --- utils/frame/try-runtime/cli/src/commands/fast_forward.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/frame/try-runtime/cli/src/commands/fast_forward.rs b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs index ada2eb5fc6f94..f85475f220c9b 100644 --- a/utils/frame/try-runtime/cli/src/commands/fast_forward.rs +++ b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs @@ -16,7 +16,7 @@ use sp_runtime::{ use std::{fmt::Debug, str::FromStr}; use substrate_rpc_client::{ws_client, ChainApi}; -/// Configurations of the [`Command::FastForward`]. +/// Configurations of the [`crate::Command::FastForward`]. #[derive(Debug, Clone, clap::Parser)] pub struct FastForwardCmd { /// How many blocks should be processed. If `None`, then blocks will be produced and processed From 9ba596e6ada928a810e371d8bed0c4a426590f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Tue, 10 Jan 2023 15:20:52 +0100 Subject: [PATCH 07/13] Feature-gated imports in node-template --- bin/node-template/node/src/command.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bin/node-template/node/src/command.rs b/bin/node-template/node/src/command.rs index aeb579643b049..ad7ae2cc3418c 100644 --- a/bin/node-template/node/src/command.rs +++ b/bin/node-template/node/src/command.rs @@ -8,12 +8,16 @@ use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE use node_template_runtime::{Block, EXISTENTIAL_DEPOSIT}; use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli}; use sc_service::PartialComponents; -use sp_consensus_aura::{Slot, SlotDuration, AURA_ENGINE_ID}; -use sp_core::Encode; -use sp_inherents::InherentData; use sp_keyring::Sr25519Keyring; -use sp_runtime::{Digest, DigestItem}; -use sp_timestamp::TimestampInherentData; + +#[cfg(feature = "try-runtime")] +use { + sp_consensus_aura::{Slot, SlotDuration, AURA_ENGINE_ID}, + sp_core::Encode, + sp_inherents::InherentData, + sp_runtime::{Digest, DigestItem}, + sp_timestamp::TimestampInherentData, +}; impl SubstrateCli for Cli { fn impl_name() -> String { From b72c49d44bfb8637f099faffb118de5c4aa2659a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 15:31:40 +0100 Subject: [PATCH 08/13] Move trait, blanket implementation and auxiliary functions to a new module --- Cargo.lock | 5 + bin/node-template/node/src/command.rs | 29 +---- bin/node/cli/src/command.rs | 40 +------ utils/frame/try-runtime/cli/Cargo.toml | 5 + .../cli/src/block_building_info.rs | 101 ++++++++++++++++++ .../cli/src/commands/fast_forward.rs | 44 +------- utils/frame/try-runtime/cli/src/lib.rs | 3 +- 7 files changed, 120 insertions(+), 107 deletions(-) create mode 100644 utils/frame/try-runtime/cli/src/block_building_info.rs diff --git a/Cargo.lock b/Cargo.lock index 9e0d400ffc2ad..6476412535f8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11371,6 +11371,9 @@ dependencies = [ "serde", "serde_json", "sp-api", + "sp-authorship", + "sp-consensus-aura", + "sp-consensus-babe", "sp-core", "sp-debug-derive", "sp-externalities", @@ -11380,6 +11383,8 @@ dependencies = [ "sp-rpc", "sp-runtime", "sp-state-machine", + "sp-timestamp", + "sp-transaction-storage-proof", "sp-version", "sp-weights", "substrate-rpc-client", diff --git a/bin/node-template/node/src/command.rs b/bin/node-template/node/src/command.rs index ad7ae2cc3418c..c3dc098cdfb3a 100644 --- a/bin/node-template/node/src/command.rs +++ b/bin/node-template/node/src/command.rs @@ -11,13 +11,7 @@ use sc_service::PartialComponents; use sp_keyring::Sr25519Keyring; #[cfg(feature = "try-runtime")] -use { - sp_consensus_aura::{Slot, SlotDuration, AURA_ENGINE_ID}, - sp_core::Encode, - sp_inherents::InherentData, - sp_runtime::{Digest, DigestItem}, - sp_timestamp::TimestampInherentData, -}; +use try_runtime_cli::block_building_info::timestamp_with_aura_info; impl SubstrateCli for Cli { fn impl_name() -> String { @@ -193,26 +187,7 @@ pub fn run() -> sc_cli::Result<()> { let task_manager = sc_service::TaskManager::new(config.tokio_handle.clone(), registry) .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?; - - let info_provider = |_, maybe_prev_info: Option<(InherentData, Digest)>| async { - const BLOCKTIME_MILLIS: u64 = 2 * 3_000; - - let timestamp_idp = match maybe_prev_info { - Some((inherent_data, _)) => sp_timestamp::InherentDataProvider::new( - inherent_data.timestamp_inherent_data().unwrap().unwrap() + - BLOCKTIME_MILLIS, - ), - None => sp_timestamp::InherentDataProvider::from_system_time(), - }; - - let slot = Slot::from_timestamp( - *timestamp_idp, - SlotDuration::from_millis(BLOCKTIME_MILLIS), - ); - let digest = vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())]; - - Ok((timestamp_idp, digest)) - }; + let info_provider = timestamp_with_aura_info(6000); Ok(( cmd.run:: Result<()> { sc_service::TaskManager::new(config.tokio_handle.clone(), registry) .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?; - let info_provider = |_, maybe_prev_info: Option<(InherentData, Digest)>| async { - let uncles_idp = sp_authorship::InherentDataProvider::
::new(vec![]); - - let timestamp_idp = match maybe_prev_info { - Some((inherent_data, _)) => sp_timestamp::InherentDataProvider::new( - inherent_data.timestamp_inherent_data().unwrap().unwrap() + - SLOT_DURATION, - ), - None => sp_timestamp::InherentDataProvider::from_system_time(), - }; - - let slot = Slot::from_timestamp( - *timestamp_idp, - SlotDuration::from_millis(SLOT_DURATION), - ); - let slot_idp = sp_consensus_babe::inherents::InherentDataProvider::new(slot); - - let storage_proof_idp = - sp_transaction_storage_proof::InherentDataProvider::new(None); - - let digest = vec![DigestItem::PreRuntime( - BABE_ENGINE_ID, - PreDigest::SecondaryPlain(SecondaryPlainPreDigest { - slot, - authority_index: 0, - }) - .encode(), - )]; - - Ok(((slot_idp, timestamp_idp, uncles_idp, storage_proof_idp), digest)) - }; + let info_provider = timestamp_with_babe_info(SLOT_DURATION); Ok(( cmd.run:: { + type InherentDataProviders: InherentDataProvider; + + async fn get_inherent_providers_and_pre_digest( + &self, + parent_hash: Block::Hash, + extra_args: ExtraArgs, + ) -> Result<(Self::InherentDataProviders, Vec)>; +} + +#[async_trait::async_trait] +impl BlockBuildingInfoProvider for F +where + Block: BlockT, + F: Fn(Block::Hash, ExtraArgs) -> Fut + Sync + Send, + Fut: std::future::Future)>> + Send + 'static, + IDP: InherentDataProvider + 'static, + ExtraArgs: Send + 'static, +{ + type InherentDataProviders = IDP; + + async fn get_inherent_providers_and_pre_digest( + &self, + parent: Block::Hash, + extra_args: ExtraArgs, + ) -> Result<(Self::InherentDataProviders, Vec)> { + (*self)(parent, extra_args).await + } +} + +/// Provides [`BlockBuildingInfoProvider`] implementation for chains that include timestamp inherent +/// and use Aura for a block production. +pub fn timestamp_with_aura_info( + blocktime_millis: u64, +) -> impl BlockBuildingInfoProvider> { + move |_, maybe_prev_info: Option<(InherentData, Digest)>| async move { + let timestamp_idp = match maybe_prev_info { + Some((inherent_data, _)) => sp_timestamp::InherentDataProvider::new( + inherent_data.timestamp_inherent_data().unwrap().unwrap() + blocktime_millis, + ), + None => sp_timestamp::InherentDataProvider::from_system_time(), + }; + + let slot = + Slot::from_timestamp(*timestamp_idp, SlotDuration::from_millis(blocktime_millis)); + let digest = vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())]; + + Ok((timestamp_idp, digest)) + } +} + +/// Provides [`BlockBuildingInfoProvider`] implementation for chains that include timestamp inherent +/// and use Babe for a block production. +pub fn timestamp_with_babe_info( + blocktime_millis: u64, +) -> impl BlockBuildingInfoProvider> { + move |_, maybe_prev_info: Option<(InherentData, Digest)>| async move { + let uncles_idp = sp_authorship::InherentDataProvider::::new(vec![]); + + let timestamp_idp = match maybe_prev_info { + Some((inherent_data, _)) => sp_timestamp::InherentDataProvider::new( + inherent_data.timestamp_inherent_data().unwrap().unwrap() + blocktime_millis, + ), + None => sp_timestamp::InherentDataProvider::from_system_time(), + }; + + let slot = + Slot::from_timestamp(*timestamp_idp, SlotDuration::from_millis(blocktime_millis)); + let slot_idp = sp_consensus_babe::inherents::InherentDataProvider::new(slot); + + let storage_proof_idp = sp_transaction_storage_proof::InherentDataProvider::new(None); + + let digest = vec![DigestItem::PreRuntime( + BABE_ENGINE_ID, + PreDigest::SecondaryPlain(SecondaryPlainPreDigest { slot, authority_index: 0 }) + .encode(), + )]; + + Ok(((slot_idp, timestamp_idp, uncles_idp, storage_proof_idp), digest)) + } +} diff --git a/utils/frame/try-runtime/cli/src/commands/fast_forward.rs b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs index f85475f220c9b..470b75e442298 100644 --- a/utils/frame/try-runtime/cli/src/commands/fast_forward.rs +++ b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs @@ -1,6 +1,6 @@ use crate::{ - build_executor, full_extensions, rpc_err_handler, state_machine_call, BlockT, LiveState, - SharedParams, State, + block_building_info::BlockBuildingInfoProvider, build_executor, full_extensions, + rpc_err_handler, state_machine_call, BlockT, LiveState, SharedParams, State, }; use parity_scale_codec::{Decode, Encode}; use sc_cli::Result; @@ -11,7 +11,7 @@ use sp_inherents::{InherentData, InherentDataProvider}; use sp_io::TestExternalities; use sp_runtime::{ traits::{Header, NumberFor, One}, - Digest, DigestItem, + Digest, }; use std::{fmt::Debug, str::FromStr}; use substrate_rpc_client::{ws_client, ChainApi}; @@ -59,44 +59,6 @@ impl FastForwardCmd { } } -/// Something that can create inherent data providers and pre-runtime digest. -/// -/// It is possible for the caller to provide custom arguments to the callee by setting the -/// `ExtraArgs` generic parameter. -/// -/// This module already provides some convenience implementation of this trait for closures. So, it -/// should not be required to implement it directly. -#[async_trait::async_trait] -pub trait BlockBuildingInfoProvider { - type InherentDataProviders: InherentDataProvider; - - async fn get_inherent_providers_and_pre_digest( - &self, - parent_hash: Block::Hash, - extra_args: ExtraArgs, - ) -> Result<(Self::InherentDataProviders, Vec)>; -} - -#[async_trait::async_trait] -impl BlockBuildingInfoProvider for F -where - Block: BlockT, - F: Fn(Block::Hash, ExtraArgs) -> Fut + Sync + Send, - Fut: std::future::Future)>> + Send + 'static, - IDP: InherentDataProvider + 'static, - ExtraArgs: Send + 'static, -{ - type InherentDataProviders = IDP; - - async fn get_inherent_providers_and_pre_digest( - &self, - parent: Block::Hash, - extra_args: ExtraArgs, - ) -> Result<(Self::InherentDataProviders, Vec)> { - (*self)(parent, extra_args).await - } -} - /// Read the block number corresponding to `hash` with an RPC call to `ws_uri`. async fn get_block_number( hash: Block::Hash, diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index f358cd6aa304d..551b3a0822acf 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -358,7 +358,7 @@ #![cfg(feature = "try-runtime")] -use crate::commands::fast_forward::BlockBuildingInfoProvider; +use crate::block_building_info::BlockBuildingInfoProvider; use parity_scale_codec::Decode; use remote_externalities::{ Builder, Mode, OfflineConfig, OnlineConfig, RemoteExternalities, SnapshotConfig, @@ -392,6 +392,7 @@ use sp_state_machine::{CompactProof, OverlayedChanges, StateMachine, TrieBackend use sp_version::StateVersion; use std::{fmt::Debug, path::PathBuf, str::FromStr}; +pub mod block_building_info; pub mod commands; pub(crate) mod parse; pub(crate) const LOG_TARGET: &str = "try-runtime::cli"; From 3d4a6d2a49490698231e8aa1720c1090660bb1ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Tue, 17 Jan 2023 08:54:55 +0100 Subject: [PATCH 09/13] Distinguish between plain babe+timestamp and substrate enhanced info --- bin/node/cli/src/command.rs | 4 +-- .../cli/src/block_building_info.rs | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index c040d8e78f8be..2a6fd06643f29 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -35,7 +35,7 @@ use std::sync::Arc; #[cfg(feature = "try-runtime")] use { kitchensink_runtime::constants::time::SLOT_DURATION, - try_runtime_cli::block_building_info::timestamp_with_babe_info, + try_runtime_cli::block_building_info::substrate_info, }; impl SubstrateCli for Cli { @@ -243,7 +243,7 @@ pub fn run() -> Result<()> { sc_service::TaskManager::new(config.tokio_handle.clone(), registry) .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?; - let info_provider = timestamp_with_babe_info(SLOT_DURATION); + let info_provider = substrate_info(SLOT_DURATION); Ok(( cmd.run::( /// and use Babe for a block production. pub fn timestamp_with_babe_info( blocktime_millis: u64, +) -> impl BlockBuildingInfoProvider> { + move |_, maybe_prev_info: Option<(InherentData, Digest)>| async move { + let timestamp_idp = match maybe_prev_info { + Some((inherent_data, _)) => sp_timestamp::InherentDataProvider::new( + inherent_data.timestamp_inherent_data().unwrap().unwrap() + blocktime_millis, + ), + None => sp_timestamp::InherentDataProvider::from_system_time(), + }; + + let slot = + Slot::from_timestamp(*timestamp_idp, SlotDuration::from_millis(blocktime_millis)); + let slot_idp = sp_consensus_babe::inherents::InherentDataProvider::new(slot); + + let digest = vec![DigestItem::PreRuntime( + BABE_ENGINE_ID, + PreDigest::SecondaryPlain(SecondaryPlainPreDigest { slot, authority_index: 0 }) + .encode(), + )]; + + Ok(((slot_idp, timestamp_idp), digest)) + } +} + +/// Provides [`BlockBuildingInfoProvider`] implementation for chains that use: +/// - timestamp inherent, +/// - Babe for a block production (inherent + digest), +/// - uncles inherent, +/// - storage proof inherent +pub fn substrate_info( + blocktime_millis: u64, ) -> impl BlockBuildingInfoProvider> { move |_, maybe_prev_info: Option<(InherentData, Digest)>| async move { let uncles_idp = sp_authorship::InherentDataProvider::::new(vec![]); From 9bd97b95f743fe450b5eceec8decaca80caaa849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 2 Feb 2023 07:51:07 +0100 Subject: [PATCH 10/13] Remove uncles inherents --- utils/frame/try-runtime/cli/Cargo.toml | 1 - utils/frame/try-runtime/cli/src/block_building_info.rs | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/utils/frame/try-runtime/cli/Cargo.toml b/utils/frame/try-runtime/cli/Cargo.toml index 6dac81f829dd2..a220289542464 100644 --- a/utils/frame/try-runtime/cli/Cargo.toml +++ b/utils/frame/try-runtime/cli/Cargo.toml @@ -16,7 +16,6 @@ remote-externalities = { version = "0.10.0-dev", path = "../../remote-externalit sc-cli = { version = "0.10.0-dev", path = "../../../../client/cli" } sc-executor = { version = "0.10.0-dev", path = "../../../../client/executor" } sc-service = { version = "0.10.0-dev", default-features = false, path = "../../../../client/service" } -sp-authorship = { path = "../../../../primitives/authorship" } sp-consensus-aura = { path = "../../../../primitives/consensus/aura" } sp-consensus-babe = { path = "../../../../primitives/consensus/babe" } sp-core = { version = "7.0.0", path = "../../../../primitives/core" } diff --git a/utils/frame/try-runtime/cli/src/block_building_info.rs b/utils/frame/try-runtime/cli/src/block_building_info.rs index 34f41436172aa..bd20f28f9a386 100644 --- a/utils/frame/try-runtime/cli/src/block_building_info.rs +++ b/utils/frame/try-runtime/cli/src/block_building_info.rs @@ -105,8 +105,6 @@ pub fn substrate_info( blocktime_millis: u64, ) -> impl BlockBuildingInfoProvider> { move |_, maybe_prev_info: Option<(InherentData, Digest)>| async move { - let uncles_idp = sp_authorship::InherentDataProvider::::new(vec![]); - let timestamp_idp = match maybe_prev_info { Some((inherent_data, _)) => sp_timestamp::InherentDataProvider::new( inherent_data.timestamp_inherent_data().unwrap().unwrap() + blocktime_millis, @@ -126,6 +124,6 @@ pub fn substrate_info( .encode(), )]; - Ok(((slot_idp, timestamp_idp, uncles_idp, storage_proof_idp), digest)) + Ok(((slot_idp, timestamp_idp, storage_proof_idp), digest)) } } From 30e34289a2849590b618e044fcb70ef2841b078b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 2 Feb 2023 08:03:15 +0100 Subject: [PATCH 11/13] Missing argument --- Cargo.lock | 1 - utils/frame/try-runtime/cli/src/commands/fast_forward.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fa7259fcb92b2..c7f0d38c12fd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11428,7 +11428,6 @@ dependencies = [ "serde", "serde_json", "sp-api", - "sp-authorship", "sp-consensus-aura", "sp-consensus-babe", "sp-core", diff --git a/utils/frame/try-runtime/cli/src/commands/fast_forward.rs b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs index 470b75e442298..72a44ef31b8de 100644 --- a/utils/frame/try-runtime/cli/src/commands/fast_forward.rs +++ b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs @@ -203,7 +203,7 @@ where BBIP: BlockBuildingInfoProvider>, { let executor = build_executor::(&shared); - let ext = command.state.into_ext::(&shared, &executor, None).await?; + let ext = command.state.into_ext::(&shared, &executor, None, true).await?; let mut last_block_hash = ext.block_hash; let mut last_block_number = From 5bbc309abcb3c31a27dbafe2ce07f42f52180f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 9 Feb 2023 10:23:58 +0100 Subject: [PATCH 12/13] Add doc comment about `blocktime_millis` --- utils/frame/try-runtime/cli/src/block_building_info.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/utils/frame/try-runtime/cli/src/block_building_info.rs b/utils/frame/try-runtime/cli/src/block_building_info.rs index bd20f28f9a386..9162f26898bc7 100644 --- a/utils/frame/try-runtime/cli/src/block_building_info.rs +++ b/utils/frame/try-runtime/cli/src/block_building_info.rs @@ -50,6 +50,8 @@ where /// Provides [`BlockBuildingInfoProvider`] implementation for chains that include timestamp inherent /// and use Aura for a block production. +/// +/// It depends only on the expected block production frequency, i.e. `blocktime_millis`. pub fn timestamp_with_aura_info( blocktime_millis: u64, ) -> impl BlockBuildingInfoProvider> { @@ -71,6 +73,8 @@ pub fn timestamp_with_aura_info( /// Provides [`BlockBuildingInfoProvider`] implementation for chains that include timestamp inherent /// and use Babe for a block production. +/// +/// It depends only on the expected block production frequency, i.e. `blocktime_millis`. pub fn timestamp_with_babe_info( blocktime_millis: u64, ) -> impl BlockBuildingInfoProvider> { @@ -101,6 +105,8 @@ pub fn timestamp_with_babe_info( /// - Babe for a block production (inherent + digest), /// - uncles inherent, /// - storage proof inherent +/// +/// It depends only on the expected block production frequency, i.e. `blocktime_millis`. pub fn substrate_info( blocktime_millis: u64, ) -> impl BlockBuildingInfoProvider> { From cc6781c70bfc0f97c0aeb91e5f50d2f1b5c2b826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 15 Feb 2023 10:15:51 +0100 Subject: [PATCH 13/13] Add licenses --- .../try-runtime/cli/src/block_building_info.rs | 17 +++++++++++++++++ .../cli/src/commands/fast_forward.rs | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/utils/frame/try-runtime/cli/src/block_building_info.rs b/utils/frame/try-runtime/cli/src/block_building_info.rs index 9162f26898bc7..b68bf081fee3e 100644 --- a/utils/frame/try-runtime/cli/src/block_building_info.rs +++ b/utils/frame/try-runtime/cli/src/block_building_info.rs @@ -1,3 +1,20 @@ +// This file is part of Substrate. + +// Copyright (C) 2021-2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use crate::BlockT; use parity_scale_codec::Encode; use sc_cli::Result; diff --git a/utils/frame/try-runtime/cli/src/commands/fast_forward.rs b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs index 72a44ef31b8de..ae8f9a5cf17f2 100644 --- a/utils/frame/try-runtime/cli/src/commands/fast_forward.rs +++ b/utils/frame/try-runtime/cli/src/commands/fast_forward.rs @@ -1,3 +1,20 @@ +// This file is part of Substrate. + +// Copyright (C) 2021-2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use crate::{ block_building_info::BlockBuildingInfoProvider, build_executor, full_extensions, rpc_err_handler, state_machine_call, BlockT, LiveState, SharedParams, State,