Skip to content

Commit fd69ffb

Browse files
committed
Merge bitcoin/bitcoin#28427: index: coinstats reorg, fail when block cannot be reversed
c0bf667 index: add [nodiscard] attribute to functions writing to the db (furszy) eef5955 index: coinstats reorg, fail when block cannot be reversed (furszy) Pull request description: Found it while reviewing bitcoin/bitcoin#24230 (comment). During a reorg, continuing execution when a block cannot be reversed leaves the coinstats index in an inconsistent state. This was surely overlooked when 'CustomRewind' was implemented. ACKs for top commit: ryanofsky: Code review ACK c0bf667. Only change since last review is new commit adding [[nodiscard]] Tree-SHA512: f4fc8522508d23e4fff09a29c935971819b1bd3b2a260e08e2e2b72f9340980d74fbec742a58fe216baf61d27de057c7c8300e8fa075f8507cd1227f128af909
2 parents 8f7b9eb + c0bf667 commit fd69ffb

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

src/index/blockfilterindex.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
261261
return true;
262262
}
263263

264-
static bool CopyHeightIndexToHashIndex(CDBIterator& db_it, CDBBatch& batch,
264+
[[nodiscard]] static bool CopyHeightIndexToHashIndex(CDBIterator& db_it, CDBBatch& batch,
265265
const std::string& index_name,
266266
int start_height, int stop_height)
267267
{

src/index/coinstatsindex.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
235235
return m_db->Write(DBHeightKey(block.height), value);
236236
}
237237

238-
static bool CopyHeightIndexToHashIndex(CDBIterator& db_it, CDBBatch& batch,
238+
[[nodiscard]] static bool CopyHeightIndexToHashIndex(CDBIterator& db_it, CDBBatch& batch,
239239
const std::string& index_name,
240240
int start_height, int stop_height)
241241
{
@@ -288,7 +288,9 @@ bool CoinStatsIndex::CustomRewind(const interfaces::BlockKey& current_tip, const
288288
__func__, iter_tip->GetBlockHash().ToString());
289289
}
290290

291-
ReverseBlock(block, iter_tip);
291+
if (!ReverseBlock(block, iter_tip)) {
292+
return false; // failure cause logged internally
293+
}
292294

293295
iter_tip = iter_tip->GetAncestor(iter_tip->nHeight - 1);
294296
} while (new_tip_index != iter_tip);

src/index/coinstatsindex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CoinStatsIndex final : public BaseIndex
3838
CAmount m_total_unspendables_scripts{0};
3939
CAmount m_total_unspendables_unclaimed_rewards{0};
4040

41-
bool ReverseBlock(const CBlock& block, const CBlockIndex* pindex);
41+
[[nodiscard]] bool ReverseBlock(const CBlock& block, const CBlockIndex* pindex);
4242

4343
bool AllowPrune() const override { return true; }
4444

src/index/txindex.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TxIndex::DB : public BaseIndex::DB
2727
bool ReadTxPos(const uint256& txid, CDiskTxPos& pos) const;
2828

2929
/// Write a batch of transaction positions to the DB.
30-
bool WriteTxs(const std::vector<std::pair<uint256, CDiskTxPos>>& v_pos);
30+
[[nodiscard]] bool WriteTxs(const std::vector<std::pair<uint256, CDiskTxPos>>& v_pos);
3131
};
3232

3333
TxIndex::DB::DB(size_t n_cache_size, bool f_memory, bool f_wipe) :

0 commit comments

Comments
 (0)