Bitcoin Core 31.99.0
P2P Digital Currency
coins.cpp
Go to the documentation of this file.
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
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
18TRACEPOINT_SEMAPHORE(utxocache, add);
19TRACEPOINT_SEMAPHORE(utxocache, spent);
20TRACEPOINT_SEMAPHORE(utxocache, uncache);
21
23 : m_hasher{
24 deterministic ? 0x8e819f2607a18de6 : FastRandomContext().rand64(),
25 deterministic ? 0xf4020d2e3983b0eb : FastRandomContext().rand64()}
26{
27}
28
30{
31 static CoinsViewEmpty instance;
32 return instance;
33}
34
35std::optional<Coin> CCoinsViewCache::PeekCoin(const COutPoint& outpoint) const
36{
37 if (auto it{cacheCoins.find(outpoint)}; it != cacheCoins.end()) {
38 return it->second.coin.IsSpent() ? std::nullopt : std::optional{it->second.coin};
39 }
40 return base->PeekCoin(outpoint);
41}
42
43CCoinsViewCache::CCoinsViewCache(CCoinsView* in_base, bool deterministic) :
44 CCoinsViewBacked(in_base), m_deterministic(deterministic),
45 cacheCoins(0, SaltedCoinsCacheHasher{/*deterministic=*/deterministic}, CCoinsMap::key_equal{}, &m_cache_coins_memory_resource)
46{
47 m_sentinel.second.SelfRef(m_sentinel);
48}
49
52}
53
54std::optional<Coin> CCoinsViewCache::FetchCoinFromBase(const COutPoint& outpoint) const
55{
56 return base->GetCoin(outpoint);
57}
58
59CCoinsMap::iterator CCoinsViewCache::FetchCoin(const COutPoint &outpoint) const {
60 const auto [ret, inserted] = cacheCoins.try_emplace(outpoint);
61 if (inserted) {
62 if (auto coin{FetchCoinFromBase(outpoint)}) {
63 ret->second.coin = std::move(*coin);
64 cachedCoinsUsage += ret->second.coin.DynamicMemoryUsage();
65 Assert(!ret->second.coin.IsSpent());
66 } else {
67 cacheCoins.erase(ret);
68 return cacheCoins.end();
69 }
70 }
71 return ret;
72}
73
74std::optional<Coin> CCoinsViewCache::GetCoin(const COutPoint& outpoint) const
75{
76 if (auto it{FetchCoin(outpoint)}; it != cacheCoins.end() && !it->second.coin.IsSpent()) return it->second.coin;
77 return std::nullopt;
78}
79
80void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possible_overwrite) {
81 assert(!coin.IsSpent());
82 if (coin.out.scriptPubKey.IsUnspendable()) return;
83 CCoinsMap::iterator it;
84 bool inserted;
85 std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());
86 bool fresh = false;
87 if (!possible_overwrite) {
88 if (!it->second.coin.IsSpent()) {
89 throw std::logic_error("Attempted to overwrite an unspent coin (when possible_overwrite is false)");
90 }
91 // If the coin exists in this cache as a spent coin and is DIRTY, then
92 // its spentness hasn't been flushed to the parent cache. We're
93 // re-adding the coin to this cache now but we can't mark it as FRESH.
94 // If we mark it FRESH and then spend it before the cache is flushed
95 // we would remove it from this cache and would never flush spentness
96 // to the parent cache.
97 //
98 // Re-adding a spent coin can happen in the case of a re-org (the coin
99 // is 'spent' when the block adding it is disconnected and then
100 // re-added when it is also added in a newly connected block).
101 //
102 // If the coin doesn't exist in the current cache, or is spent but not
103 // DIRTY, then it can be marked FRESH.
104 fresh = !it->second.IsDirty();
105 }
106 if (!inserted) {
107 Assume(TrySub(m_dirty_count, it->second.IsDirty()));
108 Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage()));
109 }
110 it->second.coin = std::move(coin);
113 if (fresh) CCoinsCacheEntry::SetFresh(*it, m_sentinel);
114 cachedCoinsUsage += it->second.coin.DynamicMemoryUsage();
115 TRACEPOINT(utxocache, add,
116 outpoint.hash.data(),
117 (uint32_t)outpoint.n,
118 (uint32_t)it->second.coin.nHeight,
119 (int64_t)it->second.coin.out.nValue,
120 (bool)it->second.coin.IsCoinBase());
121}
122
124 const auto mem_usage{coin.DynamicMemoryUsage()};
125 auto [it, inserted] = cacheCoins.try_emplace(outpoint, std::move(coin));
126 if (inserted) {
129 cachedCoinsUsage += mem_usage;
130 }
131}
132
133void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check_for_overwrite) {
134 bool fCoinbase = tx.IsCoinBase();
135 const Txid& txid = tx.GetHash();
136 for (size_t i = 0; i < tx.vout.size(); ++i) {
137 bool overwrite = check_for_overwrite ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
138 // Coinbase transactions can always be overwritten, in order to correctly
139 // deal with the pre-BIP30 occurrences of duplicate coinbase transactions.
140 cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite);
141 }
142}
143
144bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
145 CCoinsMap::iterator it = FetchCoin(outpoint);
146 if (it == cacheCoins.end()) return false;
147 Assume(TrySub(m_dirty_count, it->second.IsDirty()));
148 Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage()));
149 TRACEPOINT(utxocache, spent,
150 outpoint.hash.data(),
151 (uint32_t)outpoint.n,
152 (uint32_t)it->second.coin.nHeight,
153 (int64_t)it->second.coin.out.nValue,
154 (bool)it->second.coin.IsCoinBase());
155 if (moveout) {
156 *moveout = std::move(it->second.coin);
157 }
158 if (it->second.IsFresh()) {
159 cacheCoins.erase(it);
160 } else {
163 it->second.coin.Clear();
164 }
165 return true;
166}
167
168static const Coin coinEmpty;
169
170const Coin& CCoinsViewCache::AccessCoin(const COutPoint &outpoint) const {
171 CCoinsMap::const_iterator it = FetchCoin(outpoint);
172 if (it == cacheCoins.end()) {
173 return coinEmpty;
174 } else {
175 return it->second.coin;
176 }
177}
178
179bool CCoinsViewCache::HaveCoin(const COutPoint& outpoint) const
180{
181 CCoinsMap::const_iterator it = FetchCoin(outpoint);
182 return (it != cacheCoins.end() && !it->second.coin.IsSpent());
183}
184
185bool CCoinsViewCache::HaveCoinInCache(const COutPoint &outpoint) const {
186 CCoinsMap::const_iterator it = cacheCoins.find(outpoint);
187 return (it != cacheCoins.end() && !it->second.coin.IsSpent());
188}
189
191 if (m_block_hash.IsNull())
193 return m_block_hash;
194}
195
196void CCoinsViewCache::SetBestBlock(const uint256& in_block_hash)
197{
198 m_block_hash = in_block_hash;
199}
200
202{
203 for (auto it{cursor.Begin()}; it != cursor.End(); it = cursor.NextAndMaybeErase(*it)) {
204 if (!it->second.IsDirty()) { // TODO a cursor can only contain dirty entries
205 continue;
206 }
207 auto [itUs, inserted]{cacheCoins.try_emplace(it->first)};
208 if (inserted) {
209 if (it->second.IsFresh() && it->second.coin.IsSpent()) {
210 cacheCoins.erase(itUs); // TODO fresh coins should have been removed at spend
211 } else {
212 // The parent cache does not have an entry, while the child cache does.
213 // Move the data up and mark it as dirty.
214 CCoinsCacheEntry& entry{itUs->second};
215 assert(entry.coin.DynamicMemoryUsage() == 0);
216 if (cursor.WillErase(*it)) {
217 // Since this entry will be erased,
218 // we can move the coin into us instead of copying it
219 entry.coin = std::move(it->second.coin);
220 } else {
221 entry.coin = it->second.coin;
222 }
225 cachedCoinsUsage += entry.coin.DynamicMemoryUsage();
226 // We can mark it FRESH in the parent if it was FRESH in the child
227 // Otherwise it might have just been flushed from the parent's cache
228 // and already exist in the grandparent
229 if (it->second.IsFresh()) CCoinsCacheEntry::SetFresh(*itUs, m_sentinel);
230 }
231 } else {
232 // Found the entry in the parent cache
233 if (it->second.IsFresh() && !itUs->second.coin.IsSpent()) {
234 // The coin was marked FRESH in the child cache, but the coin
235 // exists in the parent cache. If this ever happens, it means
236 // the FRESH flag was misapplied and there is a logic error in
237 // the calling code.
238 throw std::logic_error("FRESH flag misapplied to coin that exists in parent cache");
239 }
240
241 if (itUs->second.IsFresh() && it->second.coin.IsSpent()) {
242 // The grandparent cache does not have an entry, and the coin
243 // has been spent. We can just delete it from the parent cache.
244 Assume(TrySub(m_dirty_count, itUs->second.IsDirty()));
245 Assume(TrySub(cachedCoinsUsage, itUs->second.coin.DynamicMemoryUsage()));
246 cacheCoins.erase(itUs);
247 } else {
248 // A normal modification.
249 Assume(TrySub(cachedCoinsUsage, itUs->second.coin.DynamicMemoryUsage()));
250 if (cursor.WillErase(*it)) {
251 // Since this entry will be erased,
252 // we can move the coin into us instead of copying it
253 itUs->second.coin = std::move(it->second.coin);
254 } else {
255 itUs->second.coin = it->second.coin;
256 }
257 cachedCoinsUsage += itUs->second.coin.DynamicMemoryUsage();
258 if (!itUs->second.IsDirty()) {
261 }
262 // NOTE: It isn't safe to mark the coin as FRESH in the parent
263 // cache. If it already existed and was spent in the parent
264 // cache then marking it FRESH would prevent that spentness
265 // from being flushed to the grandparent.
266 }
267 }
268 }
269 SetBestBlock(in_block_hash);
270}
271
272void CCoinsViewCache::Flush(bool reallocate_cache)
273{
274 auto cursor{CoinsViewCacheCursor(m_dirty_count, m_sentinel, cacheCoins, /*will_erase=*/true)};
275 base->BatchWrite(cursor, m_block_hash);
276 Assume(m_dirty_count == 0);
277 cacheCoins.clear();
278 if (reallocate_cache) {
280 }
282}
283
285{
286 auto cursor{CoinsViewCacheCursor(m_dirty_count, m_sentinel, cacheCoins, /*will_erase=*/false)};
287 base->BatchWrite(cursor, m_block_hash);
288 Assume(m_dirty_count == 0);
289 if (m_sentinel.second.Next() != &m_sentinel) {
290 /* BatchWrite must clear flags of all entries */
291 throw std::logic_error("Not all unspent flagged entries were cleared");
292 }
293}
294
296{
297 cacheCoins.clear();
299 m_dirty_count = 0;
301}
302
304{
305 CCoinsMap::iterator it = cacheCoins.find(hash);
306 if (it != cacheCoins.end() && !it->second.IsDirty()) {
307 Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage()));
308 TRACEPOINT(utxocache, uncache,
309 hash.hash.data(),
310 (uint32_t)hash.n,
311 (uint32_t)it->second.coin.nHeight,
312 (int64_t)it->second.coin.out.nValue,
313 (bool)it->second.coin.IsCoinBase());
314 cacheCoins.erase(it);
315 }
316}
317
318unsigned int CCoinsViewCache::GetCacheSize() const {
319 return cacheCoins.size();
320}
321
323{
324 if (!tx.IsCoinBase()) {
325 for (unsigned int i = 0; i < tx.vin.size(); i++) {
326 if (!HaveCoin(tx.vin[i].prevout)) {
327 return false;
328 }
329 }
330 }
331 return true;
332}
333
335{
336 // Cache should be empty when we're calling this.
337 assert(cacheCoins.size() == 0);
338 cacheCoins.~CCoinsMap();
339 m_cache_coins_memory_resource.~CCoinsMapMemoryResource();
341 ::new (&cacheCoins) CCoinsMap{0, SaltedCoinsCacheHasher{/*deterministic=*/m_deterministic}, CCoinsMap::key_equal{}, &m_cache_coins_memory_resource};
342}
343
345{
346 size_t recomputed_usage = 0;
347 size_t count_dirty = 0;
348 for (const auto& [_, entry] : cacheCoins) {
349 if (entry.coin.IsSpent()) {
350 assert(entry.IsDirty() && !entry.IsFresh()); // A spent coin must be dirty and cannot be fresh
351 } else {
352 assert(entry.IsDirty() || !entry.IsFresh()); // An unspent coin must not be fresh if not dirty
353 }
354
355 // Recompute cachedCoinsUsage.
356 recomputed_usage += entry.coin.DynamicMemoryUsage();
357
358 // Count the number of entries we expect in the linked list.
359 if (entry.IsDirty()) ++count_dirty;
360 }
361 // Iterate over the linked list of flagged entries.
362 size_t count_linked = 0;
363 for (auto it = m_sentinel.second.Next(); it != &m_sentinel; it = it->second.Next()) {
364 // Verify linked list integrity.
365 assert(it->second.Next()->second.Prev() == it);
366 assert(it->second.Prev()->second.Next() == it);
367 // Verify they are actually flagged.
368 assert(it->second.IsDirty());
369 // Count the number of entries actually in the list.
370 ++count_linked;
371 }
372 assert(count_dirty == count_linked && count_dirty == m_dirty_count);
373 assert(recomputed_usage == cachedCoinsUsage);
374}
375
377{
378 Assert(m_futures.empty());
379 Assert(m_inputs.empty());
380 Assert(m_input_head.load(std::memory_order_relaxed) == 0);
381 Assert(m_input_tail == 0);
382 if (const auto workers_count{m_thread_pool->WorkersCount()}; workers_count > 0) {
383 // Loop through the block inputs and set their prevouts in the queue.
384 // Filter inputs that spend outputs created earlier in the same block. These outputs will be created
385 // directly in the cache from the tx that creates them, so they will not be requested from a base view.
386 std::unordered_set<Txid, SaltedCoinsCacheHasher> earlier_txids;
387 earlier_txids.reserve(block.vtx.size());
388 for (const auto& tx : block.vtx | std::views::drop(1)) {
389 for (const auto& input : tx->vin) {
390 if (!earlier_txids.contains(input.prevout.hash)) m_inputs.emplace_back(input.prevout);
391 }
392 earlier_txids.emplace(tx->GetHash());
393 }
394 // Only submit tasks if we have something to fetch.
395 if (m_inputs.size()) {
396 std::vector<std::function<void()>> tasks(workers_count, [this] {
397 while (ProcessInput()) {}
398 });
399 if (auto futures{m_thread_pool->Submit(std::move(tasks))}) {
400 m_futures = std::move(*futures);
401 } else {
402 // Submit can fail if a shared owner of the thread pool outside of this class calls Stop() or
403 // Interrupt() on a different thread after we call WorkersCount() above. In that case parallel
404 // fetching will not make progress, so we clear the inputs to fall back to single threaded fetching.
405 LogWarning("Failed to submit prevout fetch tasks; falling back to single-threaded fetching for this block.");
406 m_inputs.clear();
407 StopFetching(); // Assert nothing changed if we failed to start tasks.
408 }
409 }
410 }
411 return CreateResetGuard();
412}
413
416
417const Coin& AccessByTxid(const CCoinsViewCache& view, const Txid& txid)
418{
419 COutPoint iter(txid, 0);
420 while (iter.n < MAX_OUTPUTS_PER_BLOCK) {
421 const Coin& alternate = view.AccessCoin(iter);
422 if (!alternate.IsSpent()) return alternate;
423 ++iter.n;
424 }
425 return coinEmpty;
426}
427
428template <typename ReturnType, typename Func>
429static ReturnType ExecuteBackedWrapper(Func func, const std::vector<std::function<void()>>& err_callbacks)
430{
431 try {
432 return func();
433 } catch(const std::runtime_error& e) {
434 for (const auto& f : err_callbacks) {
435 f();
436 }
437 LogError("Error reading from database: %s\n", e.what());
438 // Starting the shutdown sequence and returning false to the caller would be
439 // interpreted as 'entry not found' (as opposed to unable to read data), and
440 // could lead to invalid interpretation. Just exit immediately, as we can't
441 // continue anyway, and all writes should be atomic.
442 std::abort();
443 }
444}
445
446std::optional<Coin> CCoinsViewErrorCatcher::GetCoin(const COutPoint& outpoint) const
447{
448 return ExecuteBackedWrapper<std::optional<Coin>>([&]() { return CCoinsViewBacked::GetCoin(outpoint); }, m_err_callbacks);
449}
450
452{
453 return ExecuteBackedWrapper<bool>([&]() { return CCoinsViewBacked::HaveCoin(outpoint); }, m_err_callbacks);
454}
455
456std::optional<Coin> CCoinsViewErrorCatcher::PeekCoin(const COutPoint& outpoint) const
457{
458 return ExecuteBackedWrapper<std::optional<Coin>>([&]() { return CCoinsViewBacked::PeekCoin(outpoint); }, m_err_callbacks);
459}
#define LIFETIMEBOUND
Definition: attributes.h:16
int ret
#define Assert(val)
Identity function.
Definition: check.h:116
#define Assume(val)
Assume is the identity function.
Definition: check.h:128
Definition: block.h:74
CCoinsView backed by another CCoinsView.
Definition: coins.h:416
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: coins.h:427
std::optional< Coin > PeekCoin(const COutPoint &outpoint) const override
Retrieve the Coin (unspent transaction output) for a given outpoint, without caching results.
Definition: coins.h:426
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.h:425
CCoinsView * base
Definition: coins.h:418
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:437
void Sync()
Push the modifications applied to this cache to its base while retaining the contents of this cache (...
Definition: coins.cpp:284
const bool m_deterministic
Definition: coins.h:439
CCoinsMapMemoryResource m_cache_coins_memory_resource
Definition: coins.h:447
bool SpendCoin(const COutPoint &outpoint, Coin *moveto=nullptr)
Spend a coin.
Definition: coins.cpp:144
uint256 m_block_hash
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
Definition: coins.h:446
void Uncache(const COutPoint &outpoint)
Removes the UTXO with the given outpoint from the cache, if it is not modified.
Definition: coins.cpp:303
void EmplaceCoinInternalDANGER(const COutPoint &outpoint, Coin &&coin)
Emplace a coin into cacheCoins without performing any checks, marking the emplaced coin as dirty.
Definition: coins.cpp:123
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view.
Definition: coins.cpp:322
void AddCoin(const COutPoint &outpoint, Coin &&coin, bool possible_overwrite)
Add a coin.
Definition: coins.cpp:80
virtual std::optional< Coin > FetchCoinFromBase(const COutPoint &outpoint) const
Definition: coins.cpp:54
size_t m_dirty_count
Definition: coins.h:455
CCoinsViewCache(CCoinsView *in_base, bool deterministic=false)
Definition: coins.cpp:43
virtual void Flush(bool reallocate_cache=true)
Push the modifications applied to this cache to its base and wipe local state.
Definition: coins.cpp:272
void SetBestBlock(const uint256 &block_hash)
Definition: coins.cpp:196
virtual void Reset() noexcept
Discard all modifications made to this cache without flushing to the base view.
Definition: coins.cpp:295
unsigned int GetCacheSize() const
Size of the cache (in number of transaction outputs)
Definition: coins.cpp:318
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:190
size_t cachedCoinsUsage
Definition: coins.h:453
CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const
Definition: coins.cpp:59
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
Definition: coins.cpp:185
CoinsCachePair m_sentinel
Definition: coins.h:449
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
Definition: coins.cpp:50
void BatchWrite(CoinsViewCacheCursor &cursor, const uint256 &block_hash) override
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: coins.cpp:201
std::optional< Coin > PeekCoin(const COutPoint &outpoint) const override
Retrieve the Coin (unspent transaction output) for a given outpoint, without caching results.
Definition: coins.cpp:35
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: coins.cpp:179
void SanityCheck() const
Run an internal sanity check on the cache data structure. *‍/.
Definition: coins.cpp:344
CCoinsMap cacheCoins
Definition: coins.h:450
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:74
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
Definition: coins.cpp:170
void ReallocateCache()
Force a reallocation of the cache map.
Definition: coins.cpp:334
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:446
std::vector< std::function< void()> > m_err_callbacks
A list of callbacks to execute upon leveldb read error.
Definition: coins.h:813
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: coins.cpp:451
std::optional< Coin > PeekCoin(const COutPoint &outpoint) const override
Retrieve the Coin (unspent transaction output) for a given outpoint, without caching results.
Definition: coins.cpp:456
Pure abstract view on the open txout dataset.
Definition: coins.h:356
virtual std::optional< Coin > PeekCoin(const COutPoint &outpoint) const =0
Retrieve the Coin (unspent transaction output) for a given outpoint, without caching results.
virtual std::optional< Coin > GetCoin(const COutPoint &outpoint) const =0
Retrieve the Coin (unspent transaction output) for a given outpoint.
virtual void BatchWrite(CoinsViewCacheCursor &cursor, const uint256 &block_hash)=0
Do a bulk modification (multiple Coin changes + BestBlock change).
virtual uint256 GetBestBlock() const =0
Retrieve the block hash whose state this CCoinsView currently represents.
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:29
uint32_t n
Definition: transaction.h:32
Txid hash
Definition: transaction.h:31
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:281
const std::vector< CTxOut > vout
Definition: transaction.h:292
bool IsCoinBase() const
Definition: transaction.h:341
const Txid & GetHash() const LIFETIMEBOUND
Definition: transaction.h:328
const std::vector< CTxIn > vin
Definition: transaction.h:291
An output of a transaction.
Definition: transaction.h:140
A UTXO entry.
Definition: coins.h:46
bool IsSpent() const
Either this coin never existed (see e.g.
Definition: coins.h:94
Noop coins view.
Definition: coins.h:392
static CoinsViewEmpty & Get()
Definition: coins.cpp:29
ResetGuard StartFetching(const CBlock &block LIFETIMEBOUND) noexcept
Start fetching inputs from block.
Definition: coins.cpp:376
Fast randomness source.
Definition: random.h:386
SipHash-1-3-UJ based hasher for the coins cache and related coins containers.
Definition: coins.h:240
SaltedCoinsCacheHasher(bool deterministic=false)
Definition: coins.cpp:22
constexpr bool IsNull() const
Definition: uint256.h:49
constexpr const std::byte * data() const
256-bit opaque blob.
Definition: uint256.h:196
static const uint256 ZERO
Definition: uint256.h:204
static const Coin coinEmpty
Definition: coins.cpp:168
TRACEPOINT_SEMAPHORE(utxocache, add)
static const uint64_t MAX_OUTPUTS_PER_BLOCK
Definition: coins.cpp:415
static const uint64_t MIN_TRANSACTION_OUTPUT_WEIGHT
Definition: coins.cpp:414
static ReturnType ExecuteBackedWrapper(Func func, const std::vector< std::function< void()> > &err_callbacks)
Definition: coins.cpp:429
const Coin & AccessByTxid(const CCoinsViewCache &view, const Txid &txid)
Utility function to find any unspent output with a given txid.
Definition: coins.cpp:417
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check_for_overwrite)
Utility function to add all of a transaction's outputs to a cache.
Definition: coins.cpp:133
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedCoinsCacheHasher, std::equal_to< COutPoint >, PoolAllocator< CoinsCachePair, sizeof(CoinsCachePair)+sizeof(void *) *4 > > CCoinsMap
PoolAllocator's MAX_BLOCK_SIZE_BYTES parameter here uses sizeof the data, and adds the size of 4 poin...
Definition: coins.h:272
CCoinsMap::allocator_type::ResourceType CCoinsMapMemoryResource
Definition: coins.h:274
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
Definition: consensus.h:15
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
#define LogWarning(...)
Definition: log.h:126
#define LogError(...)
Definition: log.h:127
unsigned int nHeight
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
Definition: memusage.h:31
bool Func(const std::string &str, std::span< const char > &sp)
Parse a function call.
Definition: parsing.cpp:22
constexpr bool TrySub(T &i, const U j) noexcept
Definition: overflow.h:36
uint64_t GetSerializeSize(const T &t)
Definition: serialize.h:1157
A Coin in one level of the coins database caching hierarchy.
Definition: coins.h:121
static void SetFresh(CoinsCachePair &pair, CoinsCachePair &sentinel) noexcept
Definition: coins.h:184
static void SetDirty(CoinsCachePair &pair, CoinsCachePair &sentinel) noexcept
Definition: coins.h:183
Cursor for iterating over the linked list of flagged entries in CCoinsViewCache.
Definition: coins.h:309
CoinsCachePair * NextAndMaybeErase(CoinsCachePair &current) noexcept
Return the next entry after current, possibly erasing current.
Definition: coins.h:327
bool WillErase(CoinsCachePair &current) const noexcept
Definition: coins.h:344
CoinsCachePair * Begin() const noexcept
Definition: coins.h:323
CoinsCachePair * End() const noexcept
Definition: coins.h:324
std::vector< std::function< void()> > tasks(MAX_READ_WORKERS)
auto futures
Definition: dbwrapper.cpp:457
#define TRACEPOINT(context,...)
Definition: trace.h:56
consteval auto _(util::TranslatedLiteral str)
Definition: translation.h:79
assert(!tx.IsCoinBase())