aboutsummaryrefslogtreecommitdiff
path: root/src/streams.h
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-11-13 11:17:02 -0500
committerAndrew Chow <github@achow101.com>2023-11-13 11:28:15 -0500
commitd232e36abdb1a4f01787766a758051c16940b0c5 (patch)
tree987b73296510c74c10376e32adcf9a43bc27949c /src/streams.h
parent63423480723de8f4da67e9f4a715cca15498a4ca (diff)
parentfa6b053b5c964fb35935fa994cb782c0731a56f8 (diff)
downloadbitcoin-d232e36abdb1a4f01787766a758051c16940b0c5.tar.xz
Merge bitcoin/bitcoin#28207: mempool: Persist with XOR
fa6b053b5c964fb35935fa994cb782c0731a56f8 mempool: persist with XOR (MarcoFalke) Pull request description: Currently the `mempool.dat` file stores data received from remote peers as-is. This may be problematic when a program other than Bitcoin Core tries to interpret them by accident. For example, an anti-virus program or other program may scan the file and move it into quarantine, or delete it, or corrupt it. While the local wallet is expected to re-submit any pending transactions, unrelated transactions may be missing from the mempool after a restart. This may cause fee estimates to be off, or may cause block relay to be slower. Fix this, similar to https://github.com/bitcoin/bitcoin/pull/6650, by rolling a random XOR pattern over the dat file when writing or reading it. Obviously this can only protect against programs that accidentally and unintentionally are trying to mess with the dat file. Any program that intentionally wants to mess with the dat file can still trivially do so. ACKs for top commit: achow101: re-ACK fa6b053b5c964fb35935fa994cb782c0731a56f8 glozow: reACK fa6b053b5c964fb35935fa994cb782c0731a56f8 ismaelsadeeq: ACK fa6b053b5c964fb35935fa994cb782c0731a56f8 Tree-SHA512: ded2ce3d81bc944b828263534e3178a1e45a914fe8e024f4a14c6561a73e301820944ecc75dd704b3d4221a7a3a5c0597ccab79546250c1197609ee981fe324e
Diffstat (limited to 'src/streams.h')
-rw-r--r--src/streams.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/streams.h b/src/streams.h
index ae1434cc1c..f5b441344f 100644
--- a/src/streams.h
+++ b/src/streams.h
@@ -476,7 +476,7 @@ class AutoFile
{
protected:
std::FILE* m_file;
- const std::vector<std::byte> m_xor;
+ std::vector<std::byte> m_xor;
public:
explicit AutoFile(std::FILE* file, std::vector<std::byte> data_xor={}) : m_file{file}, m_xor{std::move(data_xor)} {}
@@ -516,6 +516,9 @@ public:
*/
bool IsNull() const { return m_file == nullptr; }
+ /** Continue with a different XOR key */
+ void SetXor(std::vector<std::byte> data_xor) { m_xor = data_xor; }
+
/** Implementation detail, only used internally. */
std::size_t detail_fread(Span<std::byte> dst);