Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor code cleanup #2586

Merged
merged 2 commits into from
Jun 11, 2024
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
4 changes: 0 additions & 4 deletions consensus/src/sync/history/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ impl<TNetwork: Network> HistoryMacroSync<TNetwork> {
}
}

pub fn peers(&self) -> impl Iterator<Item = &TNetwork::PeerId> {
self.peers.keys()
}

pub fn remove_peer(&mut self, peer_id: TNetwork::PeerId) {
for cluster in self.epoch_clusters.iter_mut() {
cluster.remove_peer(&peer_id);
Expand Down
4 changes: 0 additions & 4 deletions consensus/src/sync/light/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ impl<TNetwork: Network> LightMacroSync<TNetwork> {
}
}

pub fn peers(&self) -> impl Iterator<Item = &TNetwork::PeerId> {
self.peer_requests.keys()
}

pub fn remove_peer_requests(&mut self, peer_id: TNetwork::PeerId) {
self.peer_requests.remove(&peer_id);
}
Expand Down
37 changes: 19 additions & 18 deletions consensus/src/sync/light/sync_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,6 @@ impl<TNetwork: Network> LightMacroSync<TNetwork> {
cx: &mut Context<'_>,
) -> Poll<Option<MacroSyncReturn<TNetwork::PeerId>>> {
while let Poll::Ready(Some(Some(epoch_ids))) = self.epoch_ids_stream.poll_next_unpin(cx) {
// Calculate an upper bound on the peer's head block.
// The upper bound is the last micro block of the latest batch of the peer.
#[cfg(feature = "full")]
let peer_head_upper_bound = epoch_ids
.checkpoint
.as_ref()
.map(|checkpoint| checkpoint.block_number)
.unwrap_or_else(|| {
if epoch_ids.checkpoint_epoch_number() == 0 {
return 0;
}
// FIXME: Ban peer if it sends an invalid epoch_number instead of panicking.
Policy::first_block_of(epoch_ids.checkpoint_epoch_number() as u32)
.expect("The supplied epoch number is out of bounds")
})
+ Policy::blocks_per_batch()
- 1;

// If the peer didn't find any of our locators, we are done with it and emit it.
if !epoch_ids.locator_found {
debug!(
Expand Down Expand Up @@ -245,6 +227,25 @@ impl<TNetwork: Network> LightMacroSync<TNetwork> {
if let BlockchainProxy::Full(_) = self.blockchain {
let blockchain = self.blockchain.read();
let our_head = blockchain.block_number();

// Calculate an upper bound on the peer's head block.
// The upper bound is the last micro block of the latest batch of the peer.
#[cfg(feature = "full")]
let peer_head_upper_bound = epoch_ids
.checkpoint
.as_ref()
.map(|checkpoint| checkpoint.block_number)
.unwrap_or_else(|| {
if epoch_ids.checkpoint_epoch_number() == 0 {
return 0;
}
// FIXME: Ban peer if it sends an invalid epoch_number instead of panicking.
Policy::first_block_of(epoch_ids.checkpoint_epoch_number() as u32)
.expect("The supplied epoch number is out of bounds")
})
+ Policy::blocks_per_batch()
- 1;

if peer_head_upper_bound.saturating_sub(our_head) <= self.full_sync_threshold
&& blockchain.accounts_complete()
{
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/sync/syncer_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl<N: Network> SyncerProxy<N> {
gen_syncer_match!(self, num_peers)
}

/// Returns the peers of peers doing live synchronization
/// Returns the peers doing live synchronization
pub fn peers(&self) -> Vec<N::PeerId> {
gen_syncer_match!(self, peers)
}
Expand Down
Loading