refactor: inline constant return value of CDBWrapper::WriteBatch

`WriteBatch` can only ever return `true` - its errors are handled by throwing a `throw dbwrapper_error` instead.
The boolean return value is quite confusing, especially since it's symmetric with `CDBWrapper::Read`, which catches the exceptions and returns a boolean instead.
We're removing the constant return value and inlining `true` for its usages.
This commit is contained in:
Lőrinc
2025-07-22 12:18:54 -07:00
parent 9b1a7c3e8d
commit 50b63a5698
9 changed files with 16 additions and 13 deletions

View File

@@ -262,7 +262,7 @@ bool BaseIndex::Commit()
ok = CustomCommit(batch);
if (ok) {
GetDB().WriteBestBlock(batch, GetLocator(*m_chain, m_best_block_index.load()->GetBlockHash()));
ok = GetDB().WriteBatch(batch);
GetDB().WriteBatch(batch);
}
}
if (!ok) {

View File

@@ -338,7 +338,7 @@ bool BlockFilterIndex::CustomRemove(const interfaces::BlockInfo& block)
// But since this creates new references to the filter, the position should get updated here
// atomically as well in case Commit fails.
batch.Write(DB_FILTER_POS, m_next_filter_pos);
if (!m_db->WriteBatch(batch)) return false;
m_db->WriteBatch(batch);
// Update cached header to the previous block hash
m_last_header = *Assert(ReadFilterHeader(block.height - 1, *Assert(block.prev_hash)));

View File

@@ -263,7 +263,7 @@ bool CoinStatsIndex::CustomRemove(const interfaces::BlockInfo& block)
return false;
}
if (!m_db->WriteBatch(batch)) return false;
m_db->WriteBatch(batch);
if (!ReverseBlock(block)) {
return false; // failure cause logged internally

View File

@@ -46,7 +46,8 @@ bool TxIndex::DB::WriteTxs(const std::vector<std::pair<Txid, CDiskTxPos>>& v_pos
for (const auto& [txid, pos] : v_pos) {
batch.Write(std::make_pair(DB_TXINDEX, txid.ToUint256()), pos);
}
return WriteBatch(batch);
WriteBatch(batch);
return true;
}
TxIndex::TxIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory, bool f_wipe)