Collate only if --validator is given (#161)

This commit is contained in:
Cecile Tonglet
2020-07-29 20:49:31 +02:00
committed by GitHub
parent c66f9755cb
commit d1d40765c7
16 changed files with 1425 additions and 1363 deletions
+1222 -1212
View File
File diff suppressed because it is too large Load Diff
+8 -8
View File
@@ -47,8 +47,8 @@ use sp_runtime::{
use polkadot_collator::{
BuildParachainContext, Network as CollatorNetwork, ParachainContext, RuntimeApiCollection,
};
use polkadot_primitives::{
parachain::{self, BlockData, GlobalValidationSchedule, Id as ParaId, LocalValidationData},
use polkadot_primitives::v0::{
self as parachain, BlockData, GlobalValidationData, Id as ParaId, LocalValidationData,
Block as PBlock, DownwardMessage, Hash as PHash,
};
@@ -105,7 +105,7 @@ impl<Block: BlockT, PF, BI, BS> Collator<Block, PF, BI, BS> {
/// Get the inherent data with validation function parameters injected
fn inherent_data(
inherent_providers: InherentDataProviders,
global_validation: GlobalValidationSchedule,
global_validation: GlobalValidationData,
local_validation: LocalValidationData,
downward_messages: DownwardMessagesType,
) -> Option<InherentData> {
@@ -239,7 +239,7 @@ where
fn produce_candidate(
&mut self,
relay_chain_parent: PHash,
global_validation: GlobalValidationSchedule,
global_validation: GlobalValidationData,
local_validation: LocalValidationData,
downward_messages: Vec<DownwardMessage>,
) -> Self::ProduceCandidate {
@@ -493,10 +493,10 @@ mod tests {
use std::time::Duration;
use polkadot_collator::{collate, SignedStatement};
use polkadot_primitives::parachain::Id as ParaId;
use polkadot_primitives::v0::Id as ParaId;
use sp_blockchain::Result as ClientResult;
use sp_core::testing::SpawnBlockingExecutor;
use sp_core::testing::TaskExecutor;
use sp_inherents::InherentData;
use sp_keyring::Sr25519Keyring;
use sp_runtime::traits::{DigestFor, Header as HeaderT};
@@ -601,7 +601,7 @@ mod tests {
fn collates_produces_a_block() {
let id = ParaId::from(100);
let _ = env_logger::try_init();
let spawner = SpawnBlockingExecutor::new();
let spawner = TaskExecutor::new();
let announce_block = |_, _| ();
let block_announce_validator = DelayedBlockAnnounceValidator::new();
let client = Arc::new(TestClientBuilder::new().build());
@@ -639,7 +639,7 @@ mod tests {
let collation = collate(
Default::default(),
id,
GlobalValidationSchedule {
GlobalValidationData {
block_number: 0,
max_code_size: 0,
max_head_data_size: 0,
+2 -3
View File
@@ -26,9 +26,8 @@ use sp_runtime::{
traits::{Block as BlockT, Header as HeaderT},
};
use polkadot_primitives::{
parachain::{Id as ParaId, ParachainHost},
Block as PBlock, Hash as PHash,
use polkadot_primitives::v0::{
Id as ParaId, ParachainHost, Block as PBlock, Hash as PHash,
};
use codec::Decode;
+3 -4
View File
@@ -32,11 +32,10 @@ use sp_runtime::{
use polkadot_collator::Network as CollatorNetwork;
use polkadot_network::legacy::gossip::{GossipMessage, GossipStatement};
use polkadot_primitives::{
parachain::{Id as ParaId, ParachainHost},
Block as PBlock, Hash as PHash,
use polkadot_primitives::v0::{
Id as ParaId, ParachainHost, Block as PBlock, Hash as PHash,
};
use polkadot_statement_table::{SignedStatement, Statement};
use polkadot_statement_table::v0::{SignedStatement, Statement};
use polkadot_validation::check_statement;
use cumulus_primitives::HeadData;
+6 -9
View File
@@ -16,13 +16,10 @@
use super::*;
use cumulus_test_runtime::{Block, Header};
use polkadot_primitives::{
parachain::{
AbridgedCandidateReceipt, Chain, CollatorId, DutyRoster, GlobalValidationSchedule,
Id as ParaId, LocalValidationData, ParachainHost, Retriable, SigningContext,
ValidationCode, ValidatorId,
},
Block as PBlock, Hash as PHash, Header as PHeader,
use polkadot_primitives::v0::{
AbridgedCandidateReceipt, Chain, CollatorId, DutyRoster, GlobalValidationData,
Id as ParaId, LocalValidationData, ParachainHost, Retriable, SigningContext,
ValidationCode, ValidatorId, Block as PBlock, Hash as PHash, Header as PHeader,
};
use polkadot_test_runtime_client::{
DefaultTestClientBuilderExt, TestClient, TestClientBuilder, TestClientBuilderExt,
@@ -418,7 +415,7 @@ sp_api::mock_impl_runtime_apis! {
Some(ValidationCode(Vec::new()))
}
fn global_validation_schedule() -> GlobalValidationSchedule {
fn global_validation_data() -> GlobalValidationData {
Default::default()
}
@@ -440,7 +437,7 @@ sp_api::mock_impl_runtime_apis! {
}
}
fn downward_messages(_: ParaId) -> Vec<polkadot_primitives::DownwardMessage> {
fn downward_messages(_: ParaId) -> Vec<polkadot_primitives::v0::DownwardMessage> {
Vec::new()
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ parachain = { package = "polkadot-parachain", git = "https://github.com/parityte
# Substrate dependencies
frame-support = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", version = "2.0.0-dev", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", version = "2.0.0-rc5", default-features = false }
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
@@ -18,7 +18,7 @@
use codec::{Decode, Encode};
use polkadot_parachain::primitives::{RelayChainBlockNumber, ValidationParams};
use polkadot_primitives::parachain::{GlobalValidationSchedule, LocalValidationData};
use polkadot_primitives::v0::{GlobalValidationData, LocalValidationData};
/// Validation Function Parameters
///
@@ -48,8 +48,8 @@ impl From<&ValidationParams> for ValidationFunctionParams {
}
}
impl From<(GlobalValidationSchedule, LocalValidationData)> for ValidationFunctionParams {
fn from(t: (GlobalValidationSchedule, LocalValidationData)) -> Self {
impl From<(GlobalValidationData, LocalValidationData)> for ValidationFunctionParams {
fn from(t: (GlobalValidationData, LocalValidationData)) -> Self {
let (global_validation, local_validation) = t;
ValidationFunctionParams {
max_code_size: global_validation.max_code_size,
+1 -1
View File
@@ -16,7 +16,7 @@
//! XMCP related primitives
use polkadot_primitives::parachain::Id as ParaId;
use polkadot_primitives::v0::Id as ParaId;
use sp_std::vec::Vec;
/// A raw XCMP message that is being send between two Parachain's.
+4 -2
View File
@@ -31,15 +31,18 @@ sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "cumu
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", version = "0.8.0-alpha.5" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", version = "0.8.0-rc5" }
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-informant = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
# Cumulus dependencies
cumulus-consensus = { path = "../../consensus" }
@@ -72,6 +75,5 @@ polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch
# Substrate dependencies
pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
+7 -5
View File
@@ -152,8 +152,10 @@ pub fn run() -> Result<()> {
Some(Subcommand::Base(subcommand)) => {
let runner = cli.create_runner(subcommand)?;
runner.run_subcommand(subcommand, |config| {
Ok(new_full_start!(config).0.to_chain_ops_parts())
runner.run_subcommand(subcommand, |mut config| {
let params = crate::service::new_partial(&mut config)?;
Ok((params.client, params.backend, params.import_queue, params.task_manager))
})
}
Some(Subcommand::ExportGenesisState(params)) => {
@@ -185,7 +187,7 @@ pub fn run() -> Result<()> {
let id = ParaId::from(cli.run.parachain_id);
let parachain_account =
AccountIdConversion::<polkadot_primitives::AccountId>::into_account(&id);
AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(&id);
let block = generate_genesis_state(id)?;
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
@@ -207,8 +209,8 @@ pub fn run() -> Result<()> {
info!("Parachain Account: {}", parachain_account);
info!("Parachain genesis state: {}", genesis_state);
crate::service::run_collator(config, key, polkadot_config, id)
.map(|x| x.task_manager)
crate::service::run_collator(config, key, polkadot_config, id, cli.run.base.validator)
.map(|(x, _)| x)
})
}
}
@@ -19,7 +19,7 @@ use futures::{
future::{self, FutureExt},
pin_mut, select,
};
use polkadot_primitives::parachain::{Id as ParaId, Info, Scheduling};
use polkadot_primitives::v0::{Id as ParaId, Info, Scheduling};
use polkadot_runtime_common::registrar;
use polkadot_test_runtime_client::Sr25519Keyring;
use sc_client_api::execution_extensions::ExecutionStrategies;
@@ -43,9 +43,8 @@ static INTEGRATION_TEST_ALLOWED_TIME: Option<&str> = option_env!("INTEGRATION_TE
#[ignore]
async fn integration_test() {
let task_executor: TaskExecutor = (|fut, _| {
spawn(fut);
})
.into();
spawn(fut).map(|_| ())
}).into();
// start alice
let mut alice =
@@ -104,10 +103,10 @@ async fn integration_test() {
polkadot_config.rpc_methods = sc_service::config::RpcMethods::Unsafe;
let parachain_config =
parachain_config(task_executor.clone(), Charlie, vec![], para_id).unwrap();
let service =
crate::service::run_collator(parachain_config, key, polkadot_config, para_id).unwrap();
let (_service, charlie_client) =
crate::service::run_collator(parachain_config, key, polkadot_config, para_id, true).unwrap();
sleep(Duration::from_secs(3)).await;
service.client.wait_for_blocks(4).await;
charlie_client.wait_for_blocks(4).await;
alice.task_manager.terminate();
bob.task_manager.terminate();
+158 -104
View File
@@ -18,15 +18,15 @@ use ansi_term::Color;
use cumulus_collator::{prepare_collator_config, CollatorBuilder};
use cumulus_network::DelayedBlockAnnounceValidator;
use futures::{future::ready, FutureExt};
use polkadot_primitives::parachain::CollatorPair;
use polkadot_primitives::v0::CollatorPair;
use sc_executor::native_executor_instance;
pub use sc_executor::NativeExecutor;
use sc_finality_grandpa::{
FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider,
};
use sc_informant::OutputFormat;
use sc_service::{Configuration, ServiceComponents, TFullBackend, TFullClient};
use sc_service::{Configuration, PartialComponents, TaskManager, TFullBackend, TFullClient, Role};
use std::sync::Arc;
use sp_core::crypto::Pair;
use sp_trie::PrefixedMemoryDB;
use sp_runtime::traits::BlakeTwo256;
// Our native executor instance.
native_executor_instance!(
@@ -39,45 +39,60 @@ native_executor_instance!(
///
/// Use this macro if you don't actually need the full service, but just the builder in order to
/// be able to perform chain operations.
macro_rules! new_full_start {
($config:expr) => {{
let inherent_data_providers = sp_inherents::InherentDataProviders::new();
pub fn new_partial(config: &mut Configuration) -> Result<
PartialComponents<
TFullClient<parachain_runtime::opaque::Block, parachain_runtime::RuntimeApi, crate::service::Executor>,
TFullBackend<parachain_runtime::opaque::Block>,
(),
sp_consensus::import_queue::BasicQueue<parachain_runtime::opaque::Block, PrefixedMemoryDB<BlakeTwo256>>,
sc_transaction_pool::FullPool<parachain_runtime::opaque::Block, TFullClient<parachain_runtime::opaque::Block, parachain_runtime::RuntimeApi, crate::service::Executor>>,
(),
>,
sc_service::Error,
>
{
let inherent_data_providers = sp_inherents::InherentDataProviders::new();
let builder = sc_service::ServiceBuilder::new_full::<
let (client, backend, keystore, task_manager) =
sc_service::new_full_parts::<
parachain_runtime::opaque::Block,
parachain_runtime::RuntimeApi,
crate::service::Executor,
>($config)?
.with_select_chain(|_config, backend| Ok(sc_consensus::LongestChain::new(backend.clone())))?
.with_transaction_pool(|builder| {
let client = builder.client();
let pool_api = Arc::new(sc_transaction_pool::FullChainApi::new(
client.clone(),
builder.prometheus_registry(),
));
let pool = sc_transaction_pool::BasicPool::new_full(
builder.config().transaction_pool.clone(),
pool_api,
builder.prometheus_registry(),
builder.spawn_handle(),
client.clone(),
);
Ok(pool)
})?
.with_import_queue(|_config, client, _, _, spawner, registry| {
let import_queue = cumulus_consensus::import_queue::import_queue(
client.clone(),
client,
inherent_data_providers.clone(),
spawner,
registry,
)?;
>(&config)?;
let client = Arc::new(client);
//let select_chain = sc_consensus::LongestChain::new(backend.clone());
Ok(import_queue)
})?;
let registry = config.prometheus_registry();
(builder, inherent_data_providers)
}};
let transaction_pool = sc_transaction_pool::BasicPool::new_full(
config.transaction_pool.clone(),
//std::sync::Arc::new(pool_api),
config.prometheus_registry(),
task_manager.spawn_handle(),
client.clone(),
);
let import_queue = cumulus_consensus::import_queue::import_queue(
client.clone(),
client.clone(),
inherent_data_providers.clone(),
&task_manager.spawn_handle(),
registry.clone(),
)?;
let params = PartialComponents {
backend,
client,
import_queue,
keystore,
task_manager,
transaction_pool,
inherent_data_providers,
select_chain: (),
other: (),
};
Ok(params)
}
/// Run a collator node with the given parachain `Configuration` and relaychain `Configuration`
@@ -87,84 +102,123 @@ pub fn run_collator(
parachain_config: Configuration,
key: Arc<CollatorPair>,
mut polkadot_config: polkadot_collator::Configuration,
id: polkadot_primitives::parachain::Id,
) -> sc_service::error::Result<ServiceComponents<
parachain_runtime::opaque::Block,
TFullBackend<parachain_runtime::opaque::Block>,
sc_consensus::LongestChain<TFullBackend<parachain_runtime::opaque::Block>, parachain_runtime::opaque::Block>,
sc_transaction_pool::BasicPool<
sc_transaction_pool::FullChainApi<
TFullClient<parachain_runtime::opaque::Block, parachain_runtime::RuntimeApi, crate::service::Executor>,
parachain_runtime::opaque::Block,
>,
parachain_runtime::opaque::Block,
>,
TFullClient<parachain_runtime::opaque::Block, parachain_runtime::RuntimeApi, crate::service::Executor>,
>> {
id: polkadot_primitives::v0::Id,
validator: bool,
) -> sc_service::error::Result<(
TaskManager,
Arc<TFullClient<parachain_runtime::opaque::Block, parachain_runtime::RuntimeApi, crate::service::Executor>>,
)> {
let mut parachain_config = prepare_collator_config(parachain_config);
parachain_config.informant_output_format = OutputFormat {
enable_color: true,
prefix: format!("[{}] ", Color::Yellow.bold().paint("Parachain")),
};
let (builder, inherent_data_providers) = new_full_start!(parachain_config);
inherent_data_providers
.register_provider(sp_timestamp::InherentDataProvider)
.unwrap();
let block_announce_validator = DelayedBlockAnnounceValidator::new();
let block_announce_validator_copy = block_announce_validator.clone();
let service = builder
.with_finality_proof_provider(|client, backend| {
// GenesisAuthoritySetProvider is implemented for StorageAndProofProvider
let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)
})?
.with_block_announce_validator(|_client| Box::new(block_announce_validator_copy))?
.build_full()?;
let registry = service.prometheus_registry.clone();
let proposer_factory = sc_basic_authorship::ProposerFactory::new(
service.client.clone(),
service.transaction_pool.clone(),
registry.as_ref(),
);
let block_import = service.client.clone();
let client = service.client.clone();
let network = service.network.clone();
let announce_block = Arc::new(move |hash, data| network.announce_block(hash, data));
let builder = CollatorBuilder::new(
proposer_factory,
inherent_data_providers,
block_import,
client.clone(),
id,
client,
announce_block,
block_announce_validator,
);
polkadot_config.informant_output_format = OutputFormat {
enable_color: true,
prefix: format!("[{}] ", Color::Blue.bold().paint("Relaychain")),
};
let (polkadot_future, task_manager) =
polkadot_collator::start_collator(builder, id, key, polkadot_config)?;
let params = new_partial(&mut parachain_config)?;
params.inherent_data_providers
.register_provider(sp_timestamp::InherentDataProvider)
.unwrap();
// Make sure the polkadot task manager survives as long as the service.
let polkadot_future = polkadot_future.then(move |_| {
let _ = task_manager;
ready(())
});
let client = params.client.clone();
let backend = params.backend.clone();
let block_announce_validator = DelayedBlockAnnounceValidator::new();
let block_announce_validator_builder = {
let block_announce_validator = block_announce_validator.clone();
move |_| Box::new(block_announce_validator) as Box<_>
};
service
.task_manager
.spawn_essential_handle()
.spawn("polkadot", polkadot_future);
let prometheus_registry = parachain_config.prometheus_registry().cloned();
let transaction_pool = params.transaction_pool.clone();
let mut task_manager = params.task_manager;
let import_queue = params.import_queue;
let (network, network_status_sinks, system_rpc_tx) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &parachain_config,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
import_queue,
on_demand: None,
block_announce_validator_builder: Some(Box::new(block_announce_validator_builder)),
finality_proof_request_builder: None,
finality_proof_provider: None,
})?;
Ok(service)
let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
on_demand: None,
remote_blockchain: None,
rpc_extensions_builder: Box::new(|_| ()),
client: client.clone(),
transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager,
telemetry_connection_sinks: Default::default(),
config: parachain_config,
keystore: params.keystore,
backend,
network: network.clone(),
network_status_sinks,
system_rpc_tx,
})?;
if validator {
let proposer_factory = sc_basic_authorship::ProposerFactory::new(
client.clone(),
transaction_pool,
prometheus_registry.as_ref(),
);
let block_import = client.clone();
let announce_block = Arc::new(move |hash, data| network.announce_block(hash, data));
let builder = CollatorBuilder::new(
proposer_factory,
params.inherent_data_providers,
block_import,
client.clone(),
id,
client.clone(),
announce_block,
block_announce_validator,
);
let (polkadot_future, polkadpt_task_manager) =
polkadot_collator::start_collator(builder, id, key, polkadot_config)?;
// Make sure the polkadot task manager survives as long as the service.
let polkadot_future = polkadot_future.then(move |_| {
let _ = polkadpt_task_manager;
ready(())
});
task_manager
.spawn_essential_handle()
.spawn("polkadot", polkadot_future);
} else {
let is_light = matches!(polkadot_config.role, Role::Light);
let builder = polkadot_service::NodeBuilder::new(polkadot_config);
let mut polkadot_task_manager = if is_light {
return Err("Light client not supported.".into());
} else {
builder.build_full(
Some((key.public(), id)),
None,
false,
6000,
None,
)
}?;
let polkadot_future = async move {
polkadot_task_manager.future().await.expect("polkadot essential task failed");
};
task_manager
.spawn_essential_handle()
.spawn("polkadot", polkadot_future);
}
Ok((task_manager, client))
}
@@ -28,7 +28,7 @@ fn interrupt_polkadot_mdns_issue_test() {
fn run_command_and_kill(signal: Signal) {
let _ = fs::remove_dir_all("interrupt_polkadot_mdns_issue_test");
let mut cmd = Command::new(cargo_bin("cumulus-test-parachain-collator"))
.args(&["-d", "interrupt_polkadot_mdns_issue_test"])
.args(&["-d", "interrupt_polkadot_mdns_issue_test", "--dev", "--", "--dev"])
.spawn()
.unwrap();
@@ -29,7 +29,7 @@ fn purge_chain_works() {
let _ = fs::remove_dir_all(base_path);
let mut cmd = Command::new(cargo_bin("cumulus-test-parachain-collator"))
.args(&["-d", base_path])
.args(&["-d", base_path, "--dev", "--", "--dev"])
.spawn()
.unwrap();
@@ -28,7 +28,7 @@ fn running_the_node_works_and_can_be_interrupted() {
fn run_command_and_kill(signal: Signal) {
let _ = fs::remove_dir_all("interrupt_test");
let mut cmd = Command::new(cargo_bin("cumulus-test-parachain-collator"))
.args(&["--dev", "-d", "interrupt_test"])
.args(&["--dev", "-d", "interrupt_test", "--", "--dev"])
.spawn()
.unwrap();
+1 -1
View File
@@ -7,7 +7,7 @@ build = "build.rs"
[dependencies]
runtime = { package = "cumulus-runtime", path = "../../runtime", default-features = false }
substrate-test-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch", version = "2.0.0-rc4" }
substrate-test-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch", version = "2.0.0-rc5" }
[build-dependencies]
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = " 1.0.6" }