Skip to content

Commit 0bd882b

Browse files
committed
refactor: remove RecursiveMutex cs_nBlockSequenceId
The RecursiveMutex cs_nBlockSequenceId is only used at one place in CChainState::ReceivedBlockTransactions() to atomically read-and-increment the nBlockSequenceId member. At this point, the cs_main lock is set, hence we can use a plain int for the member and mark it as guarded by cs_main.
1 parent 33707a2 commit 0bd882b

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

src/validation.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,10 +2970,7 @@ void CChainState::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pi
29702970
CBlockIndex *pindex = queue.front();
29712971
queue.pop_front();
29722972
pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx;
2973-
{
2974-
LOCK(cs_nBlockSequenceId);
2975-
pindex->nSequenceId = nBlockSequenceId++;
2976-
}
2973+
pindex->nSequenceId = nBlockSequenceId++;
29772974
if (m_chain.Tip() == nullptr || !setBlockIndexCandidates.value_comp()(pindex, m_chain.Tip())) {
29782975
setBlockIndexCandidates.insert(pindex);
29792976
}

src/validation.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,8 @@ class CChainState
558558
* Every received block is assigned a unique and increasing identifier, so we
559559
* know which one to give priority in case of a fork.
560560
*/
561-
RecursiveMutex cs_nBlockSequenceId;
562561
/** Blocks loaded from disk are assigned id 0, so start the counter at 1. */
563-
int32_t nBlockSequenceId = 1;
562+
int32_t nBlockSequenceId GUARDED_BY(::cs_main) = 1;
564563
/** Decreasing counter (used by subsequent preciousblock calls). */
565564
int32_t nBlockReverseSequenceId = -1;
566565
/** chainwork for the last block that preciousblock has been applied to. */
@@ -749,7 +748,7 @@ class CChainState
749748

750749
void PruneBlockIndexCandidates();
751750

752-
void UnloadBlockIndex();
751+
void UnloadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
753752

754753
/** Check whether we are doing an initial block download (synchronizing from disk or network) */
755754
bool IsInitialBlockDownload() const;

0 commit comments

Comments
 (0)