Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update substrate: async API fix
  • Loading branch information
cecton committed Feb 1, 2020
commit 8a43df170e52d2412cdf432d42e9ec34b4214cb9
32 changes: 20 additions & 12 deletions collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use codec::{Decode, Encode};

use log::{error, trace};

use futures::{task::Spawn, Future};
use futures::{task::Spawn, Future, future};

use std::{fmt::Debug, marker::PhantomData, sync::Arc, time::Duration, pin::Pin};

Expand Down Expand Up @@ -120,20 +120,25 @@ where
let inherent_providers = self.inherent_data_providers.clone();
let block_import = self.block_import.clone();

Box::pin(async move {
trace!(target: "cumulus-collator", "Producing candidate");

let last_head = HeadData::<Block>::decode(&mut &status.head_data.0[..]).map_err(|e| {
let last_head = match HeadData::<Block>::decode(&mut &status.head_data.0[..]) {
Ok(x) => x,
Err(e) => {
error!(target: "cumulus-collator", "Could not decode the head data: {:?}", e);
InvalidHead
})?;
return Box::pin(future::ready(Err(InvalidHead)));
}
};

let proposer_future = factory
.lock()
.init(&last_head.header);

Box::pin(async move {
trace!(target: "cumulus-collator", "Producing candidate");

let parent_state_root = *last_head.header.state_root();

let mut proposer = factory
.lock()
.init(&last_head.header)
let mut proposer = proposer_future
.await
.map_err(|e| {
error!(
target: "cumulus-collator",
Expand Down Expand Up @@ -393,9 +398,12 @@ mod tests {
impl Environment<Block> for DummyFactory {
type Proposer = DummyProposer;
type Error = Error;
type CreateProposer = Pin<Box<
dyn Future<Output = Result<Self::Proposer, Self::Error>> + Send + Unpin + 'static
>>;

fn init(&mut self, _: &Header) -> Result<Self::Proposer, Self::Error> {
Ok(DummyProposer)
fn init(&mut self, _: &Header) -> Self::CreateProposer {
Box::pin(future::ready(Ok(DummyProposer)))
}
}

Expand Down