From fa5d296e3beb312e2bc39532a12bcdf187c6da91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Sat, 5 Apr 2025 19:01:09 +0200 Subject: [PATCH] refactor: prepare mempool_persist for obfuscation key change These changes are meant to simplify the diffs for the riskier optimization commits later. --- src/node/mempool_persist.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/node/mempool_persist.cpp b/src/node/mempool_persist.cpp index 9054fd7bb88..eac8d386e74 100644 --- a/src/node/mempool_persist.cpp +++ b/src/node/mempool_persist.cpp @@ -60,15 +60,17 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active try { uint64_t version; file >> version; - std::vector obfuscation; + if (version == MEMPOOL_DUMP_VERSION_NO_XOR_KEY) { - // Leave XOR-key empty + file.SetObfuscation({}); } else if (version == MEMPOOL_DUMP_VERSION) { + std::vector 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 obfuscation(Obfuscation::KEY_SIZE); if (!pool.m_opts.persist_v1_dat) { + std::vector 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;