diff --git a/src/net_processing.cpp b/src/net_processing.cpp index cc3b865e5..0bae0805a 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2888,16 +2888,18 @@ bool SendMessages(CNode* pto, CConnman& connman, const std::atomic& interr // Address refresh broadcast int64_t nNow = GetTimeMicros(); - if (!IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) { + int64_t current_time = GetMockableTimeMicros(); // add a mockable time + + if (!IsInitialBlockDownload() && pto->nNextLocalAddrSend < current_time) { AdvertiseLocal(pto); - pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL); + pto->nNextLocalAddrSend = PoissonNextSend(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL); } // // Message: addr // - if (pto->nNextAddrSend < nNow) { - pto->nNextAddrSend = PoissonNextSend(nNow, AVG_ADDRESS_BROADCAST_INTERVAL); + if (pto->nNextAddrSend < current_time) { + pto->nNextAddrSend = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL); std::vector vAddr; vAddr.reserve(pto->vAddrToSend.size()); BOOST_FOREACH(const CAddress& addr, pto->vAddrToSend) @@ -3254,7 +3256,7 @@ bool SendMessages(CNode* pto, CConnman& connman, const std::atomic& interr (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads); if (nNow > state.nDownloadingSince + nCalculatedDlWindow) { LogPrint("net", "Timeout downloading block: window=%d; inFlight=%d; validHeaders=%d; otherDlPeers=%d;", - nCalculatedDlWindow, state.vBlocksInFlight.size(), + nCalculatedDlWindow, state.vBlocksInFlight.size(), state.nBlocksInFlightValidHeaders, nOtherPeersWithValidatedDownloads); LogPrintf("Timeout downloading block %s from peer=%d, disconnecting\n", queuedBlock.hash.ToString(), pto->id); pto->fDisconnect = true; diff --git a/src/utiltime.cpp b/src/utiltime.cpp index cf5e7f848..6b3f11d59 100644 --- a/src/utiltime.cpp +++ b/src/utiltime.cpp @@ -25,6 +25,12 @@ int64_t GetTime() return now; } +int64_t GetMockableTimeMicros() +{ + if (nMockTime) return nMockTime * 1000000; + return GetTimeMicros(); +} + void SetMockTime(int64_t nMockTimeIn) { nMockTime = nMockTimeIn; diff --git a/src/utiltime.h b/src/utiltime.h index 05c679049..12e9046b3 100644 --- a/src/utiltime.h +++ b/src/utiltime.h @@ -24,6 +24,7 @@ int64_t GetTimeMillis(); int64_t GetTimeMicros(); int64_t GetSystemTimeInSeconds(); // Like GetTime(), but not mockable int64_t GetLogTimeMicros(); +int64_t GetMockableTimeMicros(); void SetMockTime(int64_t nMockTimeIn); void MilliSleep(int64_t n);