Skip to content

Commit

Permalink
Require WriteUndoDataForBlock() to hold mutex cs_main
Browse files Browse the repository at this point in the history
Summary:
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().

This is a partial backport of [[bitcoin/bitcoin#22932 | core#22932]]
bitcoin/bitcoin@2e557ce

Depends on D13031

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/D13032
  • Loading branch information
jonatack authored and PiRK committed Jan 24, 2023
1 parent 1e299c9 commit 4d9bd4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo &blockundo,
BlockValidationState &state,
CBlockIndex *pindex,
const CChainParams &chainparams) {
AssertLockHeld(::cs_main);
// Write undo information to disk
if (pindex->GetUndoPos().IsNull()) {
FlatFilePos _pos;
Expand Down
6 changes: 5 additions & 1 deletion src/node/blockstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
#include <chain.h>
#include <fs.h>
#include <protocol.h> // For CMessageHeader::MessageStartChars
#include <sync.h>
#include <txdb.h>

extern RecursiveMutex cs_main;

class ArgsManager;
class BlockValidationState;
class CBlock;
Expand Down Expand Up @@ -173,7 +176,8 @@ class BlockManager {

bool WriteUndoDataForBlock(const CBlockUndo &blockundo,
BlockValidationState &state, CBlockIndex *pindex,
const CChainParams &chainparams);
const CChainParams &chainparams)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);

FlatFilePos SaveBlockToDisk(const CBlock &block, int nHeight,
CChain &active_chain,
Expand Down

0 comments on commit 4d9bd4f

Please sign in to comment.