Skip to content

Commit

Permalink
[Peer Monitoring Service] Only return connection metadata for network
Browse files Browse the repository at this point in the history
info requests.
  • Loading branch information
JoshLind committed Mar 28, 2023
1 parent e29d5ba commit 0f31c27
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 105 deletions.
2 changes: 1 addition & 1 deletion config/src/config/network_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ impl Default for PeerMonitoringServiceConfig {
latency_monitoring: LatencyMonitoringConfig::default(),
max_concurrent_requests: 1000,
max_network_channel_size: 1000,
max_request_jitter_ms: 1000, // Monitoring requests are very infrequent, so 1 sec is acceptable
max_request_jitter_ms: 1000, // Monitoring requests are very infrequent
metadata_update_interval_ms: 5000,
network_monitoring: NetworkMonitoringConfig::default(),
peer_monitor_interval_ms: 1000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ mod test {
// Create the service response
let peer_monitoring_service_response =
PeerMonitoringServiceResponse::NetworkInformation(NetworkInformationResponse {
connected_peers_and_metadata: Default::default(),
connected_peers: Default::default(),
distance_from_validators,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ impl PeerState {
.await;

// Stop the timer and calculate the duration
let finish_time = time_service.now();
let request_duration: Duration = finish_time.duration_since(start_time);
let request_duration_secs = request_duration.as_secs_f64();
let request_duration_secs = start_time.elapsed().as_secs_f64();

// Mark the in-flight request as now complete
request_tracker.write().request_completed();
Expand Down Expand Up @@ -169,10 +167,10 @@ impl PeerState {
.map(|network_info_response| network_info_response.distance_from_validators);
peer_monitoring_metadata.distance_from_validators = distance_from_validators;

// Get and store the connected peers and metadata
// Get and store the connected peers and connection metadata
let connected_peers_and_metadata = network_info_response
.map(|network_info_response| network_info_response.connected_peers_and_metadata);
peer_monitoring_metadata.connected_peers_and_metadata = connected_peers_and_metadata;
.map(|network_info_response| network_info_response.connected_peers);
peer_monitoring_metadata.connected_peers = connected_peers_and_metadata;

Ok(peer_monitoring_metadata)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use aptos_config::{
network_id::{NetworkId, PeerNetworkId},
};
use aptos_infallible::RwLock;
use aptos_network::{application::metadata::PeerMetadata, transport::ConnectionMetadata};
use aptos_network::transport::ConnectionMetadata;
use aptos_peer_monitoring_service_types::{
LatencyPingResponse, NetworkInformationResponse, PeerMonitoringServiceRequest,
PeerMonitoringServiceResponse,
Expand Down Expand Up @@ -107,13 +107,14 @@ async fn test_peer_updater_loop_multiple_peers() {
let peer_state = peer_states.get_mut(peer).unwrap();

// Update the network info
let connected_peers_and_metadata = hashmap! { PeerNetworkId::random() => PeerMetadata::new(ConnectionMetadata::mock(PeerId::random())) };
let connected_peers =
hashmap! { PeerNetworkId::random() => ConnectionMetadata::mock(PeerId::random()) };
let distance_from_validators = get_distance_from_validators(peer);
update_network_info_for_peer(
peers_and_metadata.clone(),
peer,
peer_state,
connected_peers_and_metadata,
connected_peers,
distance_from_validators,
1.0,
);
Expand Down Expand Up @@ -391,10 +392,11 @@ async fn test_network_info() {
let peer_monitor_state = peer_monitor_state.clone();
let handle_requests = async move {
// Create a response for the network info requests
let connected_peers_and_metadata = hashmap! { PeerNetworkId::random() => PeerMetadata::new(ConnectionMetadata::mock(PeerId::random())) };
let connected_peers =
hashmap! { PeerNetworkId::random() => ConnectionMetadata::mock(PeerId::random()) };
let response =
PeerMonitoringServiceResponse::NetworkInformation(NetworkInformationResponse {
connected_peers_and_metadata: connected_peers_and_metadata.clone(),
connected_peers: connected_peers.clone(),
distance_from_validators: 0,
});

Expand Down
89 changes: 47 additions & 42 deletions network/peer-monitoring-service/client/src/tests/single_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use aptos_config::{
config::{NodeConfig, PeerRole},
network_id::{NetworkId, PeerNetworkId},
};
use aptos_network::{application::metadata::PeerMetadata, transport::ConnectionMetadata};
use aptos_network::transport::ConnectionMetadata;
use aptos_time_service::TimeServiceTrait;
use aptos_types::PeerId;
use maplit::hashmap;
Expand Down Expand Up @@ -56,16 +56,15 @@ async fn test_basic_peer_monitor_loop() {

// Initialize all the peer states by running the peer monitor once
let mock_time = time_service.into_mock();
let (connected_peers_and_metadata, distance_from_validators) =
initialize_and_verify_peer_states(
&network_id,
&mut mock_monitoring_server,
&peer_monitor_state,
&node_config,
&validator_peer,
&mock_time,
)
.await;
let (connected_peers, distance_from_validators) = initialize_and_verify_peer_states(
&network_id,
&mut mock_monitoring_server,
&peer_monitor_state,
&node_config,
&validator_peer,
&mock_time,
)
.await;

// Elapse enough time for a latency ping and verify correct execution
verify_and_handle_latency_ping(
Expand All @@ -89,7 +88,7 @@ async fn test_basic_peer_monitor_loop() {
verify_all_requests_and_respond(
&network_id,
&mut mock_monitoring_server,
&connected_peers_and_metadata,
&connected_peers,
distance_from_validators,
)
.await;
Expand All @@ -107,7 +106,7 @@ async fn test_basic_peer_monitor_loop() {
verify_peer_monitor_state(
&peer_monitor_state,
&validator_peer,
&connected_peers_and_metadata,
&connected_peers,
distance_from_validators,
3,
);
Expand Down Expand Up @@ -197,12 +196,13 @@ async fn test_basic_peer_updater_loop() {
// Update the network info for the fullnode several times
for distance_from_validators in 2..10 {
// Update the network info for the fullnode
let connected_peers_and_metadata = hashmap! { PeerNetworkId::random() => PeerMetadata::new(ConnectionMetadata::mock(PeerId::random())) };
let connected_peers =
hashmap! { PeerNetworkId::random() => ConnectionMetadata::mock(PeerId::random()) };
update_network_info_for_peer(
peers_and_metadata.clone(),
&fullnode_peer,
&mut peer_state,
connected_peers_and_metadata,
connected_peers,
distance_from_validators,
1.0,
);
Expand Down Expand Up @@ -450,15 +450,16 @@ async fn test_network_info_requests() {
// Handle many network info requests and responses
let distance_from_validators = 0;
for _ in 0..20 {
let connected_peers_and_metadata = hashmap! { PeerNetworkId::random() => PeerMetadata::new(ConnectionMetadata::mock(PeerId::random())) };
let connected_peers =
hashmap! { PeerNetworkId::random() => ConnectionMetadata::mock(PeerId::random()) };
verify_and_handle_network_info_request(
&network_id,
&mut mock_monitoring_server,
&peer_monitor_state,
&node_config,
&validator_peer,
&mock_time,
&connected_peers_and_metadata,
&connected_peers,
distance_from_validators,
)
.await;
Expand Down Expand Up @@ -489,28 +490,28 @@ async fn test_network_info_request_failures() {

// Initialize all the peer states by running the peer monitor once
let mock_time = time_service.into_mock();
let (connected_peers_and_metadata, distance_from_validators) =
initialize_and_verify_peer_states(
&network_id,
&mut mock_monitoring_server,
&peer_monitor_state,
&node_config,
&validator_peer,
&mock_time,
)
.await;
let (connected_peers, distance_from_validators) = initialize_and_verify_peer_states(
&network_id,
&mut mock_monitoring_server,
&peer_monitor_state,
&node_config,
&validator_peer,
&mock_time,
)
.await;

// Handle several network info requests with bad responses
for i in 0..5 {
// Elapse enough time for a network info update
elapse_network_info_update_interval(node_config.clone(), mock_time.clone()).await;

// Verify that a single network info request is received and send a bad response
let connected_peers_and_metadata = hashmap! { PeerNetworkId::random() => PeerMetadata::new(ConnectionMetadata::mock(PeerId::random())) };
let connected_peers =
hashmap! { PeerNetworkId::random() => ConnectionMetadata::mock(PeerId::random()) };
verify_network_info_request_and_respond(
&network_id,
&mut mock_monitoring_server,
&connected_peers_and_metadata,
&connected_peers,
distance_from_validators,
false,
true,
Expand All @@ -526,7 +527,7 @@ async fn test_network_info_request_failures() {
verify_peer_network_state(
&peer_monitor_state,
&validator_peer,
&connected_peers_and_metadata,
&connected_peers,
distance_from_validators,
5,
);
Expand All @@ -537,11 +538,12 @@ async fn test_network_info_request_failures() {
elapse_network_info_update_interval(node_config.clone(), mock_time.clone()).await;

// Verify that a single network info request is received and send an invalid peer depth response
let connected_peers_and_metadata = hashmap! { PeerNetworkId::random() => PeerMetadata::new(ConnectionMetadata::mock(PeerId::random())) };
let connected_peers =
hashmap! { PeerNetworkId::random() => ConnectionMetadata::mock(PeerId::random()) };
verify_network_info_request_and_respond(
&network_id,
&mut mock_monitoring_server,
&connected_peers_and_metadata,
&connected_peers,
distance_from_validators,
true,
false,
Expand All @@ -557,21 +559,22 @@ async fn test_network_info_request_failures() {
verify_peer_network_state(
&peer_monitor_state,
&validator_peer,
&connected_peers_and_metadata,
&connected_peers,
distance_from_validators,
10,
);

// Elapse enough time for a network info request and perform a successful execution
let connected_peers_and_metadata = hashmap! { PeerNetworkId::random() => PeerMetadata::new(ConnectionMetadata::mock(PeerId::random())) };
let connected_peers =
hashmap! { PeerNetworkId::random() => ConnectionMetadata::mock(PeerId::random()) };
verify_and_handle_network_info_request(
&network_id,
&mut mock_monitoring_server,
&peer_monitor_state,
&node_config,
&validator_peer,
&mock_time,
&connected_peers_and_metadata,
&connected_peers,
distance_from_validators,
)
.await;
Expand All @@ -581,7 +584,7 @@ async fn test_network_info_request_failures() {
verify_peer_network_state(
&peer_monitor_state,
&validator_peer,
&connected_peers_and_metadata,
&connected_peers,
distance_from_validators,
0,
);
Expand All @@ -592,11 +595,12 @@ async fn test_network_info_request_failures() {
elapse_network_info_update_interval(node_config.clone(), mock_time.clone()).await;

// Verify that a single network info request is received and don't send a response
let connected_peers_and_metadata = hashmap! { PeerNetworkId::random() => PeerMetadata::new(ConnectionMetadata::mock(PeerId::random())) };
let connected_peers =
hashmap! { PeerNetworkId::random() => ConnectionMetadata::mock(PeerId::random()) };
verify_network_info_request_and_respond(
&network_id,
&mut mock_monitoring_server,
&connected_peers_and_metadata,
&connected_peers,
distance_from_validators,
false,
false,
Expand All @@ -612,21 +616,22 @@ async fn test_network_info_request_failures() {
verify_peer_network_state(
&peer_monitor_state,
&validator_peer,
&connected_peers_and_metadata,
&connected_peers,
distance_from_validators,
5,
);

// Elapse enough time for a latency ping and perform a successful execution
let connected_peers_and_metadata = hashmap! { PeerNetworkId::random() => PeerMetadata::new(ConnectionMetadata::mock(PeerId::random())) };
let connected_peers =
hashmap! { PeerNetworkId::random() => ConnectionMetadata::mock(PeerId::random()) };
verify_and_handle_network_info_request(
&network_id,
&mut mock_monitoring_server,
&peer_monitor_state,
&node_config,
&validator_peer,
&mock_time,
&connected_peers_and_metadata,
&connected_peers,
distance_from_validators,
)
.await;
Expand All @@ -636,7 +641,7 @@ async fn test_network_info_request_failures() {
verify_peer_network_state(
&peer_monitor_state,
&validator_peer,
&connected_peers_and_metadata,
&connected_peers,
distance_from_validators,
0,
);
Expand Down
Loading

0 comments on commit 0f31c27

Please sign in to comment.