Skip to content

Commit fc684ad

Browse files
committed
Use accurate memory for flushing decisions
1 parent 046392d commit fc684ad

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ bool AppInit2(boost::thread_group& threadGroup)
10671067
nTotalCache -= nBlockTreeDBCache;
10681068
size_t nCoinDBCache = nTotalCache / 2; // use half of the remaining cache for coindb cache
10691069
nTotalCache -= nCoinDBCache;
1070-
nCoinCacheSize = nTotalCache / 300; // coins in memory require around 300 bytes
1070+
nCoinCacheUsage = nTotalCache;
10711071

10721072
bool fLoaded = false;
10731073
while (!fLoaded) {

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ bool fPruneMode = false;
5757
bool fIsBareMultisigStd = true;
5858
bool fCheckBlockIndex = false;
5959
bool fCheckpointsEnabled = true;
60-
unsigned int nCoinCacheSize = 5000;
60+
size_t nCoinCacheUsage = 5000 * 300;
6161
uint64_t nPruneTarget = 0;
6262

6363
/** Fees smaller than this (in satoshi) are considered zero fee (for relaying and mining) */
@@ -1894,7 +1894,7 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
18941894
}
18951895
}
18961896
if ((mode == FLUSH_STATE_ALWAYS) ||
1897-
((mode == FLUSH_STATE_PERIODIC || mode == FLUSH_STATE_IF_NEEDED) && pcoinsTip->GetCacheSize() > nCoinCacheSize) ||
1897+
((mode == FLUSH_STATE_PERIODIC || mode == FLUSH_STATE_IF_NEEDED) && pcoinsTip->DynamicMemoryUsage() > nCoinCacheUsage) ||
18981898
(mode == FLUSH_STATE_PERIODIC && GetTimeMicros() > nLastWrite + DATABASE_WRITE_INTERVAL * 1000000) ||
18991899
fFlushForPrune) {
19001900
// Typical CCoins structures on disk are around 100 bytes in size.
@@ -3197,7 +3197,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
31973197
}
31983198
}
31993199
// check level 3: check for inconsistencies during memory-only disconnect of tip blocks
3200-
if (nCheckLevel >= 3 && pindex == pindexState && (coins.GetCacheSize() + pcoinsTip->GetCacheSize()) <= nCoinCacheSize) {
3200+
if (nCheckLevel >= 3 && pindex == pindexState && (coins.DynamicMemoryUsage() + pcoinsTip->DynamicMemoryUsage()) <= nCoinCacheUsage) {
32013201
bool fClean = true;
32023202
if (!DisconnectBlock(block, state, pindex, coins, &fClean))
32033203
return error("VerifyDB(): *** irrecoverable inconsistency in block data at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());

src/main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ extern bool fTxIndex;
119119
extern bool fIsBareMultisigStd;
120120
extern bool fCheckBlockIndex;
121121
extern bool fCheckpointsEnabled;
122-
extern unsigned int nCoinCacheSize;
122+
extern size_t nCoinCacheUsage;
123123
extern CFeeRate minRelayTxFee;
124124

125125
/** Best header we've seen so far (used for getheaders queries' starting points). */

0 commit comments

Comments
 (0)