Unverified Commit 1bf984ea authored by Cecile Tonglet's avatar Cecile Tonglet Committed by GitHub
Browse files

Spawn a future to start the collator (#851)

* Running a node without a database set in config is a bug, not a user error
parent 853b8d3e
Pipeline #80844 passed with stages
in 22 minutes and 9 seconds
......@@ -217,8 +217,7 @@ pub async fn collate<P>(
Ok(collation)
}
/// Run the collator node using the given `service`.
fn run_collator_node<S, P, Extrinsic>(
fn build_collator_service<S, P, Extrinsic>(
service: S,
para_id: ParaId,
key: Arc<CollatorPair>,
......@@ -381,6 +380,51 @@ fn run_collator_node<S, P, Extrinsic>(
Ok(service)
}
/// Async function that will run the collator node with the given `RelayChainContext` and `ParachainContext`
/// built by the given `BuildParachainContext` and arguments to the underlying polkadot node.
pub async fn start_collator<P>(
build_parachain_context: P,
para_id: ParaId,
key: Arc<CollatorPair>,
config: Configuration,
) -> Result<(), polkadot_service::Error>
where
P: BuildParachainContext,
P::ParachainContext: Send + 'static,
<P::ParachainContext as ParachainContext>::ProduceCandidate: Send,
{
match (config.expect_chain_spec().is_kusama(), config.roles) {
(true, Roles::LIGHT) =>
build_collator_service(
service::kusama_new_light(config, Some((key.public(), para_id)))?,
para_id,
key,
build_parachain_context,
)?.await,
(true, _) =>
build_collator_service(
service::kusama_new_full(config, Some((key.public(), para_id)), None, false, 6000)?,
para_id,
key,
build_parachain_context,
)?.await,
(false, Roles::LIGHT) =>
build_collator_service(
service::polkadot_new_light(config, Some((key.public(), para_id)))?,
para_id,
key,
build_parachain_context,
)?.await,
(false, _) =>
build_collator_service(
service::polkadot_new_full(config, Some((key.public(), para_id)), None, false, 6000)?,
para_id,
key,
build_parachain_context,
)?.await,
}
}
fn compute_targets(para_id: ParaId, session_keys: &[ValidatorId], roster: DutyRoster) -> HashSet<ValidatorId> {
use polkadot_primitives::parachain::Chain;
......@@ -392,7 +436,7 @@ fn compute_targets(para_id: ParaId, session_keys: &[ValidatorId], roster: DutyRo
}
/// Run a collator node with the given `RelayChainContext` and `ParachainContext`
/// build by the given `BuildParachainContext` and arguments to the underlying polkadot node.
/// built by the given `BuildParachainContext` and arguments to the underlying polkadot node.
///
/// This function blocks until done.
pub fn run_collator<P>(
......@@ -408,7 +452,7 @@ pub fn run_collator<P>(
match (config.expect_chain_spec().is_kusama(), config.roles) {
(true, Roles::LIGHT) =>
sc_cli::run_service_until_exit(config, |config| {
run_collator_node(
build_collator_service(
service::kusama_new_light(config, Some((key.public(), para_id)))?,
para_id,
key,
......@@ -417,7 +461,7 @@ pub fn run_collator<P>(
}),
(true, _) =>
sc_cli::run_service_until_exit(config, |config| {
run_collator_node(
build_collator_service(
service::kusama_new_full(config, Some((key.public(), para_id)), None, false, 6000)?,
para_id,
key,
......@@ -426,7 +470,7 @@ pub fn run_collator<P>(
}),
(false, Roles::LIGHT) =>
sc_cli::run_service_until_exit(config, |config| {
run_collator_node(
build_collator_service(
service::polkadot_new_light(config, Some((key.public(), para_id)))?,
para_id,
key,
......@@ -435,7 +479,7 @@ pub fn run_collator<P>(
}),
(false, _) =>
sc_cli::run_service_until_exit(config, |config| {
run_collator_node(
build_collator_service(
service::polkadot_new_full(config, Some((key.public(), para_id)), None, false, 6000)?,
para_id,
key,
......
......@@ -272,7 +272,7 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(
let is_authority = config.roles.is_authority() && !is_collator;
let force_authoring = config.force_authoring;
let max_block_data_size = max_block_data_size;
let db_path = if let Some(DatabaseConfig::Path { ref path, .. }) = config.database {
let db_path = if let DatabaseConfig::Path { ref path, .. } = config.expect_database() {
path.clone()
} else {
return Err("Starting a Polkadot service with a custom database isn't supported".to_string().into());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment