Coverage Report

Created: 2026-07-14 18:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/bitcoin/src/coins.cpp
Line
Count
Source
1
// Copyright (c) 2012-present 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 <random.h>
9
#include <uint256.h>
10
#include <util/log.h>
11
#include <util/trace.h>
12
13
TRACEPOINT_SEMAPHORE(utxocache, add);
14
TRACEPOINT_SEMAPHORE(utxocache, spent);
15
TRACEPOINT_SEMAPHORE(utxocache, uncache);
16
17
CoinsViewEmpty& CoinsViewEmpty::Get()
18
2.52M
{
19
2.52M
    static CoinsViewEmpty instance;
20
2.52M
    return instance;
21
2.52M
}
22
23
std::optional<Coin> CCoinsViewCache::PeekCoin(const COutPoint& outpoint) const
24
570k
{
25
570k
    if (auto it{cacheCoins.find(outpoint)}; it != cacheCoins.end()) {
  Branch (25:45): [True: 49.6k, False: 521k]
26
49.6k
        return it->second.coin.IsSpent() ? std::nullopt : std::optional{it->second.coin};
  Branch (26:16): [True: 16.6k, False: 33.0k]
27
49.6k
    }
28
521k
    return base->PeekCoin(outpoint);
29
570k
}
30
31
CCoinsViewCache::CCoinsViewCache(CCoinsView* in_base, bool deterministic) :
32
3.99M
    CCoinsViewBacked(in_base), m_deterministic(deterministic),
33
3.99M
    cacheCoins(0, SaltedOutpointHasher(/*deterministic=*/deterministic), CCoinsMap::key_equal{}, &m_cache_coins_memory_resource)
34
3.99M
{
35
3.99M
    m_sentinel.second.SelfRef(m_sentinel);
36
3.99M
}
37
38
5.00M
size_t CCoinsViewCache::DynamicMemoryUsage() const {
39
5.00M
    return memusage::DynamicUsage(cacheCoins) + cachedCoinsUsage;
40
5.00M
}
41
42
std::optional<Coin> CCoinsViewCache::FetchCoinFromBase(const COutPoint& outpoint) const
43
5.72M
{
44
5.72M
    return base->GetCoin(outpoint);
45
5.72M
}
46
47
71.6M
CCoinsMap::iterator CCoinsViewCache::FetchCoin(const COutPoint &outpoint) const {
48
71.6M
    const auto [ret, inserted] = cacheCoins.try_emplace(outpoint);
49
71.6M
    if (inserted) {
  Branch (49:9): [True: 6.29M, False: 65.3M]
50
6.29M
        if (auto coin{FetchCoinFromBase(outpoint)}) {
  Branch (50:18): [True: 2.69M, False: 3.59M]
51
2.69M
            ret->second.coin = std::move(*coin);
52
2.69M
            cachedCoinsUsage += ret->second.coin.DynamicMemoryUsage();
53
2.69M
            Assert(!ret->second.coin.IsSpent());
54
3.59M
        } else {
55
3.59M
            cacheCoins.erase(ret);
56
3.59M
            return cacheCoins.end();
57
3.59M
        }
58
6.29M
    }
59
68.0M
    return ret;
60
71.6M
}
61
62
std::optional<Coin> CCoinsViewCache::GetCoin(const COutPoint& outpoint) const
63
4.31M
{
64
4.31M
    if (auto it{FetchCoin(outpoint)}; it != cacheCoins.end() && !it->second.coin.IsSpent()) return it->second.coin;
  Branch (64:39): [True: 2.79M, False: 1.52M]
  Branch (64:39): [True: 2.78M, False: 1.53M]
  Branch (64:65): [True: 2.78M, False: 10.8k]
65
1.53M
    return std::nullopt;
66
4.31M
}
67
68
15.2M
void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possible_overwrite) {
69
15.2M
    assert(!coin.IsSpent());
  Branch (69:5): [True: 15.2M, False: 0]
70
15.2M
    if (coin.out.scriptPubKey.IsUnspendable()) return;
  Branch (70:9): [True: 520k, False: 14.7M]
71
14.7M
    CCoinsMap::iterator it;
72
14.7M
    bool inserted;
73
14.7M
    std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());
74
14.7M
    bool fresh = false;
75
14.7M
    if (!possible_overwrite) {
  Branch (75:9): [True: 14.6M, False: 84.7k]
76
14.6M
        if (!it->second.coin.IsSpent()) {
  Branch (76:13): [True: 0, False: 14.6M]
77
0
            throw std::logic_error("Attempted to overwrite an unspent coin (when possible_overwrite is false)");
78
0
        }
79
        // If the coin exists in this cache as a spent coin and is DIRTY, then
80
        // its spentness hasn't been flushed to the parent cache. We're
81
        // re-adding the coin to this cache now but we can't mark it as FRESH.
82
        // If we mark it FRESH and then spend it before the cache is flushed
83
        // we would remove it from this cache and would never flush spentness
84
        // to the parent cache.
85
        //
86
        // Re-adding a spent coin can happen in the case of a re-org (the coin
87
        // is 'spent' when the block adding it is disconnected and then
88
        // re-added when it is also added in a newly connected block).
89
        //
90
        // If the coin doesn't exist in the current cache, or is spent but not
91
        // DIRTY, then it can be marked FRESH.
92
14.6M
        fresh = !it->second.IsDirty();
93
14.6M
    }
94
14.7M
    if (!inserted) {
  Branch (94:9): [True: 0, False: 14.7M]
95
0
        Assume(TrySub(m_dirty_count, it->second.IsDirty()));
96
0
        Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage()));
97
0
    }
98
14.7M
    it->second.coin = std::move(coin);
99
14.7M
    CCoinsCacheEntry::SetDirty(*it, m_sentinel);
100
14.7M
    ++m_dirty_count;
101
14.7M
    if (fresh) CCoinsCacheEntry::SetFresh(*it, m_sentinel);
  Branch (101:9): [True: 14.6M, False: 84.7k]
102
14.7M
    cachedCoinsUsage += it->second.coin.DynamicMemoryUsage();
103
14.7M
    TRACEPOINT(utxocache, add,
104
14.7M
           outpoint.hash.data(),
105
14.7M
           (uint32_t)outpoint.n,
106
14.7M
           (uint32_t)it->second.coin.nHeight,
107
14.7M
           (int64_t)it->second.coin.out.nValue,
108
14.7M
           (bool)it->second.coin.IsCoinBase());
109
14.7M
}
110
111
0
void CCoinsViewCache::EmplaceCoinInternalDANGER(COutPoint&& outpoint, Coin&& coin) {
112
0
    const auto mem_usage{coin.DynamicMemoryUsage()};
113
0
    auto [it, inserted] = cacheCoins.try_emplace(std::move(outpoint), std::move(coin));
114
0
    if (inserted) {
  Branch (114:9): [True: 0, False: 0]
115
0
        CCoinsCacheEntry::SetDirty(*it, m_sentinel);
116
0
        ++m_dirty_count;
117
0
        cachedCoinsUsage += mem_usage;
118
0
    }
119
0
}
120
121
14.4M
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check_for_overwrite) {
122
14.4M
    bool fCoinbase = tx.IsCoinBase();
123
14.4M
    const Txid& txid = tx.GetHash();
124
29.6M
    for (size_t i = 0; i < tx.vout.size(); ++i) {
  Branch (124:24): [True: 15.1M, False: 14.4M]
125
15.1M
        bool overwrite = check_for_overwrite ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
  Branch (125:26): [True: 0, False: 15.1M]
126
        // Coinbase transactions can always be overwritten, in order to correctly
127
        // deal with the pre-BIP30 occurrences of duplicate coinbase transactions.
128
15.1M
        cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite);
129
15.1M
    }
130
14.4M
}
131
132
14.7M
bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
133
14.7M
    CCoinsMap::iterator it = FetchCoin(outpoint);
134
14.7M
    if (it == cacheCoins.end()) return false;
  Branch (134:9): [True: 0, False: 14.7M]
135
14.7M
    Assume(TrySub(m_dirty_count, it->second.IsDirty()));
136
14.7M
    Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage()));
137
14.7M
    TRACEPOINT(utxocache, spent,
138
14.7M
           outpoint.hash.data(),
139
14.7M
           (uint32_t)outpoint.n,
140
14.7M
           (uint32_t)it->second.coin.nHeight,
141
14.7M
           (int64_t)it->second.coin.out.nValue,
142
14.7M
           (bool)it->second.coin.IsCoinBase());
143
14.7M
    if (moveout) {
  Branch (143:9): [True: 258k, False: 14.5M]
144
258k
        *moveout = std::move(it->second.coin);
145
258k
    }
146
14.7M
    if (it->second.IsFresh()) {
  Branch (146:9): [True: 12.6M, False: 2.11M]
147
12.6M
        cacheCoins.erase(it);
148
12.6M
    } else {
149
2.11M
        CCoinsCacheEntry::SetDirty(*it, m_sentinel);
150
2.11M
        ++m_dirty_count;
151
2.11M
        it->second.coin.Clear();
152
2.11M
    }
153
14.7M
    return true;
154
14.7M
}
155
156
static const Coin coinEmpty;
157
158
20.0M
const Coin& CCoinsViewCache::AccessCoin(const COutPoint &outpoint) const {
159
20.0M
    CCoinsMap::const_iterator it = FetchCoin(outpoint);
160
20.0M
    if (it == cacheCoins.end()) {
  Branch (160:9): [True: 0, False: 20.0M]
161
0
        return coinEmpty;
162
20.0M
    } else {
163
20.0M
        return it->second.coin;
164
20.0M
    }
165
20.0M
}
166
167
bool CCoinsViewCache::HaveCoin(const COutPoint& outpoint) const
168
32.4M
{
169
32.4M
    CCoinsMap::const_iterator it = FetchCoin(outpoint);
170
32.4M
    return (it != cacheCoins.end() && !it->second.coin.IsSpent());
  Branch (170:13): [True: 30.3M, False: 2.07M]
  Branch (170:39): [True: 30.3M, False: 2.27k]
171
32.4M
}
172
173
3.58M
bool CCoinsViewCache::HaveCoinInCache(const COutPoint &outpoint) const {
174
3.58M
    CCoinsMap::const_iterator it = cacheCoins.find(outpoint);
175
3.58M
    return (it != cacheCoins.end() && !it->second.coin.IsSpent());
  Branch (175:13): [True: 137k, False: 3.44M]
  Branch (175:39): [True: 135k, False: 1.79k]
176
3.58M
}
177
178
2.01M
uint256 CCoinsViewCache::GetBestBlock() const {
179
2.01M
    if (m_block_hash.IsNull())
  Branch (179:9): [True: 575k, False: 1.43M]
180
575k
        m_block_hash = base->GetBestBlock();
181
2.01M
    return m_block_hash;
182
2.01M
}
183
184
void CCoinsViewCache::SetBestBlock(const uint256& in_block_hash)
185
184k
{
186
184k
    m_block_hash = in_block_hash;
187
184k
}
188
189
void CCoinsViewCache::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& in_block_hash)
190
64.3k
{
191
240k
    for (auto it{cursor.Begin()}; it != cursor.End(); it = cursor.NextAndMaybeErase(*it)) {
  Branch (191:35): [True: 176k, False: 64.3k]
192
176k
        if (!it->second.IsDirty()) { // TODO a cursor can only contain dirty entries
  Branch (192:13): [True: 0, False: 176k]
193
0
            continue;
194
0
        }
195
176k
        auto [itUs, inserted]{cacheCoins.try_emplace(it->first)};
196
176k
        if (inserted) {
  Branch (196:13): [True: 87.5k, False: 88.6k]
197
87.5k
            if (it->second.IsFresh() && it->second.coin.IsSpent()) {
  Branch (197:17): [True: 32.9k, False: 54.6k]
  Branch (197:41): [True: 0, False: 32.9k]
198
0
                cacheCoins.erase(itUs); // TODO fresh coins should have been removed at spend
199
87.5k
            } else {
200
                // The parent cache does not have an entry, while the child cache does.
201
                // Move the data up and mark it as dirty.
202
87.5k
                CCoinsCacheEntry& entry{itUs->second};
203
87.5k
                assert(entry.coin.DynamicMemoryUsage() == 0);
  Branch (203:17): [True: 87.5k, False: 0]
204
87.5k
                if (cursor.WillErase(*it)) {
  Branch (204:21): [True: 87.5k, False: 0]
205
                    // Since this entry will be erased,
206
                    // we can move the coin into us instead of copying it
207
87.5k
                    entry.coin = std::move(it->second.coin);
208
87.5k
                } else {
209
0
                    entry.coin = it->second.coin;
210
0
                }
211
87.5k
                CCoinsCacheEntry::SetDirty(*itUs, m_sentinel);
212
87.5k
                ++m_dirty_count;
213
87.5k
                cachedCoinsUsage += entry.coin.DynamicMemoryUsage();
214
                // We can mark it FRESH in the parent if it was FRESH in the child
215
                // Otherwise it might have just been flushed from the parent's cache
216
                // and already exist in the grandparent
217
87.5k
                if (it->second.IsFresh()) CCoinsCacheEntry::SetFresh(*itUs, m_sentinel);
  Branch (217:21): [True: 32.9k, False: 54.6k]
218
87.5k
            }
219
88.6k
        } else {
220
            // Found the entry in the parent cache
221
88.6k
            if (it->second.IsFresh() && !itUs->second.coin.IsSpent()) {
  Branch (221:17): [True: 11.0k, False: 77.6k]
  Branch (221:41): [True: 0, False: 11.0k]
222
                // The coin was marked FRESH in the child cache, but the coin
223
                // exists in the parent cache. If this ever happens, it means
224
                // the FRESH flag was misapplied and there is a logic error in
225
                // the calling code.
226
0
                throw std::logic_error("FRESH flag misapplied to coin that exists in parent cache");
227
0
            }
228
229
88.6k
            if (itUs->second.IsFresh() && it->second.coin.IsSpent()) {
  Branch (229:17): [True: 19.2k, False: 69.3k]
  Branch (229:43): [True: 19.2k, False: 0]
230
                // The grandparent cache does not have an entry, and the coin
231
                // has been spent. We can just delete it from the parent cache.
232
19.2k
                Assume(TrySub(m_dirty_count, itUs->second.IsDirty()));
233
19.2k
                Assume(TrySub(cachedCoinsUsage, itUs->second.coin.DynamicMemoryUsage()));
234
19.2k
                cacheCoins.erase(itUs);
235
69.3k
            } else {
236
                // A normal modification.
237
69.3k
                Assume(TrySub(cachedCoinsUsage, itUs->second.coin.DynamicMemoryUsage()));
238
69.3k
                if (cursor.WillErase(*it)) {
  Branch (238:21): [True: 69.3k, False: 0]
239
                    // Since this entry will be erased,
240
                    // we can move the coin into us instead of copying it
241
69.3k
                    itUs->second.coin = std::move(it->second.coin);
242
69.3k
                } else {
243
0
                    itUs->second.coin = it->second.coin;
244
0
                }
245
69.3k
                cachedCoinsUsage += itUs->second.coin.DynamicMemoryUsage();
246
69.3k
                if (!itUs->second.IsDirty()) {
  Branch (246:21): [True: 8.54k, False: 60.8k]
247
8.54k
                    CCoinsCacheEntry::SetDirty(*itUs, m_sentinel);
248
8.54k
                    ++m_dirty_count;
249
8.54k
                }
250
                // NOTE: It isn't safe to mark the coin as FRESH in the parent
251
                // cache. If it already existed and was spent in the parent
252
                // cache then marking it FRESH would prevent that spentness
253
                // from being flushed to the grandparent.
254
69.3k
            }
255
88.6k
        }
256
176k
    }
257
64.3k
    SetBestBlock(in_block_hash);
258
64.3k
}
259
260
void CCoinsViewCache::Flush(bool reallocate_cache)
261
364k
{
262
364k
    auto cursor{CoinsViewCacheCursor(m_dirty_count, m_sentinel, cacheCoins, /*will_erase=*/true)};
263
364k
    base->BatchWrite(cursor, m_block_hash);
264
364k
    Assume(m_dirty_count == 0);
265
364k
    cacheCoins.clear();
266
364k
    if (reallocate_cache) {
  Branch (266:9): [True: 300k, False: 64.3k]
267
300k
        ReallocateCache();
268
300k
    }
269
364k
    cachedCoinsUsage = 0;
270
364k
}
271
272
void CCoinsViewCache::Sync()
273
5.44k
{
274
5.44k
    auto cursor{CoinsViewCacheCursor(m_dirty_count, m_sentinel, cacheCoins, /*will_erase=*/false)};
275
5.44k
    base->BatchWrite(cursor, m_block_hash);
276
5.44k
    Assume(m_dirty_count == 0);
277
5.44k
    if (m_sentinel.second.Next() != &m_sentinel) {
  Branch (277:9): [True: 0, False: 5.44k]
278
        /* BatchWrite must clear flags of all entries */
279
0
        throw std::logic_error("Not all unspent flagged entries were cleared");
280
0
    }
281
5.44k
}
282
283
void CCoinsViewCache::Reset() noexcept
284
55.7k
{
285
55.7k
    cacheCoins.clear();
286
55.7k
    cachedCoinsUsage = 0;
287
55.7k
    m_dirty_count = 0;
288
55.7k
    SetBestBlock(uint256::ZERO);
289
55.7k
}
290
291
void CCoinsViewCache::Uncache(const COutPoint& hash)
292
2.02M
{
293
2.02M
    CCoinsMap::iterator it = cacheCoins.find(hash);
294
2.02M
    if (it != cacheCoins.end() && !it->second.IsDirty()) {
  Branch (294:9): [True: 450k, False: 1.57M]
  Branch (294:9): [True: 449k, False: 1.58M]
  Branch (294:35): [True: 449k, False: 1.73k]
295
449k
        Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage()));
296
449k
        TRACEPOINT(utxocache, uncache,
297
449k
               hash.hash.data(),
298
449k
               (uint32_t)hash.n,
299
449k
               (uint32_t)it->second.coin.nHeight,
300
449k
               (int64_t)it->second.coin.out.nValue,
301
449k
               (bool)it->second.coin.IsCoinBase());
302
449k
        cacheCoins.erase(it);
303
449k
    }
304
2.02M
}
305
306
2.53M
unsigned int CCoinsViewCache::GetCacheSize() const {
307
2.53M
    return cacheCoins.size();
308
2.53M
}
309
310
bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const
311
14.9M
{
312
14.9M
    if (!tx.IsCoinBase()) {
  Branch (312:9): [True: 14.9M, False: 0]
313
30.1M
        for (unsigned int i = 0; i < tx.vin.size(); i++) {
  Branch (313:34): [True: 15.2M, False: 14.9M]
314
15.2M
            if (!HaveCoin(tx.vin[i].prevout)) {
  Branch (314:17): [True: 8.93k, False: 15.2M]
315
8.93k
                return false;
316
8.93k
            }
317
15.2M
        }
318
14.9M
    }
319
14.9M
    return true;
320
14.9M
}
321
322
void CCoinsViewCache::ReallocateCache()
323
300k
{
324
    // Cache should be empty when we're calling this.
325
300k
    assert(cacheCoins.size() == 0);
  Branch (325:5): [True: 300k, False: 0]
326
300k
    cacheCoins.~CCoinsMap();
327
300k
    m_cache_coins_memory_resource.~CCoinsMapMemoryResource();
328
300k
    ::new (&m_cache_coins_memory_resource) CCoinsMapMemoryResource{};
329
300k
    ::new (&cacheCoins) CCoinsMap{0, SaltedOutpointHasher{/*deterministic=*/m_deterministic}, CCoinsMap::key_equal{}, &m_cache_coins_memory_resource};
330
300k
}
331
332
void CCoinsViewCache::SanityCheck() const
333
0
{
334
0
    size_t recomputed_usage = 0;
335
0
    size_t count_dirty = 0;
336
0
    for (const auto& [_, entry] : cacheCoins) {
  Branch (336:33): [True: 0, False: 0]
337
0
        if (entry.coin.IsSpent()) {
  Branch (337:13): [True: 0, False: 0]
338
0
            assert(entry.IsDirty() && !entry.IsFresh()); // A spent coin must be dirty and cannot be fresh
  Branch (338:13): [True: 0, False: 0]
  Branch (338:13): [True: 0, False: 0]
  Branch (338:13): [True: 0, False: 0]
339
0
        } else {
340
0
            assert(entry.IsDirty() || !entry.IsFresh()); // An unspent coin must not be fresh if not dirty
  Branch (340:13): [True: 0, False: 0]
  Branch (340:13): [True: 0, False: 0]
  Branch (340:13): [True: 0, False: 0]
341
0
        }
342
343
        // Recompute cachedCoinsUsage.
344
0
        recomputed_usage += entry.coin.DynamicMemoryUsage();
345
346
        // Count the number of entries we expect in the linked list.
347
0
        if (entry.IsDirty()) ++count_dirty;
  Branch (347:13): [True: 0, False: 0]
348
0
    }
349
    // Iterate over the linked list of flagged entries.
350
0
    size_t count_linked = 0;
351
0
    for (auto it = m_sentinel.second.Next(); it != &m_sentinel; it = it->second.Next()) {
  Branch (351:46): [True: 0, False: 0]
352
        // Verify linked list integrity.
353
0
        assert(it->second.Next()->second.Prev() == it);
  Branch (353:9): [True: 0, False: 0]
354
0
        assert(it->second.Prev()->second.Next() == it);
  Branch (354:9): [True: 0, False: 0]
355
        // Verify they are actually flagged.
356
0
        assert(it->second.IsDirty());
  Branch (356:9): [True: 0, False: 0]
357
        // Count the number of entries actually in the list.
358
0
        ++count_linked;
359
0
    }
360
0
    assert(count_dirty == count_linked && count_dirty == m_dirty_count);
  Branch (360:5): [True: 0, False: 0]
  Branch (360:5): [True: 0, False: 0]
  Branch (360:5): [True: 0, False: 0]
361
0
    assert(recomputed_usage == cachedCoinsUsage);
  Branch (361:5): [True: 0, False: 0]
362
0
}
363
364
static const uint64_t MIN_TRANSACTION_OUTPUT_WEIGHT{WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut())};
365
static const uint64_t MAX_OUTPUTS_PER_BLOCK{MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT};
366
367
const Coin& AccessByTxid(const CCoinsViewCache& view, const Txid& txid)
368
0
{
369
0
    COutPoint iter(txid, 0);
370
0
    while (iter.n < MAX_OUTPUTS_PER_BLOCK) {
  Branch (370:12): [True: 0, False: 0]
371
0
        const Coin& alternate = view.AccessCoin(iter);
372
0
        if (!alternate.IsSpent()) return alternate;
  Branch (372:13): [True: 0, False: 0]
373
0
        ++iter.n;
374
0
    }
375
0
    return coinEmpty;
376
0
}
377
378
template <typename ReturnType, typename Func>
379
static ReturnType ExecuteBackedWrapper(Func func, const std::vector<std::function<void()>>& err_callbacks)
380
2.04M
{
381
2.04M
    try {
382
2.04M
        return func();
383
2.04M
    } catch(const std::runtime_error& e) {
384
0
        for (const auto& f : err_callbacks) {
  Branch (384:28): [True: 0, False: 0]
  Branch (384:28): [True: 0, False: 0]
  Branch (384:28): [True: 0, False: 0]
385
0
            f();
386
0
        }
387
0
        LogError("Error reading from database: %s\n", e.what());
388
        // Starting the shutdown sequence and returning false to the caller would be
389
        // interpreted as 'entry not found' (as opposed to unable to read data), and
390
        // could lead to invalid interpretation. Just exit immediately, as we can't
391
        // continue anyway, and all writes should be atomic.
392
0
        std::abort();
393
0
    }
394
2.04M
}
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
380
1.52M
{
381
1.52M
    try {
382
1.52M
        return func();
383
1.52M
    } catch(const std::runtime_error& e) {
384
0
        for (const auto& f : err_callbacks) {
  Branch (384:28): [True: 0, False: 0]
385
0
            f();
386
0
        }
387
0
        LogError("Error reading from database: %s\n", e.what());
388
        // Starting the shutdown sequence and returning false to the caller would be
389
        // interpreted as 'entry not found' (as opposed to unable to read data), and
390
        // could lead to invalid interpretation. Just exit immediately, as we can't
391
        // continue anyway, and all writes should be atomic.
392
0
        std::abort();
393
0
    }
394
1.52M
}
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&)
coins.cpp:std::optional<Coin> ExecuteBackedWrapper<std::optional<Coin>, CCoinsViewErrorCatcher::PeekCoin(COutPoint const&) const::$_0>(CCoinsViewErrorCatcher::PeekCoin(COutPoint const&) const::$_0, std::vector<std::function<void ()>, std::allocator<std::function<void ()> > > const&)
Line
Count
Source
380
521k
{
381
521k
    try {
382
521k
        return func();
383
521k
    } catch(const std::runtime_error& e) {
384
0
        for (const auto& f : err_callbacks) {
  Branch (384:28): [True: 0, False: 0]
385
0
            f();
386
0
        }
387
0
        LogError("Error reading from database: %s\n", e.what());
388
        // Starting the shutdown sequence and returning false to the caller would be
389
        // interpreted as 'entry not found' (as opposed to unable to read data), and
390
        // could lead to invalid interpretation. Just exit immediately, as we can't
391
        // continue anyway, and all writes should be atomic.
392
0
        std::abort();
393
0
    }
394
521k
}
395
396
std::optional<Coin> CCoinsViewErrorCatcher::GetCoin(const COutPoint& outpoint) const
397
1.52M
{
398
1.52M
    return ExecuteBackedWrapper<std::optional<Coin>>([&]() { return CCoinsViewBacked::GetCoin(outpoint); }, m_err_callbacks);
399
1.52M
}
400
401
bool CCoinsViewErrorCatcher::HaveCoin(const COutPoint& outpoint) const
402
0
{
403
0
    return ExecuteBackedWrapper<bool>([&]() { return CCoinsViewBacked::HaveCoin(outpoint); }, m_err_callbacks);
404
0
}
405
406
std::optional<Coin> CCoinsViewErrorCatcher::PeekCoin(const COutPoint& outpoint) const
407
521k
{
408
521k
    return ExecuteBackedWrapper<std::optional<Coin>>([&]() { return CCoinsViewBacked::PeekCoin(outpoint); }, m_err_callbacks);
409
521k
}