mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 18:53:23 -03:00
versionbits: Use dedicated lock instead of cs_main
This commit is contained in:
parent
36a4ba0aaa
commit
eccd736f3d
4 changed files with 11 additions and 7 deletions
|
@ -1361,7 +1361,7 @@ static void BuriedForkDescPushBack(UniValue& softforks, const std::string &name,
|
|||
softforks.pushKV(name, rv);
|
||||
}
|
||||
|
||||
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)
|
||||
static void BIP9SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue& softforks, const std::string &name, const Consensus::Params& consensusParams, Consensus::DeploymentPos id)
|
||||
{
|
||||
// For BIP9 deployments.
|
||||
// Deployments that are never active are hidden.
|
||||
|
|
|
@ -1606,11 +1606,10 @@ void StopScriptCheckWorkerThreads()
|
|||
scriptcheckqueue.StopWorkerThreads();
|
||||
}
|
||||
|
||||
VersionBitsCache versionbitscache GUARDED_BY(cs_main);
|
||||
VersionBitsCache versionbitscache;
|
||||
|
||||
int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
int32_t nVersion = VERSIONBITS_TOP_BITS;
|
||||
|
||||
for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {
|
||||
|
@ -1659,9 +1658,8 @@ static bool IsScriptWitnessEnabled(const Consensus::Params& params)
|
|||
return params.SegwitHeight != std::numeric_limits<int>::max();
|
||||
}
|
||||
|
||||
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& consensusparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& consensusparams)
|
||||
{
|
||||
unsigned int flags = SCRIPT_VERIFY_NONE;
|
||||
|
||||
// BIP16 didn't become active until Apr 1 2012 (on mainnet, and
|
||||
|
|
|
@ -192,6 +192,7 @@ public:
|
|||
|
||||
ThresholdState VersionBitsState(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache)
|
||||
{
|
||||
LOCK(cache.mutex);
|
||||
return VersionBitsConditionChecker(pos).GetStateFor(pindexPrev, params, cache.caches[pos]);
|
||||
}
|
||||
|
||||
|
@ -202,6 +203,7 @@ BIP9Stats VersionBitsStatistics(const CBlockIndex* pindexPrev, const Consensus::
|
|||
|
||||
int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache)
|
||||
{
|
||||
LOCK(cache.mutex);
|
||||
return VersionBitsConditionChecker(pos).GetStateSinceHeightFor(pindexPrev, params, cache.caches[pos]);
|
||||
}
|
||||
|
||||
|
@ -212,6 +214,7 @@ uint32_t VersionBitsMask(const Consensus::Params& params, Consensus::DeploymentP
|
|||
|
||||
void VersionBitsCache::Clear()
|
||||
{
|
||||
LOCK(mutex);
|
||||
for (unsigned int d = 0; d < Consensus::MAX_VERSION_BITS_DEPLOYMENTS; d++) {
|
||||
caches[d].clear();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#define BITCOIN_VERSIONBITS_H
|
||||
|
||||
#include <chain.h>
|
||||
#include <sync.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
/** What block version to use for new blocks (pre versionbits) */
|
||||
|
@ -75,7 +77,8 @@ public:
|
|||
* keyed by the bit position used to signal support. */
|
||||
struct VersionBitsCache
|
||||
{
|
||||
ThresholdConditionCache caches[Consensus::MAX_VERSION_BITS_DEPLOYMENTS];
|
||||
Mutex mutex;
|
||||
ThresholdConditionCache caches[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] GUARDED_BY(mutex);
|
||||
|
||||
void Clear();
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue