Skip to content

Commit

Permalink
publish dummy infos for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
saketh-are committed Nov 2, 2023
1 parent cf07eb8 commit 6b02fa2
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion chain/network/src/peer_manager/peer_manager_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::tcp;
use crate::types::{
ConnectedPeerInfo, HighestHeightPeerInfo, KnownProducer, NetworkInfo, NetworkRequests,
NetworkResponses, PeerInfo, PeerManagerMessageRequest, PeerManagerMessageResponse, PeerType,
SetChainInfo,
SetChainInfo, SnapshotHostInfo,
};
use actix::fut::future::wrap_future;
use actix::{Actor as _, AsyncContext as _};
Expand All @@ -26,7 +26,9 @@ use near_async::time;
use near_o11y::{handler_debug_span, handler_trace_span, OpenTelemetrySpanExt, WithSpanContext};
use near_performance_metrics_macros::perf;
use near_primitives::block::GenesisId;
use near_primitives::hash::CryptoHash;
use near_primitives::network::{AnnounceAccount, PeerId};
use near_primitives::types::EpochHeight;
use near_primitives::views::{
ConnectionInfoView, EdgeView, KnownPeerStateView, NetworkGraphView, PeerStoreView,
RecentOutboundConnectionsView,
Expand Down Expand Up @@ -240,6 +242,7 @@ impl PeerManagerActor {
let arbiter = arbiter.clone();
let state = state.clone();
let clock = clock.clone();
let peer_id = my_peer_id.clone();
async move {
// Start server if address provided.
if let Some(server_addr) = &state.config.node_addr {
Expand Down Expand Up @@ -328,6 +331,35 @@ impl PeerManagerActor {
}
}
});

// Testing purposes only! Periodically publish some dummy SnapshotHostInfo.
arbiter.spawn({
let state = state.clone();

let mut interval = time::Interval::new(clock.now(), time::Duration::seconds(30));

let mut epoch_height: EpochHeight = 9876543210;

async move {
loop {
interval.tick(&clock).await;

let hash = CryptoHash::hash_bytes(&[(epoch_height % 12345) as u8]);

epoch_height += 1;

let data = SnapshotHostInfo::new(
peer_id.clone(),
hash,
epoch_height,
vec![23, epoch_height % 10],
&state.config.node_key,
);

state.add_snapshot_hosts(vec![data.into()]).await;
}
}
});
}
});
Ok(Self::start_in_arbiter(&arbiter, move |_ctx| Self {
Expand Down

0 comments on commit 6b02fa2

Please sign in to comment.