Skip to content

Commit 1a8f0d5

Browse files
committed
[tools] update nNextInvSend to use mockable time
1 parent 4de6303 commit 1a8f0d5

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ class CNode
762762
bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
763763
// Last time a "MEMPOOL" request was serviced.
764764
std::atomic<std::chrono::seconds> m_last_mempool_req{std::chrono::seconds{0}};
765-
int64_t nNextInvSend{0};
765+
std::chrono::microseconds nNextInvSend{0};
766766

767767
CCriticalSection cs_feeFilter;
768768
// Minimum fee rate with which to filter inv's to this node

src/net_processing.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,6 +3548,8 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
35483548

35493549
// Address refresh broadcast
35503550
int64_t nNow = GetTimeMicros();
3551+
auto current_time = GetTime<std::chrono::microseconds>();
3552+
35513553
if (pto->IsAddrRelayPeer() && !::ChainstateActive().IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) {
35523554
AdvertiseLocal(pto);
35533555
pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
@@ -3768,13 +3770,13 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
37683770
LOCK(pto->m_tx_relay->cs_tx_inventory);
37693771
// Check whether periodic sends should happen
37703772
bool fSendTrickle = pto->HasPermission(PF_NOBAN);
3771-
if (pto->m_tx_relay->nNextInvSend < nNow) {
3773+
if (pto->m_tx_relay->nNextInvSend < current_time) {
37723774
fSendTrickle = true;
37733775
if (pto->fInbound) {
3774-
pto->m_tx_relay->nNextInvSend = connman->PoissonNextSendInbound(nNow, INVENTORY_BROADCAST_INTERVAL);
3776+
pto->m_tx_relay->nNextInvSend = std::chrono::microseconds{connman->PoissonNextSendInbound(nNow, INVENTORY_BROADCAST_INTERVAL)};
37753777
} else {
37763778
// Use half the delay for outbound peers, as there is less privacy concern for them.
3777-
pto->m_tx_relay->nNextInvSend = PoissonNextSend(nNow, INVENTORY_BROADCAST_INTERVAL >> 1);
3779+
pto->m_tx_relay->nNextInvSend = PoissonNextSend(current_time, std::chrono::seconds{INVENTORY_BROADCAST_INTERVAL >> 1});
37783780
}
37793781
}
37803782

@@ -3889,7 +3891,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
38893891
connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
38903892

38913893
// Detect whether we're stalling
3892-
const auto current_time = GetTime<std::chrono::microseconds>();
3894+
current_time = GetTime<std::chrono::microseconds>();
38933895
// nNow is the current system time (GetTimeMicros is not mockable) and
38943896
// should be replaced by the mockable current_time eventually
38953897
nNow = GetTimeMicros();

0 commit comments

Comments
 (0)