mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 05:38:00 +00:00
Switch the client to new futures (#3103)
* Switch the client to new futures * No need for compat in the client * Fix client tests * Address review
This commit is contained in:
committed by
Bastian Köcher
parent
f5e921281e
commit
bf2551a854
@@ -19,6 +19,7 @@
|
||||
use crate::protocol::on_demand::RequestData;
|
||||
use std::sync::Arc;
|
||||
use futures::{prelude::*, sync::mpsc, sync::oneshot};
|
||||
use futures03::compat::{Compat01As03, Future01CompatExt as _};
|
||||
use parking_lot::Mutex;
|
||||
use client::error::Error as ClientError;
|
||||
use client::light::fetcher::{Fetcher, FetchChecker, RemoteHeaderRequest,
|
||||
@@ -82,22 +83,22 @@ impl<B> Fetcher<B> for OnDemand<B> where
|
||||
B: BlockT,
|
||||
B::Header: HeaderT,
|
||||
{
|
||||
type RemoteHeaderResult = RemoteResponse<B::Header>;
|
||||
type RemoteReadResult = RemoteResponse<Option<Vec<u8>>>;
|
||||
type RemoteCallResult = RemoteResponse<Vec<u8>>;
|
||||
type RemoteChangesResult = RemoteResponse<Vec<(NumberFor<B>, u32)>>;
|
||||
type RemoteBodyResult = RemoteResponse<Vec<B::Extrinsic>>;
|
||||
type RemoteHeaderResult = Compat01As03<RemoteResponse<B::Header>>;
|
||||
type RemoteReadResult = Compat01As03<RemoteResponse<Option<Vec<u8>>>>;
|
||||
type RemoteCallResult = Compat01As03<RemoteResponse<Vec<u8>>>;
|
||||
type RemoteChangesResult = Compat01As03<RemoteResponse<Vec<(NumberFor<B>, u32)>>>;
|
||||
type RemoteBodyResult = Compat01As03<RemoteResponse<Vec<B::Extrinsic>>>;
|
||||
|
||||
fn remote_header(&self, request: RemoteHeaderRequest<B::Header>) -> Self::RemoteHeaderResult {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
let _ = self.requests_send.unbounded_send(RequestData::RemoteHeader(request, sender));
|
||||
RemoteResponse { receiver }
|
||||
RemoteResponse { receiver }.compat()
|
||||
}
|
||||
|
||||
fn remote_read(&self, request: RemoteReadRequest<B::Header>) -> Self::RemoteReadResult {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
let _ = self.requests_send.unbounded_send(RequestData::RemoteRead(request, sender));
|
||||
RemoteResponse { receiver }
|
||||
RemoteResponse { receiver }.compat()
|
||||
}
|
||||
|
||||
fn remote_read_child(
|
||||
@@ -106,25 +107,25 @@ impl<B> Fetcher<B> for OnDemand<B> where
|
||||
) -> Self::RemoteReadResult {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
let _ = self.requests_send.unbounded_send(RequestData::RemoteReadChild(request, sender));
|
||||
RemoteResponse { receiver }
|
||||
RemoteResponse { receiver }.compat()
|
||||
}
|
||||
|
||||
fn remote_call(&self, request: RemoteCallRequest<B::Header>) -> Self::RemoteCallResult {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
let _ = self.requests_send.unbounded_send(RequestData::RemoteCall(request, sender));
|
||||
RemoteResponse { receiver }
|
||||
RemoteResponse { receiver }.compat()
|
||||
}
|
||||
|
||||
fn remote_changes(&self, request: RemoteChangesRequest<B::Header>) -> Self::RemoteChangesResult {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
let _ = self.requests_send.unbounded_send(RequestData::RemoteChanges(request, sender));
|
||||
RemoteResponse { receiver }
|
||||
RemoteResponse { receiver }.compat()
|
||||
}
|
||||
|
||||
fn remote_body(&self, request: RemoteBodyRequest<B::Header>) -> Self::RemoteBodyResult {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
let _ = self.requests_send.unbounded_send(RequestData::RemoteBody(request, sender));
|
||||
RemoteResponse { receiver }
|
||||
RemoteResponse { receiver }.compat()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ use std::sync::Arc;
|
||||
use crate::config::build_multiaddr;
|
||||
use log::trace;
|
||||
use crate::chain::FinalityProofProvider;
|
||||
use client::{self, ClientInfo, BlockchainEvents, ImportNotifications, FinalityNotifications};
|
||||
use client::{self, ClientInfo, BlockchainEvents, BlockImportNotification, FinalityNotifications, FinalityNotification};
|
||||
use client::{in_mem::Backend as InMemoryBackend, error::Result as ClientResult};
|
||||
use client::block_builder::BlockBuilder;
|
||||
use client::backend::AuxStore;
|
||||
@@ -40,6 +40,7 @@ use consensus::block_import::{BlockImport, ImportResult};
|
||||
use consensus::{Error as ConsensusError, well_known_cache_keys::{self, Id as CacheKeyId}};
|
||||
use consensus::{BlockOrigin, ForkChoiceStrategy, ImportBlock, JustificationImport};
|
||||
use futures::prelude::*;
|
||||
use futures03::{StreamExt as _, TryStreamExt as _};
|
||||
use crate::{NetworkWorker, NetworkService, config::ProtocolId};
|
||||
use crate::config::{NetworkConfiguration, TransportConfig, BoxFinalityProofRequestBuilder};
|
||||
use libp2p::PeerId;
|
||||
@@ -216,8 +217,8 @@ pub struct Peer<D, S: NetworkSpecialization<Block>> {
|
||||
/// instead of going through the import queue.
|
||||
block_import: Box<dyn BlockImport<Block, Error = ConsensusError>>,
|
||||
network: NetworkWorker<Block, S, <Block as BlockT>::Hash>,
|
||||
imported_blocks_stream: futures::stream::Fuse<ImportNotifications<Block>>,
|
||||
finality_notification_stream: futures::stream::Fuse<FinalityNotifications<Block>>,
|
||||
imported_blocks_stream: Box<dyn Stream<Item = BlockImportNotification<Block>, Error = ()> + Send>,
|
||||
finality_notification_stream: Box<dyn Stream<Item = FinalityNotification<Block>, Error = ()> + Send>,
|
||||
}
|
||||
|
||||
impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
|
||||
@@ -482,8 +483,10 @@ pub trait TestNetFactory: Sized {
|
||||
peer.network.add_known_address(network.service().local_peer_id(), listen_addr.clone());
|
||||
}
|
||||
|
||||
let imported_blocks_stream = client.import_notification_stream().fuse();
|
||||
let finality_notification_stream = client.finality_notification_stream().fuse();
|
||||
let imported_blocks_stream = Box::new(client.import_notification_stream()
|
||||
.map(|v| Ok::<_, ()>(v)).compat().fuse());
|
||||
let finality_notification_stream = Box::new(client.finality_notification_stream()
|
||||
.map(|v| Ok::<_, ()>(v)).compat().fuse());
|
||||
|
||||
peers.push(Peer {
|
||||
data,
|
||||
@@ -539,8 +542,10 @@ pub trait TestNetFactory: Sized {
|
||||
peer.network.add_known_address(network.service().local_peer_id(), listen_addr.clone());
|
||||
}
|
||||
|
||||
let imported_blocks_stream = client.import_notification_stream().fuse();
|
||||
let finality_notification_stream = client.finality_notification_stream().fuse();
|
||||
let imported_blocks_stream = Box::new(client.import_notification_stream()
|
||||
.map(|v| Ok::<_, ()>(v)).compat().fuse());
|
||||
let finality_notification_stream = Box::new(client.finality_notification_stream()
|
||||
.map(|v| Ok::<_, ()>(v)).compat().fuse());
|
||||
|
||||
peers.push(Peer {
|
||||
data,
|
||||
|
||||
Reference in New Issue
Block a user