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

@@ -1258,6 +1258,11 @@ bool AppInitMain(NodeContext& node)
CScheduler::Function serviceLoop = std::bind(&CScheduler::serviceQueue, &scheduler);
threadGroup.create_thread(std::bind(&TraceThread<CScheduler::Function>, "scheduler", serviceLoop));
// Gather some entropy once per minute.
scheduler.scheduleEvery([]{
RandAddPeriodic();
}, 60000);
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
GetMainSignals().RegisterWithMempoolSignals(mempool);