mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 20:27:58 +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:
@@ -24,9 +24,7 @@ pub mod warp;
|
||||
|
||||
use libp2p::PeerId;
|
||||
use message::{BlockAnnounce, BlockData, BlockRequest, BlockResponse};
|
||||
use sc_consensus::{
|
||||
import_queue::RuntimeOrigin, BlockImportError, BlockImportStatus, IncomingBlock,
|
||||
};
|
||||
use sc_consensus::{import_queue::RuntimeOrigin, IncomingBlock};
|
||||
use sp_consensus::BlockOrigin;
|
||||
use sp_runtime::{
|
||||
traits::{Block as BlockT, NumberFor},
|
||||
@@ -317,6 +315,12 @@ pub trait ChainSync<Block: BlockT>: Send {
|
||||
response: BlockResponse<Block>,
|
||||
) -> Result<OnBlockData<Block>, BadPeer>;
|
||||
|
||||
/// Procss received block data.
|
||||
fn process_block_response_data(
|
||||
&mut self,
|
||||
blocks_to_import: Result<OnBlockData<Block>, BadPeer>,
|
||||
);
|
||||
|
||||
/// Handle a response from the remote to a justification request that we made.
|
||||
///
|
||||
/// `request` must be the original request that triggered `response`.
|
||||
@@ -326,17 +330,6 @@ pub trait ChainSync<Block: BlockT>: Send {
|
||||
response: BlockResponse<Block>,
|
||||
) -> Result<OnBlockJustification<Block>, BadPeer>;
|
||||
|
||||
/// A batch of blocks have been processed, with or without errors.
|
||||
///
|
||||
/// Call this when a batch of blocks have been processed by the import
|
||||
/// queue, with or without errors.
|
||||
fn on_blocks_processed(
|
||||
&mut self,
|
||||
imported: usize,
|
||||
count: usize,
|
||||
results: Vec<(Result<BlockImportStatus<NumberFor<Block>>, BlockImportError>, Block::Hash)>,
|
||||
) -> Box<dyn Iterator<Item = Result<(PeerId, BlockRequest<Block>), BadPeer>>>;
|
||||
|
||||
/// Call this when a justification has been processed by the import queue,
|
||||
/// with or without errors.
|
||||
fn on_justification_import(
|
||||
@@ -378,7 +371,7 @@ pub trait ChainSync<Block: BlockT>: Send {
|
||||
/// Call when a peer has disconnected.
|
||||
/// Canceled obsolete block request may result in some blocks being ready for
|
||||
/// import, so this functions checks for such blocks and returns them.
|
||||
fn peer_disconnected(&mut self, who: &PeerId) -> Option<OnBlockData<Block>>;
|
||||
fn peer_disconnected(&mut self, who: &PeerId);
|
||||
|
||||
/// Return some key metrics.
|
||||
fn metrics(&self) -> Metrics;
|
||||
@@ -395,7 +388,10 @@ pub trait ChainSync<Block: BlockT>: Send {
|
||||
/// Internally calls [`ChainSync::poll_block_announce_validation()`] and
|
||||
/// this function should be polled until it returns [`Poll::Pending`] to
|
||||
/// consume all pending events.
|
||||
fn poll(&mut self, cx: &mut std::task::Context) -> Poll<PollResult<Block>>;
|
||||
fn poll(
|
||||
&mut self,
|
||||
cx: &mut std::task::Context,
|
||||
) -> Poll<PollBlockAnnounceValidation<Block::Header>>;
|
||||
|
||||
/// Send block request to peer
|
||||
fn send_block_request(&mut self, who: PeerId, request: BlockRequest<Block>);
|
||||
|
||||
Reference in New Issue
Block a user