mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
[wallet] Don't hold cs_LastBlockFile while calling setBestChain
cs_LastBlockFile shouldn't be held while calling wallet functions.
This commit is contained in:
parent
2376bfcf24
commit
83f1ec33ce
@ -1863,13 +1863,17 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
|
||||
*/
|
||||
bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &state, FlushStateMode mode, int nManualPruneHeight) {
|
||||
int64_t nMempoolUsage = mempool.DynamicMemoryUsage();
|
||||
LOCK2(cs_main, cs_LastBlockFile);
|
||||
LOCK(cs_main);
|
||||
static int64_t nLastWrite = 0;
|
||||
static int64_t nLastFlush = 0;
|
||||
static int64_t nLastSetChain = 0;
|
||||
std::set<int> setFilesToPrune;
|
||||
bool fFlushForPrune = false;
|
||||
bool fDoFullFlush = false;
|
||||
int64_t nNow = 0;
|
||||
try {
|
||||
{
|
||||
LOCK(cs_LastBlockFile);
|
||||
if (fPruneMode && (fCheckForPruning || nManualPruneHeight > 0) && !fReindex) {
|
||||
if (nManualPruneHeight > 0) {
|
||||
FindFilesToPruneManual(setFilesToPrune, nManualPruneHeight);
|
||||
@ -1885,7 +1889,7 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
|
||||
}
|
||||
}
|
||||
}
|
||||
int64_t nNow = GetTimeMicros();
|
||||
nNow = GetTimeMicros();
|
||||
// Avoid writing/flushing immediately after startup.
|
||||
if (nLastWrite == 0) {
|
||||
nLastWrite = nNow;
|
||||
@ -1908,7 +1912,7 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
|
||||
// It's been very long since we flushed the cache. Do this infrequently, to optimize cache usage.
|
||||
bool fPeriodicFlush = mode == FLUSH_STATE_PERIODIC && nNow > nLastFlush + (int64_t)DATABASE_FLUSH_INTERVAL * 1000000;
|
||||
// Combine all conditions that result in a full cache flush.
|
||||
bool fDoFullFlush = (mode == FLUSH_STATE_ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune;
|
||||
fDoFullFlush = (mode == FLUSH_STATE_ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune;
|
||||
// Write blocks and block index to disk.
|
||||
if (fDoFullFlush || fPeriodicWrite) {
|
||||
// Depend on nMinDiskSpace to ensure we can write block index
|
||||
@ -1953,6 +1957,7 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
|
||||
return AbortNode(state, "Failed to write to coin database");
|
||||
nLastFlush = nNow;
|
||||
}
|
||||
}
|
||||
if (fDoFullFlush || ((mode == FLUSH_STATE_ALWAYS || mode == FLUSH_STATE_PERIODIC) && nNow > nLastSetChain + (int64_t)DATABASE_WRITE_INTERVAL * 1000000)) {
|
||||
// Update best block in wallet (so we can detect restored wallets).
|
||||
GetMainSignals().SetBestChain(chainActive.GetLocator());
|
||||
|
Loading…
Reference in New Issue
Block a user