Skip to content

[draft] TXO check (BIP30) optimization in coins cache#9

Draft
optout21 wants to merge 1 commit into
masterfrom
2605-txo-check
Draft

[draft] TXO check (BIP30) optimization in coins cache#9
optout21 wants to merge 1 commit into
masterfrom
2605-txo-check

Conversation

@optout21

@optout21 optout21 commented May 4, 2026

Copy link
Copy Markdown
Owner

For the coins DB cache, a large portion of cache misses are due to new TXO checks. Since new TXOs are not existing anywhere, their lookup results in a cache miss, and they are also checked in the DB. Therefore this is a performance-critical pathway.

In CCoinsViewCache lookups are optimistic: first they are checked in the cache, and if they are not present, they are inserted. If they are not found in the lower layer, they are removed from the cache.

The new TXO checks are not optimal, because the cache map is is mutated (inserted & erased) unnecessarily.

Also, the HaveCoin check is turned into a GetCoin at the DB level (first into PeekCoin at the CoinsViewOverlay level, the to GetCoin), which results in a full Read in the DB, as opposed to only Exists.

The following changes are made as an optimization:

  • Introduce a HaveCoinDontCache variant, similar to HaveCoin with the difference that it does not cache. In case if it needs to go to the lower layer, it does a HaveCoinDontCache instead of a GetCoin.
  • In validation.cpp, in ConnectBlock, HaveCoinDontCache is used for TXO checks.

@optout21
optout21 force-pushed the 2605-txo-check branch 4 times, most recently from 027310d to 5d5a881 Compare May 5, 2026 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant