index: shrink txospenderindex value markers
What changed, and why it matters
This is a minor storage optimization for a Bitcoin Core index. It changes the on-disk value stored alongside each index entry from an empty string to a zero-byte value, saving one byte per entry when the index is rebuilt. The lookup logic only reads the keys, so existing indexes with the old format continue to work normally. There is no security issue.
No security action needed. This is a benign optimization and backward-compatible format change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies TxoSpenderIndex::WriteSpenderInfos to write std::span
Changed components
src/index/txospenderindex.cppInspect captured patch +6 / −3
diff --git a/src/index/txospenderindex.cpp b/src/index/txospenderindex.cpp
index 3d7b56b6..50b9bfeb 100644
--- a/src/index/txospenderindex.cpp
+++ b/src/index/txospenderindex.cpp
@@ -23,15 +23,17 @@
#include <util/fs.h>
#include <validation.h>
+#include <cstddef>
#include <cstdio>
#include <exception>
#include <ios>
+#include <span>
#include <string>
#include <utility>
#include <vector>
/* The database is used to find the spending transaction of a given utxo.
- * For every input of every transaction it stores a key that is a pair(siphash(input outpoint), transaction location on disk) and an empty value.
+ * For every input of every transaction it stores a key that is a pair(siphash(input outpoint), transaction location on disk) and a zero-byte value.
* To find the spending transaction of an outpoint, we perform a range query on siphash(outpoint), and for each returned key load the transaction
* and return it if it does spend the provided outpoint.
*/
@@ -91,8 +93,9 @@ void TxoSpenderIndex::WriteSpenderInfos(const std::vector<std::pair<COutPoint, C
CDBBatch batch(*m_db);
for (const auto& [outpoint, pos] : items) {
DBKey key(CreateKey(m_siphash_key, outpoint, pos));
- // key is hash(spent outpoint) | disk pos, value is empty
- batch.Write(key, "");
+ // The key encodes the spent outpoint hash and disk position. The value is only a marker.
+ // Older entries may contain serialized empty strings; FindSpender() reads only keys.
+ batch.Write(key, std::span<const std::byte>{});
}
m_db->WriteBatch(batch);
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.