Skip to content

Commit

Permalink
send full sync on connect
Browse files Browse the repository at this point in the history
  • Loading branch information
saketh-are committed Nov 2, 2023
1 parent f345afb commit cf07eb8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions chain/network/src/peer/peer_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::network_protocol::{
DistanceVector, Edge, EdgeState, Encoding, OwnedAccount, ParsePeerMessageError,
PartialEdgeInfo, PeerChainInfoV2, PeerIdOrHash, PeerInfo, PeersRequest, PeersResponse,
RawRoutedMessage, RoutedMessageBody, RoutingTableUpdate, StateResponseInfo, SyncAccountsData,
SyncSnapshotHosts,
};
use crate::peer::stream;
use crate::peer::tracker::Tracker;
Expand Down Expand Up @@ -785,6 +786,8 @@ impl PeerActor {
}
// Sync the RoutingTable.
act.sync_routing_table();
// Sync snapshot hosts
act.sync_snapshot_hosts();
}

act.network_state.config.event_sink.push(Event::HandshakeCompleted(HandshakeCompletedEvent{
Expand Down Expand Up @@ -817,6 +820,12 @@ impl PeerActor {
)));
}

// Send all known snapshot hosts.
fn sync_snapshot_hosts(&self) {
let hosts = self.network_state.snapshot_hosts.get_hosts();
self.send_message_or_log(&PeerMessage::SyncSnapshotHosts(SyncSnapshotHosts { hosts }));
}

fn handle_msg_connecting(&mut self, ctx: &mut actix::Context<Self>, msg: PeerMessage) {
match (&mut self.peer_status, msg) {
(
Expand Down
7 changes: 5 additions & 2 deletions chain/network/src/snapshot_hosts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Cache of SnapshotHostInfos.
//!
//! Each node in the network which is willing to generate and serve state snapshots
//! publishes a SnapshotHostInfo once per epoch. The info is flooded to all nodes in
//! the network and stored locally in this cache.
//! publishes a SnapshotHostInfo once per epoch. The info is flooded to all nodes in the network and stored locally in this cache.
use crate::concurrency;
use crate::concurrency::arc_mutex::ArcMutex;
Expand Down Expand Up @@ -110,4 +109,8 @@ impl SnapshotHostsCache {
// Return the inserted data.
(inserted, err)
}

pub fn get_hosts(&self) -> Vec<Arc<SnapshotHostInfo>> {
self.0.load().hosts.values().cloned().collect()
}
}

0 comments on commit cf07eb8

Please sign in to comment.