fix: make nCoinCacheUsage std::atomic to close an adaptive-dbcache data race
The scheduled AdjustCoinCacheForMemoryPressure task writes nCoinCacheUsage from the scheduler thread holding no lock, while cs_main-holding threads (FlushStateToDisk, VerifyDB) read it -- an unsynchronized read/write of a non-atomic size_t (C++ UB). Make it std::atomic<size_t>; correct the comment that incorrectly described the access as lock-free/race-free. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -109,7 +109,7 @@ bool fIsBareMultisigStd = true;
|
|||||||
bool fCheckBlockIndex = false;
|
bool fCheckBlockIndex = false;
|
||||||
bool fCheckpointsEnabled = true;
|
bool fCheckpointsEnabled = true;
|
||||||
bool fCoinbaseEnforcedProtectionEnabled = true;
|
bool fCoinbaseEnforcedProtectionEnabled = true;
|
||||||
size_t nCoinCacheUsage = 5000 * 300;
|
std::atomic<size_t> nCoinCacheUsage(5000 * 300);
|
||||||
uint64_t nPruneTarget = 0;
|
uint64_t nPruneTarget = 0;
|
||||||
// If the tip is older than this (in seconds), the node is considered to be in initial block download.
|
// If the tip is older than this (in seconds), the node is considered to be in initial block download.
|
||||||
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
|
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
#include "txmempool.h"
|
#include "txmempool.h"
|
||||||
#include "uint256.h"
|
#include "uint256.h"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -189,7 +190,7 @@ extern bool fCheckpointsEnabled;
|
|||||||
// TODO: remove this flag by structuring our code such that
|
// TODO: remove this flag by structuring our code such that
|
||||||
// it is unneeded for testing
|
// it is unneeded for testing
|
||||||
extern bool fCoinbaseEnforcedProtectionEnabled;
|
extern bool fCoinbaseEnforcedProtectionEnabled;
|
||||||
extern size_t nCoinCacheUsage;
|
extern std::atomic<size_t> nCoinCacheUsage;
|
||||||
extern CFeeRate minRelayTxFee;
|
extern CFeeRate minRelayTxFee;
|
||||||
extern int64_t nMaxTipAge;
|
extern int64_t nMaxTipAge;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user