Skip to content

Commit 55b2cb1

Browse files
committed
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 461e547 commit 55b2cb1

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
@@ -450,17 +450,7 @@ void LockingCallbackOpenSSL(int mode, int i, const char* file, int line) NO_THRE
450450

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

466456
static void SeedTimestamp(CSHA512& hasher) noexcept
@@ -516,7 +506,7 @@ static void SeedStrengthen(CSHA512& hasher, RNGState& rng, int microseconds) noe
516506
Strengthen(strengthen_seed, microseconds, hasher);
517507
}
518508

519-
static void SeedPeriodic(CSHA512& hasher, RNGState& rng)
509+
static void SeedPeriodic(CSHA512& hasher, RNGState& rng) noexcept
520510
{
521511
// Everything that the 'fast' seeder includes
522512
SeedFast(hasher);
@@ -598,7 +588,7 @@ static void ProcRand(unsigned char* out, int num, RNGLevel level)
598588

599589
void GetRandBytes(unsigned char* buf, int num) noexcept { ProcRand(buf, num, RNGLevel::FAST); }
600590
void GetStrongRandBytes(unsigned char* buf, int num) noexcept { ProcRand(buf, num, RNGLevel::SLOW); }
601-
void RandAddPeriodic() { ProcRand(nullptr, 0, RNGLevel::PERIODIC); }
591+
void RandAddPeriodic() noexcept { ProcRand(nullptr, 0, RNGLevel::PERIODIC); }
602592

603593
bool g_mock_deterministic_tests{false};
604594

src/random.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void GetStrongRandBytes(unsigned char* buf, int num) noexcept;
8888
*
8989
* Thread-safe.
9090
*/
91-
void RandAddPeriodic();
91+
void RandAddPeriodic() noexcept;
9292

9393
/**
9494
* Fast randomness source. This is seeded once with secure random data, but

0 commit comments

Comments
 (0)