Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Extract block announce validation from ChainSync #14675

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d8860f0
Extract block announce validation/polling from `ChainSync`
dmitry-markin Jul 27, 2023
26be480
Get rid of `push_block_announce_validation_inner`
dmitry-markin Jul 27, 2023
e48c931
Extend `ChainSync` trait with `on_validated_block_announce`
dmitry-markin Jul 28, 2023
66b205f
minor: fix visibilities
dmitry-markin Jul 28, 2023
e48af26
Fix: poll `ChainSync` from `SyncingEngine`
dmitry-markin Jul 28, 2023
210aac4
minor: spelling
dmitry-markin Jul 28, 2023
56cc4d9
Unify `PeerId` variable names as `peer_id`
dmitry-markin Jul 31, 2023
919e84c
Assert when deallocating block announce validation slot counter
dmitry-markin Jul 31, 2023
8c26a6a
Extract block announce validation from `SyncingEngine`
dmitry-markin Jul 31, 2023
49bac21
Simplify naming in `BlockAnnounceValidator`
dmitry-markin Jul 31, 2023
76af1c0
Implement `Stream` trait for `BlockAnnounceValidator`
dmitry-markin Jul 31, 2023
dbdb22d
minor: simplify code a little
dmitry-markin Jul 31, 2023
33c04f8
WIP: wake-up task if new validation is added to `BlockAnnounceValidator`
dmitry-markin Jul 31, 2023
1c4b584
Wake up task when new validation is added to `BlockAnnounceValidator`
dmitry-markin Aug 1, 2023
734294b
Get rid of `PreValidateBlockAnnounce`
dmitry-markin Aug 1, 2023
f77f8e8
Remove now unneeded polling after pushing block announce validation
dmitry-markin Aug 1, 2023
3630b31
Add tests for validation slot allocation
dmitry-markin Aug 1, 2023
65abf22
Merge remote-tracking branch 'origin/master' into dm-move-ba-validati…
dmitry-markin Aug 1, 2023
8d62a27
minor: make rutdoc happy
dmitry-markin Aug 1, 2023
927c9f7
Apply suggestions from code review
dmitry-markin Aug 2, 2023
f137c55
Use `futures::ready!` to simplify polling
dmitry-markin Aug 2, 2023
c717dbc
Prepare `BloackAnnounceValidator` for pushing block announcements fro…
dmitry-markin Aug 24, 2023
cfb1912
minor: comment
dmitry-markin Aug 24, 2023
5879f61
minor: rustfmt
dmitry-markin Aug 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 7 additions & 61 deletions client/network/common/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ pub mod message;
pub mod metrics;
pub mod warp;

use crate::{role::Roles, types::ReputationChange};
use crate::{role::Roles, sync::message::BlockAnnounce, types::ReputationChange};
use futures::Stream;

use libp2p_identity::PeerId;

use message::{BlockAnnounce, BlockData, BlockRequest, BlockResponse};
use message::{BlockData, BlockRequest, BlockResponse};
use sc_consensus::{import_queue::RuntimeOrigin, IncomingBlock};
use sp_consensus::BlockOrigin;
use sp_runtime::{
Expand Down Expand Up @@ -157,38 +157,6 @@ pub enum ImportResult<B: BlockT> {
JustificationImport(RuntimeOrigin, B::Hash, NumberFor<B>, Justifications),
}

/// Value polled from `ChainSync`
#[derive(Debug)]
pub enum PollResult<B: BlockT> {
Import(ImportResult<B>),
Announce(PollBlockAnnounceValidation<B::Header>),
}

/// Result of [`ChainSync::poll_block_announce_validation`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PollBlockAnnounceValidation<H> {
/// The announcement failed at validation.
///
/// The peer reputation should be decreased.
Failure {
/// Who sent the processed block announcement?
who: PeerId,
/// Should the peer be disconnected?
disconnect: bool,
},
/// The announcement does not require further handling.
Nothing {
/// Who sent the processed block announcement?
who: PeerId,
/// Was this their new best block?
is_best: bool,
/// The announcement.
announce: BlockAnnounce<H>,
},
/// The block announcement should be skipped.
Skip,
}

/// Sync operation mode.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum SyncMode {
Expand Down Expand Up @@ -408,29 +376,14 @@ pub trait ChainSync<Block: BlockT>: Send {
/// Notify about finalization of the given block.
fn on_block_finalized(&mut self, hash: &Block::Hash, number: NumberFor<Block>);

/// Push a block announce validation.
///
/// It is required that [`ChainSync::poll_block_announce_validation`] is called
/// to check for finished block announce validations.
fn push_block_announce_validation(
/// Notify about pre-validated block announcement.
fn on_validated_block_announce(
&mut self,
who: PeerId,
hash: Block::Hash,
announce: BlockAnnounce<Block::Header>,
is_best: bool,
who: PeerId,
announce: &BlockAnnounce<Block::Header>,
);

/// Poll block announce validation.
///
/// Block announce validations can be pushed by using
/// [`ChainSync::push_block_announce_validation`].
///
/// This should be polled until it returns [`Poll::Pending`].
fn poll_block_announce_validation(
&mut self,
cx: &mut std::task::Context<'_>,
) -> Poll<PollBlockAnnounceValidation<Block::Header>>;

/// 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.
Expand All @@ -447,14 +400,7 @@ pub trait ChainSync<Block: BlockT>: Send {
) -> Result<Vec<BlockData<Block>>, String>;

/// Advance the state of `ChainSync`
///
/// 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<PollBlockAnnounceValidation<Block::Header>>;
fn poll(&mut self, cx: &mut std::task::Context) -> Poll<()>;

/// Send block request to peer
fn send_block_request(&mut self, who: PeerId, request: BlockRequest<Block>);
Expand Down
1 change: 1 addition & 0 deletions client/network/sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ array-bytes = "6.1"
async-channel = "1.8.0"
async-trait = "0.1.58"
codec = { package = "parity-scale-codec", version = "3.6.1", features = ["derive"] }
event-listener = "2.5.3"
futures = "0.3.21"
futures-timer = "3.0.2"
libp2p = "0.52.1"
Expand Down
Loading