Merge 24d5cf9314 into merged_master (Bitcoin PR bitcoin/bitcoin#27425)

This commit is contained in:
Byron Hambly 2025-07-01 13:43:46 +02:00
commit 4fd04eb7d7
9 changed files with 72 additions and 53 deletions

View file

@ -37,6 +37,7 @@
#include <policy/policy.h>
#include <policy/settings.h>
#include <streams.h>
#include <random.h>
#include <rpc/blockchain.h>
#include <rpc/server.h>
#include <rpc/register.h>
@ -44,6 +45,7 @@
#include <script/sigcache.h>
#include <shutdown.h>
#include <test/util/net.h>
#include <test/util/random.h>
#include <test/util/txmempool.h>
#include <timedata.h>
#include <txdb.h>
@ -77,29 +79,9 @@ using node::VerifyLoadedChainstate;
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
UrlDecodeFn* const URL_DECODE = nullptr;
FastRandomContext g_insecure_rand_ctx;
/** Random context to get unique temp data dirs. Separate from g_insecure_rand_ctx, which can be seeded from a const env var */
static FastRandomContext g_insecure_rand_ctx_temp_path;
/** Return the unsigned from the environment var if available, otherwise 0 */
static uint256 GetUintFromEnv(const std::string& env_name)
{
const char* num = std::getenv(env_name.c_str());
if (!num) return {};
return uint256S(num);
}
void Seed(FastRandomContext& ctx)
{
// Should be enough to get the seed once for the process
static uint256 seed{};
static const std::string RANDOM_CTX_SEED{"RANDOM_CTX_SEED"};
if (seed.IsNull()) seed = GetUintFromEnv(RANDOM_CTX_SEED);
if (seed.IsNull()) seed = GetRandHash();
LogPrintf("%s: Setting random seed for current tests to %s=%s\n", __func__, RANDOM_CTX_SEED, seed.GetHex());
ctx = FastRandomContext(seed);
}
std::ostream& operator<<(std::ostream& os, const uint256& num)
{
os << num.ToString();