Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Do not require the collator key to be passed (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr authored Jun 2, 2021
1 parent 6467858 commit b1e5e7d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 48 deletions.
76 changes: 51 additions & 25 deletions client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,30 @@ use sp_consensus::{
import_queue::{ImportQueue, IncomingBlock, Link, Origin},
BlockImport, BlockOrigin,
};
use sp_core::traits::SpawnNamed;
use sp_core::{traits::SpawnNamed, Pair};
use sp_runtime::{
traits::{BlakeTwo256, Block as BlockT, NumberFor},
Justifications,
};
use std::{marker::PhantomData, sync::Arc};
use std::{marker::PhantomData, ops::Deref, sync::Arc};

pub mod genesis;

/// Relay chain full node handles.
type RFullNode<C> = polkadot_service::NewFull<C>;
/// The relay chain full node handle.
pub struct RFullNode<C> {
/// The relay chain full node handles.
pub relay_chain_full_node: polkadot_service::NewFull<C>,
/// The collator key used by the node.
pub collator_key: CollatorPair,
}

impl<C> Deref for RFullNode<C> {
type Target = polkadot_service::NewFull<C>;

fn deref(&self) -> &Self::Target {
&self.relay_chain_full_node
}
}

/// Parameters given to [`start_collator`].
pub struct StartCollatorParams<'a, Block: BlockT, BS, Client, Spawner, RClient, IQ> {
Expand All @@ -53,7 +66,6 @@ pub struct StartCollatorParams<'a, Block: BlockT, BS, Client, Spawner, RClient,
pub announce_block: Arc<dyn Fn(Block::Hash, Option<Vec<u8>>) + Send + Sync>,
pub spawner: Spawner,
pub para_id: ParaId,
pub collator_key: CollatorPair,
pub relay_chain_full_node: RFullNode<RClient>,
pub task_manager: &'a mut TaskManager,
pub parachain_consensus: Box<dyn ParachainConsensus<Block>>,
Expand All @@ -72,7 +84,6 @@ pub async fn start_collator<'a, Block, BS, Client, Backend, Spawner, RClient, IQ
announce_block,
spawner,
para_id,
collator_key,
task_manager,
relay_chain_full_node,
parachain_consensus,
Expand Down Expand Up @@ -106,33 +117,36 @@ where
_phantom: PhantomData,
});

relay_chain_full_node.client.execute_with(StartPoVRecovery {
para_id,
client: client.clone(),
import_queue,
task_manager,
overseer_handler: relay_chain_full_node
.overseer_handler
.clone()
.ok_or_else(|| "Polkadot full node did not provided an `OverseerHandler`!")?,
_phantom: PhantomData,
})?;
relay_chain_full_node
.client
.execute_with(StartPoVRecovery {
para_id,
client: client.clone(),
import_queue,
task_manager,
overseer_handler: relay_chain_full_node
.overseer_handler
.clone()
.ok_or_else(|| "Polkadot full node did not provided an `OverseerHandler`!")?,
_phantom: PhantomData,
})?;

cumulus_client_collator::start_collator(cumulus_client_collator::StartCollatorParams {
runtime_api: client.clone(),
block_status,
announce_block,
overseer_handler: relay_chain_full_node
.overseer_handler
.clone()
.ok_or_else(|| "Polkadot full node did not provided an `OverseerHandler`!")?,
spawner,
para_id,
key: collator_key,
key: relay_chain_full_node.collator_key.clone(),
parachain_consensus,
})
.await;

task_manager.add_child(relay_chain_full_node.task_manager);
task_manager.add_child(relay_chain_full_node.relay_chain_full_node.task_manager);

Ok(())
}
Expand Down Expand Up @@ -180,7 +194,7 @@ where
_phantom: PhantomData,
});

task_manager.add_child(relay_chain_full_node.task_manager);
task_manager.add_child(relay_chain_full_node.relay_chain_full_node.task_manager);

Ok(())
}
Expand Down Expand Up @@ -234,12 +248,17 @@ struct StartPoVRecovery<'a, Block: BlockT, Client, IQ> {
para_id: ParaId,
client: Arc<Client>,
task_manager: &'a mut TaskManager,

overseer_handler: OverseerHandler,
import_queue: IQ,


_phantom: PhantomData<Block>,
}


impl<'a, Block, Client, IQ> polkadot_service::ExecuteWithClient for StartPoVRecovery<'a, Block, Client, IQ>
impl<'a, Block, Client, IQ> polkadot_service::ExecuteWithClient
for StartPoVRecovery<'a, Block, Client, IQ>
where
Block: BlockT,
Client: UsageProvider<Block>
Expand Down Expand Up @@ -291,7 +310,6 @@ pub fn prepare_node_config(mut parachain_config: Configuration) -> Configuration
#[sc_tracing::logging::prefix_logs_with("Relaychain")]
pub fn build_polkadot_full_node(
config: Configuration,
collator_pair: CollatorPair,
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
) -> Result<RFullNode<PClient>, polkadot_service::Error> {
let is_light = matches!(config.role, Role::Light);
Expand All @@ -300,14 +318,22 @@ pub fn build_polkadot_full_node(
"Light client not supported.".into(),
))
} else {
polkadot_service::build_full(
let collator_key = CollatorPair::generate().0;

let relay_chain_full_node = polkadot_service::build_full(
config,
polkadot_service::IsCollator::Yes(collator_pair),
polkadot_service::IsCollator::Yes(collator_key.clone()),
None,
true,
None,
telemetry_worker_handle,
)
)?;

Ok(RFullNode {
relay_chain_full_node,
collator_key,
})

}
}

Expand Down
2 changes: 0 additions & 2 deletions polkadot-parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "m
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "master" }



[build-dependencies]
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "master" }

Expand Down
10 changes: 2 additions & 8 deletions polkadot-parachains/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,6 @@ pub fn run() -> Result<()> {
let runner = cli.create_runner(&cli.run.normalize())?;

runner.run_node_until_exit(|config| async move {
// TODO
let key = sp_core::Pair::generate().0;

let para_id =
chain_spec::Extensions::try_get(&*config.chain_spec).map(|e| e.para_id);

Expand Down Expand Up @@ -433,7 +430,6 @@ pub fn run() -> Result<()> {
if config.chain_spec.is_statemint() {
crate::service::start_statemint_node::<statemint_runtime::RuntimeApi, StatemintRuntimeExecutor>(
config,
key,
polkadot_config,
id,
)
Expand All @@ -443,7 +439,6 @@ pub fn run() -> Result<()> {
} else if config.chain_spec.is_statemine() {
crate::service::start_statemint_node::<statemine_runtime::RuntimeApi, StatemineRuntimeExecutor>(
config,
key,
polkadot_config,
id,
)
Expand All @@ -453,20 +448,19 @@ pub fn run() -> Result<()> {
} else if config.chain_spec.is_westmint() {
crate::service::start_statemint_node::<westmint_runtime::RuntimeApi, WestmintRuntimeExecutor>(
config,
key,
polkadot_config,
id,
)
.await
.map(|r| r.0)
.map_err(Into::into)
} else if config.chain_spec.is_shell() {
crate::service::start_shell_node(config, key, polkadot_config, id)
crate::service::start_shell_node(config, polkadot_config, id)
.await
.map(|r| r.0)
.map_err(Into::into)
} else {
crate::service::start_rococo_parachain_node(config, key, polkadot_config, id)
crate::service::start_rococo_parachain_node(config, polkadot_config, id)
.await
.map(|r| r.0)
.map_err(Into::into)
Expand Down
10 changes: 0 additions & 10 deletions polkadot-parachains/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use cumulus_client_service::{
use cumulus_primitives_core::{
ParaId, relay_chain::v1::{Hash as PHash, PersistedValidationData},
};
use polkadot_primitives::v1::CollatorPair;

use sc_client_api::ExecutorProvider;
use sc_executor::native_executor_instance;
Expand Down Expand Up @@ -195,7 +194,6 @@ where
#[sc_tracing::logging::prefix_logs_with("Parachain")]
async fn start_node_impl<RuntimeApi, Executor, RB, BIQ, BIC>(
parachain_config: Configuration,
collator_key: CollatorPair,
polkadot_config: Configuration,
id: ParaId,
rpc_ext_builder: RB,
Expand Down Expand Up @@ -255,7 +253,6 @@ where

let relay_chain_full_node = cumulus_client_service::build_polkadot_full_node(
polkadot_config,
collator_key.clone(),
telemetry_worker_handle,
)
.map_err(|e| match e {
Expand Down Expand Up @@ -333,7 +330,6 @@ where
announce_block,
client: client.clone(),
task_manager: &mut task_manager,
collator_key,
relay_chain_full_node,
spawner,
parachain_consensus,
Expand Down Expand Up @@ -404,7 +400,6 @@ pub fn rococo_parachain_build_import_queue(
/// Start a rococo parachain node.
pub async fn start_rococo_parachain_node(
parachain_config: Configuration,
collator_key: CollatorPair,
polkadot_config: Configuration,
id: ParaId,
) -> sc_service::error::Result<(
Expand All @@ -413,7 +408,6 @@ pub async fn start_rococo_parachain_node(
)> {
start_node_impl::<rococo_parachain_runtime::RuntimeApi, RococoParachainRuntimeExecutor, _, _, _>(
parachain_config,
collator_key,
polkadot_config,
id,
|_| Default::default(),
Expand Down Expand Up @@ -522,7 +516,6 @@ pub fn shell_build_import_queue(
/// Start a polkadot-shell parachain node.
pub async fn start_shell_node(
parachain_config: Configuration,
collator_key: CollatorPair,
polkadot_config: Configuration,
id: ParaId,
) -> sc_service::error::Result<(
Expand All @@ -531,7 +524,6 @@ pub async fn start_shell_node(
)> {
start_node_impl::<shell_runtime::RuntimeApi, ShellRuntimeExecutor, _, _, _>(
parachain_config,
collator_key,
polkadot_config,
id,
|_| Default::default(),
Expand Down Expand Up @@ -790,7 +782,6 @@ where
/// Start a statemint/statemine/westmint parachain node.
pub async fn start_statemint_node<RuntimeApi, Executor>(
parachain_config: Configuration,
collator_key: CollatorPair,
polkadot_config: Configuration,
id: ParaId,
) -> sc_service::error::Result<(
Expand All @@ -817,7 +808,6 @@ where
{
start_node_impl::<RuntimeApi, Executor, _, _, _>(
parachain_config,
collator_key,
polkadot_config,
id,
|_| Default::default(),
Expand Down
11 changes: 8 additions & 3 deletions test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,11 @@ where
spawner: task_manager.spawn_handle(),
task_manager: &mut task_manager,
para_id,
collator_key,
parachain_consensus,
relay_chain_full_node,
relay_chain_full_node: cumulus_client_service::RFullNode {
relay_chain_full_node,
collator_key,
},
import_queue,
};

Expand All @@ -319,7 +321,10 @@ where
announce_block,
task_manager: &mut task_manager,
para_id,
relay_chain_full_node,
relay_chain_full_node: cumulus_client_service::RFullNode {
relay_chain_full_node,
collator_key: CollatorPair::generate().0,
},
};

start_full_node(params)?;
Expand Down

0 comments on commit b1e5e7d

Please sign in to comment.