Asyncify launch_work a bit more (#777)

* Asyncify launch_work a bit more

* An error message misword

* A bit more async in collator
This commit is contained in:
Fedor Sakharov
2020-01-20 19:13:48 +03:00
committed by GitHub
parent 3a49649a51
commit 9a9860c8bd
2 changed files with 34 additions and 41 deletions
@@ -34,7 +34,7 @@ use sp_blockchain::HeaderBackend;
use block_builder::BlockBuilderApi;
use consensus::SelectChain;
use futures::prelude::*;
use futures::{future::{ready, select}, task::{Spawn, SpawnExt}};
use futures::{future::select, task::{Spawn, SpawnExt}};
use polkadot_primitives::{Block, Hash, BlockId};
use polkadot_primitives::parachain::{
Chain, ParachainHost, Id as ParaId, ValidatorIndex, ValidatorId, ValidatorPair,
@@ -384,18 +384,18 @@ impl<C, N, P> ParachainValidationInstances<C, N, P> where
let (collators, client) = (self.collators.clone(), self.client.clone());
let availability_store = self.availability_store.clone();
let with_router = move |router: N::TableRouter| {
let with_router = move |router: N::TableRouter| async move {
// fetch a local collation from connected collators.
let collation_work = crate::collation::collation_fetch(
match crate::collation::collation_fetch(
validation_para,
relay_parent,
collators,
client.clone(),
max_block_data_size,
);
).await {
Ok(collation_work) => {
let (collation, outgoing_targeted, fees_charged) = collation_work;
collation_work.map(move |result| match result {
Ok((collation, outgoing_targeted, fees_charged)) => {
match crate::collation::produce_receipt_and_chunks(
authorities_num,
&collation.pov,
@@ -410,41 +410,33 @@ impl<C, N, P> ParachainValidationInstances<C, N, P> where
let chunks_clone = chunks.clone();
let receipt_clone = receipt.clone();
let res = async move {
if let Err(e) = av_clone.clone().add_erasure_chunks(
relay_parent.clone(),
receipt_clone,
chunks_clone,
).await {
warn!(target: "validation", "Failed to add erasure chunks: {}", e);
}
}
.unit_error()
.boxed()
.then(move |_| {
if let Err(e) = av_clone.clone().add_erasure_chunks(
relay_parent.clone(),
receipt_clone,
chunks_clone,
).await {
warn!(
target: "validation",
"Failed to add erasure chunks: {}", e
);
} else {
router.local_collation(
collation,
receipt,
outgoing_targeted,
(local_id, &chunks),
);
ready(())
});
Some(res)
}
}
Err(e) => {
warn!(target: "validation", "Failed to produce a receipt: {:?}", e);
None
}
}
};
}
Err(e) => {
warn!(target: "validation", "Failed to collate candidate: {:?}", e);
None
warn!(target: "validation", "Failed to fetch a candidate: {:?}", e);
}
})
}
};
let router = build_router