@@ -582,7 +582,7 @@ static bool MarkBlockAsReceived(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs
582
582
}
583
583
if (state->vBlocksInFlight .begin () == itInFlight->second .second ) {
584
584
// First block on the queue was received, update the start download time for the next one
585
- state->nDownloadingSince = std::max (state->nDownloadingSince , GetTimeMicros ( ));
585
+ state->nDownloadingSince = std::max (state->nDownloadingSince , count_microseconds (GetTime<std::chrono::microseconds>() ));
586
586
}
587
587
state->vBlocksInFlight .erase (itInFlight->second .second );
588
588
state->nBlocksInFlight --;
@@ -617,7 +617,7 @@ static bool MarkBlockAsInFlight(CTxMemPool& mempool, NodeId nodeid, const uint25
617
617
state->nBlocksInFlightValidHeaders += it->fValidatedHeaders ;
618
618
if (state->nBlocksInFlight == 1 ) {
619
619
// We're starting a block download (batch) from this peer.
620
- state->nDownloadingSince = GetTimeMicros ();
620
+ state->nDownloadingSince = GetTime<std::chrono::microseconds>(). count ();
621
621
}
622
622
if (state->nBlocksInFlightValidHeaders == 1 && pindex != nullptr ) {
623
623
nPeersWithValidatedDownloads++;
@@ -3637,7 +3637,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
3637
3637
// Matching pong received, this ping is no longer outstanding
3638
3638
bPingFinished = true ;
3639
3639
const auto ping_time = ping_end - pfrom.m_ping_start .load ();
3640
- if (ping_time.count () > 0 ) {
3640
+ if (ping_time.count () >= 0 ) {
3641
3641
// Successful ping time measurement, replace previous
3642
3642
pfrom.nPingUsecTime = count_microseconds (ping_time);
3643
3643
pfrom.nMinPingUsecTime = std::min (pfrom.nMinPingUsecTime .load (), count_microseconds (ping_time));
@@ -4102,7 +4102,6 @@ bool PeerManager::SendMessages(CNode* pto)
4102
4102
CNodeState &state = *State (pto->GetId ());
4103
4103
4104
4104
// Address refresh broadcast
4105
- int64_t nNow = GetTimeMicros ();
4106
4105
auto current_time = GetTime<std::chrono::microseconds>();
4107
4106
4108
4107
if (pto->RelayAddrsWithConn () && !::ChainstateActive ().IsInitialBlockDownload () && pto->m_next_local_addr_send < current_time) {
@@ -4148,7 +4147,7 @@ bool PeerManager::SendMessages(CNode* pto)
4148
4147
// Only actively request headers from a single peer, unless we're close to today.
4149
4148
if ((nSyncStarted == 0 && fFetch ) || pindexBestHeader->GetBlockTime () > GetAdjustedTime () - 24 * 60 * 60 ) {
4150
4149
state.fSyncStarted = true ;
4151
- state.nHeadersSyncTimeout = GetTimeMicros ( ) + HEADERS_DOWNLOAD_TIMEOUT_BASE + HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER * (GetAdjustedTime () - pindexBestHeader->GetBlockTime ())/(consensusParams.nPowTargetSpacing );
4150
+ state.nHeadersSyncTimeout = count_microseconds (current_time ) + HEADERS_DOWNLOAD_TIMEOUT_BASE + HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER * (GetAdjustedTime () - pindexBestHeader->GetBlockTime ())/(consensusParams.nPowTargetSpacing );
4152
4151
nSyncStarted++;
4153
4152
const CBlockIndex *pindexStart = pindexBestHeader;
4154
4153
/* If possible, start at the block preceding the currently
@@ -4329,7 +4328,7 @@ bool PeerManager::SendMessages(CNode* pto)
4329
4328
if (pto->m_tx_relay ->nNextInvSend < current_time) {
4330
4329
fSendTrickle = true ;
4331
4330
if (pto->IsInboundConn ()) {
4332
- pto->m_tx_relay ->nNextInvSend = std::chrono::microseconds{m_connman.PoissonNextSendInbound (nNow , INVENTORY_BROADCAST_INTERVAL)};
4331
+ pto->m_tx_relay ->nNextInvSend = std::chrono::microseconds{m_connman.PoissonNextSendInbound (count_microseconds (current_time) , INVENTORY_BROADCAST_INTERVAL)};
4333
4332
} else {
4334
4333
// Use half the delay for outbound peers, as there is less privacy concern for them.
4335
4334
pto->m_tx_relay ->nNextInvSend = PoissonNextSend (current_time, std::chrono::seconds{INVENTORY_BROADCAST_INTERVAL >> 1 });
@@ -4428,20 +4427,20 @@ bool PeerManager::SendMessages(CNode* pto)
4428
4427
nRelayedTransactions++;
4429
4428
{
4430
4429
// Expire old relay messages
4431
- while (!vRelayExpiration.empty () && vRelayExpiration.front ().first < nNow )
4430
+ while (!vRelayExpiration.empty () && vRelayExpiration.front ().first < count_microseconds (current_time) )
4432
4431
{
4433
4432
mapRelay.erase (vRelayExpiration.front ().second );
4434
4433
vRelayExpiration.pop_front ();
4435
4434
}
4436
4435
4437
4436
auto ret = mapRelay.emplace (txid, std::move (txinfo.tx ));
4438
4437
if (ret.second ) {
4439
- vRelayExpiration.emplace_back (nNow + std::chrono::microseconds{RELAY_TX_CACHE_TIME}. count ( ), ret.first );
4438
+ vRelayExpiration.emplace_back (count_microseconds (current_time + std::chrono::microseconds{RELAY_TX_CACHE_TIME}), ret.first );
4440
4439
}
4441
4440
// Add wtxid-based lookup into mapRelay as well, so that peers can request by wtxid
4442
4441
auto ret2 = mapRelay.emplace (wtxid, ret.first ->second );
4443
4442
if (ret2.second ) {
4444
- vRelayExpiration.emplace_back (nNow + std::chrono::microseconds{RELAY_TX_CACHE_TIME}. count ( ), ret2.first );
4443
+ vRelayExpiration.emplace_back (count_microseconds (current_time + std::chrono::microseconds{RELAY_TX_CACHE_TIME}), ret2.first );
4445
4444
}
4446
4445
}
4447
4446
if (vInv.size () == MAX_INV_SZ) {
@@ -4466,10 +4465,7 @@ bool PeerManager::SendMessages(CNode* pto)
4466
4465
4467
4466
// Detect whether we're stalling
4468
4467
current_time = GetTime<std::chrono::microseconds>();
4469
- // nNow is the current system time (GetTimeMicros is not mockable) and
4470
- // should be replaced by the mockable current_time eventually
4471
- nNow = GetTimeMicros ();
4472
- if (state.nStallingSince && state.nStallingSince < nNow - 1000000 * BLOCK_STALLING_TIMEOUT) {
4468
+ if (state.nStallingSince && state.nStallingSince < count_microseconds (current_time) - 1000000 * BLOCK_STALLING_TIMEOUT) {
4473
4469
// Stalling only triggers when the block download window cannot move. During normal steady state,
4474
4470
// the download window should be much larger than the to-be-downloaded set of blocks, so disconnection
4475
4471
// should only happen during initial block download.
@@ -4485,7 +4481,7 @@ bool PeerManager::SendMessages(CNode* pto)
4485
4481
if (state.vBlocksInFlight .size () > 0 ) {
4486
4482
QueuedBlock &queuedBlock = state.vBlocksInFlight .front ();
4487
4483
int nOtherPeersWithValidatedDownloads = nPeersWithValidatedDownloads - (state.nBlocksInFlightValidHeaders > 0 );
4488
- if (nNow > state.nDownloadingSince + consensusParams.nPowTargetSpacing * (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads)) {
4484
+ if (count_microseconds (current_time) > state.nDownloadingSince + consensusParams.nPowTargetSpacing * (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads)) {
4489
4485
LogPrintf (" Timeout downloading block %s from peer=%d, disconnecting\n " , queuedBlock.hash .ToString (), pto->GetId ());
4490
4486
pto->fDisconnect = true ;
4491
4487
return true ;
@@ -4495,7 +4491,7 @@ bool PeerManager::SendMessages(CNode* pto)
4495
4491
if (state.fSyncStarted && state.nHeadersSyncTimeout < std::numeric_limits<int64_t >::max ()) {
4496
4492
// Detect whether this is a stalling initial-headers-sync peer
4497
4493
if (pindexBestHeader->GetBlockTime () <= GetAdjustedTime () - 24 * 60 * 60 ) {
4498
- if (nNow > state.nHeadersSyncTimeout && nSyncStarted == 1 && (nPreferredDownload - state.fPreferredDownload >= 1 )) {
4494
+ if (count_microseconds (current_time) > state.nHeadersSyncTimeout && nSyncStarted == 1 && (nPreferredDownload - state.fPreferredDownload >= 1 )) {
4499
4495
// Disconnect a peer (without the noban permission) if it is our only sync peer,
4500
4496
// and we have others we could be using instead.
4501
4497
// Note: If all our peers are inbound, then we won't
@@ -4545,7 +4541,7 @@ bool PeerManager::SendMessages(CNode* pto)
4545
4541
}
4546
4542
if (state.nBlocksInFlight == 0 && staller != -1 ) {
4547
4543
if (State (staller)->nStallingSince == 0 ) {
4548
- State (staller)->nStallingSince = nNow ;
4544
+ State (staller)->nStallingSince = count_microseconds (current_time) ;
4549
4545
LogPrint (BCLog::NET, " Stall started peer=%d\n " , staller);
4550
4546
}
4551
4547
}
@@ -4629,7 +4625,6 @@ bool PeerManager::SendMessages(CNode* pto)
4629
4625
!pto->HasPermission (PF_FORCERELAY) // peers with the forcerelay permission should not filter txs to us
4630
4626
) {
4631
4627
CAmount currentFilter = m_mempool.GetMinFee (gArgs .GetArg (" -maxmempool" , DEFAULT_MAX_MEMPOOL_SIZE) * 1000000 ).GetFeePerK ();
4632
- int64_t timeNow = GetTimeMicros ();
4633
4628
static FeeFilterRounder g_filter_rounder{CFeeRate{DEFAULT_MIN_RELAY_TX_FEE}};
4634
4629
if (m_chainman.ActiveChainstate ().IsInitialBlockDownload ()) {
4635
4630
// Received tx-inv messages are discarded when the active
@@ -4640,24 +4635,24 @@ bool PeerManager::SendMessages(CNode* pto)
4640
4635
if (pto->m_tx_relay ->lastSentFeeFilter == MAX_FILTER) {
4641
4636
// Send the current filter if we sent MAX_FILTER previously
4642
4637
// and made it out of IBD.
4643
- pto->m_tx_relay ->nextSendTimeFeeFilter = timeNow - 1 ;
4638
+ pto->m_tx_relay ->nextSendTimeFeeFilter = count_microseconds (current_time) - 1 ;
4644
4639
}
4645
4640
}
4646
- if (timeNow > pto->m_tx_relay ->nextSendTimeFeeFilter ) {
4641
+ if (count_microseconds (current_time) > pto->m_tx_relay ->nextSendTimeFeeFilter ) {
4647
4642
CAmount filterToSend = g_filter_rounder.round (currentFilter);
4648
4643
// We always have a fee filter of at least minRelayTxFee
4649
4644
filterToSend = std::max (filterToSend, ::minRelayTxFee.GetFeePerK ());
4650
4645
if (filterToSend != pto->m_tx_relay ->lastSentFeeFilter ) {
4651
4646
m_connman.PushMessage (pto, msgMaker.Make (NetMsgType::FEEFILTER, filterToSend));
4652
4647
pto->m_tx_relay ->lastSentFeeFilter = filterToSend;
4653
4648
}
4654
- pto->m_tx_relay ->nextSendTimeFeeFilter = PoissonNextSend (timeNow , AVG_FEEFILTER_BROADCAST_INTERVAL);
4649
+ pto->m_tx_relay ->nextSendTimeFeeFilter = PoissonNextSend (count_microseconds (current_time) , AVG_FEEFILTER_BROADCAST_INTERVAL);
4655
4650
}
4656
4651
// If the fee filter has changed substantially and it's still more than MAX_FEEFILTER_CHANGE_DELAY
4657
4652
// until scheduled broadcast, then move the broadcast to within MAX_FEEFILTER_CHANGE_DELAY.
4658
- else if (timeNow + MAX_FEEFILTER_CHANGE_DELAY * 1000000 < pto->m_tx_relay ->nextSendTimeFeeFilter &&
4653
+ else if (count_microseconds (current_time) + MAX_FEEFILTER_CHANGE_DELAY * 1000000 < pto->m_tx_relay ->nextSendTimeFeeFilter &&
4659
4654
(currentFilter < 3 * pto->m_tx_relay ->lastSentFeeFilter / 4 || currentFilter > 4 * pto->m_tx_relay ->lastSentFeeFilter / 3 )) {
4660
- pto->m_tx_relay ->nextSendTimeFeeFilter = timeNow + GetRandInt (MAX_FEEFILTER_CHANGE_DELAY) * 1000000 ;
4655
+ pto->m_tx_relay ->nextSendTimeFeeFilter = count_microseconds (current_time) + GetRandInt (MAX_FEEFILTER_CHANGE_DELAY) * 1000000 ;
4661
4656
}
4662
4657
}
4663
4658
} // release cs_main
0 commit comments