Skip to content

Commit

Permalink
GH-1072 Fix for net_latency_ns not being calculated yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Jun 6, 2023
1 parent 703f8eb commit 1341215
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3239,14 +3239,16 @@ namespace eosio {

// called from connection strand
uint32_t connection::calc_block_latency() {
// number of blocks syncing node is behind from a peer node, round up
uint32_t nblk_behind_by_net_latency = std::lround( static_cast<double>(net_latency_ns.load()) / static_cast<double>(block_interval_ns) );
// 2x for time it takes for message to reach back to peer node
uint32_t nblk_combined_latency = 2 * nblk_behind_by_net_latency;
// message in the log below is used in p2p_high_latency_test.py test
peer_dlog(this, "Network latency is ${lat}ms, ${num} blocks discrepancy by network latency, ${tot_num} blocks discrepancy expected once message received",
("lat", net_latency_ns/1000000)("num", nblk_behind_by_net_latency)("tot_num", nblk_combined_latency));

uint32_t nblk_combined_latency = 0;
if (net_latency_ns != std::numeric_limits<uint64_t>::max()) {
// number of blocks syncing node is behind from a peer node, round up
uint32_t nblk_behind_by_net_latency = std::lround(static_cast<double>(net_latency_ns.load()) / static_cast<double>(block_interval_ns));
// 2x for time it takes for message to reach back to peer node
nblk_combined_latency = 2 * nblk_behind_by_net_latency;
// message in the log below is used in p2p_high_latency_test.py test
peer_dlog(this, "Network latency is ${lat}ms, ${num} blocks discrepancy by network latency, ${tot_num} blocks discrepancy expected once message received",
("lat", net_latency_ns / 1000000)("num", nblk_behind_by_net_latency)("tot_num", nblk_combined_latency));
}
return nblk_combined_latency;
}

Expand Down Expand Up @@ -3308,7 +3310,7 @@ namespace eosio {
auto msg_xmt = normalize_epoch_to_ns(msg.xmt);
auto msg_org = normalize_epoch_to_ns(msg.org);

if (msg_org == normalize_epoch_to_ns(org)) {
if (msg_org != 0 && msg_org == normalize_epoch_to_ns(org)) {
auto latency = msg.dst - msg_org;
peer_dlog(this, "send_time latency ${l}us", ("l", latency/2/1000));
net_latency_ns = latency/2;
Expand Down Expand Up @@ -3342,6 +3344,11 @@ namespace eosio {
g_conn.unlock();
send_handshake();
}

// make sure we also get the latency we need
if (net_latency_ns == std::numeric_limits<uint64_t>::max()) {
send_time();
}
}

void connection::handle_message( const notice_message& msg ) {
Expand Down

0 comments on commit 1341215

Please sign in to comment.