Skip to content

Commit fa5d296

Browse files
committed
refactor: prepare mempool_persist for obfuscation key change
These changes are meant to simplify the diffs for the riskier optimization commits later.
1 parent 6bbf2d9 commit fa5d296

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/node/mempool_persist.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,17 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active
6060
try {
6161
uint64_t version;
6262
file >> version;
63-
std::vector<std::byte> obfuscation;
63+
6464
if (version == MEMPOOL_DUMP_VERSION_NO_XOR_KEY) {
65-
// Leave XOR-key empty
65+
file.SetObfuscation({});
6666
} else if (version == MEMPOOL_DUMP_VERSION) {
67+
std::vector<std::byte> obfuscation(Obfuscation::KEY_SIZE);
6768
file >> obfuscation;
69+
file.SetObfuscation(obfuscation);
6870
} else {
6971
return false;
7072
}
71-
file.SetObfuscation(obfuscation);
73+
7274
uint64_t total_txns_to_load;
7375
file >> total_txns_to_load;
7476
uint64_t txns_tried = 0;
@@ -180,12 +182,14 @@ bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path, FopenFn mock
180182
const uint64_t version{pool.m_opts.persist_v1_dat ? MEMPOOL_DUMP_VERSION_NO_XOR_KEY : MEMPOOL_DUMP_VERSION};
181183
file << version;
182184

183-
std::vector<std::byte> obfuscation(Obfuscation::KEY_SIZE);
184185
if (!pool.m_opts.persist_v1_dat) {
186+
std::vector<std::byte> obfuscation(Obfuscation::KEY_SIZE);
185187
FastRandomContext{}.fillrand(obfuscation);
186188
file << obfuscation;
189+
file.SetObfuscation(obfuscation);
190+
} else {
191+
file.SetObfuscation({});
187192
}
188-
file.SetObfuscation(obfuscation);
189193

190194
uint64_t mempool_transactions_to_write(vinfo.size());
191195
file << mempool_transactions_to_write;

0 commit comments

Comments
 (0)