Network sync refactoring (part 1) (#11303)

* Remove unnecessary imports, move one internal re-export into where it is actually used, make one import explicit

* Move a few data structures down into modules

* Use generic parameters in `sc-network` instead of `chain::Client` trait

* Remove unnecessary bound
This commit is contained in:
Nazar Mokrynskyi
2022-04-29 17:02:03 +03:00
committed by GitHub
parent 887acda7d0
commit af6773aba9
15 changed files with 380 additions and 206 deletions
+16 -12
View File
@@ -20,12 +20,9 @@
//! Only supports bitswap 1.2.0.
//! CID is expected to reference 256-bit Blake2b transaction hash.
use crate::{
chain::Client,
schema::bitswap::{
message::{wantlist::WantType, Block as MessageBlock, BlockPresence, BlockPresenceType},
Message as BitswapMessage,
},
use crate::schema::bitswap::{
message::{wantlist::WantType, Block as MessageBlock, BlockPresence, BlockPresenceType},
Message as BitswapMessage,
};
use cid::Version;
use core::pin::Pin;
@@ -44,10 +41,12 @@ use libp2p::{
};
use log::{debug, error, trace};
use prost::Message;
use sc_client_api::BlockBackend;
use sp_runtime::traits::Block as BlockT;
use std::{
collections::VecDeque,
io,
marker::PhantomData,
sync::Arc,
task::{Context, Poll},
};
@@ -181,19 +180,24 @@ impl Prefix {
}
/// Network behaviour that handles sending and receiving IPFS blocks.
pub struct Bitswap<B> {
client: Arc<dyn Client<B>>,
pub struct Bitswap<B, Client> {
client: Arc<Client>,
ready_blocks: VecDeque<(PeerId, BitswapMessage)>,
_block: PhantomData<B>,
}
impl<B: BlockT> Bitswap<B> {
impl<B, Client> Bitswap<B, Client> {
/// Create a new instance of the bitswap protocol handler.
pub fn new(client: Arc<dyn Client<B>>) -> Self {
Self { client, ready_blocks: Default::default() }
pub fn new(client: Arc<Client>) -> Self {
Self { client, ready_blocks: Default::default(), _block: PhantomData::default() }
}
}
impl<B: BlockT> NetworkBehaviour for Bitswap<B> {
impl<B, Client> NetworkBehaviour for Bitswap<B, Client>
where
B: BlockT,
Client: BlockBackend<B> + Send + Sync + 'static,
{
type ConnectionHandler = OneShotHandler<BitswapConfig, BitswapMessage, HandlerEvent>;
type OutEvent = void::Void;