refactor: prepare mempool_persist for obfuscation key change

These changes are meant to simplify the diffs for the riskier optimization commits later.
This commit is contained in:
Lőrinc
2025-04-05 19:01:09 +02:00
parent 6bbf2d9311
commit fa5d296e3b

View File

@@ -60,15 +60,17 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active
try {
uint64_t version;
file >> version;
std::vector<std::byte> obfuscation;
if (version == MEMPOOL_DUMP_VERSION_NO_XOR_KEY) {
// Leave XOR-key empty
file.SetObfuscation({});
} else if (version == MEMPOOL_DUMP_VERSION) {
std::vector<std::byte> obfuscation(Obfuscation::KEY_SIZE);
file >> obfuscation;
file.SetObfuscation(obfuscation);
} else {
return false;
}
file.SetObfuscation(obfuscation);
uint64_t total_txns_to_load;
file >> total_txns_to_load;
uint64_t txns_tried = 0;
@@ -180,12 +182,14 @@ bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path, FopenFn mock
const uint64_t version{pool.m_opts.persist_v1_dat ? MEMPOOL_DUMP_VERSION_NO_XOR_KEY : MEMPOOL_DUMP_VERSION};
file << version;
std::vector<std::byte> obfuscation(Obfuscation::KEY_SIZE);
if (!pool.m_opts.persist_v1_dat) {
std::vector<std::byte> obfuscation(Obfuscation::KEY_SIZE);
FastRandomContext{}.fillrand(obfuscation);
file << obfuscation;
file.SetObfuscation(obfuscation);
} else {
file.SetObfuscation({});
}
file.SetObfuscation(obfuscation);
uint64_t mempool_transactions_to_write(vinfo.size());
file << mempool_transactions_to_write;