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

fix(network): only send responded updates on handshake/ping/pong #3463

Merged
merged 1 commit into from
Feb 8, 2022
Merged
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
31 changes: 25 additions & 6 deletions zebra-network/src/peer/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,15 @@ where
let _ = address_book_updater.send(alt_addr).await;
}

// The handshake succeeded: update the peer status from AttemptPending to Responded
if let Some(book_addr) = connected_addr.get_address_book_addr() {
// the collector doesn't depend on network activity,
// so this await should not hang
let _ = address_book_updater
.send(MetaAddr::new_responded(&book_addr, &remote_services))
.await;
}

// Set the connection's version to the minimum of the received version or our own.
let negotiated_version =
std::cmp::min(remote_version, constants::CURRENT_NETWORK_PROTOCOL_VERSION);
Expand Down Expand Up @@ -864,8 +873,13 @@ where

// CORRECTNESS
//
// Every message and error must update the peer address state via
// Ping/Pong messages and every error must update the peer address state via
// the inbound_ts_collector.
//
// The heartbeat task sends regular Ping/Pong messages,
// and it ends the connection if the heartbeat times out.
// So we can just track peer activity based on Ping and Pong.
// (This significantly improves performance, by reducing time system calls.)
let inbound_ts_collector = address_book_updater.clone();
let inv_collector = inv_collector.clone();
let ts_inner_conn_span = connection_span.clone();
Expand All @@ -888,11 +902,16 @@ where
);

if let Some(book_addr) = connected_addr.get_address_book_addr() {
// the collector doesn't depend on network activity,
// so this await should not hang
let _ = inbound_ts_collector
.send(MetaAddr::new_responded(&book_addr, &remote_services))
.await;
if matches!(msg, Message::Ping(_) | Message::Pong(_)) {
// the collector doesn't depend on network activity,
// so this await should not hang
let _ = inbound_ts_collector
.send(MetaAddr::new_responded(
&book_addr,
&remote_services,
))
.await;
}
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Err(err) => {
Expand Down