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

Move code for starting new routing table sync to RoutingTableActor #5163

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 14 additions & 12 deletions chain/network/src/peer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use crate::types::{
};
use crate::types::{GetPeerId, GetPeerIdResult};
#[cfg(feature = "protocol_feature_routing_exchange_algorithm")]
use crate::types::{RoutingState, RoutingSyncV2, RoutingVersion2};
use crate::types::{RoutingSyncV2, RoutingVersion2};

/// How often to request peers from active peers.
const REQUEST_PEERS_INTERVAL: Duration = Duration::from_millis(60_000);
Expand Down Expand Up @@ -353,9 +353,9 @@ impl PeerManagerActor {
act.routing_table_pool
.send(RoutingTableMessages::AddPeerIfMissing(peer_id, None))
.into_actor(act)
.map(move |response, act, _ctx| match response {
.map(move |response, act, ctx| match response {
Ok(RoutingTableMessagesResponse::AddPeerResponse { seed }) => {
act.start_routing_table_syncv2(addr, seed)
act.start_routing_table_syncv2(ctx, addr, seed)
}
_ => error!(target: "network", "expected AddIbfSetResponse"),
})
Expand All @@ -364,15 +364,17 @@ impl PeerManagerActor {
});
}
#[cfg(feature = "protocol_feature_routing_exchange_algorithm")]
fn start_routing_table_syncv2(&self, addr: Addr<Peer>, seed: u64) {
let _ = addr.do_send(SendMessage {
message: PeerMessage::RoutingTableSyncV2(RoutingSyncV2::Version2(RoutingVersion2 {
known_edges: self.routing_table.get_edges_len(),
seed,
edges: Default::default(),
routing_state: RoutingState::InitializeIbf,
})),
});
fn start_routing_table_syncv2(&self, ctx: &mut Context<Self>, addr: Addr<Peer>, seed: u64) {
self.routing_table_pool
.send(RoutingTableMessages::StartRoutingTableSync { seed })
.into_actor(self)
.map(move |response, _act, _ctx| match response {
Ok(RoutingTableMessagesResponse::StartRoutingTableSyncResponse(response)) => {
let _ = addr.do_send(SendMessage { message: response });
}
_ => error!(target: "network", "expected StartRoutingTableSyncResponse"),
})
.spawn(ctx);
}

/// Register a direct connection to a new peer. This will be called after successfully
Expand Down
19 changes: 18 additions & 1 deletion chain/network/src/routing_table_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::routing::Edge;
use crate::routing::{SimpleEdge, ValidIBFLevel, MIN_IBF_LEVEL};
use crate::types::StopMsg;
#[cfg(feature = "protocol_feature_routing_exchange_algorithm")]
use crate::types::{PartialSync, RoutingState, RoutingVersion2};
use crate::types::{PartialSync, PeerMessage, RoutingState, RoutingSyncV2, RoutingVersion2};

/// Actor that maintains routing table information.
/// TODO (PIOTR, #4859) Finish moving routing table computation to new thread.
Expand Down Expand Up @@ -68,6 +68,10 @@ pub enum RoutingTableMessages {
peer_id: PeerId,
ibf_msg: RoutingVersion2,
},
#[cfg(feature = "protocol_feature_routing_exchange_algorithm")]
StartRoutingTableSync {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's start improving the documentation:

can you add the description of what will happen when this message is received?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, once we merge other PR changes I'll add documentation.

seed: u64,
},
}

impl Message for RoutingTableMessages {
Expand All @@ -88,6 +92,8 @@ pub enum RoutingTableMessagesResponse {
RequestRoutingTableResponse {
edges_info: Vec<Edge>,
},
#[cfg(feature = "protocol_feature_routing_exchange_algorithm")]
StartRoutingTableSyncResponse(PeerMessage),
}

#[cfg(feature = "protocol_feature_routing_exchange_algorithm")]
Expand Down Expand Up @@ -142,6 +148,17 @@ impl Handler<RoutingTableMessages> for RoutingTableActor {
}
RoutingTableMessagesResponse::Empty
}
#[cfg(feature = "protocol_feature_routing_exchange_algorithm")]
RoutingTableMessages::StartRoutingTableSync { seed } => {
RoutingTableMessagesResponse::StartRoutingTableSyncResponse(
PeerMessage::RoutingTableSyncV2(RoutingSyncV2::Version2(RoutingVersion2 {
known_edges: self.edges_info.len() as u64,
seed,
edges: Default::default(),
routing_state: RoutingState::InitializeIbf,
})),
)
}
RoutingTableMessages::RequestRoutingTable => {
RoutingTableMessagesResponse::RequestRoutingTableResponse {
edges_info: self.edges_info.iter().map(|(_k, v)| v.clone()).collect(),
Expand Down