Skip to content

Commit 2c0f019

Browse files
committed
Merge pull request #4505
d4d3fbd Do not flush the cache after every block outside of IBD (Pieter Wuille)
2 parents 1f5e8fe + d4d3fbd commit 2c0f019

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
@@ -111,7 +111,12 @@ bool CCoinsViewCache::SetCoins(const uint256 &txid, const CCoins &coins) {
111111
}
112112

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

117122
uint256 CCoinsViewCache::GetBestBlock() {

src/main.cpp

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

0 commit comments

Comments
 (0)