Merge bitcoin/bitcoin#30372: util: Use SteadyClock in RandAddSeedPerfmon

fa360b047fc578fd855b8f7420d84dc967884f4a util: Use SteadyClock in RandAddSeedPerfmon (MarcoFalke)

Pull request description:

  `GetTime` is mockable in tests and system-changeable in production. This should be fine and not lead to issues, but using `SteadyClock` is more correct in this context to do an expensive task only so often.

ACKs for top commit:
  sipa:
    utACK fa360b047fc578fd855b8f7420d84dc967884f4a
  TheCharlatan:
    ACK fa360b047fc578fd855b8f7420d84dc967884f4a

Tree-SHA512: 1958b9e9e356c9801ac981014b4b528cfc8ce6612853d8b45f6519b16f0b1839ff765abb8b3368b86f00958ddc6a686f6b90278c57a7ad4858bdf3ea33775cca
This commit is contained in:
merge-script 2024-07-12 10:28:43 +01:00 committed by pasta
parent ebed8af1d0
commit 69c04b2c48
No known key found for this signature in database
GPG Key ID: E2F3D7916E722D38

View File

@ -71,10 +71,10 @@ void RandAddSeedPerfmon(CSHA512& hasher)
// This can take up to 2 seconds, so only do it every 10 minutes. // This can take up to 2 seconds, so only do it every 10 minutes.
// Initialize last_perfmon to 0 seconds, we don't skip the first call. // Initialize last_perfmon to 0 seconds, we don't skip the first call.
static std::atomic<std::chrono::seconds> last_perfmon{0s}; static std::atomic<SteadyClock::time_point> last_perfmon{SteadyClock::time_point{0s}};
auto last_time = last_perfmon.load(); auto last_time = last_perfmon.load();
auto current_time = GetTime<std::chrono::seconds>(); auto current_time = SteadyClock::now();
if (current_time < last_time + std::chrono::minutes{10}) return; if (current_time < last_time + 10min) return;
last_perfmon = current_time; last_perfmon = current_time;
std::vector<unsigned char> vData(250000, 0); std::vector<unsigned char> vData(250000, 0);