Skip to content

Commit

Permalink
check for empty blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Nov 20, 2024
1 parent 35bb479 commit e3bb5ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/server/p2p/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub struct ShareChainSyncResponse {
version: u64,
peer_id: PeerId,
algo: u64,
blocks: Vec<P2Block>,
pub blocks: Vec<P2Block>,
}

impl ShareChainSyncResponse {
Expand Down
16 changes: 11 additions & 5 deletions src/server/p2p/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,11 +910,12 @@ where S: ShareChain
let local_peer_id = *self.swarm.local_peer_id();
let squad = self.config.squad.clone();
tokio::spawn(async move {
let response = ShareChainSyncResponse::new(
local_peer_id,
request.algo(),
&share_chain.get_blocks(request.missing_blocks()).await,
);
let blocks = share_chain.get_blocks(request.missing_blocks()).await;
if blocks.is_empty() {
warn!(target: LOG_TARGET, squad; "No blocks found for sync request");
return;
}
let response = ShareChainSyncResponse::new(local_peer_id, request.algo(), &blocks);

if tx.send(InnerRequest::SyncChainRequest((channel, response))).is_err() {
error!(target: LOG_TARGET, squad; "Failed to send block sync response");
Expand All @@ -932,6 +933,11 @@ where S: ShareChain
trace!(target: LOG_TARGET, squad = &self.config.squad; "Peer {} has an outdated version, skipping", peer);
return;
}

if response.blocks.is_empty() {
trace!(target: LOG_TARGET, squad = &self.config.squad; "Peer {} sent 0 blocks", peer);
return;
}
let timer = Instant::now();
// if !self.sync_in_progress.load(Ordering::SeqCst) {
// return;
Expand Down

0 comments on commit e3bb5ba

Please sign in to comment.