Skip to content

Commit 2e557ce

Browse files
committed
Require WriteUndoDataForBlock() to hold mutex cs_main
Mutex cs_main is already held by the caller of WriteUndoDataForBlock(). This change is needed to require CBlockIndex::GetUndoPos() to hold cs_main and CBlockIndex::nStatus to be guarded by cs_main in the following commits without adding 2 unnecessary cs_main locks to WriteUndoDataForBlock().
1 parent 6fd4341 commit 2e557ce

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/node/blockstorage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ static bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos, const CMessa
712712

713713
bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex* pindex, const CChainParams& chainparams)
714714
{
715+
AssertLockHeld(::cs_main);
715716
// Write undo information to disk
716717
if (pindex->GetUndoPos().IsNull()) {
717718
FlatFilePos _pos;

src/node/blockstorage.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77

88
#include <fs.h>
99
#include <protocol.h> // For CMessageHeader::MessageStartChars
10+
#include <sync.h>
1011
#include <txdb.h>
1112

1213
#include <atomic>
1314
#include <cstdint>
1415
#include <vector>
1516

17+
extern RecursiveMutex cs_main;
18+
1619
class ArgsManager;
1720
class BlockValidationState;
1821
class CBlock;
@@ -146,7 +149,8 @@ class BlockManager
146149
/** Get block file info entry for one block file */
147150
CBlockFileInfo* GetBlockFileInfo(size_t n);
148151

149-
bool WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex* pindex, const CChainParams& chainparams);
152+
bool WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex* pindex, const CChainParams& chainparams)
153+
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
150154

151155
FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp);
152156

0 commit comments

Comments
 (0)