Skip to content

Commit

Permalink
Require CBlockIndex::GetUndoPos() to hold mutex cs_main
Browse files Browse the repository at this point in the history
Summary:
This is a partial backport of [[bitcoin/bitcoin#22932 | core#22932]]
bitcoin/bitcoin@5723934

Depends on D13032

Test Plan:
With clang and DEBUG:

`ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13033
  • Loading branch information
PiRK committed Jan 24, 2023
1 parent 4d9bd4f commit 99d5b83
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/blockindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ class CBlockIndex {
return ret;
}

FlatFilePos GetUndoPos() const {
FlatFilePos GetUndoPos() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
AssertLockHeld(::cs_main);
FlatFilePos ret;
if (nStatus.hasUndo()) {
ret.nFile = nFile;
Expand Down
3 changes: 2 additions & 1 deletion src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ static bool UndoWriteToDisk(const CBlockUndo &blockundo, FlatFilePos &pos,
}

bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex) {
FlatFilePos pos = pindex->GetUndoPos();
const FlatFilePos pos{WITH_LOCK(::cs_main, return pindex->GetUndoPos())};

if (pos.IsNull()) {
return error("%s: no undo data available", __func__);
}
Expand Down

0 comments on commit 99d5b83

Please sign in to comment.