Run background seeding periodically instead of unpredictably

* Instead of calling RandAddSeedSleep anytime the scheduler goes
  idle, call its replacement (RandAddSeedPeriodic) just once per
  minute. This has better guarantees of actually being run, and
  helps limit how frequently the dynamic env data is gathered.
* Since this code runs once per minute regardless now, we no
  longer need to keep track of the last time strengthening was
  run; just do it always.
* Make strengthening time context dependent (100 ms at startup,
  10 ms once per minute afterwards).
This commit is contained in:
Pieter Wuille
2019-10-29 11:55:59 -07:00
parent 483b94292e
commit d61f2bb076
4 changed files with 24 additions and 33 deletions

View File

@@ -84,11 +84,11 @@ uint256 GetRandHash() noexcept;
void GetStrongRandBytes(unsigned char* buf, int num) noexcept;
/**
* Sleep for 1ms, gather entropy from various sources, and feed them to the PRNG state.
* Gather entropy from various expensive sources, and feed them to the PRNG state.
*
* Thread-safe.
*/
void RandAddSeedSleep();
void RandAddPeriodic();
/**
* Fast randomness source. This is seeded once with secure random data, but