diff --git a/node/collation-generation/src/error.rs b/node/collation-generation/src/error.rs
new file mode 100644
index 000000000000..b256df751e4b
--- /dev/null
+++ b/node/collation-generation/src/error.rs
@@ -0,0 +1,32 @@
+// Copyright 2020 Parity Technologies (UK) Ltd.
+// This file is part of Polkadot.
+
+// Polkadot 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.
+
+// Polkadot 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 Polkadot. If not, see .
+
+
+#[derive(Debug, derive_more::From)]
+pub enum Error {
+ #[from]
+ Subsystem(polkadot_node_subsystem::SubsystemError),
+ #[from]
+ OneshotRecv(futures::channel::oneshot::Canceled),
+ #[from]
+ Runtime(polkadot_node_subsystem::errors::RuntimeApiError),
+ #[from]
+ Util(polkadot_node_subsystem_util::Error),
+ #[from]
+ Erasure(polkadot_erasure_coding::Error),
+}
+
+pub type Result = std::result::Result;
diff --git a/node/collation-generation/src/lib.rs b/node/collation-generation/src/lib.rs
index c2f6f9bc2ceb..ce671324f1d4 100644
--- a/node/collation-generation/src/lib.rs
+++ b/node/collation-generation/src/lib.rs
@@ -19,7 +19,7 @@
#![deny(missing_docs)]
use futures::{
- channel::{mpsc, oneshot},
+ channel::mpsc,
future::FutureExt,
join,
select,
@@ -28,13 +28,12 @@ use futures::{
};
use polkadot_node_primitives::CollationGenerationConfig;
use polkadot_node_subsystem::{
- errors::RuntimeApiError,
messages::{AllMessages, CollationGenerationMessage, CollatorProtocolMessage},
- FromOverseer, SpawnedSubsystem, Subsystem, SubsystemContext, SubsystemError, SubsystemResult,
+ FromOverseer, SpawnedSubsystem, Subsystem, SubsystemContext, SubsystemResult,
metrics::{self, prometheus},
};
use polkadot_node_subsystem_util::{
- self as util, request_availability_cores_ctx, request_full_validation_data_ctx,
+ request_availability_cores_ctx, request_full_validation_data_ctx,
request_validators_ctx,
};
use polkadot_primitives::v1::{
@@ -45,6 +44,10 @@ use polkadot_primitives::v1::{
use sp_core::crypto::Pair;
use std::sync::Arc;
+mod error;
+
+const LOG_TARGET: &'static str = "collation_generation";
+
/// Collation Generation Subsystem
pub struct CollationGenerationSubsystem {
config: Option>,
@@ -92,7 +95,7 @@ impl CollationGenerationSubsystem {
msg = receiver.next().fuse() => {
if let Some(msg) = msg {
if let Err(err) = ctx.send_message(msg).await {
- log::warn!(target: "collation_generation", "failed to forward message to overseer: {:?}", err);
+ log::warn!(target: LOG_TARGET, "failed to forward message to overseer: {:?}", err);
break;
}
}
@@ -126,7 +129,7 @@ impl CollationGenerationSubsystem {
if let Err(err) =
handle_new_activations(config.clone(), &activated, ctx, metrics, sender).await
{
- log::warn!(target: "collation_generation", "failed to handle new activations: {:?}", err);
+ log::warn!(target: LOG_TARGET, "failed to handle new activations: {:?}", err);
return true;
};
}
@@ -137,7 +140,7 @@ impl CollationGenerationSubsystem {
msg: CollationGenerationMessage::Initialize(config),
}) => {
if self.config.is_some() {
- log::warn!(target: "collation_generation", "double initialization");
+ log::warn!(target: LOG_TARGET, "double initialization");
true
} else {
self.config = Some(Arc::new(config));
@@ -146,7 +149,11 @@ impl CollationGenerationSubsystem {
}
Ok(Signal(BlockFinalized(_))) => false,
Err(err) => {
- log::error!(target: "collation_generation", "error receiving message from subsystem context: {:?}", err);
+ log::error!(
+ target: LOG_TARGET,
+ "error receiving message from subsystem context: {:?}",
+ err
+ );
true
}
}
@@ -169,29 +176,13 @@ where
}
}
-#[derive(Debug, derive_more::From)]
-enum Error {
- #[from]
- Subsystem(SubsystemError),
- #[from]
- OneshotRecv(oneshot::Canceled),
- #[from]
- Runtime(RuntimeApiError),
- #[from]
- Util(util::Error),
- #[from]
- Erasure(polkadot_erasure_coding::Error),
-}
-
-type Result = std::result::Result;
-
async fn handle_new_activations(
config: Arc,
activated: &[Hash],
ctx: &mut Context,
metrics: Metrics,
sender: &mpsc::Sender,
-) -> Result<()> {
+) -> crate::error::Result<()> {
// follow the procedure from the guide:
// https://w3f.github.io/parachain-implementers-guide/node/collators/collation-generation.html
@@ -262,7 +253,12 @@ async fn handle_new_activations(
) {
Ok(erasure_root) => erasure_root,
Err(err) => {
- log::error!(target: "collation_generation", "failed to calculate erasure root for para_id {}: {:?}", scheduled_core.para_id, err);
+ log::error!(
+ target: LOG_TARGET,
+ "failed to calculate erasure root for para_id {}: {:?}",
+ scheduled_core.para_id,
+ err
+ );
return
}
};
@@ -292,7 +288,12 @@ async fn handle_new_activations(
if let Err(err) = task_sender.send(AllMessages::CollatorProtocol(
CollatorProtocolMessage::DistributeCollation(ccr, collation.proof_of_validity)
)).await {
- log::warn!(target: "collation_generation", "failed to send collation result for para_id {}: {:?}", scheduled_core.para_id, err);
+ log::warn!(
+ target: LOG_TARGET,
+ "failed to send collation result for para_id {}: {:?}",
+ scheduled_core.para_id,
+ err
+ );
}
})).await?;
}
@@ -305,7 +306,7 @@ fn erasure_root(
n_validators: usize,
persisted_validation: PersistedValidationData,
pov: PoV,
-) -> Result {
+) -> crate::error::Result {
let available_data = AvailableData {
validation_data: persisted_validation,
pov,
@@ -333,7 +334,7 @@ impl Metrics {
}
impl metrics::Metrics for Metrics {
- fn try_register(registry: &prometheus::Registry) -> std::result::Result {
+ fn try_register(registry: &prometheus::Registry) -> Result {
let metrics = MetricsInner {
collations_generated_total: prometheus::register(
prometheus::Counter::new(
diff --git a/roadmap/implementers-guide/src/node/collators/collation-generation.md b/roadmap/implementers-guide/src/node/collators/collation-generation.md
index ab3f80273d60..6649cd0d33ab 100644
--- a/roadmap/implementers-guide/src/node/collators/collation-generation.md
+++ b/roadmap/implementers-guide/src/node/collators/collation-generation.md
@@ -29,7 +29,7 @@ pub struct Collation {
struct CollationGenerationConfig {
key: CollatorPair,
- collator: Box Box>>
+ collator: Box Box>>
para_id: ParaId,
}
```