diff --git a/chain/network/src/peer/peer_actor.rs b/chain/network/src/peer/peer_actor.rs index 22cdbc3d172..a84e2c85069 100644 --- a/chain/network/src/peer/peer_actor.rs +++ b/chain/network/src/peer/peer_actor.rs @@ -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; @@ -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{ @@ -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, msg: PeerMessage) { match (&mut self.peer_status, msg) { ( diff --git a/chain/network/src/snapshot_hosts/mod.rs b/chain/network/src/snapshot_hosts/mod.rs index ee3664d89d4..b0a6c30f7bb 100644 --- a/chain/network/src/snapshot_hosts/mod.rs +++ b/chain/network/src/snapshot_hosts/mod.rs @@ -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; @@ -110,4 +109,8 @@ impl SnapshotHostsCache { // Return the inserted data. (inserted, err) } + + pub fn get_hosts(&self) -> Vec> { + self.0.load().hosts.values().cloned().collect() + } }