Coverage Report

Created: 2026-07-13 07:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bitcoin-core/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 <primitives/block.h>
9
#include <random.h>
10
#include <uint256.h>
11
#include <util/log.h>
12
#include <util/threadpool.h>
13
#include <util/trace.h>
14
15
#include <ranges>
16
#include <unordered_set>
17
18
TRACEPOINT_SEMAPHORE(utxocache, add);
19
TRACEPOINT_SEMAPHORE(utxocache, spent);
20
TRACEPOINT_SEMAPHORE(utxocache, uncache);
21
22
CoinsViewEmpty& CoinsViewEmpty::Get()
23
4.15M
{
24
4.15M
    static CoinsViewEmpty instance;
25
4.15M
    return instance;
26
4.15M
}
27
28
std::optional<Coin> CCoinsViewCache::PeekCoin(const COutPoint& outpoint) const
29
30.9M
{
30
30.9M
    if (auto it{cacheCoins.find(outpoint)}; it != cacheCoins.end()) {
31
1.21M
        return it->second.coin.IsSpent() ? std::nullopt : std::optional{it->second.coin};
32
1.21M
    }
33
29.7M
    return base->PeekCoin(outpoint);
34
30.9M
}
35
36
CCoinsViewCache::CCoinsViewCache(CCoinsView* in_base, bool deterministic) :
37
3.97M
    CCoinsViewBacked(in_base), m_deterministic(deterministic),
38
3.97M
    cacheCoins(0, SaltedOutpointHasher(/*deterministic=*/deterministic), CCoinsMap::key_equal{}, &m_cache_coins_memory_resource)
39
3.97M
{
40
3.97M
    m_sentinel.second.SelfRef(m_sentinel);
41
3.97M
}
42
43
9.64M
size_t CCoinsViewCache::DynamicMemoryUsage() const {
44
9.64M
    return memusage::DynamicUsage(cacheCoins) + cachedCoinsUsage;
45
9.64M
}
46
47
std::optional<Coin> CCoinsViewCache::FetchCoinFromBase(const COutPoint& outpoint) const
48
16.9M
{
49
16.9M
    return base->GetCoin(outpoint);
50
16.9M
}
51
52
93.2M
CCoinsMap::iterator CCoinsViewCache::FetchCoin(const COutPoint &outpoint) const {
53
93.2M
    const auto [ret, inserted] = cacheCoins.try_emplace(outpoint);
54
93.2M
    if (inserted) {
55
18.4M
        if (auto coin{FetchCoinFromBase(outpoint)}) {
56
9.22M
            ret->second.coin = std::move(*coin);
57
9.22M
            cachedCoinsUsage += ret->second.coin.DynamicMemoryUsage();
58
9.22M
            Assert(!ret->second.coin.IsSpent());
59
9.22M
        } else {
60
9.20M
            cacheCoins.erase(ret);
61
9.20M
            return cacheCoins.end();
62
9.20M
        }
63
18.4M
    }
64
84.0M
    return ret;
65
93.2M
}
66
67
std::optional<Coin> CCoinsViewCache::GetCoin(const COutPoint& outpoint) const
68
34.8M
{
69
34.8M
    if (auto it{FetchCoin(outpoint)}; it != cacheCoins.end() && !it->second.coin.IsSpent()) return it->second.coin;
70
2.75M
    return std::nullopt;
71
34.8M
}
72
73
9.57M
void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possible_overwrite) {
74
9.57M
    assert(!coin.IsSpent());
75
9.57M
    if (coin.out.scriptPubKey.IsUnspendable()) return;
76
8.28M
    CCoinsMap::iterator it;
77
8.28M
    bool inserted;
78
8.28M
    std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());
79
8.28M
    bool fresh = false;
80
8.28M
    if (!possible_overwrite) {
81
6.51M
        if (!it->second.coin.IsSpent()) {
82
0
            throw std::logic_error("Attempted to overwrite an unspent coin (when possible_overwrite is false)");
83
0
        }
84
        // If the coin exists in this cache as a spent coin and is DIRTY, then
85
        // its spentness hasn't been flushed to the parent cache. We're
86
        // re-adding the coin to this cache now but we can't mark it as FRESH.
87
        // If we mark it FRESH and then spend it before the cache is flushed
88
        // we would remove it from this cache and would never flush spentness
89
        // to the parent cache.
90
        //
91
        // Re-adding a spent coin can happen in the case of a re-org (the coin
92
        // is 'spent' when the block adding it is disconnected and then
93
        // re-added when it is also added in a newly connected block).
94
        //
95
        // If the coin doesn't exist in the current cache, or is spent but not
96
        // DIRTY, then it can be marked FRESH.
97
6.51M
        fresh = !it->second.IsDirty();
98
6.51M
    }
99
8.28M
    if (!inserted) {
100
221k
        Assume(TrySub(m_dirty_count, it->second.IsDirty()));
101
221k
        Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage()));
102
221k
    }
103
8.28M
    it->second.coin = std::move(coin);
104
8.28M
    CCoinsCacheEntry::SetDirty(*it, m_sentinel);
105
8.28M
    ++m_dirty_count;
106
8.28M
    if (fresh) CCoinsCacheEntry::SetFresh(*it, m_sentinel);
107
8.28M
    cachedCoinsUsage += it->second.coin.DynamicMemoryUsage();
108
8.28M
    TRACEPOINT(utxocache, add,
109
8.28M
           outpoint.hash.data(),
110
8.28M
           (uint32_t)outpoint.n,
111
8.28M
           (uint32_t)it->second.coin.nHeight,
112
8.28M
           (int64_t)it->second.coin.out.nValue,
113
8.28M
           (bool)it->second.coin.IsCoinBase());
114
8.28M
}
115
116
3.62M
void CCoinsViewCache::EmplaceCoinInternalDANGER(COutPoint&& outpoint, Coin&& coin) {
117
3.62M
    const auto mem_usage{coin.DynamicMemoryUsage()};
118
3.62M
    auto [it, inserted] = cacheCoins.try_emplace(std::move(outpoint), std::move(coin));
119
3.62M
    if (inserted) {
120
230k
        CCoinsCacheEntry::SetDirty(*it, m_sentinel);
121
230k
        ++m_dirty_count;
122
230k
        cachedCoinsUsage += mem_usage;
123
230k
    }
124
3.62M
}
125
126
1.80M
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check_for_overwrite) {
127
1.80M
    bool fCoinbase = tx.IsCoinBase();
128
1.80M
    const Txid& txid = tx.GetHash();
129
10.7M
    for (size_t i = 0; i < tx.vout.size(); ++i) {
130
8.94M
        bool overwrite = check_for_overwrite ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
131
        // Coinbase transactions can always be overwritten, in order to correctly
132
        // deal with the pre-BIP30 occurrences of duplicate coinbase transactions.
133
8.94M
        cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite);
134
8.94M
    }
135
1.80M
}
136
137
1.47M
bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
138
1.47M
    CCoinsMap::iterator it = FetchCoin(outpoint);
139
1.47M
    if (it == cacheCoins.end()) return false;
140
1.02M
    Assume(TrySub(m_dirty_count, it->second.IsDirty()));
141
1.02M
    Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage()));
142
1.02M
    TRACEPOINT(utxocache, spent,
143
1.02M
           outpoint.hash.data(),
144
1.02M
           (uint32_t)outpoint.n,
145
1.02M
           (uint32_t)it->second.coin.nHeight,
146
1.02M
           (int64_t)it->second.coin.out.nValue,
147
1.02M
           (bool)it->second.coin.IsCoinBase());
148
1.02M
    if (moveout) {
149
269k
        *moveout = std::move(it->second.coin);
150
269k
    }
151
1.02M
    if (it->second.IsFresh()) {
152
341k
        cacheCoins.erase(it);
153
682k
    } else {
154
682k
        CCoinsCacheEntry::SetDirty(*it, m_sentinel);
155
682k
        ++m_dirty_count;
156
682k
        it->second.coin.Clear();
157
682k
    }
158
1.02M
    return true;
159
1.47M
}
160
161
static const Coin coinEmpty;
162
163
34.9M
const Coin& CCoinsViewCache::AccessCoin(const COutPoint &outpoint) const {
164
34.9M
    CCoinsMap::const_iterator it = FetchCoin(outpoint);
165
34.9M
    if (it == cacheCoins.end()) {
166
613k
        return coinEmpty;
167
34.3M
    } else {
168
34.3M
        return it->second.coin;
169
34.3M
    }
170
34.9M
}
171
172
bool CCoinsViewCache::HaveCoin(const COutPoint& outpoint) const
173
21.8M
{
174
21.8M
    CCoinsMap::const_iterator it = FetchCoin(outpoint);
175
21.8M
    return (it != cacheCoins.end() && !it->second.coin.IsSpent());
176
21.8M
}
177
178
12.2M
bool CCoinsViewCache::HaveCoinInCache(const COutPoint &outpoint) const {
179
12.2M
    CCoinsMap::const_iterator it = cacheCoins.find(outpoint);
180
12.2M
    return (it != cacheCoins.end() && !it->second.coin.IsSpent());
181
12.2M
}
182
183
7.62M
uint256 CCoinsViewCache::GetBestBlock() const {
184
7.62M
    if (m_block_hash.IsNull())
185
2.64M
        m_block_hash = base->GetBestBlock();
186
7.62M
    return m_block_hash;
187
7.62M
}
188
189
void CCoinsViewCache::SetBestBlock(const uint256& in_block_hash)
190
2.35M
{
191
2.35M
    m_block_hash = in_block_hash;
192
2.35M
}
193
194
void CCoinsViewCache::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& in_block_hash)
195
743k
{
196
1.53M
    for (auto it{cursor.Begin()}; it != cursor.End(); it = cursor.NextAndMaybeErase(*it)) {
197
789k
        if (!it->second.IsDirty()) { // TODO a cursor can only contain dirty entries
198
0
            continue;
199
0
        }
200
789k
        auto [itUs, inserted]{cacheCoins.try_emplace(it->first)};
201
789k
        if (inserted) {
202
751k
            if (it->second.IsFresh() && it->second.coin.IsSpent()) {
203
8.70k
                cacheCoins.erase(itUs); // TODO fresh coins should have been removed at spend
204
742k
            } else {
205
                // The parent cache does not have an entry, while the child cache does.
206
                // Move the data up and mark it as dirty.
207
742k
                CCoinsCacheEntry& entry{itUs->second};
208
742k
                assert(entry.coin.DynamicMemoryUsage() == 0);
209
742k
                if (cursor.WillErase(*it)) {
210
                    // Since this entry will be erased,
211
                    // we can move the coin into us instead of copying it
212
703k
                    entry.coin = std::move(it->second.coin);
213
703k
                } else {
214
38.9k
                    entry.coin = it->second.coin;
215
38.9k
                }
216
742k
                CCoinsCacheEntry::SetDirty(*itUs, m_sentinel);
217
742k
                ++m_dirty_count;
218
742k
                cachedCoinsUsage += entry.coin.DynamicMemoryUsage();
219
                // We can mark it FRESH in the parent if it was FRESH in the child
220
                // Otherwise it might have just been flushed from the parent's cache
221
                // and already exist in the grandparent
222
742k
                if (it->second.IsFresh()) CCoinsCacheEntry::SetFresh(*itUs, m_sentinel);
223
742k
            }
224
751k
        } else {
225
            // Found the entry in the parent cache
226
38.3k
            if (it->second.IsFresh() && !itUs->second.coin.IsSpent()) {
227
                // The coin was marked FRESH in the child cache, but the coin
228
                // exists in the parent cache. If this ever happens, it means
229
                // the FRESH flag was misapplied and there is a logic error in
230
                // the calling code.
231
0
                throw std::logic_error("FRESH flag misapplied to coin that exists in parent cache");
232
0
            }
233
234
38.3k
            if (itUs->second.IsFresh() && it->second.coin.IsSpent()) {
235
                // The grandparent cache does not have an entry, and the coin
236
                // has been spent. We can just delete it from the parent cache.
237
1.15k
                Assume(TrySub(m_dirty_count, itUs->second.IsDirty()));
238
1.15k
                Assume(TrySub(cachedCoinsUsage, itUs->second.coin.DynamicMemoryUsage()));
239
1.15k
                cacheCoins.erase(itUs);
240
37.2k
            } else {
241
                // A normal modification.
242
37.2k
                Assume(TrySub(cachedCoinsUsage, itUs->second.coin.DynamicMemoryUsage()));
243
37.2k
                if (cursor.WillErase(*it)) {
244
                    // Since this entry will be erased,
245
                    // we can move the coin into us instead of copying it
246
28.8k
                    itUs->second.coin = std::move(it->second.coin);
247
28.8k
                } else {
248
8.39k
                    itUs->second.coin = it->second.coin;
249
8.39k
                }
250
37.2k
                cachedCoinsUsage += itUs->second.coin.DynamicMemoryUsage();
251
37.2k
                if (!itUs->second.IsDirty()) {
252
8.23k
                    CCoinsCacheEntry::SetDirty(*itUs, m_sentinel);
253
8.23k
                    ++m_dirty_count;
254
8.23k
                }
255
                // NOTE: It isn't safe to mark the coin as FRESH in the parent
256
                // cache. If it already existed and was spent in the parent
257
                // cache then marking it FRESH would prevent that spentness
258
                // from being flushed to the grandparent.
259
37.2k
            }
260
38.3k
        }
261
789k
    }
262
743k
    SetBestBlock(in_block_hash);
263
743k
}
264
265
void CCoinsViewCache::Flush(bool reallocate_cache)
266
1.45M
{
267
1.45M
    auto cursor{CoinsViewCacheCursor(m_dirty_count, m_sentinel, cacheCoins, /*will_erase=*/true)};
268
1.45M
    base->BatchWrite(cursor, m_block_hash);
269
1.45M
    Assume(m_dirty_count == 0);
270
1.45M
    cacheCoins.clear();
271
1.45M
    if (reallocate_cache) {
272
782k
        ReallocateCache();
273
782k
    }
274
1.45M
    cachedCoinsUsage = 0;
275
1.45M
}
276
277
void CCoinsViewCache::Sync()
278
3.65M
{
279
3.65M
    auto cursor{CoinsViewCacheCursor(m_dirty_count, m_sentinel, cacheCoins, /*will_erase=*/false)};
280
3.65M
    base->BatchWrite(cursor, m_block_hash);
281
3.65M
    Assume(m_dirty_count == 0);
282
3.65M
    if (m_sentinel.second.Next() != &m_sentinel) {
283
        /* BatchWrite must clear flags of all entries */
284
0
        throw std::logic_error("Not all unspent flagged entries were cleared");
285
0
    }
286
3.65M
}
287
288
void CCoinsViewCache::Reset() noexcept
289
900k
{
290
900k
    cacheCoins.clear();
291
900k
    cachedCoinsUsage = 0;
292
900k
    m_dirty_count = 0;
293
900k
    SetBestBlock(uint256::ZERO);
294
900k
}
295
296
void CCoinsViewCache::Uncache(const COutPoint& hash)
297
14.0M
{
298
14.0M
    CCoinsMap::iterator it = cacheCoins.find(hash);
299
14.0M
    if (it != cacheCoins.end() && !it->second.IsDirty()) {
300
4.84M
        Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage()));
301
4.84M
        TRACEPOINT(utxocache, uncache,
302
4.84M
               hash.hash.data(),
303
4.84M
               (uint32_t)hash.n,
304
4.84M
               (uint32_t)it->second.coin.nHeight,
305
4.84M
               (int64_t)it->second.coin.out.nValue,
306
4.84M
               (bool)it->second.coin.IsCoinBase());
307
4.84M
        cacheCoins.erase(it);
308
4.84M
    }
309
14.0M
}
310
311
5.17M
unsigned int CCoinsViewCache::GetCacheSize() const {
312
5.17M
    return cacheCoins.size();
313
5.17M
}
314
315
bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const
316
2.17M
{
317
2.17M
    if (!tx.IsCoinBase()) {
318
9.29M
        for (unsigned int i = 0; i < tx.vin.size(); i++) {
319
7.13M
            if (!HaveCoin(tx.vin[i].prevout)) {
320
13.5k
                return false;
321
13.5k
            }
322
7.13M
        }
323
2.17M
    }
324
2.15M
    return true;
325
2.17M
}
326
327
void CCoinsViewCache::ReallocateCache()
328
782k
{
329
    // Cache should be empty when we're calling this.
330
782k
    assert(cacheCoins.size() == 0);
331
782k
    cacheCoins.~CCoinsMap();
332
782k
    m_cache_coins_memory_resource.~CCoinsMapMemoryResource();
333
782k
    ::new (&m_cache_coins_memory_resource) CCoinsMapMemoryResource{};
334
782k
    ::new (&cacheCoins) CCoinsMap{0, SaltedOutpointHasher{/*deterministic=*/m_deterministic}, CCoinsMap::key_equal{}, &m_cache_coins_memory_resource};
335
782k
}
336
337
void CCoinsViewCache::SanityCheck() const
338
102k
{
339
102k
    size_t recomputed_usage = 0;
340
102k
    size_t count_dirty = 0;
341
123k
    for (const auto& [_, entry] : cacheCoins) {
342
123k
        if (entry.coin.IsSpent()) {
343
11.6k
            assert(entry.IsDirty() && !entry.IsFresh()); // A spent coin must be dirty and cannot be fresh
344
112k
        } else {
345
112k
            assert(entry.IsDirty() || !entry.IsFresh()); // An unspent coin must not be fresh if not dirty
346
112k
        }
347
348
        // Recompute cachedCoinsUsage.
349
123k
        recomputed_usage += entry.coin.DynamicMemoryUsage();
350
351
        // Count the number of entries we expect in the linked list.
352
123k
        if (entry.IsDirty()) ++count_dirty;
353
123k
    }
354
    // Iterate over the linked list of flagged entries.
355
102k
    size_t count_linked = 0;
356
173k
    for (auto it = m_sentinel.second.Next(); it != &m_sentinel; it = it->second.Next()) {
357
        // Verify linked list integrity.
358
70.4k
        assert(it->second.Next()->second.Prev() == it);
359
70.4k
        assert(it->second.Prev()->second.Next() == it);
360
        // Verify they are actually flagged.
361
70.4k
        assert(it->second.IsDirty());
362
        // Count the number of entries actually in the list.
363
70.4k
        ++count_linked;
364
70.4k
    }
365
102k
    assert(count_dirty == count_linked && count_dirty == m_dirty_count);
366
102k
    assert(recomputed_usage == cachedCoinsUsage);
367
102k
}
368
369
CCoinsViewCache::ResetGuard CoinsViewOverlay::StartFetching(const CBlock& block LIFETIMEBOUND) noexcept
370
770k
{
371
770k
    Assert(m_futures.empty());
372
770k
    Assert(m_inputs.empty());
373
770k
    Assert(m_input_head.load(std::memory_order_relaxed) == 0);
374
770k
    Assert(m_input_tail == 0);
375
770k
    if (const auto workers_count{m_thread_pool->WorkersCount()}; workers_count > 0) {
376
        // Loop through the block inputs and set their prevouts in the queue.
377
        // Filter inputs that spend outputs created earlier in the same block. These outputs will be created
378
        // directly in the cache from the tx that creates them, so they will not be requested from a base view.
379
770k
        std::unordered_set<Txid, SaltedTxidHasher> earlier_txids;
380
770k
        earlier_txids.reserve(block.vtx.size());
381
770k
        for (const auto& tx : block.vtx | std::views::drop(1)) {
382
38.0M
            for (const auto& input : tx->vin) {
383
38.0M
                if (!earlier_txids.contains(input.prevout.hash)) m_inputs.emplace_back(input.prevout);
384
38.0M
            }
385
191k
            earlier_txids.emplace(tx->GetHash());
386
191k
        }
387
        // Only submit tasks if we have something to fetch.
388
770k
        if (m_inputs.size()) {
389
1.29M
            std::vector<std::function<void()>> tasks(workers_count, [this] {
390
12.4M
                while (ProcessInput()) {}
391
1.29M
            });
392
161k
            if (auto futures{m_thread_pool->Submit(std::move(tasks))}) {
393
161k
                m_futures = std::move(*futures);
394
161k
            } else {
395
                // Submit can fail if a shared owner of the thread pool outside of this class calls Stop() or
396
                // Interrupt() on a different thread after we call WorkersCount() above. In that case parallel
397
                // fetching will not make progress, so we clear the inputs to fall back to single threaded fetching.
398
0
                LogWarning("Failed to submit prevout fetch tasks; falling back to single-threaded fetching for this block.");
399
0
                m_inputs.clear();
400
0
                StopFetching(); // Assert nothing changed if we failed to start tasks.
401
0
            }
402
161k
        }
403
770k
    }
404
770k
    return CreateResetGuard();
405
770k
}
406
407
static const uint64_t MIN_TRANSACTION_OUTPUT_WEIGHT{WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut())};
408
static const uint64_t MAX_OUTPUTS_PER_BLOCK{MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT};
409
410
const Coin& AccessByTxid(const CCoinsViewCache& view, const Txid& txid)
411
0
{
412
0
    COutPoint iter(txid, 0);
413
0
    while (iter.n < MAX_OUTPUTS_PER_BLOCK) {
414
0
        const Coin& alternate = view.AccessCoin(iter);
415
0
        if (!alternate.IsSpent()) return alternate;
416
0
        ++iter.n;
417
0
    }
418
0
    return coinEmpty;
419
0
}
420
421
template <typename ReturnType, typename Func>
422
static ReturnType ExecuteBackedWrapper(Func func, const std::vector<std::function<void()>>& err_callbacks)
423
4.38M
{
424
4.38M
    try {
425
4.38M
        return func();
426
4.38M
    } catch(const std::runtime_error& e) {
427
0
        for (const auto& f : err_callbacks) {
428
0
            f();
429
0
        }
430
0
        LogError("Error reading from database: %s\n", e.what());
431
        // Starting the shutdown sequence and returning false to the caller would be
432
        // interpreted as 'entry not found' (as opposed to unable to read data), and
433
        // could lead to invalid interpretation. Just exit immediately, as we can't
434
        // continue anyway, and all writes should be atomic.
435
0
        std::abort();
436
0
    }
437
4.38M
}
coins.cpp:std::__1::optional<Coin> ExecuteBackedWrapper<std::__1::optional<Coin>, CCoinsViewErrorCatcher::GetCoin(COutPoint const&) const::$_0>(CCoinsViewErrorCatcher::GetCoin(COutPoint const&) const::$_0, std::__1::vector<std::__1::function<void ()>, std::__1::allocator<std::__1::function<void ()> > > const&)
Line
Count
Source
423
3.11M
{
424
3.11M
    try {
425
3.11M
        return func();
426
3.11M
    } catch(const std::runtime_error& e) {
427
0
        for (const auto& f : err_callbacks) {
428
0
            f();
429
0
        }
430
0
        LogError("Error reading from database: %s\n", e.what());
431
        // Starting the shutdown sequence and returning false to the caller would be
432
        // interpreted as 'entry not found' (as opposed to unable to read data), and
433
        // could lead to invalid interpretation. Just exit immediately, as we can't
434
        // continue anyway, and all writes should be atomic.
435
0
        std::abort();
436
0
    }
437
3.11M
}
Unexecuted instantiation: coins.cpp:bool ExecuteBackedWrapper<bool, CCoinsViewErrorCatcher::HaveCoin(COutPoint const&) const::$_0>(CCoinsViewErrorCatcher::HaveCoin(COutPoint const&) const::$_0, std::__1::vector<std::__1::function<void ()>, std::__1::allocator<std::__1::function<void ()> > > const&)
coins.cpp:std::__1::optional<Coin> ExecuteBackedWrapper<std::__1::optional<Coin>, CCoinsViewErrorCatcher::PeekCoin(COutPoint const&) const::$_0>(CCoinsViewErrorCatcher::PeekCoin(COutPoint const&) const::$_0, std::__1::vector<std::__1::function<void ()>, std::__1::allocator<std::__1::function<void ()> > > const&)
Line
Count
Source
423
1.26M
{
424
1.26M
    try {
425
1.26M
        return func();
426
1.26M
    } catch(const std::runtime_error& e) {
427
0
        for (const auto& f : err_callbacks) {
428
0
            f();
429
0
        }
430
0
        LogError("Error reading from database: %s\n", e.what());
431
        // Starting the shutdown sequence and returning false to the caller would be
432
        // interpreted as 'entry not found' (as opposed to unable to read data), and
433
        // could lead to invalid interpretation. Just exit immediately, as we can't
434
        // continue anyway, and all writes should be atomic.
435
0
        std::abort();
436
0
    }
437
1.26M
}
438
439
std::optional<Coin> CCoinsViewErrorCatcher::GetCoin(const COutPoint& outpoint) const
440
3.11M
{
441
3.11M
    return ExecuteBackedWrapper<std::optional<Coin>>([&]() { return CCoinsViewBacked::GetCoin(outpoint); }, m_err_callbacks);
442
3.11M
}
443
444
bool CCoinsViewErrorCatcher::HaveCoin(const COutPoint& outpoint) const
445
0
{
446
0
    return ExecuteBackedWrapper<bool>([&]() { return CCoinsViewBacked::HaveCoin(outpoint); }, m_err_callbacks);
447
0
}
448
449
std::optional<Coin> CCoinsViewErrorCatcher::PeekCoin(const COutPoint& outpoint) const
450
1.26M
{
451
1.26M
    return ExecuteBackedWrapper<std::optional<Coin>>([&]() { return CCoinsViewBacked::PeekCoin(outpoint); }, m_err_callbacks);
452
1.26M
}