/root/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 | 41.3k | { |
19 | 41.3k | static CoinsViewEmpty instance; |
20 | 41.3k | return instance; |
21 | 41.3k | } |
22 | | |
23 | | std::optional<Coin> CCoinsViewCache::PeekCoin(const COutPoint& outpoint) const |
24 | 372k | { |
25 | 372k | if (auto it{cacheCoins.find(outpoint)}; it != cacheCoins.end()) { |
26 | 176 | return it->second.coin.IsSpent() ? std::nullopt0 : std::optional{it->second.coin}; |
27 | 176 | } |
28 | 372k | return base->PeekCoin(outpoint); |
29 | 372k | } |
30 | | |
31 | | CCoinsViewCache::CCoinsViewCache(CCoinsView* in_base, bool deterministic) : |
32 | 427k | CCoinsViewBacked(in_base), m_deterministic(deterministic), |
33 | 427k | cacheCoins(0, SaltedOutpointHasher(/*deterministic=*/deterministic), CCoinsMap::key_equal{}, &m_cache_coins_memory_resource) |
34 | 427k | { |
35 | 427k | m_sentinel.second.SelfRef(m_sentinel); |
36 | 427k | } |
37 | | |
38 | 1.35M | size_t CCoinsViewCache::DynamicMemoryUsage() const { |
39 | 1.35M | return memusage::DynamicUsage(cacheCoins) + cachedCoinsUsage; |
40 | 1.35M | } |
41 | | |
42 | | std::optional<Coin> CCoinsViewCache::FetchCoinFromBase(const COutPoint& outpoint) const |
43 | 813k | { |
44 | 813k | return base->GetCoin(outpoint); |
45 | 813k | } |
46 | | |
47 | 1.92M | CCoinsMap::iterator CCoinsViewCache::FetchCoin(const COutPoint &outpoint) const { |
48 | 1.92M | const auto [ret, inserted] = cacheCoins.try_emplace(outpoint); |
49 | 1.92M | if (inserted) { |
50 | 1.18M | if (auto coin{FetchCoinFromBase(outpoint)}) { |
51 | 54.7k | ret->second.coin = std::move(*coin); |
52 | 54.7k | cachedCoinsUsage += ret->second.coin.DynamicMemoryUsage(); |
53 | 54.7k | Assert(!ret->second.coin.IsSpent()); Line | Count | Source | 116 | 54.7k | #define Assert(val) inline_assertion_check<true>(val, std::source_location::current(), #val) |
|
54 | 1.13M | } else { |
55 | 1.13M | cacheCoins.erase(ret); |
56 | 1.13M | return cacheCoins.end(); |
57 | 1.13M | } |
58 | 1.18M | } |
59 | 789k | return ret; |
60 | 1.92M | } |
61 | | |
62 | | std::optional<Coin> CCoinsViewCache::GetCoin(const COutPoint& outpoint) const |
63 | 530k | { |
64 | 530k | if (auto it{FetchCoin(outpoint)}; it != cacheCoins.end() && !it->second.coin.IsSpent()150k ) return it->second.coin150k ; |
65 | 379k | return std::nullopt; |
66 | 530k | } |
67 | | |
68 | 867k | void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possible_overwrite) { |
69 | 867k | assert(!coin.IsSpent()); |
70 | 867k | if (coin.out.scriptPubKey.IsUnspendable()) return371k ; |
71 | 496k | CCoinsMap::iterator it; |
72 | 496k | bool inserted; |
73 | 496k | std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>()); |
74 | 496k | bool fresh = false; |
75 | 496k | if (!possible_overwrite) { |
76 | 125k | if (!it->second.coin.IsSpent()) { |
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 | 125k | fresh = !it->second.IsDirty(); |
93 | 125k | } |
94 | 496k | if (!inserted) { |
95 | 0 | Assume(TrySub(m_dirty_count, it->second.IsDirty())); Line | Count | Source | 128 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
96 | 0 | Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage())); Line | Count | Source | 128 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
97 | 0 | } |
98 | 496k | it->second.coin = std::move(coin); |
99 | 496k | CCoinsCacheEntry::SetDirty(*it, m_sentinel); |
100 | 496k | ++m_dirty_count; |
101 | 496k | if (fresh) CCoinsCacheEntry::SetFresh(*it, m_sentinel)125k ; |
102 | 496k | cachedCoinsUsage += it->second.coin.DynamicMemoryUsage(); |
103 | 496k | TRACEPOINT(utxocache, add, |
104 | 496k | outpoint.hash.data(), |
105 | 496k | (uint32_t)outpoint.n, |
106 | 496k | (uint32_t)it->second.coin.nHeight, |
107 | 496k | (int64_t)it->second.coin.out.nValue, |
108 | 496k | (bool)it->second.coin.IsCoinBase()); |
109 | 496k | } |
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) { |
115 | 0 | CCoinsCacheEntry::SetDirty(*it, m_sentinel); |
116 | 0 | ++m_dirty_count; |
117 | 0 | cachedCoinsUsage += mem_usage; |
118 | 0 | } |
119 | 0 | } |
120 | | |
121 | 496k | void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check_for_overwrite) { |
122 | 496k | bool fCoinbase = tx.IsCoinBase(); |
123 | 496k | const Txid& txid = tx.GetHash(); |
124 | 1.36M | for (size_t i = 0; i < tx.vout.size(); ++i867k ) { |
125 | 867k | bool overwrite = check_for_overwrite ? cache.HaveCoin(COutPoint(txid, i))0 : fCoinbase; |
126 | | // Coinbase transactions can always be overwritten, in order to correctly |
127 | | // deal with the pre-BIP30 occurrences of duplicate coinbase transactions. |
128 | 867k | cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite); |
129 | 867k | } |
130 | 496k | } |
131 | | |
132 | 125k | bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) { |
133 | 125k | CCoinsMap::iterator it = FetchCoin(outpoint); |
134 | 125k | if (it == cacheCoins.end()) return false0 ; |
135 | 125k | Assume(TrySub(m_dirty_count, it->second.IsDirty())); Line | Count | Source | 128 | 125k | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
136 | 125k | Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage())); Line | Count | Source | 128 | 125k | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
137 | 125k | TRACEPOINT(utxocache, spent, |
138 | 125k | outpoint.hash.data(), |
139 | 125k | (uint32_t)outpoint.n, |
140 | 125k | (uint32_t)it->second.coin.nHeight, |
141 | 125k | (int64_t)it->second.coin.out.nValue, |
142 | 125k | (bool)it->second.coin.IsCoinBase()); |
143 | 125k | if (moveout) { |
144 | 293 | *moveout = std::move(it->second.coin); |
145 | 293 | } |
146 | 125k | if (it->second.IsFresh()) { |
147 | 85.3k | cacheCoins.erase(it); |
148 | 85.3k | } else { |
149 | 39.7k | CCoinsCacheEntry::SetDirty(*it, m_sentinel); |
150 | 39.7k | ++m_dirty_count; |
151 | 39.7k | it->second.coin.Clear(); |
152 | 39.7k | } |
153 | 125k | return true; |
154 | 125k | } |
155 | | |
156 | | static const Coin coinEmpty; |
157 | | |
158 | 234k | const Coin& CCoinsViewCache::AccessCoin(const COutPoint &outpoint) const { |
159 | 234k | CCoinsMap::const_iterator it = FetchCoin(outpoint); |
160 | 234k | if (it == cacheCoins.end()) { |
161 | 0 | return coinEmpty; |
162 | 234k | } else { |
163 | 234k | return it->second.coin; |
164 | 234k | } |
165 | 234k | } |
166 | | |
167 | | bool CCoinsViewCache::HaveCoin(const COutPoint& outpoint) const |
168 | 1.03M | { |
169 | 1.03M | CCoinsMap::const_iterator it = FetchCoin(outpoint); |
170 | 1.03M | return (it != cacheCoins.end() && !it->second.coin.IsSpent()278k ); |
171 | 1.03M | } |
172 | | |
173 | 34.3k | bool CCoinsViewCache::HaveCoinInCache(const COutPoint &outpoint) const { |
174 | 34.3k | CCoinsMap::const_iterator it = cacheCoins.find(outpoint); |
175 | 34.3k | return (it != cacheCoins.end() && !it->second.coin.IsSpent()3.84k ); |
176 | 34.3k | } |
177 | | |
178 | 790k | uint256 CCoinsViewCache::GetBestBlock() const { |
179 | 790k | if (m_block_hash.IsNull()) |
180 | 389k | m_block_hash = base->GetBestBlock(); |
181 | 790k | return m_block_hash; |
182 | 790k | } |
183 | | |
184 | | void CCoinsViewCache::SetBestBlock(const uint256& in_block_hash) |
185 | 560k | { |
186 | 560k | m_block_hash = in_block_hash; |
187 | 560k | } |
188 | | |
189 | | void CCoinsViewCache::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& in_block_hash) |
190 | 186k | { |
191 | 373k | for (auto it{cursor.Begin()}; it != cursor.End(); it = cursor.NextAndMaybeErase(*it)186k ) { |
192 | 186k | if (!it->second.IsDirty()) { // TODO a cursor can only contain dirty entries |
193 | 0 | continue; |
194 | 0 | } |
195 | 186k | auto [itUs, inserted]{cacheCoins.try_emplace(it->first)}; |
196 | 186k | if (inserted) { |
197 | 186k | if (it->second.IsFresh() && it->second.coin.IsSpent()110 ) { |
198 | 0 | cacheCoins.erase(itUs); // TODO fresh coins should have been removed at spend |
199 | 186k | } 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 | 186k | CCoinsCacheEntry& entry{itUs->second}; |
203 | 186k | assert(entry.coin.DynamicMemoryUsage() == 0); |
204 | 186k | if (cursor.WillErase(*it)) { |
205 | | // Since this entry will be erased, |
206 | | // we can move the coin into us instead of copying it |
207 | 186k | entry.coin = std::move(it->second.coin); |
208 | 186k | } else { |
209 | 0 | entry.coin = it->second.coin; |
210 | 0 | } |
211 | 186k | CCoinsCacheEntry::SetDirty(*itUs, m_sentinel); |
212 | 186k | ++m_dirty_count; |
213 | 186k | 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 | 186k | if (it->second.IsFresh()) CCoinsCacheEntry::SetFresh(*itUs, m_sentinel)110 ; |
218 | 186k | } |
219 | 186k | } else { |
220 | | // Found the entry in the parent cache |
221 | 110 | if (it->second.IsFresh() && !itUs->second.coin.IsSpent()0 ) { |
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 | 110 | if (itUs->second.IsFresh() && it->second.coin.IsSpent()2 ) { |
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 | 2 | Assume(TrySub(m_dirty_count, itUs->second.IsDirty())); Line | Count | Source | 128 | 2 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
233 | 2 | Assume(TrySub(cachedCoinsUsage, itUs->second.coin.DynamicMemoryUsage())); Line | Count | Source | 128 | 2 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
234 | 2 | cacheCoins.erase(itUs); |
235 | 108 | } else { |
236 | | // A normal modification. |
237 | 108 | Assume(TrySub(cachedCoinsUsage, itUs->second.coin.DynamicMemoryUsage())); Line | Count | Source | 128 | 108 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
238 | 108 | if (cursor.WillErase(*it)) { |
239 | | // Since this entry will be erased, |
240 | | // we can move the coin into us instead of copying it |
241 | 108 | itUs->second.coin = std::move(it->second.coin); |
242 | 108 | } else { |
243 | 0 | itUs->second.coin = it->second.coin; |
244 | 0 | } |
245 | 108 | cachedCoinsUsage += itUs->second.coin.DynamicMemoryUsage(); |
246 | 108 | if (!itUs->second.IsDirty()) { |
247 | 0 | CCoinsCacheEntry::SetDirty(*itUs, m_sentinel); |
248 | 0 | ++m_dirty_count; |
249 | 0 | } |
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 | 108 | } |
255 | 110 | } |
256 | 186k | } |
257 | 186k | SetBestBlock(in_block_hash); |
258 | 186k | } |
259 | | |
260 | | void CCoinsViewCache::Flush(bool reallocate_cache) |
261 | 186k | { |
262 | 186k | auto cursor{CoinsViewCacheCursor(m_dirty_count, m_sentinel, cacheCoins, /*will_erase=*/true)}; |
263 | 186k | base->BatchWrite(cursor, m_block_hash); |
264 | 186k | Assume(m_dirty_count == 0); Line | Count | Source | 128 | 186k | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
265 | 186k | cacheCoins.clear(); |
266 | 186k | if (reallocate_cache) { |
267 | 0 | ReallocateCache(); |
268 | 0 | } |
269 | 186k | cachedCoinsUsage = 0; |
270 | 186k | } |
271 | | |
272 | | void CCoinsViewCache::Sync() |
273 | 0 | { |
274 | 0 | auto cursor{CoinsViewCacheCursor(m_dirty_count, m_sentinel, cacheCoins, /*will_erase=*/false)}; |
275 | 0 | base->BatchWrite(cursor, m_block_hash); |
276 | 0 | Assume(m_dirty_count == 0); Line | Count | Source | 128 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
277 | 0 | if (m_sentinel.second.Next() != &m_sentinel) { |
278 | | /* BatchWrite must clear flags of all entries */ |
279 | 0 | throw std::logic_error("Not all unspent flagged entries were cleared"); |
280 | 0 | } |
281 | 0 | } |
282 | | |
283 | | void CCoinsViewCache::Reset() noexcept |
284 | 186k | { |
285 | 186k | cacheCoins.clear(); |
286 | 186k | cachedCoinsUsage = 0; |
287 | 186k | m_dirty_count = 0; |
288 | 186k | SetBestBlock(uint256::ZERO); |
289 | 186k | } |
290 | | |
291 | | void CCoinsViewCache::Uncache(const COutPoint& hash) |
292 | 26.9k | { |
293 | 26.9k | CCoinsMap::iterator it = cacheCoins.find(hash); |
294 | 26.9k | if (it != cacheCoins.end() && !it->second.IsDirty()11.0k ) { |
295 | 11.0k | Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage())); Line | Count | Source | 128 | 11.0k | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
296 | 11.0k | TRACEPOINT(utxocache, uncache, |
297 | 11.0k | hash.hash.data(), |
298 | 11.0k | (uint32_t)hash.n, |
299 | 11.0k | (uint32_t)it->second.coin.nHeight, |
300 | 11.0k | (int64_t)it->second.coin.out.nValue, |
301 | 11.0k | (bool)it->second.coin.IsCoinBase()); |
302 | 11.0k | cacheCoins.erase(it); |
303 | 11.0k | } |
304 | 26.9k | } |
305 | | |
306 | 773k | unsigned int CCoinsViewCache::GetCacheSize() const { |
307 | 773k | return cacheCoins.size(); |
308 | 773k | } |
309 | | |
310 | | bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const |
311 | 138k | { |
312 | 138k | if (!tx.IsCoinBase()) { |
313 | 277k | for (unsigned int i = 0; i < tx.vin.size(); i++138k ) { |
314 | 138k | if (!HaveCoin(tx.vin[i].prevout)) { |
315 | 39 | return false; |
316 | 39 | } |
317 | 138k | } |
318 | 138k | } |
319 | 138k | return true; |
320 | 138k | } |
321 | | |
322 | | void CCoinsViewCache::ReallocateCache() |
323 | 0 | { |
324 | | // Cache should be empty when we're calling this. |
325 | 0 | assert(cacheCoins.size() == 0); |
326 | 0 | cacheCoins.~CCoinsMap(); |
327 | 0 | m_cache_coins_memory_resource.~CCoinsMapMemoryResource(); |
328 | 0 | ::new (&m_cache_coins_memory_resource) CCoinsMapMemoryResource{}; |
329 | 0 | ::new (&cacheCoins) CCoinsMap{0, SaltedOutpointHasher{/*deterministic=*/m_deterministic}, CCoinsMap::key_equal{}, &m_cache_coins_memory_resource}; |
330 | 0 | } |
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) { |
337 | 0 | if (entry.coin.IsSpent()) { |
338 | 0 | assert(entry.IsDirty() && !entry.IsFresh()); // A spent coin must be dirty and cannot be fresh |
339 | 0 | } else { |
340 | 0 | assert(entry.IsDirty() || !entry.IsFresh()); // An unspent coin must not be fresh if not dirty |
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; |
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()) { |
352 | | // Verify linked list integrity. |
353 | 0 | assert(it->second.Next()->second.Prev() == it); |
354 | 0 | assert(it->second.Prev()->second.Next() == it); |
355 | | // Verify they are actually flagged. |
356 | 0 | assert(it->second.IsDirty()); |
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); |
361 | 0 | assert(recomputed_usage == cachedCoinsUsage); |
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) { |
371 | 0 | const Coin& alternate = view.AccessCoin(iter); |
372 | 0 | if (!alternate.IsSpent()) return alternate; |
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 | 752k | { |
381 | 752k | try { |
382 | 752k | return func(); |
383 | 752k | } catch(const std::runtime_error& e) { |
384 | 0 | for (const auto& f : err_callbacks) { |
385 | 0 | f(); |
386 | 0 | } |
387 | 0 | LogError("Error reading from database: %s\n", e.what());Line | Count | Source | 105 | 0 | #define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, /*should_ratelimit=*/true, __VA_ARGS__) Line | Count | Source | 97 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(SourceLocation{__func__}, category, level, should_ratelimit, __VA_ARGS__) |
|
| LogError("Error reading from database: %s\n", e.what());Line | Count | Source | 105 | 0 | #define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, /*should_ratelimit=*/true, __VA_ARGS__) Line | Count | Source | 97 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(SourceLocation{__func__}, category, level, should_ratelimit, __VA_ARGS__) |
|
| LogError("Error reading from database: %s\n", e.what());Line | Count | Source | 105 | 0 | #define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, /*should_ratelimit=*/true, __VA_ARGS__) Line | Count | Source | 97 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(SourceLocation{__func__}, category, level, should_ratelimit, __VA_ARGS__) |
|
|
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 | 752k | } 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 | 379k | { | 381 | 379k | try { | 382 | 379k | return func(); | 383 | 379k | } catch(const std::runtime_error& e) { | 384 | 0 | for (const auto& f : err_callbacks) { | 385 | 0 | f(); | 386 | 0 | } | 387 | 0 | LogError("Error reading from database: %s\n", e.what());Line | Count | Source | 105 | 0 | #define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, /*should_ratelimit=*/true, __VA_ARGS__) Line | Count | Source | 97 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(SourceLocation{__func__}, category, level, should_ratelimit, __VA_ARGS__) |
|
| 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 | 379k | } |
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 | 372k | { | 381 | 372k | try { | 382 | 372k | return func(); | 383 | 372k | } catch(const std::runtime_error& e) { | 384 | 0 | for (const auto& f : err_callbacks) { | 385 | 0 | f(); | 386 | 0 | } | 387 | 0 | LogError("Error reading from database: %s\n", e.what());Line | Count | Source | 105 | 0 | #define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, /*should_ratelimit=*/true, __VA_ARGS__) Line | Count | Source | 97 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(SourceLocation{__func__}, category, level, should_ratelimit, __VA_ARGS__) |
|
| 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 | 372k | } |
|
395 | | |
396 | | std::optional<Coin> CCoinsViewErrorCatcher::GetCoin(const COutPoint& outpoint) const |
397 | 379k | { |
398 | 379k | return ExecuteBackedWrapper<std::optional<Coin>>([&]() { return CCoinsViewBacked::GetCoin(outpoint); }, m_err_callbacks); |
399 | 379k | } |
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 | 372k | { |
408 | 372k | return ExecuteBackedWrapper<std::optional<Coin>>([&]() { return CCoinsViewBacked::PeekCoin(outpoint); }, m_err_callbacks); |
409 | 372k | } |