mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-27 03:33:27 -03:00
[tools] update nNextInvSend to use mockable time
This commit is contained in:
parent
4de630354f
commit
1a8f0d5a74
2 changed files with 7 additions and 5 deletions
|
@ -762,7 +762,7 @@ public:
|
||||||
bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
|
bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
|
||||||
// Last time a "MEMPOOL" request was serviced.
|
// Last time a "MEMPOOL" request was serviced.
|
||||||
std::atomic<std::chrono::seconds> m_last_mempool_req{std::chrono::seconds{0}};
|
std::atomic<std::chrono::seconds> m_last_mempool_req{std::chrono::seconds{0}};
|
||||||
int64_t nNextInvSend{0};
|
std::chrono::microseconds nNextInvSend{0};
|
||||||
|
|
||||||
CCriticalSection cs_feeFilter;
|
CCriticalSection cs_feeFilter;
|
||||||
// Minimum fee rate with which to filter inv's to this node
|
// Minimum fee rate with which to filter inv's to this node
|
||||||
|
|
|
@ -3548,6 +3548,8 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
|
|
||||||
// Address refresh broadcast
|
// Address refresh broadcast
|
||||||
int64_t nNow = GetTimeMicros();
|
int64_t nNow = GetTimeMicros();
|
||||||
|
auto current_time = GetTime<std::chrono::microseconds>();
|
||||||
|
|
||||||
if (pto->IsAddrRelayPeer() && !::ChainstateActive().IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) {
|
if (pto->IsAddrRelayPeer() && !::ChainstateActive().IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) {
|
||||||
AdvertiseLocal(pto);
|
AdvertiseLocal(pto);
|
||||||
pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
|
pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
|
||||||
|
@ -3768,13 +3770,13 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
LOCK(pto->m_tx_relay->cs_tx_inventory);
|
LOCK(pto->m_tx_relay->cs_tx_inventory);
|
||||||
// Check whether periodic sends should happen
|
// Check whether periodic sends should happen
|
||||||
bool fSendTrickle = pto->HasPermission(PF_NOBAN);
|
bool fSendTrickle = pto->HasPermission(PF_NOBAN);
|
||||||
if (pto->m_tx_relay->nNextInvSend < nNow) {
|
if (pto->m_tx_relay->nNextInvSend < current_time) {
|
||||||
fSendTrickle = true;
|
fSendTrickle = true;
|
||||||
if (pto->fInbound) {
|
if (pto->fInbound) {
|
||||||
pto->m_tx_relay->nNextInvSend = connman->PoissonNextSendInbound(nNow, INVENTORY_BROADCAST_INTERVAL);
|
pto->m_tx_relay->nNextInvSend = std::chrono::microseconds{connman->PoissonNextSendInbound(nNow, INVENTORY_BROADCAST_INTERVAL)};
|
||||||
} else {
|
} else {
|
||||||
// Use half the delay for outbound peers, as there is less privacy concern for them.
|
// Use half the delay for outbound peers, as there is less privacy concern for them.
|
||||||
pto->m_tx_relay->nNextInvSend = PoissonNextSend(nNow, INVENTORY_BROADCAST_INTERVAL >> 1);
|
pto->m_tx_relay->nNextInvSend = PoissonNextSend(current_time, std::chrono::seconds{INVENTORY_BROADCAST_INTERVAL >> 1});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3889,7 +3891,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
|
connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
|
||||||
|
|
||||||
// Detect whether we're stalling
|
// Detect whether we're stalling
|
||||||
const auto current_time = GetTime<std::chrono::microseconds>();
|
current_time = GetTime<std::chrono::microseconds>();
|
||||||
// nNow is the current system time (GetTimeMicros is not mockable) and
|
// nNow is the current system time (GetTimeMicros is not mockable) and
|
||||||
// should be replaced by the mockable current_time eventually
|
// should be replaced by the mockable current_time eventually
|
||||||
nNow = GetTimeMicros();
|
nNow = GetTimeMicros();
|
||||||
|
|
Loading…
Add table
Reference in a new issue