Skip to content

Commit 88c2ae5

Browse files
fanquakeFuzzbawls
authored andcommitted
random: mark RandAddPeriodic and SeedPeriodic as noexcept
The usage of MilliSleep() in SeedPeriodic (previously SeedSleep) was removed in bitcoin#17270, meaning it, and its users can now be marked noexcept.
1 parent 81d382f commit 88c2ae5

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

src/random.cpp

+3-13
Original file line numberDiff line numberDiff line change
@@ -455,17 +455,7 @@ void LockingCallbackOpenSSL(int mode, int i, const char* file, int line) NO_THRE
455455

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

471461
static void SeedTimestamp(CSHA512& hasher) noexcept
@@ -541,7 +531,7 @@ static void SeedStrengthen(CSHA512& hasher, RNGState& rng, int microseconds) noe
541531
Strengthen(strengthen_seed, microseconds, hasher);
542532
}
543533

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

623613
void GetRandBytes(unsigned char* buf, int num) noexcept { ProcRand(buf, num, RNGLevel::FAST); }
624614
void GetStrongRandBytes(unsigned char* buf, int num) noexcept { ProcRand(buf, num, RNGLevel::SLOW); }
625-
void RandAddPeriodic() { ProcRand(nullptr, 0, RNGLevel::PERIODIC); }
615+
void RandAddPeriodic() noexcept { ProcRand(nullptr, 0, RNGLevel::PERIODIC); }
626616

627617
void RandAddEvent(const uint32_t event_info) {
628618
LOCK(events_mutex);

src/random.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void GetStrongRandBytes(unsigned char* buf, int num) noexcept;
8787
*
8888
* Thread-safe.
8989
*/
90-
void RandAddPeriodic();
90+
void RandAddPeriodic() noexcept;
9191

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

0 commit comments

Comments
 (0)