Skip to content

Commit eccd736

Browse files
committed
versionbits: Use dedicated lock instead of cs_main
1 parent 36a4ba0 commit eccd736

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ static void BuriedForkDescPushBack(UniValue& softforks, const std::string &name,
13611361
softforks.pushKV(name, rv);
13621362
}
13631363

1364-
static void BIP9SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue& softforks, const std::string &name, const Consensus::Params& consensusParams, Consensus::DeploymentPos id) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1364+
static void BIP9SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue& softforks, const std::string &name, const Consensus::Params& consensusParams, Consensus::DeploymentPos id)
13651365
{
13661366
// For BIP9 deployments.
13671367
// Deployments that are never active are hidden.

src/validation.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,11 +1606,10 @@ void StopScriptCheckWorkerThreads()
16061606
scriptcheckqueue.StopWorkerThreads();
16071607
}
16081608

1609-
VersionBitsCache versionbitscache GUARDED_BY(cs_main);
1609+
VersionBitsCache versionbitscache;
16101610

16111611
int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params)
16121612
{
1613-
LOCK(cs_main);
16141613
int32_t nVersion = VERSIONBITS_TOP_BITS;
16151614

16161615
for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {
@@ -1659,9 +1658,8 @@ static bool IsScriptWitnessEnabled(const Consensus::Params& params)
16591658
return params.SegwitHeight != std::numeric_limits<int>::max();
16601659
}
16611660

1662-
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& consensusparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
1663-
AssertLockHeld(cs_main);
1664-
1661+
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& consensusparams)
1662+
{
16651663
unsigned int flags = SCRIPT_VERIFY_NONE;
16661664

16671665
// BIP16 didn't become active until Apr 1 2012 (on mainnet, and

src/versionbits.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class VersionBitsConditionChecker : public AbstractThresholdConditionChecker {
192192

193193
ThresholdState VersionBitsState(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache)
194194
{
195+
LOCK(cache.mutex);
195196
return VersionBitsConditionChecker(pos).GetStateFor(pindexPrev, params, cache.caches[pos]);
196197
}
197198

@@ -202,6 +203,7 @@ BIP9Stats VersionBitsStatistics(const CBlockIndex* pindexPrev, const Consensus::
202203

203204
int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache)
204205
{
206+
LOCK(cache.mutex);
205207
return VersionBitsConditionChecker(pos).GetStateSinceHeightFor(pindexPrev, params, cache.caches[pos]);
206208
}
207209

@@ -212,6 +214,7 @@ uint32_t VersionBitsMask(const Consensus::Params& params, Consensus::DeploymentP
212214

213215
void VersionBitsCache::Clear()
214216
{
217+
LOCK(mutex);
215218
for (unsigned int d = 0; d < Consensus::MAX_VERSION_BITS_DEPLOYMENTS; d++) {
216219
caches[d].clear();
217220
}

src/versionbits.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define BITCOIN_VERSIONBITS_H
77

88
#include <chain.h>
9+
#include <sync.h>
10+
911
#include <map>
1012

1113
/** What block version to use for new blocks (pre versionbits) */
@@ -75,7 +77,8 @@ class AbstractThresholdConditionChecker {
7577
* keyed by the bit position used to signal support. */
7678
struct VersionBitsCache
7779
{
78-
ThresholdConditionCache caches[Consensus::MAX_VERSION_BITS_DEPLOYMENTS];
80+
Mutex mutex;
81+
ThresholdConditionCache caches[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] GUARDED_BY(mutex);
7982

8083
void Clear();
8184
};

0 commit comments

Comments
 (0)