Skip to content

Commit 02a01ef

Browse files
committed
Centralize heartbeat logic in PeerManager
- Remove redundant HeartbeatManager::heartbeat() wrapper function - Consolidate all heartbeat logic directly in PeerManager::heartbeat() - Simplify HeartbeatManager to only handle timing (poll_tick) - Clean up unused imports in heartbeat.rs - Improve code organization with clear separation of concerns: - HeartbeatManager: Timer management only - PeerManager: All heartbeat logic and orchestration - PeerDiscovery: Peer discovery/connection logic This eliminates an unnecessary layer of indirection and centralizes heartbeat functionality for better maintainability.
1 parent ad24609 commit 02a01ef

File tree

2 files changed

+3
-30
lines changed

2 files changed

+3
-30
lines changed
Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
use std::{collections::HashSet, time::Duration};
1+
use std::time::Duration;
22

3-
use discv5::libp2p_identity::PeerId;
4-
use peer_store::memory_store::MemoryStore;
5-
use subnet_service::SubnetId;
63
use tokio::time::{MissedTickBehavior, interval};
7-
use tracing::info;
8-
9-
use super::{connection::ConnectionManager, discovery::PeerDiscovery, types::ConnectActions};
10-
use crate::Enr;
114

125
/// Interval between heartbeat events in seconds
136
const HEARTBEAT_INTERVAL: u64 = 30;
@@ -32,25 +25,4 @@ impl HeartbeatManager {
3225
) -> std::task::Poll<tokio::time::Instant> {
3326
self.heartbeat.poll_tick(cx)
3427
}
35-
36-
/// Log network status and check for needed peer actions
37-
pub fn heartbeat(
38-
needed_subnets: &HashSet<SubnetId>,
39-
peer_store: &MemoryStore<Enr>,
40-
connection_manager: &ConnectionManager,
41-
blocked_peers: &HashSet<PeerId>,
42-
) -> Option<ConnectActions> {
43-
info!(
44-
subnets = needed_subnets.len(),
45-
peers = connection_manager.connected.len(),
46-
"Network status"
47-
);
48-
49-
PeerDiscovery::check_subnet_peers(
50-
needed_subnets,
51-
peer_store,
52-
connection_manager,
53-
blocked_peers,
54-
)
55-
}
5628
}

anchor/network/src/peer_manager/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ impl PeerManager {
9292
// Check and unblock peers that have been blocked long enough
9393
self.blocking_manager.check_and_unblock_expired_peers();
9494

95-
HeartbeatManager::heartbeat(
95+
// Check if any subnets need more peers and return dial/discovery actions
96+
PeerDiscovery::check_subnet_peers(
9697
&self.needed_subnets,
9798
self.peer_store.store(),
9899
&self.connection_manager,

0 commit comments

Comments
 (0)