mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-07 18:57:23 +00:00
Move import queue out of sc-network (#12764)
* Move import queue out of `sc-network` Add supplementary asynchronous API for the import queue which means it can be run as an independent task and communicated with through the `ImportQueueService`. This commit removes removes block and justification imports from `sc-network` and provides `ChainSync` with a handle to import queue so it can import blocks and justifications. Polling of the import queue is moved complete out of `sc-network` and `sc_consensus::Link` is implemented for `ChainSyncInterfaceHandled` so the import queue can still influence the syncing process. * Fix tests * Apply review comments * Apply suggestions from code review Co-authored-by: Bastian Köcher <git@kchr.de> * Update client/network/sync/src/lib.rs Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -32,7 +32,6 @@ use libp2p::{
|
||||
NetworkBehaviour,
|
||||
};
|
||||
|
||||
use sc_consensus::import_queue::{IncomingBlock, RuntimeOrigin};
|
||||
use sc_network_common::{
|
||||
protocol::{
|
||||
event::DhtEvent,
|
||||
@@ -43,18 +42,14 @@ use sc_network_common::{
|
||||
};
|
||||
use sc_peerset::{PeersetHandle, ReputationChange};
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_consensus::BlockOrigin;
|
||||
use sp_runtime::{
|
||||
traits::{Block as BlockT, NumberFor},
|
||||
Justifications,
|
||||
};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use std::{collections::HashSet, time::Duration};
|
||||
|
||||
pub use crate::request_responses::{InboundFailure, OutboundFailure, RequestId, ResponseFailure};
|
||||
|
||||
/// General behaviour of the network. Combines all protocols together.
|
||||
#[derive(NetworkBehaviour)]
|
||||
#[behaviour(out_event = "BehaviourOut<B>")]
|
||||
#[behaviour(out_event = "BehaviourOut")]
|
||||
pub struct Behaviour<B, Client>
|
||||
where
|
||||
B: BlockT,
|
||||
@@ -72,10 +67,7 @@ where
|
||||
}
|
||||
|
||||
/// Event generated by `Behaviour`.
|
||||
pub enum BehaviourOut<B: BlockT> {
|
||||
BlockImport(BlockOrigin, Vec<IncomingBlock<B>>),
|
||||
JustificationImport(RuntimeOrigin, B::Hash, NumberFor<B>, Justifications),
|
||||
|
||||
pub enum BehaviourOut {
|
||||
/// Started a random iterative Kademlia discovery query.
|
||||
RandomKademliaStarted,
|
||||
|
||||
@@ -107,10 +99,7 @@ pub enum BehaviourOut<B: BlockT> {
|
||||
},
|
||||
|
||||
/// A request protocol handler issued reputation changes for the given peer.
|
||||
ReputationChanges {
|
||||
peer: PeerId,
|
||||
changes: Vec<ReputationChange>,
|
||||
},
|
||||
ReputationChanges { peer: PeerId, changes: Vec<ReputationChange> },
|
||||
|
||||
/// Opened a substream with the given node with the given notifications protocol.
|
||||
///
|
||||
@@ -306,13 +295,9 @@ fn reported_roles_to_observed_role(roles: Roles) -> ObservedRole {
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: BlockT> From<CustomMessageOutcome<B>> for BehaviourOut<B> {
|
||||
impl<B: BlockT> From<CustomMessageOutcome<B>> for BehaviourOut {
|
||||
fn from(event: CustomMessageOutcome<B>) -> Self {
|
||||
match event {
|
||||
CustomMessageOutcome::BlockImport(origin, blocks) =>
|
||||
BehaviourOut::BlockImport(origin, blocks),
|
||||
CustomMessageOutcome::JustificationImport(origin, hash, nb, justification) =>
|
||||
BehaviourOut::JustificationImport(origin, hash, nb, justification),
|
||||
CustomMessageOutcome::NotificationStreamOpened {
|
||||
remote,
|
||||
protocol,
|
||||
@@ -344,7 +329,7 @@ impl<B: BlockT> From<CustomMessageOutcome<B>> for BehaviourOut<B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: BlockT> From<request_responses::Event> for BehaviourOut<B> {
|
||||
impl From<request_responses::Event> for BehaviourOut {
|
||||
fn from(event: request_responses::Event) -> Self {
|
||||
match event {
|
||||
request_responses::Event::InboundRequest { peer, protocol, result } =>
|
||||
@@ -357,14 +342,14 @@ impl<B: BlockT> From<request_responses::Event> for BehaviourOut<B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: BlockT> From<peer_info::PeerInfoEvent> for BehaviourOut<B> {
|
||||
impl From<peer_info::PeerInfoEvent> for BehaviourOut {
|
||||
fn from(event: peer_info::PeerInfoEvent) -> Self {
|
||||
let peer_info::PeerInfoEvent::Identified { peer_id, info } = event;
|
||||
BehaviourOut::PeerIdentify { peer_id, info }
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: BlockT> From<DiscoveryOut> for BehaviourOut<B> {
|
||||
impl From<DiscoveryOut> for BehaviourOut {
|
||||
fn from(event: DiscoveryOut) -> Self {
|
||||
match event {
|
||||
DiscoveryOut::UnroutablePeer(_peer_id) => {
|
||||
|
||||
Reference in New Issue
Block a user