Skip to content

Commit 00a685c

Browse files
amitiuttarwarfurszy
authored andcommitted
[tools] update nNextInvSend to use mockable time
1 parent 3b832c9 commit 00a685c

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/net.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
23322332
fGetAddr = false;
23332333
nNextLocalAddrSend = 0;
23342334
nNextAddrSend = 0;
2335-
nNextInvSend = 0;
23362335
fRelayTxes = false;
23372336
pfilter = new CBloomFilter();
23382337
timeLastMempoolReq = 0;

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ class CNode
623623
std::multimap<int64_t, CInv> mapAskFor;
624624
std::set<uint256> setAskFor;
625625
std::vector<uint256> vBlockRequested;
626-
int64_t nNextInvSend;
626+
std::chrono::microseconds nNextInvSend{0};
627627
// Used for BIP35 mempool sending, also protected by cs_inventory
628628
bool fSendMempool;
629629

src/net_processing.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,8 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& interruptM
21322132

21332133
// Address refresh broadcast
21342134
int64_t nNow = GetTimeMicros();
2135+
auto current_time = GetTime<std::chrono::microseconds>();
2136+
21352137
if (!IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) {
21362138
AdvertiseLocal(pto);
21372139
pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
@@ -2214,10 +2216,10 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& interruptM
22142216

22152217
// Check whether periodic send should happen
22162218
bool fSendTrickle = pto->fWhitelisted;
2217-
if (pto->nNextInvSend < nNow) {
2219+
if (pto->nNextInvSend < current_time) {
22182220
fSendTrickle = true;
22192221
// Use half the delay for outbound peers, as there is less privacy concern for them.
2220-
pto->nNextInvSend = PoissonNextSend(nNow, INVENTORY_BROADCAST_INTERVAL >> !pto->fInbound);
2222+
pto->nNextInvSend = PoissonNextSend(current_time, std::chrono::seconds{INVENTORY_BROADCAST_INTERVAL >> !pto->fInbound});
22212223
}
22222224

22232225
// Time to send but the peer has requested we not relay transactions.
@@ -2301,6 +2303,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& interruptM
23012303
connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
23022304

23032305
// Detect whether we're stalling
2306+
current_time = GetTime<std::chrono::microseconds>();
23042307
nNow = GetTimeMicros();
23052308
if (state.nStallingSince && state.nStallingSince < nNow - 1000000 * BLOCK_STALLING_TIMEOUT) {
23062309
// Stalling only triggers when the block download window cannot move. During normal steady state,

0 commit comments

Comments
 (0)