Skip to content

Commit 5723934

Browse files
committed
Require CBlockIndex::GetUndoPos() to hold mutex cs_main
1 parent 2e557ce commit 5723934

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/chain.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,9 @@ class CBlockIndex
237237
return ret;
238238
}
239239

240-
FlatFilePos GetUndoPos() const
240+
FlatFilePos GetUndoPos() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
241241
{
242+
AssertLockHeld(::cs_main);
242243
FlatFilePos ret;
243244
if (nStatus & BLOCK_HAVE_UNDO) {
244245
ret.nFile = nFile;

src/node/blockstorage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ static bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const
513513

514514
bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex)
515515
{
516-
FlatFilePos pos = pindex->GetUndoPos();
516+
const FlatFilePos pos{WITH_LOCK(::cs_main, return pindex->GetUndoPos())};
517+
517518
if (pos.IsNull()) {
518519
return error("%s: no undo data available", __func__);
519520
}

0 commit comments

Comments
 (0)