Make everything compile again

This commit is contained in:
Bastian Köcher
2019-10-02 16:52:08 +02:00
parent 1ceecff053
commit e91c8e78f2
5 changed files with 97 additions and 134 deletions
+2 -61
View File
@@ -22,9 +22,7 @@ use sr_primitives::traits::{Block as BlockT, Header as HeaderT, ProvideRuntimeAp
use polkadot_primitives::{Hash as PHash, Block as PBlock};
use polkadot_primitives::parachain::{Id as ParaId, ParachainHost};
use futures03::{
Stream, stream, StreamExt, TryStreamExt, TryStream, future, Future, TryFutureExt, FutureExt,
};
use futures::{Stream, StreamExt, TryStreamExt, future, Future, TryFutureExt, FutureExt};
use codec::{Encode, Decode};
use log::warn;
@@ -35,10 +33,6 @@ pub trait LocalClient {
/// The block type of the local client.
type Block: BlockT;
/// Mark the given block as the best block.
/// Returns `false` if the block is not known.
fn mark_best(&self, hash: <Self::Block as BlockT>::Hash) -> ClientResult<bool>;
/// Finalize the given block.
/// Returns `false` if the block is not known.
fn finalize(&self, hash: <Self::Block as BlockT>::Hash) -> ClientResult<bool>;
@@ -67,13 +61,9 @@ pub trait PolkadotClient: Clone {
/// The error type for interacting with the Polkadot client.
type Error: std::fmt::Debug + Send;
/// A stream that yields updates to the parachain head.
type HeadUpdates: Stream<Item = HeadUpdate> + Send;
/// A stream that yields finalized head-data for a certain parachain.
type Finalized: Stream<Item = Vec<u8>> + Send;
/// Get a stream of head updates.
fn head_updates(&self, para_id: ParaId) -> ClientResult<Self::HeadUpdates>;
/// Get a stream of finalized heads.
fn finalized_heads(&self, para_id: ParaId) -> ClientResult<Self::Finalized>;
}
@@ -85,23 +75,8 @@ pub fn follow_polkadot<'a, L: 'a, P: 'a>(para_id: ParaId, local: Arc<L>, polkado
L: LocalClient + Send + Sync,
P: PolkadotClient + Send + Sync,
{
let head_updates = polkadot.head_updates(para_id)?;
let finalized_heads = polkadot.finalized_heads(para_id)?;
let follow_best = {
let local = local.clone();
head_updates
.map(|update| {
<Option<<L::Block as BlockT>::Header>>::decode(&mut &update.head_data[..])
.map_err(|_| Error::InvalidHeadData)
})
.try_filter_map(|h| future::ready(Ok(h)))
.try_for_each(move |p_head| {
future::ready(local.mark_best(p_head.hash()).map_err(Error::Client).map(|_| ()))
})
};
let follow_finalized = {
let local = local.clone();
@@ -117,7 +92,7 @@ pub fn follow_polkadot<'a, L: 'a, P: 'a>(para_id: ParaId, local: Arc<L>, polkado
};
Ok(
future::try_join(follow_best, follow_finalized)
follow_finalized
.map_err(|e| warn!("Could not follow relay-chain: {:?}", e))
.map(|_| ())
)
@@ -130,16 +105,6 @@ impl<B, E, Block, RA> LocalClient for Client<B, E, Block, RA> where
{
type Block = Block;
fn mark_best(&self, hash: <Self::Block as BlockT>::Hash) -> ClientResult<bool> {
match self.set_head(BlockId::hash(hash)) {
Ok(()) => Ok(true),
Err(e) => match e {
ClientError::UnknownBlock(_) => Ok(false),
_ => Err(e),
}
}
}
fn finalize(&self, hash: <Self::Block as BlockT>::Hash) -> ClientResult<bool> {
match self.finalize_block(BlockId::hash(hash), None, true) {
Ok(()) => Ok(true),
@@ -168,32 +133,8 @@ impl<B, E, RA> PolkadotClient for Arc<Client<B, E, PBlock, RA>> where
{
type Error = ClientError;
type HeadUpdates = Box<dyn Stream<Item=HeadUpdate> + Send + Unpin>;
type Finalized = Box<dyn Stream<Item=Vec<u8>> + Send + Unpin>;
fn head_updates(&self, para_id: ParaId) -> ClientResult<Self::HeadUpdates> {
let parachain_key = parachain_key(para_id);
let stream = self.storage_changes_notification_stream(Some(&[parachain_key.clone()]), None)?;
let s = stream.filter_map(move |(hash, changes)| {
let head_data = changes.iter()
.filter_map(|(_, k, v)| if k == &parachain_key { Some(v) } else { None })
.next();
let res = match head_data {
Some(Some(head_data)) => Some(HeadUpdate {
relay_hash: hash,
head_data: head_data.0.clone(),
}),
Some(None) | None => None,
};
future::ready(res)
});
Ok(Box::new(s))
}
fn finalized_heads(&self, para_id: ParaId) -> ClientResult<Self::Finalized> {
let polkadot = self.clone();
let parachain_key = parachain_key(para_id);