Skip to content

Commit 948238a

Browse files
ryanofskyMarcoFalke
authored andcommitted
test: Remove FastRandomContext global
Drop g_insecure_rand_ctx
1 parent fa0fe08 commit 948238a

File tree

5 files changed

+5
-40
lines changed

5 files changed

+5
-40
lines changed

src/bench/sign_transaction.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ static void SignTransactionSchnorr(benchmark::Bench& bench) { SignTransactionSin
6969

7070
static void SignSchnorrTapTweakBenchmark(benchmark::Bench& bench, bool use_null_merkle_root)
7171
{
72+
FastRandomContext rng;
7273
ECC_Context ecc_context{};
7374

7475
auto key = GenerateRandomKey();
75-
auto msg = InsecureRand256();
76-
auto merkle_root = use_null_merkle_root ? uint256() : InsecureRand256();
77-
auto aux = InsecureRand256();
76+
auto msg = rng.rand256();
77+
auto merkle_root = use_null_merkle_root ? uint256() : rng.rand256();
78+
auto aux = rng.rand256();
7879
std::vector<unsigned char> sig(64);
7980

8081
bench.minEpochIterations(100).run([&] {

src/test/fuzz/fuzz.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ void initialize()
107107
// - GetStrongRandBytes(), which is used for the creation of private key material.
108108
// - Creating a BasicTestingSetup or derived class will switch to a random seed.
109109
SeedRandomStateForTest(SeedRand::ZEROS);
110-
g_insecure_rand_ctx.Reseed(GetRandHash());
111110

112111
// Terminate immediately if a fuzzing harness ever tries to create a socket.
113112
// Individual tests can override this by pointing CreateSock to a mocked alternative.

src/test/util/random.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include <cstdlib>
1212
#include <string>
1313

14-
FastRandomContext g_insecure_rand_ctx;
15-
1614
extern void MakeRandDeterministicDANGEROUS(const uint256& seed) noexcept;
1715

1816
void SeedRandomStateForTest(SeedRand seedtype)

src/test/util/random.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@
1111

1212
#include <cstdint>
1313

14-
/**
15-
* This global and the helpers that use it are not thread-safe.
16-
*
17-
* If thread-safety is needed, a per-thread instance could be
18-
* used in the multi-threaded test.
19-
*/
20-
extern FastRandomContext g_insecure_rand_ctx;
21-
2214
enum class SeedRand {
2315
ZEROS, //!< Seed with a compile time constant of zeros
2416
SEED, //!< Use (and report) random seed from environment, or a (truly) random one.
@@ -27,31 +19,6 @@ enum class SeedRand {
2719
/** Seed the global RNG state for testing and log the seed value. This affects all randomness, except GetStrongRandBytes(). */
2820
void SeedRandomStateForTest(SeedRand seed);
2921

30-
static inline uint32_t InsecureRand32()
31-
{
32-
return g_insecure_rand_ctx.rand32();
33-
}
34-
35-
static inline uint256 InsecureRand256()
36-
{
37-
return g_insecure_rand_ctx.rand256();
38-
}
39-
40-
static inline uint64_t InsecureRandBits(int bits)
41-
{
42-
return g_insecure_rand_ctx.randbits(bits);
43-
}
44-
45-
static inline uint64_t InsecureRandRange(uint64_t range)
46-
{
47-
return g_insecure_rand_ctx.randrange(range);
48-
}
49-
50-
static inline bool InsecureRandBool()
51-
{
52-
return g_insecure_rand_ctx.randbool();
53-
}
54-
5522
template <RandomNumberGenerator Rng>
5623
inline CAmount RandMoney(Rng&& rng)
5724
{

src/test/util/setup_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct BasicTestingSetup {
6666
util::SignalInterrupt m_interrupt;
6767
node::NodeContext m_node; // keep as first member to be destructed last
6868

69-
FastRandomContext& m_rng{g_insecure_rand_ctx}; // Alias (reference) for the global, to allow easy removal of the global in the future.
69+
FastRandomContext m_rng;
7070
/** Seed the global RNG state and m_rng for testing and log the seed value. This affects all randomness, except GetStrongRandBytes(). */
7171
void SeedRandomForTest(SeedRand seed = SeedRand::SEED)
7272
{

0 commit comments

Comments
 (0)