Skip to content

Commit

Permalink
Return removed inflight blocks count when disconnect
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <[email protected]>
  • Loading branch information
eval-exec committed Oct 31, 2023
1 parent e0d0280 commit d932788
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions sync/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,21 +760,23 @@ impl InflightBlocks {
download_scheduler.hashes.insert(block)
}

pub fn remove_by_peer(&mut self, peer: PeerIndex) -> bool {
pub fn remove_by_peer(&mut self, peer: PeerIndex) -> usize {
let trace = &mut self.trace_number;
let state = &mut self.inflight_states;

self.download_schedulers
.remove(&peer)
.map(|blocks| {
let blocks_count = blocks.hashes.iter().len();
for block in blocks.hashes {
state.remove(&block);
if !trace.is_empty() {
trace.remove(&block);
}
}
blocks_count
})
.is_some()
.unwrap_or_default()
}

pub fn remove_by_block(&mut self, block: BlockNumberAndHash) -> bool {
Expand Down Expand Up @@ -1725,7 +1727,13 @@ impl SyncState {
// TODO: record peer's connection duration (disconnect time - connect established time)
// and report peer's connection duration to ckb_metrics
pub fn disconnected(&self, pi: PeerIndex) {
self.write_inflight_blocks().remove_by_peer(pi);
let removed_inflight_blocks_count = self.write_inflight_blocks().remove_by_peer(pi);
if removed_inflight_blocks_count > 0 {
debug!(
"disconnected {}, remove {} inflight blocks",
pi, removed_inflight_blocks_count
)
}
self.peers().disconnected(pi);
}

Expand Down

0 comments on commit d932788

Please sign in to comment.