Skip to content

Commit

Permalink
random: mark RandAddPeriodic and SeedPeriodic as noexcept
Browse files Browse the repository at this point in the history
The usage of MilliSleep() in SeedPeriodic (previously SeedSleep) was
removed in bitcoin#17270, meaning it, and its users can now be marked noexcept.
  • Loading branch information
fanquake authored and Fuzzbawls committed Apr 14, 2021
1 parent 81d382f commit 88c2ae5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
16 changes: 3 additions & 13 deletions src/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,7 @@ void LockingCallbackOpenSSL(int mode, int i, const char* file, int line) NO_THRE

/* A note on the use of noexcept in the seeding functions below:
*
* None of the RNG code should ever throw any exception, with the sole exception
* of MilliSleep in SeedSleep, which can (and does) support interruptions which
* cause a boost::thread_interrupted to be thrown.
*
* This means that SeedSleep, and all functions that invoke it are throwing.
* However, we know that GetRandBytes() and GetStrongRandBytes() never trigger
* this sleeping logic, so they are noexcept. The same is true for all the
* GetRand*() functions that use GetRandBytes() indirectly.
*
* TODO: After moving away from interruptible boost-based thread management,
* everything can become noexcept here.
* None of the RNG code should ever throw any exception.
*/

static void SeedTimestamp(CSHA512& hasher) noexcept
Expand Down Expand Up @@ -541,7 +531,7 @@ static void SeedStrengthen(CSHA512& hasher, RNGState& rng, int microseconds) noe
Strengthen(strengthen_seed, microseconds, hasher);
}

static void SeedPeriodic(CSHA512& hasher, RNGState& rng)
static void SeedPeriodic(CSHA512& hasher, RNGState& rng) noexcept
{
// Everything that the 'fast' seeder includes
SeedFast(hasher);
Expand Down Expand Up @@ -622,7 +612,7 @@ static void ProcRand(unsigned char* out, int num, RNGLevel level)

void GetRandBytes(unsigned char* buf, int num) noexcept { ProcRand(buf, num, RNGLevel::FAST); }
void GetStrongRandBytes(unsigned char* buf, int num) noexcept { ProcRand(buf, num, RNGLevel::SLOW); }
void RandAddPeriodic() { ProcRand(nullptr, 0, RNGLevel::PERIODIC); }
void RandAddPeriodic() noexcept { ProcRand(nullptr, 0, RNGLevel::PERIODIC); }

void RandAddEvent(const uint32_t event_info) {
LOCK(events_mutex);
Expand Down
2 changes: 1 addition & 1 deletion src/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void GetStrongRandBytes(unsigned char* buf, int num) noexcept;
*
* Thread-safe.
*/
void RandAddPeriodic();
void RandAddPeriodic() noexcept;

/**
* Gathers entropy from the low bits of the time at which events occur. Should
Expand Down

0 comments on commit 88c2ae5

Please sign in to comment.