Skip to content

Commit d4d3fbd

Browse files
committed
Do not flush the cache after every block outside of IBD
1 parent d3165ed commit d4d3fbd

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/coins.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ bool CCoinsViewCache::SetCoins(const uint256 &txid, const CCoins &coins) {
107107
}
108108

109109
bool CCoinsViewCache::HaveCoins(const uint256 &txid) {
110-
return FetchCoins(txid) != cacheCoins.end();
110+
CCoinsMap::iterator it = FetchCoins(txid);
111+
// We're using vtx.empty() instead of IsPruned here for performance reasons,
112+
// as we only care about the case where an transaction was replaced entirely
113+
// in a reorganization (which wipes vout entirely, as opposed to spending
114+
// which just cleans individual outputs).
115+
return (it != cacheCoins.end() && !it->second.vout.empty());
111116
}
112117

113118
uint256 CCoinsViewCache::GetBestBlock() {

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
19151915
// Update the on-disk chain state.
19161916
bool static WriteChainState(CValidationState &state) {
19171917
static int64_t nLastWrite = 0;
1918-
if (!IsInitialBlockDownload() || pcoinsTip->GetCacheSize() > nCoinCacheSize || GetTimeMicros() > nLastWrite + 600*1000000) {
1918+
if (pcoinsTip->GetCacheSize() > nCoinCacheSize || (!IsInitialBlockDownload() && GetTimeMicros() > nLastWrite + 600*1000000)) {
19191919
// Typical CCoins structures on disk are around 100 bytes in size.
19201920
// Pushing a new one to the database can cause it to be written
19211921
// twice (once in the log, and once in the tables). This is already

0 commit comments

Comments
 (0)