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 committed 2025-07-16 14:33:07 -07:00
1 parent 6bbf2d9311
commit fa5d296e3b
1 file changed
+9 -5
+9 -5
View File
@@ -60,15 +60,17 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active
try { try {
uint64_t version; uint64_t version;
file >> version; file >> version;
std::vector<std::byte> obfuscation;
if (version == MEMPOOL_DUMP_VERSION_NO_XOR_KEY) { if (version == MEMPOOL_DUMP_VERSION_NO_XOR_KEY) {
// Leave XOR-key empty file.SetObfuscation({});
} else if (version == MEMPOOL_DUMP_VERSION) { } else if (version == MEMPOOL_DUMP_VERSION) {
std::vector<std::byte> obfuscation(Obfuscation::KEY_SIZE);
file >> obfuscation; file >> obfuscation;
file.SetObfuscation(obfuscation);
} else { } else {
return false; return false;
} }
file.SetObfuscation(obfuscation);
uint64_t total_txns_to_load; uint64_t total_txns_to_load;
file >> total_txns_to_load; file >> total_txns_to_load;
uint64_t txns_tried = 0; 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}; const uint64_t version{pool.m_opts.persist_v1_dat ? MEMPOOL_DUMP_VERSION_NO_XOR_KEY : MEMPOOL_DUMP_VERSION};
file << version; file << version;
std::vector<std::byte> obfuscation(Obfuscation::KEY_SIZE);
if (!pool.m_opts.persist_v1_dat) { if (!pool.m_opts.persist_v1_dat) {
std::vector<std::byte> obfuscation(Obfuscation::KEY_SIZE);
FastRandomContext{}.fillrand(obfuscation); FastRandomContext{}.fillrand(obfuscation);
file << obfuscation; file << obfuscation;
file.SetObfuscation(obfuscation);
} else {
file.SetObfuscation({});
} }
file.SetObfuscation(obfuscation);
uint64_t mempool_transactions_to_write(vinfo.size()); uint64_t mempool_transactions_to_write(vinfo.size());
file << mempool_transactions_to_write; file << mempool_transactions_to_write;