Skip to content

Commit 78aa61c

Browse files
committed
net: Make addr relay mockable
Adaptation of btc@fa47a0b003f53708b6d5df1ed4e7f8a7c68aa3ac
1 parent ba954ca commit 78aa61c

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

src/net.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,8 +2311,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
23112311
filterInventoryKnown.reset();
23122312
fSendMempool = false;
23132313
fGetAddr = false;
2314-
nNextLocalAddrSend = 0;
2315-
nNextAddrSend = 0;
23162314
fRelayTxes = false;
23172315
pfilter = std::make_unique<CBloomFilter>();
23182316
timeLastMempoolReq = 0;

src/net.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ class CNode
607607
CRollingBloomFilter addrKnown;
608608
bool fGetAddr;
609609
std::set<uint256> setKnown;
610-
int64_t nNextAddrSend;
611-
int64_t nNextLocalAddrSend;
610+
std::chrono::microseconds m_next_addr_send GUARDED_BY(cs_sendProcessing){0};
611+
std::chrono::microseconds m_next_local_addr_send GUARDED_BY(cs_sendProcessing){0};
612612

613613
// inventory based relay
614614
CRollingBloomFilter filterInventoryKnown;

src/net_processing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,16 +2101,16 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& interruptM
21012101
int64_t nNow = GetTimeMicros();
21022102
auto current_time = GetTime<std::chrono::microseconds>();
21032103

2104-
if (!IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) {
2104+
if (!IsInitialBlockDownload() && pto->m_next_local_addr_send < current_time) {
21052105
AdvertiseLocal(pto);
2106-
pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
2106+
pto->m_next_local_addr_send = PoissonNextSend(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
21072107
}
21082108

21092109
//
21102110
// Message: addr
21112111
//
2112-
if (pto->nNextAddrSend < nNow) {
2113-
pto->nNextAddrSend = PoissonNextSend(nNow, AVG_ADDRESS_BROADCAST_INTERVAL);
2112+
if (pto->m_next_addr_send < current_time) {
2113+
pto->m_next_addr_send = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL);
21142114
std::vector<CAddress> vAddr;
21152115
vAddr.reserve(pto->vAddrToSend.size());
21162116

src/validation.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
103103
static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
104104
/** Time to wait (in seconds) between flushing chainstate to disk. */
105105
static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
106-
/** Average delay between local address broadcasts in seconds. */
107-
static const unsigned int AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL = 24 * 24 * 60;
108-
/** Average delay between peer address broadcasts in seconds. */
109-
static const unsigned int AVG_ADDRESS_BROADCAST_INTERVAL = 30;
106+
/** Average delay between local address broadcasts */
107+
static constexpr std::chrono::hours AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL{24};
108+
/** Average delay between peer address broadcasts */
109+
static constexpr std::chrono::seconds AVG_ADDRESS_BROADCAST_INTERVAL{30};
110110
/** Default multiplier used in the computation for shielded txes min fee */
111111
static const unsigned int DEFAULT_SHIELDEDTXFEE_K = 100;
112112
/** Enable bloom filter */

0 commit comments

Comments
 (0)