Bitcoin Core  31.0.0
P2P Digital Currency
coins.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-present The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_COINS_H
7 #define BITCOIN_COINS_H
8 
9 #include <attributes.h>
10 #include <compressor.h>
11 #include <core_memusage.h>
12 #include <memusage.h>
13 #include <primitives/transaction.h>
14 #include <serialize.h>
16 #include <uint256.h>
17 #include <util/check.h>
18 #include <util/overflow.h>
19 #include <util/hasher.h>
20 
21 #include <cassert>
22 #include <cstdint>
23 
24 #include <functional>
25 #include <unordered_map>
26 
34 class Coin
35 {
36 public:
39 
41  unsigned int fCoinBase : 1;
42 
44  uint32_t nHeight : 31;
45 
47  Coin(CTxOut&& outIn, int nHeightIn, bool fCoinBaseIn) : out(std::move(outIn)), fCoinBase(fCoinBaseIn), nHeight(nHeightIn) {}
48  Coin(const CTxOut& outIn, int nHeightIn, bool fCoinBaseIn) : out(outIn), fCoinBase(fCoinBaseIn),nHeight(nHeightIn) {}
49 
50  void Clear() {
51  out.SetNull();
52  fCoinBase = false;
53  nHeight = 0;
54  }
55 
57  Coin() : fCoinBase(false), nHeight(0) { }
58 
59  bool IsCoinBase() const {
60  return fCoinBase;
61  }
62 
63  template<typename Stream>
64  void Serialize(Stream &s) const {
65  assert(!IsSpent());
66  uint32_t code = nHeight * uint32_t{2} + fCoinBase;
67  ::Serialize(s, VARINT(code));
68  ::Serialize(s, Using<TxOutCompression>(out));
69  }
70 
71  template<typename Stream>
72  void Unserialize(Stream &s) {
73  uint32_t code = 0;
74  ::Unserialize(s, VARINT(code));
75  nHeight = code >> 1;
76  fCoinBase = code & 1;
77  ::Unserialize(s, Using<TxOutCompression>(out));
78  }
79 
83  bool IsSpent() const {
84  return out.IsNull();
85  }
86 
87  size_t DynamicMemoryUsage() const {
89  }
90 };
91 
92 struct CCoinsCacheEntry;
93 using CoinsCachePair = std::pair<const COutPoint, CCoinsCacheEntry>;
94 
110 {
111 private:
124  uint8_t m_flags{0};
125 
127  static void AddFlags(uint8_t flags, CoinsCachePair& pair, CoinsCachePair& sentinel) noexcept
128  {
129  Assume(flags & (DIRTY | FRESH));
130  if (!pair.second.m_flags) {
131  Assume(!pair.second.m_prev && !pair.second.m_next);
132  pair.second.m_prev = sentinel.second.m_prev;
133  pair.second.m_next = &sentinel;
134  sentinel.second.m_prev = &pair;
135  pair.second.m_prev->second.m_next = &pair;
136  }
137  Assume(pair.second.m_prev && pair.second.m_next);
138  pair.second.m_flags |= flags;
139  }
140 
141 public:
142  Coin coin; // The actual cached data.
143 
144  enum Flags {
152  DIRTY = (1 << 0),
162  FRESH = (1 << 1),
163  };
164 
165  CCoinsCacheEntry() noexcept = default;
166  explicit CCoinsCacheEntry(Coin&& coin_) noexcept : coin(std::move(coin_)) {}
168  {
169  SetClean();
170  }
171 
172  static void SetDirty(CoinsCachePair& pair, CoinsCachePair& sentinel) noexcept { AddFlags(DIRTY, pair, sentinel); }
173  static void SetFresh(CoinsCachePair& pair, CoinsCachePair& sentinel) noexcept { AddFlags(FRESH, pair, sentinel); }
174 
175  void SetClean() noexcept
176  {
177  if (!m_flags) return;
178  m_next->second.m_prev = m_prev;
179  m_prev->second.m_next = m_next;
180  m_flags = 0;
181  m_prev = m_next = nullptr;
182  }
183  bool IsDirty() const noexcept { return m_flags & DIRTY; }
184  bool IsFresh() const noexcept { return m_flags & FRESH; }
185 
187  CoinsCachePair* Next() const noexcept
188  {
189  Assume(m_flags);
190  return m_next;
191  }
192 
194  CoinsCachePair* Prev() const noexcept
195  {
196  Assume(m_flags);
197  return m_prev;
198  }
199 
201  void SelfRef(CoinsCachePair& pair) noexcept
202  {
203  Assume(&pair.second == this);
204  m_prev = &pair;
205  m_next = &pair;
206  // Set sentinel to DIRTY so we can call Next on it
207  m_flags = DIRTY;
208  }
209 };
210 
219 using CCoinsMap = std::unordered_map<COutPoint,
222  std::equal_to<COutPoint>,
224  sizeof(CoinsCachePair) + sizeof(void*) * 4>>;
225 
226 using CCoinsMapMemoryResource = CCoinsMap::allocator_type::ResourceType;
227 
230 {
231 public:
232  CCoinsViewCursor(const uint256 &hashBlockIn): hashBlock(hashBlockIn) {}
233  virtual ~CCoinsViewCursor() = default;
234 
235  virtual bool GetKey(COutPoint &key) const = 0;
236  virtual bool GetValue(Coin &coin) const = 0;
237 
238  virtual bool Valid() const = 0;
239  virtual void Next() = 0;
240 
242  const uint256 &GetBestBlock() const { return hashBlock; }
243 private:
245 };
246 
261 {
269  CoinsViewCacheCursor(size_t& dirty_count LIFETIMEBOUND,
270  CoinsCachePair& sentinel LIFETIMEBOUND,
272  bool will_erase) noexcept
273  : m_dirty_count(dirty_count), m_sentinel(sentinel), m_map(map), m_will_erase(will_erase) {}
274 
275  inline CoinsCachePair* Begin() const noexcept { return m_sentinel.second.Next(); }
276  inline CoinsCachePair* End() const noexcept { return &m_sentinel; }
277 
280  {
281  const auto next_entry{current.second.Next()};
282  Assume(TrySub(m_dirty_count, current.second.IsDirty()));
283  // If we are not going to erase the cache, we must still erase spent entries.
284  // Otherwise, clear the state of the entry.
285  if (!m_will_erase) {
286  if (current.second.coin.IsSpent()) {
287  assert(current.second.coin.DynamicMemoryUsage() == 0); // scriptPubKey was already cleared in SpendCoin
288  m_map.erase(current.first);
289  } else {
290  current.second.SetClean();
291  }
292  }
293  return next_entry;
294  }
295 
296  inline bool WillErase(CoinsCachePair& current) const noexcept { return m_will_erase || current.second.coin.IsSpent(); }
297  size_t GetDirtyCount() const noexcept { return m_dirty_count; }
298  size_t GetTotalCount() const noexcept { return m_map.size(); }
299 private:
300  size_t& m_dirty_count;
304 };
305 
308 {
309 public:
312  virtual std::optional<Coin> GetCoin(const COutPoint& outpoint) const;
313 
316  virtual std::optional<Coin> PeekCoin(const COutPoint& outpoint) const;
317 
320  virtual bool HaveCoin(const COutPoint &outpoint) const;
321 
323  virtual uint256 GetBestBlock() const;
324 
329  virtual std::vector<uint256> GetHeadBlocks() const;
330 
333  virtual void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock);
334 
336  virtual std::unique_ptr<CCoinsViewCursor> Cursor() const;
337 
339  virtual ~CCoinsView() = default;
340 
342  virtual size_t EstimateSize() const { return 0; }
343 };
344 
345 
348 {
349 protected:
351 
352 public:
353  CCoinsViewBacked(CCoinsView *viewIn);
354  std::optional<Coin> GetCoin(const COutPoint& outpoint) const override;
355  std::optional<Coin> PeekCoin(const COutPoint& outpoint) const override;
356  bool HaveCoin(const COutPoint &outpoint) const override;
357  uint256 GetBestBlock() const override;
358  std::vector<uint256> GetHeadBlocks() const override;
359  void SetBackend(CCoinsView &viewIn);
360  void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock) override;
361  std::unique_ptr<CCoinsViewCursor> Cursor() const override;
362  size_t EstimateSize() const override;
363 };
364 
365 
368 {
369 private:
370  const bool m_deterministic;
371 
372 protected:
379  /* The starting sentinel of the flagged entry circular doubly linked list. */
382 
383  /* Cached dynamic memory usage for the inner Coin objects. */
384  mutable size_t cachedCoinsUsage{0};
385  /* Running count of dirty Coin cache entries. */
386  mutable size_t m_dirty_count{0};
387 
392  void Reset() noexcept;
393 
394  /* Fetch the coin from base. Used for cache misses in FetchCoin. */
395  virtual std::optional<Coin> FetchCoinFromBase(const COutPoint& outpoint) const;
396 
397 public:
398  CCoinsViewCache(CCoinsView *baseIn, bool deterministic = false);
399 
403  CCoinsViewCache(const CCoinsViewCache &) = delete;
404 
405  // Standard CCoinsView methods
406  std::optional<Coin> GetCoin(const COutPoint& outpoint) const override;
407  std::optional<Coin> PeekCoin(const COutPoint& outpoint) const override;
408  bool HaveCoin(const COutPoint &outpoint) const override;
409  uint256 GetBestBlock() const override;
410  void SetBestBlock(const uint256 &hashBlock);
411  void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock) override;
412  std::unique_ptr<CCoinsViewCursor> Cursor() const override {
413  throw std::logic_error("CCoinsViewCache cursor iteration not supported.");
414  }
415 
421  bool HaveCoinInCache(const COutPoint &outpoint) const;
422 
433  const Coin& AccessCoin(const COutPoint &output) const;
434 
439  void AddCoin(const COutPoint& outpoint, Coin&& coin, bool possible_overwrite);
440 
448  void EmplaceCoinInternalDANGER(COutPoint&& outpoint, Coin&& coin);
449 
455  bool SpendCoin(const COutPoint &outpoint, Coin* moveto = nullptr);
456 
464  void Flush(bool reallocate_cache = true);
465 
472  void Sync();
473 
478  void Uncache(const COutPoint &outpoint);
479 
481  unsigned int GetCacheSize() const;
482 
484  size_t GetDirtyCount() const noexcept { return m_dirty_count; }
485 
487  size_t DynamicMemoryUsage() const;
488 
490  bool HaveInputs(const CTransaction& tx) const;
491 
497  void ReallocateCache();
498 
500  void SanityCheck() const;
501 
503  {
504  private:
507  explicit ResetGuard(CCoinsViewCache& cache LIFETIMEBOUND) noexcept : m_cache{cache} {}
508 
509  public:
510  ResetGuard(const ResetGuard&) = delete;
511  ResetGuard& operator=(const ResetGuard&) = delete;
512  ResetGuard(ResetGuard&&) = delete;
513  ResetGuard& operator=(ResetGuard&&) = delete;
514 
516  };
517 
519  [[nodiscard]] ResetGuard CreateResetGuard() noexcept { return ResetGuard{*this}; }
520 
521 private:
526  CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const;
527 };
528 
539 {
540 private:
541  std::optional<Coin> FetchCoinFromBase(const COutPoint& outpoint) const override
542  {
543  return base->PeekCoin(outpoint);
544  }
545 
546 public:
548 };
549 
554 // TODO: pass in a boolean to limit these possible overwrites to known
555 // (pre-BIP34) cases.
556 void AddCoins(CCoinsViewCache& cache, const CTransaction& tx, int nHeight, bool check = false);
557 
562 const Coin& AccessByTxid(const CCoinsViewCache& cache, const Txid& txid);
563 
572 {
573 public:
575 
576  void AddReadErrCallback(std::function<void()> f) {
577  m_err_callbacks.emplace_back(std::move(f));
578  }
579 
580  std::optional<Coin> GetCoin(const COutPoint& outpoint) const override;
581  bool HaveCoin(const COutPoint &outpoint) const override;
582  std::optional<Coin> PeekCoin(const COutPoint& outpoint) const override;
583 
584 private:
586  std::vector<std::function<void()>> m_err_callbacks;
587 
588 };
589 
590 #endif // BITCOIN_COINS_H
CoinsCachePair * NextAndMaybeErase(CoinsCachePair &current) noexcept
Return the next entry after current, possibly erasing current.
Definition: coins.h:279
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:37
#define VARINT(obj)
Definition: serialize.h:491
CCoinsViewCache(CCoinsView *baseIn, bool deterministic=false)
Definition: coins.cpp:52
bool IsSpent() const
Either this coin never existed (see e.g.
Definition: coins.h:83
constexpr bool TrySub(T &i, const U j) noexcept
Definition: overflow.h:35
void SetNull()
Definition: transaction.h:154
size_t m_dirty_count
Definition: coins.h:386
bool IsCoinBase() const
Definition: coins.h:59
~CCoinsCacheEntry()
Definition: coins.h:167
CoinsCachePair m_sentinel
Definition: coins.h:380
A Coin in one level of the coins database caching hierarchy.
Definition: coins.h:109
assert(!tx.IsCoinBase())
CScript scriptPubKey
Definition: transaction.h:143
CoinsCachePair * m_next
Definition: coins.h:123
const Coin & AccessByTxid(const CCoinsViewCache &cache, const Txid &txid)
Utility function to find any unspent output with a given txid.
Definition: coins.cpp:386
Flags
Definition: coins.h:144
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
Definition: coins.cpp:179
void SetBackend(CCoinsView &viewIn)
Definition: coins.cpp:39
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher, std::equal_to< COutPoint >, PoolAllocator< CoinsCachePair, sizeof(CoinsCachePair)+sizeof(void *) *4 > > CCoinsMap
PoolAllocator&#39;s MAX_BLOCK_SIZE_BYTES parameter here uses sizeof the data, and adds the size of 4 poin...
Definition: coins.h:224
A UTXO entry.
Definition: coins.h:34
CCoinsMap & m_map
Definition: coins.h:302
ResetGuard(CCoinsViewCache &cache LIFETIMEBOUND) noexcept
Definition: coins.h:507
T check(T ptr)
CoinsCachePair * End() const noexcept
Definition: coins.h:276
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
Definition: memusage.h:31
size_t & m_dirty_count
Definition: coins.h:300
size_t GetDirtyCount() const noexcept
Definition: coins.h:297
std::optional< Coin > FetchCoinFromBase(const COutPoint &outpoint) const override
Definition: coins.h:541
std::vector< std::function< void()> > m_err_callbacks
A list of callbacks to execute upon leveldb read error.
Definition: coins.h:586
CCoinsMapMemoryResource m_cache_coins_memory_resource
Definition: coins.h:378
virtual void Next()=0
CoinsCachePair * m_prev
These are used to create a doubly linked list of flagged entries.
Definition: coins.h:122
void AddReadErrCallback(std::function< void()> f)
Definition: coins.h:576
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
Definition: coins.cpp:59
CTxOut out
unspent transaction output
Definition: coins.h:38
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 WillErase(CoinsCachePair &current) const noexcept
Definition: coins.h:296
std::vector< uint256 > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
Definition: coins.cpp:38
virtual ~CCoinsViewCursor()=default
unsigned int fCoinBase
whether containing transaction was a coinbase
Definition: coins.h:41
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
Definition: coins.cpp:193
bool IsFresh() const noexcept
Definition: coins.h:184
void ReallocateCache()
Force a reallocation of the cache map.
Definition: coins.cpp:341
CCoinsViewCache overlay that avoids populating/mutating parent cache layers on cache misses...
Definition: coins.h:538
Definition: common.h:29
virtual bool HaveCoin(const COutPoint &outpoint) const
Just check whether a given outpoint is unspent.
Definition: coins.cpp:28
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:44
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:329
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:83
void Serialize(Stream &s) const
Definition: coins.h:64
CCoinsMap::allocator_type::ResourceType CCoinsMapMemoryResource
Definition: coins.h:226
const bool m_deterministic
Definition: coins.h:370
bool SpendCoin(const COutPoint &outpoint, Coin *moveto=nullptr)
Spend a coin.
Definition: coins.cpp:153
DIRTY means the CCoinsCacheEntry is potentially different from the version in the parent cache...
Definition: coins.h:152
bool IsNull() const
Definition: transaction.h:160
CCoinsViewErrorCatcher(CCoinsView *view)
Definition: coins.h:574
uint256 hashBlock
Definition: coins.h:244
void SetBestBlock(const uint256 &hashBlock)
Definition: coins.cpp:204
virtual bool GetValue(Coin &coin) const =0
CoinsCachePair & m_sentinel
Definition: coins.h:301
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
Definition: coins.h:44
unsigned int GetCacheSize() const
Size of the cache (in number of transaction outputs)
Definition: coins.cpp:325
CCoinsCacheEntry() noexcept=default
std::pair< const COutPoint, CCoinsCacheEntry > CoinsCachePair
Definition: coins.h:93
CCoinsMap cacheCoins
Definition: coins.h:381
void EmplaceCoinInternalDANGER(COutPoint &&outpoint, Coin &&coin)
Emplace a coin into cacheCoins without performing any checks, marking the emplaced coin as dirty...
Definition: coins.cpp:132
#define LIFETIMEBOUND
Definition: attributes.h:16
virtual bool Valid() const =0
Abstract view on the open txout dataset.
Definition: coins.h:307
CoinsCachePair * Next() const noexcept
Only call Next when this entry is DIRTY, FRESH, or both.
Definition: coins.h:187
CCoinsView * base
Definition: coins.h:350
void Flush(bool reallocate_cache=true)
Push the modifications applied to this cache to its base and wipe local state.
Definition: coins.cpp:279
Cursor for iterating over the linked list of flagged entries in CCoinsViewCache.
Definition: coins.h:260
std::unique_ptr< CCoinsViewCursor > Cursor() const override
Get a cursor to iterate over the whole state.
Definition: coins.cpp:41
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:34
CoinsViewCacheCursor(size_t &dirty_count LIFETIMEBOUND, CoinsCachePair &sentinel LIFETIMEBOUND, CCoinsMap &map LIFETIMEBOUND, bool will_erase) noexcept
If will_erase is not set, iterating through the cursor will erase spent coins from the map...
Definition: coins.h:269
ResetGuard CreateResetGuard() noexcept
Create a scoped guard that will call Reset() on this cache when it goes out of scope.
Definition: coins.h:519
virtual std::vector< uint256 > GetHeadBlocks() const
Retrieve the range of blocks that may have been only partially written.
Definition: coins.cpp:20
virtual std::optional< Coin > PeekCoin(const COutPoint &outpoint) const
Retrieve the Coin (unspent transaction output) for a given outpoint, without caching results...
Definition: coins.cpp:18
uint8_t m_flags
Definition: coins.h:124
An output of a transaction.
Definition: transaction.h:139
CoinsCachePair * Prev() const noexcept
Only call Prev when this entry is DIRTY, FRESH, or both.
Definition: coins.h:194
virtual void BatchWrite(CoinsViewCacheCursor &cursor, const uint256 &hashBlock)
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: coins.cpp:21
void BatchWrite(CoinsViewCacheCursor &cursor, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: coins.cpp:40
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:28
virtual ~CCoinsView()=default
As we use CCoinsViews polymorphically, have a virtual destructor.
unsigned int nHeight
Coin()
empty constructor
Definition: coins.h:57
CCoinsViewBacked(CCoinsView *viewIn)
Definition: coins.cpp:33
#define Assume(val)
Assume is the identity function.
Definition: check.h:125
void AddCoin(const COutPoint &outpoint, Coin &&coin, bool possible_overwrite)
Add a coin.
Definition: coins.cpp:89
virtual bool GetKey(COutPoint &key) const =0
std::unique_ptr< CCoinsViewCursor > Cursor() const override
Get a cursor to iterate over the whole state.
Definition: coins.h:412
CoinsCachePair * Begin() const noexcept
Definition: coins.h:275
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:198
Forwards all allocations/deallocations to the PoolResource.
Definition: pool.h:289
int flags
Definition: bitcoin-tx.cpp:529
size_t GetTotalCount() const noexcept
Definition: coins.h:298
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: coins.cpp:36
256-bit opaque blob.
Definition: uint256.h:195
uint256 hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
Definition: coins.h:377
size_t GetDirtyCount() const noexcept
Number of dirty cache entries (transaction outputs)
Definition: coins.h:484
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check=false)
Utility function to add all of a transaction&#39;s outputs to a cache.
Definition: coins.cpp:142
void Sync()
Push the modifications applied to this cache to its base while retaining the contents of this cache (...
Definition: coins.cpp:291
void Unserialize(Stream &s)
Definition: coins.h:72
FRESH means the parent cache does not have this coin or that it is a spent coin in the parent cache...
Definition: coins.h:162
static void SetDirty(CoinsCachePair &pair, CoinsCachePair &sentinel) noexcept
Definition: coins.h:172
virtual size_t EstimateSize() const
Estimate database size (0 if not implemented)
Definition: coins.h:342
void SelfRef(CoinsCachePair &pair) noexcept
Only use this for initializing the linked list sentinel.
Definition: coins.h:201
void Uncache(const COutPoint &outpoint)
Removes the UTXO with the given outpoint from the cache, if it is not modified.
Definition: coins.cpp:310
virtual uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:19
CCoinsViewCache & m_cache
Definition: coins.h:506
size_t DynamicMemoryUsage() const
Definition: coins.h:87
ResetGuard & operator=(const ResetGuard &)=delete
virtual std::optional< Coin > GetCoin(const COutPoint &outpoint) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:17
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:415
size_t cachedCoinsUsage
Definition: coins.h:384
void Clear()
Definition: coins.h:50
CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const
Definition: coins.cpp:68
CCoinsViewCursor(const uint256 &hashBlockIn)
Definition: coins.h:232
virtual std::unique_ptr< CCoinsViewCursor > Cursor() const
Get a cursor to iterate over the whole state.
Definition: coins.cpp:26
static void AddFlags(uint8_t flags, CoinsCachePair &pair, CoinsCachePair &sentinel) noexcept
Adding a flag requires a reference to the sentinel of the flagged pair linked list.
Definition: coins.h:127
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:280
void SanityCheck() const
Run an internal sanity check on the cache data structure. */.
Definition: coins.cpp:351
CCoinsView backed by another CCoinsView.
Definition: coins.h:347
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
Definition: coins.cpp:42
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:367
static void SetFresh(CoinsCachePair &pair, CoinsCachePair &sentinel) noexcept
Definition: coins.h:173
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: coins.cpp:420
void Reset() noexcept
Discard all modifications made to this cache without flushing to the base view.
Definition: coins.cpp:302
const uint256 & GetBestBlock() const
Get best block at the time this cursor was created.
Definition: coins.h:242
bool IsDirty() const noexcept
Definition: coins.h:183
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate...
Definition: coins.h:571
Coin(const CTxOut &outIn, int nHeightIn, bool fCoinBaseIn)
Definition: coins.h:48
void SetClean() noexcept
Definition: coins.h:175
void BatchWrite(CoinsViewCacheCursor &cursor, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: coins.cpp:208
virtual std::optional< Coin > FetchCoinFromBase(const COutPoint &outpoint) const
Definition: coins.cpp:63
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:425
Coin coin
Definition: coins.h:142
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: coins.cpp:188
Coin(CTxOut &&outIn, int nHeightIn, bool fCoinBaseIn)
construct a Coin from a CTxOut and height/coinbase information.
Definition: coins.h:47
Cursor for iterating over CoinsView state.
Definition: coins.h:229