mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 04:37:57 +00:00
Move import queue from ChainSync to SyncingEngine (#1736)
This PR is part of [Sync 2.0](https://github.com/paritytech/polkadot-sdk/issues/534) refactoring aimed at making `ChainSync` a pure state machine. Resolves https://github.com/paritytech/polkadot-sdk/issues/501.
This commit is contained in:
@@ -116,11 +116,18 @@ impl fmt::Display for BadPeer {
|
||||
|
||||
impl std::error::Error for BadPeer {}
|
||||
|
||||
/// Action that the parent of [`ChainSync`] should perform if we want to import blocks.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ImportBlocksAction<B: BlockT> {
|
||||
pub origin: BlockOrigin,
|
||||
pub blocks: Vec<IncomingBlock<B>>,
|
||||
}
|
||||
|
||||
/// Result of [`ChainSync::on_block_data`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum OnBlockData<Block: BlockT> {
|
||||
/// The block should be imported.
|
||||
Import(BlockOrigin, Vec<IncomingBlock<Block>>),
|
||||
Import(ImportBlocksAction<Block>),
|
||||
/// A new block request needs to be made to the given peer.
|
||||
Request(PeerId, BlockRequest<Block>),
|
||||
/// Continue processing events.
|
||||
@@ -134,7 +141,7 @@ pub enum OnBlockJustification<Block: BlockT> {
|
||||
Nothing,
|
||||
/// The justification should be imported.
|
||||
Import {
|
||||
peer: PeerId,
|
||||
peer_id: PeerId,
|
||||
hash: Block::Hash,
|
||||
number: NumberFor<Block>,
|
||||
justifications: Justifications,
|
||||
@@ -309,6 +316,7 @@ pub trait ChainSync<Block: BlockT>: Send {
|
||||
/// Handle a new connected peer.
|
||||
///
|
||||
/// Call this method whenever we connect to a new peer.
|
||||
#[must_use]
|
||||
fn new_peer(
|
||||
&mut self,
|
||||
who: PeerId,
|
||||
@@ -340,6 +348,7 @@ pub trait ChainSync<Block: BlockT>: Send {
|
||||
///
|
||||
/// If this corresponds to a valid block, this outputs the block that
|
||||
/// must be imported in the import queue.
|
||||
#[must_use]
|
||||
fn on_block_data(
|
||||
&mut self,
|
||||
who: &PeerId,
|
||||
@@ -350,6 +359,7 @@ pub trait ChainSync<Block: BlockT>: Send {
|
||||
/// Handle a response from the remote to a justification request that we made.
|
||||
///
|
||||
/// `request` must be the original request that triggered `response`.
|
||||
#[must_use]
|
||||
fn on_block_justification(
|
||||
&mut self,
|
||||
who: PeerId,
|
||||
@@ -379,7 +389,8 @@ 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);
|
||||
#[must_use]
|
||||
fn peer_disconnected(&mut self, who: &PeerId) -> Option<ImportBlocksAction<Block>>;
|
||||
|
||||
/// Return some key metrics.
|
||||
fn metrics(&self) -> Metrics;
|
||||
|
||||
Reference in New Issue
Block a user