Skip to content

Commit

Permalink
Remove unnecessary peer status requesting on epoch start
Browse files Browse the repository at this point in the history
  • Loading branch information
povi committed Dec 10, 2024
1 parent ca00548 commit 993779a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 39 deletions.
12 changes: 1 addition & 11 deletions p2p/src/block_sync_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;
use anyhow::Result;
use database::Database;
use eth1_api::RealController;
use eth2_libp2p::{rpc::StatusMessage, PeerAction, PeerId, ReportSource};
use eth2_libp2p::{PeerAction, PeerId, ReportSource};
use fork_choice_control::SyncMessage;
use futures::{
channel::mpsc::{UnboundedReceiver, UnboundedSender},
Expand Down Expand Up @@ -236,7 +236,6 @@ impl<P: Preset> BlockSyncService<P> {
}
P2pToSync::AddPeer(peer_id, status) => {
self.sync_manager.add_peer(peer_id, status);
self.request_peer_status_update(status)?;
self.request_blobs_and_blocks_if_ready()?;
}
P2pToSync::RemovePeer(peer_id) => {
Expand Down Expand Up @@ -553,15 +552,6 @@ impl<P: Preset> BlockSyncService<P> {
Ok(())
}

fn request_peer_status_update(&mut self, status: StatusMessage) -> Result<()> {
for peer_id in self.sync_manager.outdated_peers(status) {
debug!("Update outdated peer: {peer_id}");
self.request_peer_status(peer_id)?;
}

Ok(())
}

fn request_id(&mut self) -> Result<RequestId> {
let request_id = self.next_request_id;
self.next_request_id = self.next_request_id.checked_add(1).ok_or(Error)?;
Expand Down
28 changes: 0 additions & 28 deletions p2p/src/sync_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const GREEDY_MODE_PEER_LIMIT: usize = 2;
const MAX_SYNC_DISTANCE_IN_SLOTS: u64 = 10000;
const NOT_ENOUGH_PEERS_MESSAGE_COOLDOWN: Duration = Duration::from_secs(10);
const PEER_UPDATE_COOLDOWN_IN_SECONDS: u64 = 12;
const PEERS_BEFORE_STATUS_UPDATE: usize = 1;
const SEQUENTIAL_REDOWNLOADS_TILL_RESET: usize = 5;

#[derive(Debug, Eq, PartialEq, Clone, Copy)]
Expand Down Expand Up @@ -603,33 +602,6 @@ impl SyncManager {
self.block_requests.expired_range_batches()
}

pub fn outdated_peers(&mut self, status: StatusMessage) -> Vec<PeerId> {
if let Some(chain) = self.chain_with_max_peer_count() {
let status_chain = ChainId::from(&status);

if chain != status_chain
&& status_chain.finalized_epoch == chain.finalized_epoch + 1
&& self.chain_peers(&status_chain).len() >= PEERS_BEFORE_STATUS_UPDATE
&& self
.status_updates_cache
.cache_get(&status_chain.finalized_epoch)
.is_none()
{
self.status_updates_cache
.cache_set(status_chain.finalized_epoch, ());

return self
.peers
.iter()
.filter(move |(_, status)| ChainId::from(*status) == chain)
.map(|(peer_id, _)| *peer_id)
.collect();
}
}

vec![]
}

pub fn cache_clear(&mut self) {
self.blob_requests.cache_clear();
self.block_requests.cache_clear();
Expand Down

0 comments on commit 993779a

Please sign in to comment.