Part of: #24303 Depends on: #24322
The GetUTXOStats
function has 2 codepaths:
- One which queries the
CoinStatsIndex
for the UTXO hash - One which actually performs the hashing
For libbitcoinkernel
, the only place where we call GetUTXOStats
is in PopulateAndValidateSnapshots
, which uses the SHA256D
hash, and is therefore unable to use the CoinStatsIndex
since that only provides MuHash
hashes. Not that I think indices necessarily belong in libbitcoinkernel
anyway.
This PR separates these 2 aforementioned codepaths of GetUTXOStats
, uses the hashing codepath in PopulateAndValidateSnapshots
, and removes the need to link in index/coinstatsindex.cpp
and node/coinstats.cpp
.
Logistically, this PR:
- Extracts out the
index_requested
andhash_type
members ofCoinStats
, which served as “in-params” toGetUTXOStats
embedded within theCoinStats
struct. This allowsCoinStats
to only consist of “out-param” members, and be returned byGetUTXOStats
without needing to be an “in-out” param - Introduce the purely virtual
UTXOHashers
class, with 3 implementations:SHA256DHasher
,MuHashHasher
, andNullHasher
. These replace the existing template-based polymorphism. - Split
GetUTXOStats
into:CalculateUTXOStatsWithHasher(UTXOHasher&, ...)
, andLookupUTXOStatsWithIndex(CoinStatsIndex&, ...)
- Use
CalculateUTXOStatsWithHasher
directly where appropriate (src/validation.cpp
andsrc/fuzz
) - Move
GetUTXOStats
torpc/blockchain
, which is the only place that depends onGetUTXOStats
’s weird fallback behaviour - Move
LookupUTXOStatsWithIndex
toindex/coinstatsindex
Code organization:
src/
kernel/
→ only contains the hashing codepathcoinstats.cpp
→ hashing codepath implementationscoinstats.h
→ header forkernel/coinstats.cpp
index/
→ only contains the index codepathcoinstatsindex.cpp
→ index codepath implementationscoinstatsindex.h
validation.cpp
→ only uses the hashing codepathrpc/blockchain.cpp
→ uses both the hashing and index codepath, oldGetUTXOStats
fallback logic moved here as statictest/fuzz/coins_view.cpp
→ only uses the hashing codepath
TODOs:
- Commit messages could be fleshed out more
Would love any feedback!