Merge 9ecc7af41f into merged_master (Bitcoin PR bitcoin/bitcoin#31674)

This commit is contained in:
ivanlele 2026-04-14 08:26:34 +00:00
commit aaaedd07d4
No known key found for this signature in database
6 changed files with 46 additions and 24 deletions

View file

@ -1212,7 +1212,19 @@ static auto InitBlocksdirXorKey(const BlockManager::Options& opts)
// size of the XOR-key file.
std::array<std::byte, 8> xor_key{};
if (opts.use_xor && fs::is_empty(opts.blocks_dir)) {
// Consider this to be the first run if the blocksdir contains only hidden
// files (those which start with a .). Checking for a fully-empty dir would
// be too aggressive as a .lock file may have already been written.
bool first_run = true;
for (const auto& entry : fs::directory_iterator(opts.blocks_dir)) {
const std::string path = fs::PathToString(entry.path().filename());
if (!entry.is_regular_file() || !path.starts_with('.')) {
first_run = false;
break;
}
}
if (opts.use_xor && first_run) {
// Only use random fresh key when the boolean option is set and on the
// very first start of the program.
FastRandomContext{}.fillrand(xor_key);