mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 18:31:05 +00:00
Move cumulus zombienet tests to aura & async backing (#3568)
Cumulus test-parachain node and test runtime were still using relay chain consensus and 12s blocktimes. With async backing around the corner on the major chains we should switch our tests too. Also needed to nicely test the changes coming to collators in #3168. ### Changes Overview - Followed the [migration guide](https://wiki.polkadot.network/docs/maintain-guides-async-backing) for async backing for the cumulus-test-runtime - Adjusted the cumulus-test-service to use the correct import-queue, lookahead collator etc. - The block validation function now uses the Aura Ext Executor so that the seal of the block is validated - Previous point requires that we seal block before calling into `validate_block`, I introduced a helper function for that - Test client adjusted to provide a slot to the relay chain proof and the aura pre-digest
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
use cumulus_primitives_core::ParaId;
|
||||
use cumulus_test_runtime::{AccountId, RuntimeGenesisConfig, Signature};
|
||||
use parachains_common::AuraId;
|
||||
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
|
||||
use sc_service::ChainType;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -105,21 +106,43 @@ pub fn testnet_genesis_with_default_endowed(
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
|
||||
];
|
||||
endowed.append(&mut extra_endowed_accounts);
|
||||
let invulnerables = vec![
|
||||
get_collator_keys_from_seed::<AuraId>("Alice"),
|
||||
get_collator_keys_from_seed::<AuraId>("Bob"),
|
||||
get_collator_keys_from_seed::<AuraId>("Charlie"),
|
||||
get_collator_keys_from_seed::<AuraId>("Dave"),
|
||||
get_collator_keys_from_seed::<AuraId>("Eve"),
|
||||
get_collator_keys_from_seed::<AuraId>("Ferdie"),
|
||||
];
|
||||
testnet_genesis(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
invulnerables,
|
||||
endowed,
|
||||
self_para_id,
|
||||
)
|
||||
}
|
||||
|
||||
testnet_genesis(get_account_id_from_seed::<sr25519::Public>("Alice"), endowed, self_para_id)
|
||||
/// Generate collator keys from seed.
|
||||
///
|
||||
/// This function's return type must always match the session keys of the chain in tuple format.
|
||||
pub fn get_collator_keys_from_seed<AuraId: Public>(seed: &str) -> <AuraId::Pair as Pair>::Public {
|
||||
get_from_seed::<AuraId>(seed)
|
||||
}
|
||||
|
||||
/// Creates a local testnet genesis with endowed accounts.
|
||||
pub fn testnet_genesis(
|
||||
root_key: AccountId,
|
||||
invulnerables: Vec<AuraId>,
|
||||
endowed_accounts: Vec<AccountId>,
|
||||
self_para_id: Option<ParaId>,
|
||||
) -> serde_json::Value {
|
||||
let self_para_id = self_para_id.unwrap_or(cumulus_test_runtime::PARACHAIN_ID.into());
|
||||
serde_json::json!({
|
||||
"balances": cumulus_test_runtime::BalancesConfig {
|
||||
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
|
||||
},
|
||||
"sudo": cumulus_test_runtime::SudoConfig { key: Some(root_key) },
|
||||
"testPallet": cumulus_test_runtime::TestPalletConfig { self_para_id, ..Default::default() }
|
||||
"testPallet": cumulus_test_runtime::TestPalletConfig { self_para_id: Some(self_para_id), ..Default::default() },
|
||||
"aura": cumulus_test_runtime::AuraConfig { authorities: invulnerables }
|
||||
})
|
||||
}
|
||||
|
||||
@@ -23,8 +23,15 @@ pub mod bench_utils;
|
||||
|
||||
pub mod chain_spec;
|
||||
|
||||
use cumulus_client_collator::service::CollatorService;
|
||||
use cumulus_client_consensus_aura::{
|
||||
collators::lookahead::{self as aura, Params as AuraParams},
|
||||
ImportQueueParams,
|
||||
};
|
||||
use cumulus_client_consensus_proposer::Proposer;
|
||||
use runtime::AccountId;
|
||||
use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY};
|
||||
use sp_consensus_aura::sr25519::AuthorityPair;
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
future::Future,
|
||||
@@ -45,7 +52,7 @@ use cumulus_client_service::{
|
||||
build_network, prepare_node_config, start_relay_chain_tasks, BuildNetworkParams,
|
||||
CollatorSybilResistance, DARecoveryProfile, StartRelayChainTasksParams,
|
||||
};
|
||||
use cumulus_primitives_core::ParaId;
|
||||
use cumulus_primitives_core::{relay_chain::ValidationCode, ParaId};
|
||||
use cumulus_relay_chain_inprocess_interface::RelayChainInProcessInterface;
|
||||
use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};
|
||||
use cumulus_relay_chain_minimal_node::{
|
||||
@@ -110,27 +117,10 @@ impl ParachainConsensus<Block> for NullConsensus {
|
||||
/// The signature of the announce block fn.
|
||||
pub type AnnounceBlockFn = Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>;
|
||||
|
||||
/// Native executor instance.
|
||||
pub struct RuntimeExecutor;
|
||||
|
||||
impl sc_executor::NativeExecutionDispatch for RuntimeExecutor {
|
||||
type ExtendHostFunctions = cumulus_client_service::storage_proof_size::HostFunctions;
|
||||
|
||||
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
|
||||
cumulus_test_runtime::api::dispatch(method, data)
|
||||
}
|
||||
|
||||
fn native_version() -> sc_executor::NativeVersion {
|
||||
cumulus_test_runtime::native_version()
|
||||
}
|
||||
}
|
||||
|
||||
type HostFunctions =
|
||||
(sp_io::SubstrateHostFunctions, cumulus_client_service::storage_proof_size::HostFunctions);
|
||||
/// The client type being used by the test service.
|
||||
pub type Client = TFullClient<
|
||||
runtime::NodeBlock,
|
||||
runtime::RuntimeApi,
|
||||
sc_executor::NativeElseWasmExecutor<RuntimeExecutor>,
|
||||
>;
|
||||
pub type Client = TFullClient<runtime::NodeBlock, runtime::RuntimeApi, WasmExecutor<HostFunctions>>;
|
||||
|
||||
/// The backend type being used by the test service.
|
||||
pub type Backend = TFullBackend<Block>;
|
||||
@@ -203,7 +193,7 @@ pub fn new_partial(
|
||||
.default_heap_pages
|
||||
.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static { extra_pages: h as _ });
|
||||
|
||||
let wasm = WasmExecutor::builder()
|
||||
let executor = WasmExecutor::builder()
|
||||
.with_execution_method(config.wasm_method)
|
||||
.with_onchain_heap_alloc_strategy(heap_pages)
|
||||
.with_offchain_heap_alloc_strategy(heap_pages)
|
||||
@@ -211,9 +201,6 @@ pub fn new_partial(
|
||||
.with_runtime_cache_size(config.runtime_cache_size)
|
||||
.build();
|
||||
|
||||
let executor =
|
||||
sc_executor::NativeElseWasmExecutor::<RuntimeExecutor>::new_with_wasm_executor(wasm);
|
||||
|
||||
let (client, backend, keystore_container, task_manager) =
|
||||
sc_service::new_full_parts_record_import::<Block, RuntimeApi, _>(
|
||||
config,
|
||||
@@ -223,10 +210,7 @@ pub fn new_partial(
|
||||
)?;
|
||||
let client = Arc::new(client);
|
||||
|
||||
let block_import =
|
||||
ParachainBlockImport::new_with_delayed_best_block(client.clone(), backend.clone());
|
||||
|
||||
let registry = config.prometheus_registry();
|
||||
let block_import = ParachainBlockImport::new(client.clone(), backend.clone());
|
||||
|
||||
let transaction_pool = sc_transaction_pool::BasicPool::new_full(
|
||||
config.transaction_pool.clone(),
|
||||
@@ -236,12 +220,26 @@ pub fn new_partial(
|
||||
client.clone(),
|
||||
);
|
||||
|
||||
let import_queue = cumulus_client_consensus_relay_chain::import_queue(
|
||||
client.clone(),
|
||||
block_import.clone(),
|
||||
|_, _| async { Ok(sp_timestamp::InherentDataProvider::from_system_time()) },
|
||||
&task_manager.spawn_essential_handle(),
|
||||
registry,
|
||||
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
|
||||
let import_queue = cumulus_client_consensus_aura::import_queue::<AuthorityPair, _, _, _, _, _>(
|
||||
ImportQueueParams {
|
||||
block_import: block_import.clone(),
|
||||
client: client.clone(),
|
||||
create_inherent_data_providers: move |_, ()| async move {
|
||||
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
|
||||
|
||||
let slot =
|
||||
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
|
||||
*timestamp,
|
||||
slot_duration,
|
||||
);
|
||||
|
||||
Ok((slot, timestamp))
|
||||
},
|
||||
spawner: &task_manager.spawn_essential_handle(),
|
||||
registry: None,
|
||||
telemetry: None,
|
||||
},
|
||||
)?;
|
||||
|
||||
let params = PartialComponents {
|
||||
@@ -362,12 +360,16 @@ where
|
||||
spawn_handle: task_manager.spawn_handle(),
|
||||
relay_chain_interface: relay_chain_interface.clone(),
|
||||
import_queue: params.import_queue,
|
||||
sybil_resistance_level: CollatorSybilResistance::Unresistant, // no consensus
|
||||
sybil_resistance_level: CollatorSybilResistance::Resistant, /* Either Aura that is
|
||||
* resistant or null that
|
||||
* is not producing any
|
||||
* blocks at all. */
|
||||
})
|
||||
.await?;
|
||||
|
||||
let prometheus_registry = parachain_config.prometheus_registry().cloned();
|
||||
|
||||
let keystore = params.keystore_container.keystore();
|
||||
let rpc_builder = {
|
||||
let client = client.clone();
|
||||
Box::new(move |_, _| rpc_ext_builder(client.clone()))
|
||||
@@ -379,7 +381,7 @@ where
|
||||
transaction_pool: transaction_pool.clone(),
|
||||
task_manager: &mut task_manager,
|
||||
config: parachain_config,
|
||||
keystore: params.keystore_container.keystore(),
|
||||
keystore: keystore.clone(),
|
||||
backend: backend.clone(),
|
||||
network: network.clone(),
|
||||
sync_service: sync_service.clone(),
|
||||
@@ -397,8 +399,6 @@ where
|
||||
.map(|w| (w)(announce_block.clone()))
|
||||
.unwrap_or_else(|| announce_block);
|
||||
|
||||
let relay_chain_interface_for_closure = relay_chain_interface.clone();
|
||||
|
||||
let overseer_handle = relay_chain_interface
|
||||
.overseer_handle()
|
||||
.map_err(|e| sc_service::Error::Application(Box::new(e)))?;
|
||||
@@ -429,59 +429,61 @@ where
|
||||
})?;
|
||||
|
||||
if let Some(collator_key) = collator_key {
|
||||
let parachain_consensus: Box<dyn ParachainConsensus<Block>> = match consensus {
|
||||
Consensus::RelayChain => {
|
||||
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
|
||||
task_manager.spawn_handle(),
|
||||
client.clone(),
|
||||
transaction_pool.clone(),
|
||||
prometheus_registry.as_ref(),
|
||||
None,
|
||||
);
|
||||
let relay_chain_interface2 = relay_chain_interface_for_closure.clone();
|
||||
Box::new(cumulus_client_consensus_relay_chain::RelayChainConsensus::new(
|
||||
para_id,
|
||||
proposer_factory,
|
||||
move |_, (relay_parent, validation_data)| {
|
||||
let relay_chain_interface = relay_chain_interface_for_closure.clone();
|
||||
async move {
|
||||
let parachain_inherent =
|
||||
cumulus_client_parachain_inherent::ParachainInherentDataProvider::create_at(
|
||||
relay_parent,
|
||||
&relay_chain_interface,
|
||||
&validation_data,
|
||||
para_id,
|
||||
).await;
|
||||
if let Consensus::Null = consensus {
|
||||
#[allow(deprecated)]
|
||||
old_consensus::start_collator(old_consensus::StartCollatorParams {
|
||||
block_status: client.clone(),
|
||||
announce_block,
|
||||
runtime_api: client.clone(),
|
||||
spawner: task_manager.spawn_handle(),
|
||||
para_id,
|
||||
parachain_consensus: Box::new(NullConsensus) as Box<_>,
|
||||
key: collator_key,
|
||||
overseer_handle,
|
||||
})
|
||||
.await;
|
||||
} else {
|
||||
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
|
||||
task_manager.spawn_handle(),
|
||||
client.clone(),
|
||||
transaction_pool.clone(),
|
||||
prometheus_registry.as_ref(),
|
||||
None,
|
||||
);
|
||||
let proposer = Proposer::new(proposer_factory);
|
||||
|
||||
let time = sp_timestamp::InherentDataProvider::from_system_time();
|
||||
let collator_service = CollatorService::new(
|
||||
client.clone(),
|
||||
Arc::new(task_manager.spawn_handle()),
|
||||
announce_block,
|
||||
client.clone(),
|
||||
);
|
||||
|
||||
let parachain_inherent = parachain_inherent.ok_or_else(|| {
|
||||
Box::<dyn std::error::Error + Send + Sync>::from(String::from(
|
||||
"error",
|
||||
))
|
||||
})?;
|
||||
Ok((time, parachain_inherent))
|
||||
}
|
||||
},
|
||||
block_import,
|
||||
relay_chain_interface2,
|
||||
))
|
||||
},
|
||||
Consensus::Null => Box::new(NullConsensus),
|
||||
};
|
||||
let client_for_aura = client.clone();
|
||||
let params = AuraParams {
|
||||
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
|
||||
block_import,
|
||||
para_client: client.clone(),
|
||||
para_backend: backend.clone(),
|
||||
relay_client: relay_chain_interface,
|
||||
code_hash_provider: move |block_hash| {
|
||||
client_for_aura.code_at(block_hash).ok().map(|c| ValidationCode::from(c).hash())
|
||||
},
|
||||
sync_oracle: sync_service,
|
||||
keystore,
|
||||
collator_key,
|
||||
para_id,
|
||||
overseer_handle,
|
||||
relay_chain_slot_duration,
|
||||
proposer,
|
||||
collator_service,
|
||||
authoring_duration: Duration::from_millis(2000),
|
||||
reinitialize: false,
|
||||
};
|
||||
|
||||
#[allow(deprecated)]
|
||||
old_consensus::start_collator(old_consensus::StartCollatorParams {
|
||||
block_status: client.clone(),
|
||||
announce_block,
|
||||
runtime_api: client.clone(),
|
||||
spawner: task_manager.spawn_handle(),
|
||||
para_id,
|
||||
parachain_consensus,
|
||||
key: collator_key,
|
||||
overseer_handle,
|
||||
})
|
||||
.await;
|
||||
let fut = aura::run::<Block, AuthorityPair, _, _, _, _, _, _, _, _, _>(params);
|
||||
task_manager.spawn_essential_handle().spawn("aura", None, fut);
|
||||
}
|
||||
}
|
||||
|
||||
start_network.start_network();
|
||||
@@ -510,8 +512,8 @@ pub struct TestNode {
|
||||
|
||||
#[allow(missing_docs)]
|
||||
pub enum Consensus {
|
||||
/// Use the relay-chain provided consensus.
|
||||
RelayChain,
|
||||
/// Use Aura consensus.
|
||||
Aura,
|
||||
/// Use the null consensus that will never produce any block.
|
||||
Null,
|
||||
}
|
||||
@@ -553,7 +555,7 @@ impl TestNodeBuilder {
|
||||
wrap_announce_block: None,
|
||||
storage_update_func_parachain: None,
|
||||
storage_update_func_relay_chain: None,
|
||||
consensus: Consensus::RelayChain,
|
||||
consensus: Consensus::Aura,
|
||||
endowed_accounts: Default::default(),
|
||||
relay_chain_mode: RelayChainMode::Embedded,
|
||||
record_proof_during_import: true,
|
||||
|
||||
@@ -98,7 +98,7 @@ fn main() -> Result<(), sc_cli::Error> {
|
||||
tracing::info!("Using null consensus.");
|
||||
cumulus_test_service::Consensus::Null
|
||||
})
|
||||
.unwrap_or(cumulus_test_service::Consensus::RelayChain);
|
||||
.unwrap_or(cumulus_test_service::Consensus::Aura);
|
||||
|
||||
let (mut task_manager, _, _, _, _, _) = tokio_runtime
|
||||
.block_on(async move {
|
||||
|
||||
Reference in New Issue
Block a user