Skip to content

Commit

Permalink
Rename ping members
Browse files Browse the repository at this point in the history
Summary:
Original script:
```
-BEGIN VERIFY SCRIPT-
sed -i 's/fPingQueued/m_ping_queued/g' src/net_processing.cpp
sed -i 's/nMinPingUsecTime/m_min_ping_time/g' src/net.* src/net_processing.cpp src/test/net_tests.cpp
sed -i 's/nPingNonceSent/m_ping_nonce_sent/g' src/net_processing.cpp
sed -i 's/nPingUsecTime/m_last_ping_time/g' src/net.*
-END VERIFY SCRIPT-
```

Completes backport of [[bitcoin/bitcoin#20721 | core#20721]]:
bitcoin/bitcoin@a5e15ae

Depends on D10899.

Ref T1696.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Maniphest Tasks: T1696

Differential Revision: https://reviews.bitcoinabc.org/D10900
  • Loading branch information
jnewbery authored and Fabcien committed Jan 26, 2022
1 parent 3873004 commit 05a5cdd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,8 @@ void CNode::copyStats(CNodeStats &stats) {
stats.minFeeFilter = Amount::zero();
}

stats.m_ping_usec = nPingUsecTime;
stats.m_min_ping_usec = nMinPingUsecTime;
stats.m_ping_usec = m_last_ping_time;
stats.m_min_ping_usec = m_min_ping_time;

// Leave string empty if addrLocal invalid (not filled in yet)
CService addrLocalUnlocked = GetAddrLocal();
Expand Down Expand Up @@ -865,7 +865,7 @@ size_t CConnman::SocketSendData(CNode &node) const {

static bool ReverseCompareNodeMinPingTime(const NodeEvictionCandidate &a,
const NodeEvictionCandidate &b) {
return a.nMinPingUsecTime > b.nMinPingUsecTime;
return a.m_min_ping_time > b.m_min_ping_time;
}

static bool ReverseCompareNodeTimeConnected(const NodeEvictionCandidate &a,
Expand Down Expand Up @@ -1122,7 +1122,7 @@ bool CConnman::AttemptToEvictConnection() {
NodeEvictionCandidate candidate = {
node->GetId(),
node->nTimeConnected,
node->nMinPingUsecTime,
node->m_min_ping_time,
node->nLastBlockTime,
node->nLastProofTime,
node->nLastTXTime,
Expand Down
12 changes: 6 additions & 6 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,13 +733,13 @@ class CNode {
std::atomic<int64_t> nLastProofTime{0};

/** Last measured round-trip time. Used only for RPC/GUI stats/debugging.*/
std::atomic<int64_t> nPingUsecTime{0};
std::atomic<int64_t> m_last_ping_time{0};

/**
* Lowest measured round-trip time. Used as an inbound peer eviction
* criterium in CConnman::AttemptToEvictConnection.
*/
std::atomic<int64_t> nMinPingUsecTime{std::numeric_limits<int64_t>::max()};
std::atomic<int64_t> m_min_ping_time{std::numeric_limits<int64_t>::max()};

CNode(NodeId id, ServiceFlags nLocalServicesIn, SOCKET hSocketIn,
const CAddress &addrIn, uint64_t nKeyedNetGroupIn,
Expand All @@ -755,9 +755,9 @@ class CNode {
* minimum ping times.
*/
void PongReceived(std::chrono::microseconds ping_time) {
nPingUsecTime = count_microseconds(ping_time);
nMinPingUsecTime =
std::min(nMinPingUsecTime.load(), count_microseconds(ping_time));
m_last_ping_time = count_microseconds(ping_time);
m_min_ping_time =
std::min(m_min_ping_time.load(), count_microseconds(ping_time));
}

private:
Expand Down Expand Up @@ -1451,7 +1451,7 @@ std::string userAgent(const Config &config);
struct NodeEvictionCandidate {
NodeId id;
int64_t nTimeConnected;
int64_t nMinPingUsecTime;
int64_t m_min_ping_time;
int64_t nLastBlockTime;
int64_t nLastProofTime;
int64_t nLastTXTime;
Expand Down
28 changes: 14 additions & 14 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ struct Peer {
std::atomic<int> m_starting_height{-1};

/** The pong reply we're expecting, or 0 if no pong expected. */
std::atomic<uint64_t> nPingNonceSent{0};
std::atomic<uint64_t> m_ping_nonce_sent{0};
/** When the last ping was sent, or 0 if no ping was ever sent */
std::atomic<std::chrono::microseconds> m_ping_start{
std::chrono::microseconds{0}};
/** Whether a ping has been requested by the user */
std::atomic<bool> fPingQueued{false};
std::atomic<bool> m_ping_queued{false};

/**
* Set of txids to reconsider once their parent transactions have been
Expand Down Expand Up @@ -1502,7 +1502,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
// long time in flight, the caller can immediately detect that this is
// happening.
std::chrono::microseconds ping_wait{0};
if ((0 != peer->nPingNonceSent) &&
if ((0 != peer->m_ping_nonce_sent) &&
(0 != peer->m_ping_start.load().count())) {
ping_wait =
GetTime<std::chrono::microseconds>() - peer->m_ping_start.load();
Expand Down Expand Up @@ -2132,7 +2132,7 @@ static bool AlreadyHaveProof(const avalanche::ProofId &proofid) {
void PeerManagerImpl::SendPings() {
LOCK(m_peer_mutex);
for (auto &it : m_peer_map) {
it.second->fPingQueued = true;
it.second->m_ping_queued = true;
}
}

Expand Down Expand Up @@ -4946,8 +4946,8 @@ void PeerManagerImpl::ProcessMessage(

// Only process pong message if there is an outstanding ping (old
// ping without nonce should never pong)
if (peer->nPingNonceSent != 0) {
if (nonce == peer->nPingNonceSent) {
if (peer->m_ping_nonce_sent != 0) {
if (nonce == peer->m_ping_nonce_sent) {
// Matching pong received, this ping is no longer
// outstanding
bPingFinished = true;
Expand Down Expand Up @@ -4982,11 +4982,11 @@ void PeerManagerImpl::ProcessMessage(
if (!(sProblem.empty())) {
LogPrint(BCLog::NET,
"pong peer=%d: %s, %x expected, %x received, %u bytes\n",
pfrom.GetId(), sProblem, peer->nPingNonceSent, nonce,
pfrom.GetId(), sProblem, peer->m_ping_nonce_sent, nonce,
nAvail);
}
if (bPingFinished) {
peer->nPingNonceSent = 0;
peer->m_ping_nonce_sent = 0;
}
return;
}
Expand Down Expand Up @@ -5502,7 +5502,7 @@ void PeerManagerImpl::MaybeSendPing(CNode &node_to, Peer &peer) {
// This means that setmocktime may cause pings to time out.
auto now = GetTime<std::chrono::microseconds>();

if (m_connman.RunInactivityChecks(node_to) && peer.nPingNonceSent &&
if (m_connman.RunInactivityChecks(node_to) && peer.m_ping_nonce_sent &&
now >
peer.m_ping_start.load() + std::chrono::seconds{TIMEOUT_INTERVAL}) {
LogPrint(BCLog::NET, "ping timeout: %fs peer=%d\n",
Expand All @@ -5515,12 +5515,12 @@ void PeerManagerImpl::MaybeSendPing(CNode &node_to, Peer &peer) {
const CNetMsgMaker msgMaker(node_to.GetCommonVersion());
bool pingSend = false;

if (peer.fPingQueued) {
if (peer.m_ping_queued) {
// RPC ping request by user
pingSend = true;
}

if (peer.nPingNonceSent == 0 &&
if (peer.m_ping_nonce_sent == 0 &&
now > peer.m_ping_start.load() + PING_INTERVAL) {
// Ping automatically sent as a latency probe & keepalive.
pingSend = true;
Expand All @@ -5531,16 +5531,16 @@ void PeerManagerImpl::MaybeSendPing(CNode &node_to, Peer &peer) {
while (nonce == 0) {
GetRandBytes((uint8_t *)&nonce, sizeof(nonce));
}
peer.fPingQueued = false;
peer.m_ping_queued = false;
peer.m_ping_start = now;
if (node_to.GetCommonVersion() > BIP0031_VERSION) {
peer.nPingNonceSent = nonce;
peer.m_ping_nonce_sent = nonce;
m_connman.PushMessage(&node_to,
msgMaker.Make(NetMsgType::PING, nonce));
} else {
// Peer is too old to support ping command with nonce, pong will
// never arrive.
peer.nPingNonceSent = 0;
peer.m_ping_nonce_sent = 0;
m_connman.PushMessage(&node_to, msgMaker.Make(NetMsgType::PING));
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/net_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ GetRandomNodeEvictionCandidates(const int n_candidates,
/* id */ id,
/* nTimeConnected */
static_cast<int64_t>(random_context.randrange(100)),
/* nMinPingUsecTime */
/* m_min_ping_time */
static_cast<int64_t>(random_context.randrange(100)),
/* nLastBlockTime */
static_cast<int64_t>(random_context.randrange(100)),
Expand Down Expand Up @@ -899,7 +899,7 @@ BOOST_AUTO_TEST_CASE(node_eviction_test) {
BOOST_CHECK(!IsEvicted(
number_of_nodes,
[](NodeEvictionCandidate &candidate) {
candidate.nMinPingUsecTime = candidate.id;
candidate.m_min_ping_time = candidate.id;
},
{0, 1, 2, 3, 4, 5, 6, 7}, random_context));

Expand Down Expand Up @@ -960,8 +960,8 @@ BOOST_AUTO_TEST_CASE(node_eviction_test) {
number_of_nodes,
[number_of_nodes](NodeEvictionCandidate &candidate) {
candidate.nKeyedNetGroup =
number_of_nodes - candidate.id; // 4 protected
candidate.nMinPingUsecTime = candidate.id; // 8 protected
number_of_nodes - candidate.id; // 4 protected
candidate.m_min_ping_time = candidate.id; // 8 protected
candidate.nLastTXTime =
number_of_nodes - candidate.id; // 4 protected
candidate.nLastProofTime =
Expand Down

0 comments on commit 05a5cdd

Please sign in to comment.