Skip to content

Commit

Permalink
consensus: require CBlockIndex::GetUndoPos() to hold mutex cs_main
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatack committed Sep 17, 2021
1 parent b82ad98 commit e950f0e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ class CBlockIndex
return ret;
}

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

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 Expand Up @@ -336,7 +337,7 @@ static bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos, const CMessa
bool WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex* pindex, const CChainParams& chainparams)
{
// Write undo information to disk
if (pindex->GetUndoPos().IsNull()) {
if (WITH_LOCK(cs_main, return pindex->GetUndoPos()).IsNull()) {
FlatFilePos _pos;
if (!FindUndoPos(state, pindex->nFile, _pos, ::GetSerializeSize(blockundo, CLIENT_VERSION) + 40)) {
return error("ConnectBlock(): FindUndoPos failed");
Expand Down

0 comments on commit e950f0e

Please sign in to comment.