mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
Merge bitcoin/bitcoin#33042: refactor: inline constant return values from dbwrapper write methods
743abbcbderefactor: inline constant return value of `BlockTreeDB::WriteBatchSync` and `BlockManager::WriteBlockIndexDB` and `BlockTreeDB::WriteFlag` (Lőrinc)e030240e90refactor: inline constant return value of `CDBWrapper::Erase` and `BlockTreeDB::WriteReindexing` (Lőrinc)cdab9480e9refactor: inline constant return value of `CDBWrapper::Write` (Lőrinc)d1847cf5b5refactor: inline constant return value of `TxIndex::DB::WriteTxs` (Lőrinc)50b63a5698refactor: inline constant return value of `CDBWrapper::WriteBatch` (Lőrinc) Pull request description: Related to https://github.com/bitcoin/bitcoin/pull/31144#discussion_r2223587480 ### Summary `WriteBatch` always returns `true` - the errors are handled by throwing `dbwrapper_error` instead. ### Context This boolean return value of the `Write` methods is confusing because it's inconsistent with `CDBWrapper::Read`, which catches exceptions and returns a boolean to indicate success/failure. It's bad that `Read` returns and `Write` throws - but it's a lot worse that `Write` advertises a return value when it actually communicates errors through exceptions. ### Solution This PR removes the constant return values from write methods and inlines `true` at their call sites. Many upstream methods had boolean return values only because they were propagating these constants - those have been cleaned up as well. Methods that returned a constant `true` value that now return `void`: - `CDBWrapper::WriteBatch`, `CDBWrapper::Write`, `CDBWrapper::Erase` - `TxIndex::DB::WriteTxs` - `BlockTreeDB::WriteReindexing`, `BlockTreeDB::WriteBatchSync`, `BlockTreeDB::WriteFlag` - `BlockManager::WriteBlockIndexDB` ### Note `CCoinsView::BatchWrite` (and transitively `CCoinsViewCache::Flush` & `CCoinsViewCache::Sync`) were intentionally not changed here. While all implementations return `true`, the base `CCoinsView::BatchWrite` returns `false`. Changing this would cause `coins_view` tests to fail with: > terminating due to uncaught exception of type std::logic_error: Not all unspent flagged entries were cleared We can fix that in a follow-up PR. ACKs for top commit: achow101: ACK743abbcbdejanb84: ACK743abbcbdeTheCharlatan: ACK743abbcbdesipa: ACK743abbcbdeTree-SHA512: b2a550bff066216f1958d2dd9a7ef6a9949de518cc636f8ab9c670e0b7a330c1eb8c838e458a8629acb8ac980cea6616955cd84436a7b8ab9096f6d648073b1e
This commit is contained in:
@@ -311,9 +311,7 @@ bool BlockFilterIndex::Write(const BlockFilter& filter, uint32_t block_height, c
|
||||
value.second.header = filter_header;
|
||||
value.second.pos = m_next_filter_pos;
|
||||
|
||||
if (!m_db->Write(DBHeightKey(block_height), value)) {
|
||||
return false;
|
||||
}
|
||||
m_db->Write(DBHeightKey(block_height), value);
|
||||
|
||||
m_next_filter_pos.nPos += bytes_written;
|
||||
return true;
|
||||
@@ -358,7 +356,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)));
|
||||
|
||||
Reference in New Issue
Block a user