Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sync): use routed state part request in sync actor #12111

Merged
merged 19 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
424 changes: 116 additions & 308 deletions chain/client/src/sync/state.rs

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions chain/client/src/test_utils/peer_manager_mock.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use near_network::types::SetChainInfo;
use near_network::types::{PeerManagerMessageRequest, PeerManagerMessageResponse};
use near_network::types::{
PeerManagerMessageRequest, PeerManagerMessageResponse, SetChainInfo, StateSyncEvent,
};

pub struct PeerManagerMock {
handle: Box<
Expand Down Expand Up @@ -37,3 +38,8 @@ impl actix::Handler<SetChainInfo> for PeerManagerMock {
type Result = ();
fn handle(&mut self, _msg: SetChainInfo, _ctx: &mut Self::Context) {}
}

impl actix::Handler<StateSyncEvent> for PeerManagerMock {
type Result = ();
fn handle(&mut self, _msg: StateSyncEvent, _ctx: &mut Self::Context) {}
}
21 changes: 20 additions & 1 deletion chain/network/src/peer_manager/peer_manager_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::tcp;
use crate::types::{
ConnectedPeerInfo, HighestHeightPeerInfo, KnownProducer, NetworkInfo, NetworkRequests,
NetworkResponses, PeerInfo, PeerManagerMessageRequest, PeerManagerMessageResponse, PeerType,
SetChainInfo, SnapshotHostInfo, StatePartRequestBody, Tier3RequestBody,
SetChainInfo, SnapshotHostInfo, StatePartRequestBody, StateSyncEvent, Tier3RequestBody,
};
use ::time::ext::InstantExt as _;
use actix::fut::future::wrap_future;
Expand Down Expand Up @@ -1260,6 +1260,25 @@ impl actix::Handler<WithSpanContext<PeerManagerMessageRequest>> for PeerManagerA
}
}

impl actix::Handler<WithSpanContext<StateSyncEvent>> for PeerManagerActor {
type Result = ();
#[perf]
fn handle(
&mut self,
msg: WithSpanContext<StateSyncEvent>,
_ctx: &mut Self::Context,
) -> Self::Result {
let (_span, msg) = handler_debug_span!(target: "network", msg);
let _timer =
metrics::PEER_MANAGER_MESSAGES_TIME.with_label_values(&[(&msg).into()]).start_timer();
match msg {
StateSyncEvent::StatePartReceived(shard_id, part_id) => {
self.state.snapshot_hosts.part_received(shard_id, part_id);
}
}
}
}

impl actix::Handler<GetDebugStatus> for PeerManagerActor {
type Result = DebugStatus;
#[perf]
Expand Down
1 change: 0 additions & 1 deletion chain/network/src/snapshot_hosts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ impl SnapshotHostsCache {
}

/// Triggered by state sync actor after processing a state part.
#[allow(dead_code)]
pub fn part_received(&self, shard_id: ShardId, part_id: u64) {
let mut inner = self.0.lock();
inner.peer_selector.remove(&(shard_id, part_id));
Expand Down
6 changes: 5 additions & 1 deletion chain/network/src/test_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::state_witness::{
};
use crate::types::{
NetworkRequests, NetworkResponses, PeerManagerMessageRequest, PeerManagerMessageResponse,
SetChainInfo,
SetChainInfo, StateSyncEvent,
};
use near_async::actix::ActixResult;
use near_async::futures::{FutureSpawner, FutureSpawnerExt};
Expand Down Expand Up @@ -188,6 +188,10 @@ impl Handler<SetChainInfo> for TestLoopPeerManagerActor {
fn handle(&mut self, _msg: SetChainInfo) {}
}

impl Handler<StateSyncEvent> for TestLoopPeerManagerActor {
fn handle(&mut self, _msg: StateSyncEvent) {}
}

impl Handler<PeerManagerMessageRequest> for TestLoopPeerManagerActor {
fn handle(&mut self, msg: PeerManagerMessageRequest) -> PeerManagerMessageResponse {
let PeerManagerMessageRequest::NetworkRequests(request) = msg else {
Expand Down
6 changes: 5 additions & 1 deletion chain/network/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::network_protocol::PeerInfo;
use crate::types::{
NetworkInfo, NetworkResponses, PeerManagerMessageRequest, PeerManagerMessageResponse,
SetChainInfo,
SetChainInfo, StateSyncEvent,
};
use crate::PeerManagerActor;
use actix::{Actor, ActorContext, Context, Handler};
Expand Down Expand Up @@ -259,6 +259,10 @@ impl CanSend<SetChainInfo> for MockPeerManagerAdapter {
fn send(&self, _msg: SetChainInfo) {}
}

impl CanSend<StateSyncEvent> for MockPeerManagerAdapter {
fn send(&self, _msg: StateSyncEvent) {}
}

impl MockPeerManagerAdapter {
pub fn pop(&self) -> Option<PeerManagerMessageRequest> {
self.requests.write().unwrap().pop_front()
Expand Down
7 changes: 7 additions & 0 deletions chain/network/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ pub enum NetworkRequests {
EpochSyncResponse { route_back: CryptoHash, proof: CompressedEpochSyncProof },
}

#[derive(Debug, actix::Message, strum::IntoStaticStr)]
#[rtype(result = "()")]
pub enum StateSyncEvent {
StatePartReceived(ShardId, u64),
}

/// Combines peer address info, chain.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct FullPeerInfo {
Expand Down Expand Up @@ -404,6 +410,7 @@ pub struct PeerManagerAdapter {
pub async_request_sender: AsyncSender<PeerManagerMessageRequest, PeerManagerMessageResponse>,
pub request_sender: Sender<PeerManagerMessageRequest>,
pub set_chain_info_sender: Sender<SetChainInfo>,
pub state_sync_event_sender: Sender<StateSyncEvent>,
}

#[cfg(test)]
Expand Down
Loading