Cumulus test service cleanup (#2887)

closes #2567 

Followup for https://github.com/paritytech/polkadot-sdk/pull/2331

This PR contains multiple internal cleanups:

1. This gets rid of the functionality in `generate_genesis_block` which
was only used in one benchmark
2. Fixed `transaction_pool` and `transaction_throughput` benchmarks
failing since they require a tokio runtime now.
3. Removed `parachain_id` CLI option from the test parachain
4. Removed `expect` call from `RuntimeResolver`
This commit is contained in:
Sebastian Kunert
2024-01-11 17:44:03 +01:00
committed by GitHub
parent f270b08a48
commit c93f5aba8a
8 changed files with 70 additions and 135 deletions
+2 -6
View File
@@ -38,9 +38,6 @@ pub struct TestCollatorCli {
#[command(flatten)]
pub run: cumulus_client_cli::RunCmd,
#[arg(default_value_t = 2000u32)]
pub parachain_id: u32,
/// Relay chain arguments
#[arg(raw = true)]
pub relaychain_args: Vec<String>,
@@ -256,9 +253,8 @@ impl SubstrateCli for TestCollatorCli {
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"" => Box::new(cumulus_test_service::get_chain_spec(Some(ParaId::from(
self.parachain_id,
)))) as Box<_>,
"" =>
Box::new(cumulus_test_service::get_chain_spec(Some(ParaId::from(2000)))) as Box<_>,
path => {
let chain_spec =
cumulus_test_service::chain_spec::ChainSpec::from_json_file(path.into())?;
-69
View File
@@ -1,69 +0,0 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
use codec::Encode;
use cumulus_primitives_core::ParaId;
use cumulus_test_runtime::Block;
use polkadot_primitives::HeadData;
use sc_chain_spec::ChainSpec;
use sp_runtime::{
traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero},
StateVersion,
};
/// Generate a simple test genesis block from a given ChainSpec.
pub fn generate_genesis_block<Block: BlockT>(
chain_spec: &dyn ChainSpec,
genesis_state_version: StateVersion,
) -> Result<Block, String> {
let storage = chain_spec.build_storage()?;
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
child_content.data.clone().into_iter().collect(),
genesis_state_version,
);
(sk.clone(), state_root.encode())
});
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
storage.top.clone().into_iter().chain(child_roots).collect(),
genesis_state_version,
);
let extrinsics_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
Vec::new(),
genesis_state_version,
);
Ok(Block::new(
<<Block as BlockT>::Header as HeaderT>::new(
Zero::zero(),
extrinsics_root,
state_root,
Default::default(),
Default::default(),
),
Default::default(),
))
}
/// Returns the initial head data for a parachain ID.
pub fn initial_head_data(para_id: ParaId) -> HeadData {
let spec = crate::chain_spec::get_chain_spec(Some(para_id));
let block: Block = generate_genesis_block(&spec, sp_runtime::StateVersion::V1).unwrap();
let genesis_state = block.header().encode();
genesis_state.into()
}
+4 -6
View File
@@ -23,9 +23,6 @@ pub mod bench_utils;
pub mod chain_spec;
/// Utilities for creating test genesis block and head data
pub mod genesis;
use runtime::AccountId;
use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY};
use std::{
@@ -88,7 +85,6 @@ use substrate_test_client::{
pub use chain_spec::*;
pub use cumulus_test_runtime as runtime;
pub use genesis::*;
pub use sp_keyring::Sr25519Keyring as Keyring;
const LOG_TARGET: &str = "cumulus-test-service";
@@ -922,7 +918,7 @@ pub fn run_relay_chain_validator_node(
) -> polkadot_test_service::PolkadotTestNode {
let mut config = polkadot_test_service::node_config(
storage_update_func,
tokio_handle,
tokio_handle.clone(),
key,
boot_nodes,
true,
@@ -936,5 +932,7 @@ pub fn run_relay_chain_validator_node(
workers_path.pop();
workers_path.pop();
polkadot_test_service::run_validator_node(config, Some(workers_path))
tokio_handle.block_on(async move {
polkadot_test_service::run_validator_node(config, Some(workers_path))
})
}
+7 -11
View File
@@ -19,9 +19,8 @@ mod cli;
use std::sync::Arc;
use cli::{RelayChainCli, Subcommand, TestCollatorCli};
use cumulus_primitives_core::{relay_chain::CollatorPair, ParaId};
use cumulus_test_service::{new_partial, AnnounceBlockFn};
use polkadot_service::runtime_traits::AccountIdConversion;
use cumulus_primitives_core::relay_chain::CollatorPair;
use cumulus_test_service::{chain_spec, new_partial, AnnounceBlockFn};
use sc_cli::{CliConfiguration, SubstrateCli};
use sp_core::Pair;
@@ -68,24 +67,21 @@ fn main() -> Result<(), sc_cli::Error> {
.create_configuration(&cli, tokio_handle.clone())
.expect("Should be able to generate config");
let parachain_id = ParaId::from(cli.parachain_id);
let polkadot_cli = RelayChainCli::new(
&config,
[RelayChainCli::executable_name()].iter().chain(cli.relaychain_args.iter()),
);
let parachain_account =
AccountIdConversion::<polkadot_primitives::AccountId>::into_account_truncating(
&parachain_id,
);
let tokio_handle = config.tokio_handle.clone();
let polkadot_config =
SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
.map_err(|err| format!("Relay chain argument error: {}", err))?;
let parachain_id = chain_spec::Extensions::try_get(&*config.chain_spec)
.map(|e| e.para_id)
.ok_or("Could not find parachain extension in chain-spec.")?;
tracing::info!("Parachain id: {:?}", parachain_id);
tracing::info!("Parachain Account: {}", parachain_account);
tracing::info!(
"Is collating: {}",
if config.role.is_authority() { "yes" } else { "no" }
@@ -109,7 +105,7 @@ fn main() -> Result<(), sc_cli::Error> {
config,
collator_key,
polkadot_config,
parachain_id,
parachain_id.into(),
cli.disable_block_announcements.then(wrap_announce_block),
cli.fail_pov_recovery,
|_| Ok(jsonrpsee::RpcModule::new(())),