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

Introduce mockable ChainSync object for testing #12480

Merged
merged 7 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
58 changes: 58 additions & 0 deletions Cargo.lock

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

14 changes: 8 additions & 6 deletions client/network/common/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,14 @@ pub trait ChainSync<Block: BlockT>: Send {
);

/// Get an iterator over all scheduled justification requests.
fn justification_requests(
&mut self,
) -> Box<dyn Iterator<Item = (PeerId, BlockRequest<Block>)> + '_>;
fn justification_requests<'a>(
&'a mut self,
) -> Box<dyn Iterator<Item = (PeerId, BlockRequest<Block>)> + 'a>;

/// Get an iterator over all block requests of all peers.
fn block_requests(&mut self) -> Box<dyn Iterator<Item = (&PeerId, BlockRequest<Block>)> + '_>;
fn block_requests<'a>(
&'a mut self,
) -> Box<dyn Iterator<Item = (PeerId, BlockRequest<Block>)> + 'a>;

/// Get a state request, if any.
fn state_request(&mut self) -> Option<(PeerId, OpaqueStateRequest)>;
Expand Down Expand Up @@ -359,9 +361,9 @@ pub trait ChainSync<Block: BlockT>: Send {
///
/// If [`PollBlockAnnounceValidation::ImportHeader`] is returned, then the caller MUST try to
/// import passed header (call `on_block_data`). The network request isn't sent in this case.
fn poll_block_announce_validation(
fn poll_block_announce_validation<'a>(
&mut self,
cx: &mut std::task::Context,
cx: &mut std::task::Context<'a>,
) -> Poll<PollBlockAnnounceValidation<Block::Header>>;

/// Call when a peer has disconnected.
Expand Down
2 changes: 1 addition & 1 deletion client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ where
for (id, request) in self
.chain_sync
.block_requests()
.map(|(peer_id, request)| (*peer_id, request))
.map(|(peer_id, request)| (peer_id, request))
.collect::<Vec<_>>()
{
let event =
Expand Down
2 changes: 2 additions & 0 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ use std::{

pub use behaviour::{InboundFailure, OutboundFailure, ResponseFailure};

#[cfg(test)]
mod chainsync_tests;
mod metrics;
mod out_events;
#[cfg(test)]
Expand Down
Loading