MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ComputeUTXOStats

Function ComputeUTXOStats

src/kernel/coinstats.cpp:111–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109//! Calculate statistics about the unspent transaction output set
110template <typename T>
111static std::optional<CCoinsStats> ComputeUTXOStats(T hash_obj, CCoinsView* view, node::BlockManager& blockman, const std::function<void()>& interruption_point)
112{
113 std::unique_ptr<CCoinsViewCursor> pcursor;
114 CBlockIndex* pindex;
115 {
116 LOCK(::cs_main);
117 pcursor = view->Cursor();
118 pindex = blockman.LookupBlockIndex(pcursor->GetBestBlock());
119 }
120 assert(pcursor);
121 CCoinsStats stats{Assert(pindex)->nHeight, pindex->GetBlockHash()};
122
123 Txid prevkey;
124 std::map<uint32_t, Coin> outputs;
125 while (pcursor->Valid()) {
126 if (interruption_point) interruption_point();
127 COutPoint key;
128 Coin coin;
129 if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
130 if (!outputs.empty() && key.hash != prevkey) {
131 ApplyStats(stats, outputs);
132 ApplyHash(hash_obj, prevkey, outputs);
133 outputs.clear();
134 }
135 prevkey = key.hash;
136 outputs[key.n] = std::move(coin);
137 stats.coins_count++;
138 } else {
139 LogError("%s: unable to read value\n", __func__);
140 return std::nullopt;
141 }
142 pcursor->Next();
143 }
144 if (!outputs.empty()) {
145 ApplyStats(stats, outputs);
146 ApplyHash(hash_obj, prevkey, outputs);
147 }
148
149 FinalizeHash(hash_obj, stats);
150
151 stats.nDiskSize = view->EstimateSize();
152 return stats;
153}
154
155std::optional<CCoinsStats> ComputeUTXOStats(CoinStatsHashType hash_type, CCoinsView* view, node::BlockManager& blockman, const std::function<void()>& interruption_point)
156{

Callers 5

MaybeValidateSnapshotMethod · 0.85
FUZZ_TARGETFunction · 0.85
sanity_check_snapshotFunction · 0.85
GetUTXOStatsFunction · 0.85

Calls 14

ApplyStatsFunction · 0.85
ApplyHashFunction · 0.85
FinalizeHashFunction · 0.85
LookupBlockIndexMethod · 0.80
CursorMethod · 0.45
GetBestBlockMethod · 0.45
GetBlockHashMethod · 0.45
ValidMethod · 0.45
GetKeyMethod · 0.45
GetValueMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45

Tested by 2

FUZZ_TARGETFunction · 0.68
sanity_check_snapshotFunction · 0.68