Coverage Report

Created: 2025-06-10 13:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/bitcoin/src/coins.cpp
Line
Count
Source
1
// Copyright (c) 2012-2022 The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#include <coins.h>
6
7
#include <consensus/consensus.h>
8
#include <logging.h>
9
#include <random.h>
10
#include <util/trace.h>
11
12
TRACEPOINT_SEMAPHORE(utxocache, add);
13
TRACEPOINT_SEMAPHORE(utxocache, spent);
14
TRACEPOINT_SEMAPHORE(utxocache, uncache);
15
16
0
std::optional<Coin> CCoinsView::GetCoin(const COutPoint& outpoint) const { return std::nullopt; }
17
0
uint256 CCoinsView::GetBestBlock() const { return uint256(); }
18
0
std::vector<uint256> CCoinsView::GetHeadBlocks() const { return std::vector<uint256>(); }
19
0
bool CCoinsView::BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashBlock) { return false; }
20
0
std::unique_ptr<CCoinsViewCursor> CCoinsView::Cursor() const { return nullptr; }
21
22
bool CCoinsView::HaveCoin(const COutPoint &outpoint) const
23
0
{
24
0
    return GetCoin(outpoint).has_value();
25
0
}
26
27
5.69M
CCoinsViewBacked::CCoinsViewBacked(CCoinsView *viewIn) : base(viewIn) { }
28
4.86M
std::optional<Coin> CCoinsViewBacked::GetCoin(const COutPoint& outpoint) const { return base->GetCoin(outpoint); }
29
0
bool CCoinsViewBacked::HaveCoin(const COutPoint &outpoint) const { return base->HaveCoin(outpoint); }
30
93.4k
uint256 CCoinsViewBacked::GetBestBlock() const { return base->GetBestBlock(); }
31
0
std::vector<uint256> CCoinsViewBacked::GetHeadBlocks() const { return base->GetHeadBlocks(); }
32
460k
void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; }
33
29.2k
bool CCoinsViewBacked::BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashBlock) { return base->BatchWrite(cursor, hashBlock); }
34
0
std::unique_ptr<CCoinsViewCursor> CCoinsViewBacked::Cursor() const { return base->Cursor(); }
35
0
size_t CCoinsViewBacked::EstimateSize() const { return base->EstimateSize(); }
36
37
CCoinsViewCache::CCoinsViewCache(CCoinsView* baseIn, bool deterministic) :
38
5.28M
    CCoinsViewBacked(baseIn), m_deterministic(deterministic),
39
5.28M
    cacheCoins(0, SaltedOutpointHasher(/*deterministic=*/deterministic), CCoinsMap::key_equal{}, &m_cache_coins_memory_resource)
40
5.28M
{
41
5.28M
    m_sentinel.second.SelfRef(m_sentinel);
42
5.28M
}
43
44
16.4M
size_t CCoinsViewCache::DynamicMemoryUsage() const {
45
16.4M
    return memusage::DynamicUsage(cacheCoins) + cachedCoinsUsage;
46
16.4M
}
47
48
17.4M
CCoinsMap::iterator CCoinsViewCache::FetchCoin(const COutPoint &outpoint) const {
49
17.4M
    const auto [ret, inserted] = cacheCoins.try_emplace(outpoint);
50
17.4M
    if (inserted) {
  Branch (50:9): [True: 10.2M, False: 7.15M]
51
10.2M
        if (auto coin{base->GetCoin(outpoint)}) {
  Branch (51:18): [True: 527k, False: 9.72M]
52
527k
            ret->second.coin = std::move(*coin);
53
527k
            cachedCoinsUsage += ret->second.coin.DynamicMemoryUsage();
54
527k
            if (ret->second.coin.IsSpent()) { // TODO GetCoin cannot return spent coins
  Branch (54:17): [True: 0, False: 527k]
55
                // The parent only has an empty entry for this outpoint; we can consider our version as fresh.
56
0
                CCoinsCacheEntry::SetFresh(*ret, m_sentinel);
57
0
            }
58
9.72M
        } else {
59
9.72M
            cacheCoins.erase(ret);
60
9.72M
            return cacheCoins.end();
61
9.72M
        }
62
10.2M
    }
63
7.67M
    return ret;
64
17.4M
}
65
66
std::optional<Coin> CCoinsViewCache::GetCoin(const COutPoint& outpoint) const
67
5.42M
{
68
5.42M
    if (auto it{FetchCoin(outpoint)}; it != cacheCoins.end() && !it->second.coin.IsSpent()) return it->second.coin;
  Branch (68:39): [True: 559k, False: 4.86M]
  Branch (68:39): [True: 555k, False: 4.86M]
  Branch (68:65): [True: 555k, False: 4.31k]
69
4.86M
    return std::nullopt;
70
5.42M
}
71
72
6.11M
void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possible_overwrite) {
73
6.11M
    assert(!coin.IsSpent());
  Branch (73:5): [True: 6.11M, False: 0]
74
6.11M
    if (coin.out.scriptPubKey.IsUnspendable()) return;
  Branch (74:9): [True: 2.34M, False: 3.76M]
75
3.76M
    CCoinsMap::iterator it;
76
3.76M
    bool inserted;
77
3.76M
    std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());
78
3.76M
    bool fresh = false;
79
3.76M
    if (!inserted) {
  Branch (79:9): [True: 0, False: 3.76M]
80
0
        cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
81
0
    }
82
3.76M
    if (!possible_overwrite) {
  Branch (82:9): [True: 1.53M, False: 2.22M]
83
1.53M
        if (!it->second.coin.IsSpent()) {
  Branch (83:13): [True: 0, False: 1.53M]
84
0
            throw std::logic_error("Attempted to overwrite an unspent coin (when possible_overwrite is false)");
85
0
        }
86
        // If the coin exists in this cache as a spent coin and is DIRTY, then
87
        // its spentness hasn't been flushed to the parent cache. We're
88
        // re-adding the coin to this cache now but we can't mark it as FRESH.
89
        // If we mark it FRESH and then spend it before the cache is flushed
90
        // we would remove it from this cache and would never flush spentness
91
        // to the parent cache.
92
        //
93
        // Re-adding a spent coin can happen in the case of a re-org (the coin
94
        // is 'spent' when the block adding it is disconnected and then
95
        // re-added when it is also added in a newly connected block).
96
        //
97
        // If the coin doesn't exist in the current cache, or is spent but not
98
        // DIRTY, then it can be marked FRESH.
99
1.53M
        fresh = !it->second.IsDirty();
100
1.53M
    }
101
3.76M
    it->second.coin = std::move(coin);
102
3.76M
    CCoinsCacheEntry::SetDirty(*it, m_sentinel);
103
3.76M
    if (fresh) CCoinsCacheEntry::SetFresh(*it, m_sentinel);
  Branch (103:9): [True: 1.53M, False: 2.22M]
104
3.76M
    cachedCoinsUsage += it->second.coin.DynamicMemoryUsage();
105
3.76M
    TRACEPOINT(utxocache, add,
106
3.76M
           outpoint.hash.data(),
107
3.76M
           (uint32_t)outpoint.n,
108
3.76M
           (uint32_t)it->second.coin.nHeight,
109
3.76M
           (int64_t)it->second.coin.out.nValue,
110
3.76M
           (bool)it->second.coin.IsCoinBase());
111
3.76M
}
112
113
0
void CCoinsViewCache::EmplaceCoinInternalDANGER(COutPoint&& outpoint, Coin&& coin) {
114
0
    cachedCoinsUsage += coin.DynamicMemoryUsage();
115
0
    auto [it, inserted] = cacheCoins.try_emplace(std::move(outpoint), std::move(coin));
116
0
    if (inserted) CCoinsCacheEntry::SetDirty(*it, m_sentinel);
  Branch (116:9): [True: 0, False: 0]
117
0
}
118
119
3.72M
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check_for_overwrite) {
120
3.72M
    bool fCoinbase = tx.IsCoinBase();
121
3.72M
    const Txid& txid = tx.GetHash();
122
9.82M
    for (size_t i = 0; i < tx.vout.size(); ++i) {
  Branch (122:24): [True: 6.09M, False: 3.72M]
123
6.09M
        bool overwrite = check_for_overwrite ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
  Branch (123:26): [True: 0, False: 6.09M]
124
        // Coinbase transactions can always be overwritten, in order to correctly
125
        // deal with the pre-BIP30 occurrences of duplicate coinbase transactions.
126
6.09M
        cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite);
127
6.09M
    }
128
3.72M
}
129
130
1.60M
bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
131
1.60M
    CCoinsMap::iterator it = FetchCoin(outpoint);
132
1.60M
    if (it == cacheCoins.end()) return false;
  Branch (132:9): [True: 0, False: 1.60M]
133
1.60M
    cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
134
1.60M
    TRACEPOINT(utxocache, spent,
135
1.60M
           outpoint.hash.data(),
136
1.60M
           (uint32_t)outpoint.n,
137
1.60M
           (uint32_t)it->second.coin.nHeight,
138
1.60M
           (int64_t)it->second.coin.out.nValue,
139
1.60M
           (bool)it->second.coin.IsCoinBase());
140
1.60M
    if (moveout) {
  Branch (140:9): [True: 36.9k, False: 1.56M]
141
36.9k
        *moveout = std::move(it->second.coin);
142
36.9k
    }
143
1.60M
    if (it->second.IsFresh()) {
  Branch (143:9): [True: 1.15M, False: 450k]
144
1.15M
        cacheCoins.erase(it);
145
1.15M
    } else {
146
450k
        CCoinsCacheEntry::SetDirty(*it, m_sentinel);
147
450k
        it->second.coin.Clear();
148
450k
    }
149
1.60M
    return true;
150
1.60M
}
151
152
static const Coin coinEmpty;
153
154
2.20M
const Coin& CCoinsViewCache::AccessCoin(const COutPoint &outpoint) const {
155
2.20M
    CCoinsMap::const_iterator it = FetchCoin(outpoint);
156
2.20M
    if (it == cacheCoins.end()) {
  Branch (156:9): [True: 0, False: 2.20M]
157
0
        return coinEmpty;
158
2.20M
    } else {
159
2.20M
        return it->second.coin;
160
2.20M
    }
161
2.20M
}
162
163
8.17M
bool CCoinsViewCache::HaveCoin(const COutPoint &outpoint) const {
164
8.17M
    CCoinsMap::const_iterator it = FetchCoin(outpoint);
165
8.17M
    return (it != cacheCoins.end() && !it->second.coin.IsSpent());
  Branch (165:13): [True: 3.30M, False: 4.86M]
  Branch (165:39): [True: 3.30M, False: 193]
166
8.17M
}
167
168
764k
bool CCoinsViewCache::HaveCoinInCache(const COutPoint &outpoint) const {
169
764k
    CCoinsMap::const_iterator it = cacheCoins.find(outpoint);
170
764k
    return (it != cacheCoins.end() && !it->second.coin.IsSpent());
  Branch (170:13): [True: 32.2k, False: 732k]
  Branch (170:39): [True: 32.0k, False: 189]
171
764k
}
172
173
4.72M
uint256 CCoinsViewCache::GetBestBlock() const {
174
4.72M
    if (hashBlock.IsNull())
  Branch (174:9): [True: 2.33M, False: 2.38M]
175
2.33M
        hashBlock = base->GetBestBlock();
176
4.72M
    return hashBlock;
177
4.72M
}
178
179
2.24M
void CCoinsViewCache::SetBestBlock(const uint256 &hashBlockIn) {
180
2.24M
    hashBlock = hashBlockIn;
181
2.24M
}
182
183
2.24M
bool CCoinsViewCache::BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashBlockIn) {
184
4.48M
    for (auto it{cursor.Begin()}; it != cursor.End(); it = cursor.NextAndMaybeErase(*it)) {
  Branch (184:35): [True: 2.24M, False: 2.24M]
185
        // Ignore non-dirty entries (optimization).
186
2.24M
        if (!it->second.IsDirty()) {
  Branch (186:13): [True: 0, False: 2.24M]
187
0
            continue;
188
0
        }
189
2.24M
        CCoinsMap::iterator itUs = cacheCoins.find(it->first);
190
2.24M
        if (itUs == cacheCoins.end()) {
  Branch (190:13): [True: 2.22M, False: 13.3k]
191
            // The parent cache does not have an entry, while the child cache does.
192
            // We can ignore it if it's both spent and FRESH in the child
193
2.22M
            if (!(it->second.IsFresh() && it->second.coin.IsSpent())) {
  Branch (193:19): [True: 4.63k, False: 2.22M]
  Branch (193:43): [True: 0, False: 4.63k]
194
                // Create the coin in the parent cache, move the data up
195
                // and mark it as dirty.
196
2.22M
                itUs = cacheCoins.try_emplace(it->first).first;
197
2.22M
                CCoinsCacheEntry& entry{itUs->second};
198
2.22M
                if (cursor.WillErase(*it)) {
  Branch (198:21): [True: 2.22M, False: 0]
199
                    // Since this entry will be erased,
200
                    // we can move the coin into us instead of copying it
201
2.22M
                    entry.coin = std::move(it->second.coin);
202
2.22M
                } else {
203
0
                    entry.coin = it->second.coin;
204
0
                }
205
2.22M
                cachedCoinsUsage += entry.coin.DynamicMemoryUsage();
206
2.22M
                CCoinsCacheEntry::SetDirty(*itUs, m_sentinel);
207
                // We can mark it FRESH in the parent if it was FRESH in the child
208
                // Otherwise it might have just been flushed from the parent's cache
209
                // and already exist in the grandparent
210
2.22M
                if (it->second.IsFresh()) CCoinsCacheEntry::SetFresh(*itUs, m_sentinel);
  Branch (210:21): [True: 4.63k, False: 2.22M]
211
2.22M
            }
212
2.22M
        } else {
213
            // Found the entry in the parent cache
214
13.3k
            if (it->second.IsFresh() && !itUs->second.coin.IsSpent()) {
  Branch (214:17): [True: 1.69k, False: 11.6k]
  Branch (214:41): [True: 0, False: 1.69k]
215
                // The coin was marked FRESH in the child cache, but the coin
216
                // exists in the parent cache. If this ever happens, it means
217
                // the FRESH flag was misapplied and there is a logic error in
218
                // the calling code.
219
0
                throw std::logic_error("FRESH flag misapplied to coin that exists in parent cache");
220
0
            }
221
222
13.3k
            if (itUs->second.IsFresh() && it->second.coin.IsSpent()) {
  Branch (222:17): [True: 2.13k, False: 11.2k]
  Branch (222:43): [True: 2.13k, False: 0]
223
                // The grandparent cache does not have an entry, and the coin
224
                // has been spent. We can just delete it from the parent cache.
225
2.13k
                cachedCoinsUsage -= itUs->second.coin.DynamicMemoryUsage();
226
2.13k
                cacheCoins.erase(itUs);
227
11.2k
            } else {
228
                // A normal modification.
229
11.2k
                cachedCoinsUsage -= itUs->second.coin.DynamicMemoryUsage();
230
11.2k
                if (cursor.WillErase(*it)) {
  Branch (230:21): [True: 11.2k, False: 0]
231
                    // Since this entry will be erased,
232
                    // we can move the coin into us instead of copying it
233
11.2k
                    itUs->second.coin = std::move(it->second.coin);
234
11.2k
                } else {
235
0
                    itUs->second.coin = it->second.coin;
236
0
                }
237
11.2k
                cachedCoinsUsage += itUs->second.coin.DynamicMemoryUsage();
238
11.2k
                CCoinsCacheEntry::SetDirty(*itUs, m_sentinel);
239
                // NOTE: It isn't safe to mark the coin as FRESH in the parent
240
                // cache. If it already existed and was spent in the parent
241
                // cache then marking it FRESH would prevent that spentness
242
                // from being flushed to the grandparent.
243
11.2k
            }
244
13.3k
        }
245
2.24M
    }
246
2.24M
    hashBlock = hashBlockIn;
247
2.24M
    return true;
248
2.24M
}
249
250
2.26M
bool CCoinsViewCache::Flush() {
251
2.26M
    auto cursor{CoinsViewCacheCursor(cachedCoinsUsage, m_sentinel, cacheCoins, /*will_erase=*/true)};
252
2.26M
    bool fOk = base->BatchWrite(cursor, hashBlock);
253
2.26M
    if (fOk) {
  Branch (253:9): [True: 2.26M, False: 0]
254
2.26M
        cacheCoins.clear();
255
2.26M
        ReallocateCache();
256
2.26M
    }
257
2.26M
    cachedCoinsUsage = 0;
258
2.26M
    return fOk;
259
2.26M
}
260
261
bool CCoinsViewCache::Sync()
262
7.02k
{
263
7.02k
    auto cursor{CoinsViewCacheCursor(cachedCoinsUsage, m_sentinel, cacheCoins, /*will_erase=*/false)};
264
7.02k
    bool fOk = base->BatchWrite(cursor, hashBlock);
265
7.02k
    if (fOk) {
  Branch (265:9): [True: 7.02k, False: 0]
266
7.02k
        if (m_sentinel.second.Next() != &m_sentinel) {
  Branch (266:13): [True: 0, False: 7.02k]
267
            /* BatchWrite must clear flags of all entries */
268
0
            throw std::logic_error("Not all unspent flagged entries were cleared");
269
0
        }
270
7.02k
    }
271
7.02k
    return fOk;
272
7.02k
}
273
274
void CCoinsViewCache::Uncache(const COutPoint& hash)
275
359k
{
276
359k
    CCoinsMap::iterator it = cacheCoins.find(hash);
277
359k
    if (it != cacheCoins.end() && !it->second.IsDirty() && !it->second.IsFresh()) {
  Branch (277:9): [True: 4.14k, False: 354k]
  Branch (277:9): [True: 3.98k, False: 355k]
  Branch (277:35): [True: 3.98k, False: 156]
  Branch (277:60): [True: 3.98k, False: 0]
278
3.98k
        cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
279
3.98k
        TRACEPOINT(utxocache, uncache,
280
3.98k
               hash.hash.data(),
281
3.98k
               (uint32_t)hash.n,
282
3.98k
               (uint32_t)it->second.coin.nHeight,
283
3.98k
               (int64_t)it->second.coin.out.nValue,
284
3.98k
               (bool)it->second.coin.IsCoinBase());
285
3.98k
        cacheCoins.erase(it);
286
3.98k
    }
287
359k
}
288
289
9.39M
unsigned int CCoinsViewCache::GetCacheSize() const {
290
9.39M
    return cacheCoins.size();
291
9.39M
}
292
293
bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const
294
1.56M
{
295
1.56M
    if (!tx.IsCoinBase()) {
  Branch (295:9): [True: 1.56M, False: 0]
296
3.22M
        for (unsigned int i = 0; i < tx.vin.size(); i++) {
  Branch (296:34): [True: 1.66M, False: 1.56M]
297
1.66M
            if (!HaveCoin(tx.vin[i].prevout)) {
  Branch (297:17): [True: 1.51k, False: 1.66M]
298
1.51k
                return false;
299
1.51k
            }
300
1.66M
        }
301
1.56M
    }
302
1.56M
    return true;
303
1.56M
}
304
305
void CCoinsViewCache::ReallocateCache()
306
2.26M
{
307
    // Cache should be empty when we're calling this.
308
2.26M
    assert(cacheCoins.size() == 0);
  Branch (308:5): [True: 2.26M, False: 0]
309
2.26M
    cacheCoins.~CCoinsMap();
310
2.26M
    m_cache_coins_memory_resource.~CCoinsMapMemoryResource();
311
2.26M
    ::new (&m_cache_coins_memory_resource) CCoinsMapMemoryResource{};
312
2.26M
    ::new (&cacheCoins) CCoinsMap{0, SaltedOutpointHasher{/*deterministic=*/m_deterministic}, CCoinsMap::key_equal{}, &m_cache_coins_memory_resource};
313
2.26M
}
314
315
void CCoinsViewCache::SanityCheck() const
316
0
{
317
0
    size_t recomputed_usage = 0;
318
0
    size_t count_flagged = 0;
319
0
    for (const auto& [_, entry] : cacheCoins) {
  Branch (319:33): [True: 0, False: 0]
320
0
        unsigned attr = 0;
321
0
        if (entry.IsDirty()) attr |= 1;
  Branch (321:13): [True: 0, False: 0]
322
0
        if (entry.IsFresh()) attr |= 2;
  Branch (322:13): [True: 0, False: 0]
323
0
        if (entry.coin.IsSpent()) attr |= 4;
  Branch (323:13): [True: 0, False: 0]
324
        // Only 5 combinations are possible.
325
0
        assert(attr != 2 && attr != 4 && attr != 7);
  Branch (325:9): [True: 0, False: 0]
  Branch (325:9): [True: 0, False: 0]
  Branch (325:9): [True: 0, False: 0]
  Branch (325:9): [True: 0, False: 0]
326
327
        // Recompute cachedCoinsUsage.
328
0
        recomputed_usage += entry.coin.DynamicMemoryUsage();
329
330
        // Count the number of entries we expect in the linked list.
331
0
        if (entry.IsDirty() || entry.IsFresh()) ++count_flagged;
  Branch (331:13): [True: 0, False: 0]
  Branch (331:32): [True: 0, False: 0]
332
0
    }
333
    // Iterate over the linked list of flagged entries.
334
0
    size_t count_linked = 0;
335
0
    for (auto it = m_sentinel.second.Next(); it != &m_sentinel; it = it->second.Next()) {
  Branch (335:46): [True: 0, False: 0]
336
        // Verify linked list integrity.
337
0
        assert(it->second.Next()->second.Prev() == it);
  Branch (337:9): [True: 0, False: 0]
338
0
        assert(it->second.Prev()->second.Next() == it);
  Branch (338:9): [True: 0, False: 0]
339
        // Verify they are actually flagged.
340
0
        assert(it->second.IsDirty() || it->second.IsFresh());
  Branch (340:9): [True: 0, False: 0]
  Branch (340:9): [True: 0, False: 0]
  Branch (340:9): [True: 0, False: 0]
341
        // Count the number of entries actually in the list.
342
0
        ++count_linked;
343
0
    }
344
0
    assert(count_linked == count_flagged);
  Branch (344:5): [True: 0, False: 0]
345
0
    assert(recomputed_usage == cachedCoinsUsage);
  Branch (345:5): [True: 0, False: 0]
346
0
}
347
348
static const size_t MIN_TRANSACTION_OUTPUT_WEIGHT = WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut());
349
static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT;
350
351
const Coin& AccessByTxid(const CCoinsViewCache& view, const Txid& txid)
352
0
{
353
0
    COutPoint iter(txid, 0);
354
0
    while (iter.n < MAX_OUTPUTS_PER_BLOCK) {
  Branch (354:12): [True: 0, False: 0]
355
0
        const Coin& alternate = view.AccessCoin(iter);
356
0
        if (!alternate.IsSpent()) return alternate;
  Branch (356:13): [True: 0, False: 0]
357
0
        ++iter.n;
358
0
    }
359
0
    return coinEmpty;
360
0
}
361
362
template <typename ReturnType, typename Func>
363
static ReturnType ExecuteBackedWrapper(Func func, const std::vector<std::function<void()>>& err_callbacks)
364
4.86M
{
365
4.86M
    try {
366
4.86M
        return func();
367
4.86M
    } catch(const std::runtime_error& e) {
368
0
        for (const auto& f : err_callbacks) {
  Branch (368:28): [True: 0, False: 0]
  Branch (368:28): [True: 0, False: 0]
369
0
            f();
370
0
        }
371
0
        LogError("Error reading from database: %s\n", e.what());
372
        // Starting the shutdown sequence and returning false to the caller would be
373
        // interpreted as 'entry not found' (as opposed to unable to read data), and
374
        // could lead to invalid interpretation. Just exit immediately, as we can't
375
        // continue anyway, and all writes should be atomic.
376
0
        std::abort();
377
0
    }
378
4.86M
}
coins.cpp:std::optional<Coin> ExecuteBackedWrapper<std::optional<Coin>, CCoinsViewErrorCatcher::GetCoin(COutPoint const&) const::$_0>(CCoinsViewErrorCatcher::GetCoin(COutPoint const&) const::$_0, std::vector<std::function<void ()>, std::allocator<std::function<void ()> > > const&)
Line
Count
Source
364
4.86M
{
365
4.86M
    try {
366
4.86M
        return func();
367
4.86M
    } catch(const std::runtime_error& e) {
368
0
        for (const auto& f : err_callbacks) {
  Branch (368:28): [True: 0, False: 0]
369
0
            f();
370
0
        }
371
0
        LogError("Error reading from database: %s\n", e.what());
372
        // Starting the shutdown sequence and returning false to the caller would be
373
        // interpreted as 'entry not found' (as opposed to unable to read data), and
374
        // could lead to invalid interpretation. Just exit immediately, as we can't
375
        // continue anyway, and all writes should be atomic.
376
0
        std::abort();
377
0
    }
378
4.86M
}
Unexecuted instantiation: coins.cpp:bool ExecuteBackedWrapper<bool, CCoinsViewErrorCatcher::HaveCoin(COutPoint const&) const::$_0>(CCoinsViewErrorCatcher::HaveCoin(COutPoint const&) const::$_0, std::vector<std::function<void ()>, std::allocator<std::function<void ()> > > const&)
379
380
std::optional<Coin> CCoinsViewErrorCatcher::GetCoin(const COutPoint& outpoint) const
381
4.86M
{
382
4.86M
    return ExecuteBackedWrapper<std::optional<Coin>>([&]() { return CCoinsViewBacked::GetCoin(outpoint); }, m_err_callbacks);
383
4.86M
}
384
385
bool CCoinsViewErrorCatcher::HaveCoin(const COutPoint& outpoint) const
386
0
{
387
0
    return ExecuteBackedWrapper<bool>([&]() { return CCoinsViewBacked::HaveCoin(outpoint); }, m_err_callbacks);
388
0
}