refactor: inline constant return value of `TxIndex::DB::WriteTxs`
What changed, and why it matters
This is a small internal code cleanup in Bitcoin Core's optional transaction index. The WriteTxs helper always returned true, so the caller now skips checking it and directly returns true. There is no user-facing or security-relevant change.
No action required; this is a benign refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors TxIndex::DB::WriteTxs from a [[nodiscard]] bool returning constant true to a void method. The sole caller, TxIndex::CustomAppend, now calls WriteTxs and returns true unconditionally. The underlying database write (WriteBatch) behavior is unchanged. This is a pure refactor with no functional or security impact.
Changed components
src/index/txindex.cppInspect captured patch +4 / −4
diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp
index 16038a3a..9554faf1 100644
--- a/src/index/txindex.cpp
+++ b/src/index/txindex.cpp
@@ -28,7 +28,7 @@ public:
bool ReadTxPos(const Txid& txid, CDiskTxPos& pos) const;
/// Write a batch of transaction positions to the DB.
- [[nodiscard]] bool WriteTxs(const std::vector<std::pair<Txid, CDiskTxPos>>& v_pos);
+ void WriteTxs(const std::vector<std::pair<Txid, CDiskTxPos>>& v_pos);
};
TxIndex::DB::DB(size_t n_cache_size, bool f_memory, bool f_wipe) :
@@ -40,14 +40,13 @@ bool TxIndex::DB::ReadTxPos(const Txid& txid, CDiskTxPos& pos) const
return Read(std::make_pair(DB_TXINDEX, txid.ToUint256()), pos);
}
-bool TxIndex::DB::WriteTxs(const std::vector<std::pair<Txid, CDiskTxPos>>& v_pos)
+void TxIndex::DB::WriteTxs(const std::vector<std::pair<Txid, CDiskTxPos>>& v_pos)
{
CDBBatch batch(*this);
for (const auto& [txid, pos] : v_pos) {
batch.Write(std::make_pair(DB_TXINDEX, txid.ToUint256()), pos);
}
WriteBatch(batch);
- return true;
}
TxIndex::TxIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory, bool f_wipe)
@@ -69,7 +68,8 @@ bool TxIndex::CustomAppend(const interfaces::BlockInfo& block)
vPos.emplace_back(tx->GetHash(), pos);
pos.nTxOffset += ::GetSerializeSize(TX_WITH_WITNESS(*tx));
}
- return m_db->WriteTxs(vPos);
+ m_db->WriteTxs(vPos);
+ return true;
}
BaseIndex::DB& TxIndex::GetDB() const { return *m_db; }
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.