Bitcoin Core  28.1.0
P2P Digital Currency
coins.cpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2022 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 <logging.h>
9 #include <random.h>
10 #include <util/trace.h>
11 
12 bool CCoinsView::GetCoin(const COutPoint &outpoint, Coin &coin) const { return false; }
14 std::vector<uint256> CCoinsView::GetHeadBlocks() const { return std::vector<uint256>(); }
15 bool CCoinsView::BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashBlock) { return false; }
16 std::unique_ptr<CCoinsViewCursor> CCoinsView::Cursor() const { return nullptr; }
17 
18 bool CCoinsView::HaveCoin(const COutPoint &outpoint) const
19 {
20  Coin coin;
21  return GetCoin(outpoint, coin);
22 }
23 
25 bool CCoinsViewBacked::GetCoin(const COutPoint &outpoint, Coin &coin) const { return base->GetCoin(outpoint, coin); }
26 bool CCoinsViewBacked::HaveCoin(const COutPoint &outpoint) const { return base->HaveCoin(outpoint); }
28 std::vector<uint256> CCoinsViewBacked::GetHeadBlocks() const { return base->GetHeadBlocks(); }
29 void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; }
30 bool CCoinsViewBacked::BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashBlock) { return base->BatchWrite(cursor, hashBlock); }
31 std::unique_ptr<CCoinsViewCursor> CCoinsViewBacked::Cursor() const { return base->Cursor(); }
32 size_t CCoinsViewBacked::EstimateSize() const { return base->EstimateSize(); }
33 
34 CCoinsViewCache::CCoinsViewCache(CCoinsView* baseIn, bool deterministic) :
35  CCoinsViewBacked(baseIn), m_deterministic(deterministic),
36  cacheCoins(0, SaltedOutpointHasher(/*deterministic=*/deterministic), CCoinsMap::key_equal{}, &m_cache_coins_memory_resource)
37 {
38  m_sentinel.second.SelfRef(m_sentinel);
39 }
40 
43 }
44 
45 CCoinsMap::iterator CCoinsViewCache::FetchCoin(const COutPoint &outpoint) const {
46  const auto [ret, inserted] = cacheCoins.try_emplace(outpoint);
47  if (inserted) {
48  if (!base->GetCoin(outpoint, ret->second.coin)) {
49  cacheCoins.erase(ret);
50  return cacheCoins.end();
51  }
52  if (ret->second.coin.IsSpent()) {
53  // The parent only has an empty entry for this outpoint; we can consider our version as fresh.
54  ret->second.AddFlags(CCoinsCacheEntry::FRESH, *ret, m_sentinel);
55  }
56  cachedCoinsUsage += ret->second.coin.DynamicMemoryUsage();
57  }
58  return ret;
59 }
60 
61 bool CCoinsViewCache::GetCoin(const COutPoint &outpoint, Coin &coin) const {
62  CCoinsMap::const_iterator it = FetchCoin(outpoint);
63  if (it != cacheCoins.end()) {
64  coin = it->second.coin;
65  return !coin.IsSpent();
66  }
67  return false;
68 }
69 
70 void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possible_overwrite) {
71  assert(!coin.IsSpent());
72  if (coin.out.scriptPubKey.IsUnspendable()) return;
73  CCoinsMap::iterator it;
74  bool inserted;
75  std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());
76  bool fresh = false;
77  if (!inserted) {
78  cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
79  }
80  if (!possible_overwrite) {
81  if (!it->second.coin.IsSpent()) {
82  throw std::logic_error("Attempted to overwrite an unspent coin (when possible_overwrite is false)");
83  }
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  fresh = !it->second.IsDirty();
98  }
99  it->second.coin = std::move(coin);
100  it->second.AddFlags(CCoinsCacheEntry::DIRTY | (fresh ? CCoinsCacheEntry::FRESH : 0), *it, m_sentinel);
101  cachedCoinsUsage += it->second.coin.DynamicMemoryUsage();
102  TRACE5(utxocache, add,
103  outpoint.hash.data(),
104  (uint32_t)outpoint.n,
105  (uint32_t)it->second.coin.nHeight,
106  (int64_t)it->second.coin.out.nValue,
107  (bool)it->second.coin.IsCoinBase());
108 }
109 
111  cachedCoinsUsage += coin.DynamicMemoryUsage();
112  auto [it, inserted] = cacheCoins.emplace(
113  std::piecewise_construct,
114  std::forward_as_tuple(std::move(outpoint)),
115  std::forward_as_tuple(std::move(coin)));
116  if (inserted) {
117  it->second.AddFlags(CCoinsCacheEntry::DIRTY, *it, m_sentinel);
118  }
119 }
120 
121 void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check_for_overwrite) {
122  bool fCoinbase = tx.IsCoinBase();
123  const Txid& txid = tx.GetHash();
124  for (size_t i = 0; i < tx.vout.size(); ++i) {
125  bool overwrite = check_for_overwrite ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
126  // Coinbase transactions can always be overwritten, in order to correctly
127  // deal with the pre-BIP30 occurrences of duplicate coinbase transactions.
128  cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite);
129  }
130 }
131 
132 bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
133  CCoinsMap::iterator it = FetchCoin(outpoint);
134  if (it == cacheCoins.end()) return false;
135  cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
136  TRACE5(utxocache, spent,
137  outpoint.hash.data(),
138  (uint32_t)outpoint.n,
139  (uint32_t)it->second.coin.nHeight,
140  (int64_t)it->second.coin.out.nValue,
141  (bool)it->second.coin.IsCoinBase());
142  if (moveout) {
143  *moveout = std::move(it->second.coin);
144  }
145  if (it->second.IsFresh()) {
146  cacheCoins.erase(it);
147  } else {
148  it->second.AddFlags(CCoinsCacheEntry::DIRTY, *it, m_sentinel);
149  it->second.coin.Clear();
150  }
151  return true;
152 }
153 
154 static const Coin coinEmpty;
155 
156 const Coin& CCoinsViewCache::AccessCoin(const COutPoint &outpoint) const {
157  CCoinsMap::const_iterator it = FetchCoin(outpoint);
158  if (it == cacheCoins.end()) {
159  return coinEmpty;
160  } else {
161  return it->second.coin;
162  }
163 }
164 
165 bool CCoinsViewCache::HaveCoin(const COutPoint &outpoint) const {
166  CCoinsMap::const_iterator it = FetchCoin(outpoint);
167  return (it != cacheCoins.end() && !it->second.coin.IsSpent());
168 }
169 
170 bool CCoinsViewCache::HaveCoinInCache(const COutPoint &outpoint) const {
171  CCoinsMap::const_iterator it = cacheCoins.find(outpoint);
172  return (it != cacheCoins.end() && !it->second.coin.IsSpent());
173 }
174 
176  if (hashBlock.IsNull())
178  return hashBlock;
179 }
180 
181 void CCoinsViewCache::SetBestBlock(const uint256 &hashBlockIn) {
182  hashBlock = hashBlockIn;
183 }
184 
185 bool CCoinsViewCache::BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashBlockIn) {
186  for (auto it{cursor.Begin()}; it != cursor.End(); it = cursor.NextAndMaybeErase(*it)) {
187  // Ignore non-dirty entries (optimization).
188  if (!it->second.IsDirty()) {
189  continue;
190  }
191  CCoinsMap::iterator itUs = cacheCoins.find(it->first);
192  if (itUs == cacheCoins.end()) {
193  // The parent cache does not have an entry, while the child cache does.
194  // We can ignore it if it's both spent and FRESH in the child
195  if (!(it->second.IsFresh() && it->second.coin.IsSpent())) {
196  // Create the coin in the parent cache, move the data up
197  // and mark it as dirty.
198  itUs = cacheCoins.try_emplace(it->first).first;
199  CCoinsCacheEntry& entry{itUs->second};
200  if (cursor.WillErase(*it)) {
201  // Since this entry will be erased,
202  // we can move the coin into us instead of copying it
203  entry.coin = std::move(it->second.coin);
204  } else {
205  entry.coin = it->second.coin;
206  }
207  cachedCoinsUsage += entry.coin.DynamicMemoryUsage();
208  entry.AddFlags(CCoinsCacheEntry::DIRTY, *itUs, m_sentinel);
209  // We can mark it FRESH in the parent if it was FRESH in the child
210  // Otherwise it might have just been flushed from the parent's cache
211  // and already exist in the grandparent
212  if (it->second.IsFresh()) {
213  entry.AddFlags(CCoinsCacheEntry::FRESH, *itUs, m_sentinel);
214  }
215  }
216  } else {
217  // Found the entry in the parent cache
218  if (it->second.IsFresh() && !itUs->second.coin.IsSpent()) {
219  // The coin was marked FRESH in the child cache, but the coin
220  // exists in the parent cache. If this ever happens, it means
221  // the FRESH flag was misapplied and there is a logic error in
222  // the calling code.
223  throw std::logic_error("FRESH flag misapplied to coin that exists in parent cache");
224  }
225 
226  if (itUs->second.IsFresh() && it->second.coin.IsSpent()) {
227  // The grandparent cache does not have an entry, and the coin
228  // has been spent. We can just delete it from the parent cache.
229  cachedCoinsUsage -= itUs->second.coin.DynamicMemoryUsage();
230  cacheCoins.erase(itUs);
231  } else {
232  // A normal modification.
233  cachedCoinsUsage -= itUs->second.coin.DynamicMemoryUsage();
234  if (cursor.WillErase(*it)) {
235  // Since this entry will be erased,
236  // we can move the coin into us instead of copying it
237  itUs->second.coin = std::move(it->second.coin);
238  } else {
239  itUs->second.coin = it->second.coin;
240  }
241  cachedCoinsUsage += itUs->second.coin.DynamicMemoryUsage();
242  itUs->second.AddFlags(CCoinsCacheEntry::DIRTY, *itUs, m_sentinel);
243  // NOTE: It isn't safe to mark the coin as FRESH in the parent
244  // cache. If it already existed and was spent in the parent
245  // cache then marking it FRESH would prevent that spentness
246  // from being flushed to the grandparent.
247  }
248  }
249  }
250  hashBlock = hashBlockIn;
251  return true;
252 }
253 
255  auto cursor{CoinsViewCacheCursor(cachedCoinsUsage, m_sentinel, cacheCoins, /*will_erase=*/true)};
256  bool fOk = base->BatchWrite(cursor, hashBlock);
257  if (fOk) {
258  cacheCoins.clear();
259  ReallocateCache();
260  }
261  cachedCoinsUsage = 0;
262  return fOk;
263 }
264 
266 {
267  auto cursor{CoinsViewCacheCursor(cachedCoinsUsage, m_sentinel, cacheCoins, /*will_erase=*/false)};
268  bool fOk = base->BatchWrite(cursor, hashBlock);
269  if (fOk) {
270  if (m_sentinel.second.Next() != &m_sentinel) {
271  /* BatchWrite must clear flags of all entries */
272  throw std::logic_error("Not all unspent flagged entries were cleared");
273  }
274  }
275  return fOk;
276 }
277 
279 {
280  CCoinsMap::iterator it = cacheCoins.find(hash);
281  if (it != cacheCoins.end() && !it->second.IsDirty() && !it->second.IsFresh()) {
282  cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
283  TRACE5(utxocache, uncache,
284  hash.hash.data(),
285  (uint32_t)hash.n,
286  (uint32_t)it->second.coin.nHeight,
287  (int64_t)it->second.coin.out.nValue,
288  (bool)it->second.coin.IsCoinBase());
289  cacheCoins.erase(it);
290  }
291 }
292 
293 unsigned int CCoinsViewCache::GetCacheSize() const {
294  return cacheCoins.size();
295 }
296 
298 {
299  if (!tx.IsCoinBase()) {
300  for (unsigned int i = 0; i < tx.vin.size(); i++) {
301  if (!HaveCoin(tx.vin[i].prevout)) {
302  return false;
303  }
304  }
305  }
306  return true;
307 }
308 
310 {
311  // Cache should be empty when we're calling this.
312  assert(cacheCoins.size() == 0);
313  cacheCoins.~CCoinsMap();
314  m_cache_coins_memory_resource.~CCoinsMapMemoryResource();
316  ::new (&cacheCoins) CCoinsMap{0, SaltedOutpointHasher{/*deterministic=*/m_deterministic}, CCoinsMap::key_equal{}, &m_cache_coins_memory_resource};
317 }
318 
320 {
321  size_t recomputed_usage = 0;
322  size_t count_flagged = 0;
323  for (const auto& [_, entry] : cacheCoins) {
324  unsigned attr = 0;
325  if (entry.IsDirty()) attr |= 1;
326  if (entry.IsFresh()) attr |= 2;
327  if (entry.coin.IsSpent()) attr |= 4;
328  // Only 5 combinations are possible.
329  assert(attr != 2 && attr != 4 && attr != 7);
330 
331  // Recompute cachedCoinsUsage.
332  recomputed_usage += entry.coin.DynamicMemoryUsage();
333 
334  // Count the number of entries we expect in the linked list.
335  if (entry.IsDirty() || entry.IsFresh()) ++count_flagged;
336  }
337  // Iterate over the linked list of flagged entries.
338  size_t count_linked = 0;
339  for (auto it = m_sentinel.second.Next(); it != &m_sentinel; it = it->second.Next()) {
340  // Verify linked list integrity.
341  assert(it->second.Next()->second.Prev() == it);
342  assert(it->second.Prev()->second.Next() == it);
343  // Verify they are actually flagged.
344  assert(it->second.IsDirty() || it->second.IsFresh());
345  // Count the number of entries actually in the list.
346  ++count_linked;
347  }
348  assert(count_linked == count_flagged);
349  assert(recomputed_usage == cachedCoinsUsage);
350 }
351 
354 
355 const Coin& AccessByTxid(const CCoinsViewCache& view, const Txid& txid)
356 {
357  COutPoint iter(txid, 0);
358  while (iter.n < MAX_OUTPUTS_PER_BLOCK) {
359  const Coin& alternate = view.AccessCoin(iter);
360  if (!alternate.IsSpent()) return alternate;
361  ++iter.n;
362  }
363  return coinEmpty;
364 }
365 
366 template <typename Func>
367 static bool ExecuteBackedWrapper(Func func, const std::vector<std::function<void()>>& err_callbacks)
368 {
369  try {
370  return func();
371  } catch(const std::runtime_error& e) {
372  for (const auto& f : err_callbacks) {
373  f();
374  }
375  LogError("Error reading from database: %s\n", e.what());
376  // Starting the shutdown sequence and returning false to the caller would be
377  // interpreted as 'entry not found' (as opposed to unable to read data), and
378  // could lead to invalid interpretation. Just exit immediately, as we can't
379  // continue anyway, and all writes should be atomic.
380  std::abort();
381  }
382 }
383 
384 bool CCoinsViewErrorCatcher::GetCoin(const COutPoint &outpoint, Coin &coin) const {
385  return ExecuteBackedWrapper([&]() { return CCoinsViewBacked::GetCoin(outpoint, coin); }, m_err_callbacks);
386 }
387 
388 bool CCoinsViewErrorCatcher::HaveCoin(const COutPoint &outpoint) const {
389  return ExecuteBackedWrapper([&]() { return CCoinsViewBacked::HaveCoin(outpoint); }, m_err_callbacks);
390 }
CoinsCachePair * NextAndMaybeErase(CoinsCachePair &current) noexcept
Return the next entry after current, possibly erasing current.
Definition: coins.h:278
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:384
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:27
CCoinsViewCache(CCoinsView *baseIn, bool deterministic=false)
Definition: coins.cpp:34
bool IsSpent() const
Either this coin never existed (see e.g.
Definition: coins.h:81
int ret
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
CoinsCachePair m_sentinel
Definition: coins.h:372
A Coin in one level of the coins database caching hierarchy.
Definition: coins.h:108
assert(!tx.IsCoinBase())
virtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:12
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
Definition: coins.cpp:156
bool Flush()
Push the modifications applied to this cache to its base and wipe local state.
Definition: coins.cpp:254
void SetBackend(CCoinsView &viewIn)
Definition: coins.cpp:29
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:223
A UTXO entry.
Definition: coins.h:32
CoinsCachePair * End() const noexcept
Definition: coins.h:275
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
Definition: memusage.h:30
virtual bool BatchWrite(CoinsViewCacheCursor &cursor, const uint256 &hashBlock)
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: coins.cpp:15
std::vector< std::function< void()> > m_err_callbacks
A list of callbacks to execute upon leveldb read error.
Definition: coins.h:522
CCoinsMapMemoryResource m_cache_coins_memory_resource
Definition: coins.h:370
bool BatchWrite(CoinsViewCacheCursor &cursor, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: coins.cpp:30
size_t GetSerializeSize(const T &t)
Definition: serialize.h:1101
unsigned int nHeight
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
Definition: coins.cpp:41
bool WillErase(CoinsCachePair &current) const noexcept
Definition: coins.h:294
std::vector< uint256 > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
Definition: coins.cpp:28
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
Definition: coins.cpp:170
void ReallocateCache()
Force a reallocation of the cache map.
Definition: coins.cpp:309
virtual bool HaveCoin(const COutPoint &outpoint) const
Just check whether a given outpoint is unspent.
Definition: coins.cpp:18
static const Coin coinEmpty
Definition: coins.cpp:154
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:297
CCoinsMap::allocator_type::ResourceType CCoinsMapMemoryResource
Definition: coins.h:225
bool IsCoinBase() const
Definition: transaction.h:356
const bool m_deterministic
Definition: coins.h:362
bool SpendCoin(const COutPoint &outpoint, Coin *moveto=nullptr)
Spend a coin.
Definition: coins.cpp:132
const std::vector< CTxIn > vin
Definition: transaction.h:306
bool Func(const std::string &str, Span< const char > &sp)
Parse a function call.
Definition: parsing.cpp:24
DIRTY means the CCoinsCacheEntry is potentially different from the version in the parent cache...
Definition: coins.h:142
const Coin & AccessByTxid(const CCoinsViewCache &view, const Txid &txid)
Utility function to find any unspent output with a given txid.
Definition: coins.cpp:355
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
Definition: consensus.h:15
void SetBestBlock(const uint256 &hashBlock)
Definition: coins.cpp:181
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check_for_overwrite)
Utility function to add all of a transaction&#39;s outputs to a cache.
Definition: coins.cpp:121
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transaction outputs)
Definition: coins.cpp:293
CCoinsMap cacheCoins
Definition: coins.h:373
void EmplaceCoinInternalDANGER(COutPoint &&outpoint, Coin &&coin)
Emplace a coin into cacheCoins without performing any checks, marking the emplaced coin as dirty...
Definition: coins.cpp:110
Abstract view on the open txout dataset.
Definition: coins.h:303
CCoinsView * base
Definition: coins.h:343
Cursor for iterating over the linked list of flagged entries in CCoinsViewCache.
Definition: coins.h:259
std::unique_ptr< CCoinsViewCursor > Cursor() const override
Get a cursor to iterate over the whole state.
Definition: coins.cpp:31
Txid hash
Definition: transaction.h:31
uint32_t n
Definition: transaction.h:32
const std::vector< CTxOut > vout
Definition: transaction.h:307
virtual std::vector< uint256 > GetHeadBlocks() const
Retrieve the range of blocks that may have been only partially written.
Definition: coins.cpp:14
An output of a transaction.
Definition: transaction.h:149
static bool ExecuteBackedWrapper(Func func, const std::vector< std::function< void()>> &err_callbacks)
Definition: coins.cpp:367
constexpr const std::byte * data() const
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:28
constexpr bool IsNull() const
Definition: uint256.h:46
CCoinsViewBacked(CCoinsView *viewIn)
Definition: coins.cpp:24
void AddCoin(const COutPoint &outpoint, Coin &&coin, bool possible_overwrite)
Add a coin.
Definition: coins.cpp:70
#define TRACE5(context, event, a, b, c, d, e)
Definition: trace.h:35
CoinsCachePair * Begin() const noexcept
Definition: coins.h:274
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:175
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: coins.cpp:26
256-bit opaque blob.
Definition: uint256.h:178
uint256 hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
Definition: coins.h:369
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:61
FRESH means the parent cache does not have this coin or that it is a spent coin in the parent cache...
Definition: coins.h:152
virtual size_t EstimateSize() const
Estimate database size (0 if not implemented)
Definition: coins.h:335
#define LogError(...)
Definition: logging.h:271
void Uncache(const COutPoint &outpoint)
Removes the UTXO with the given outpoint from the cache, if it is not modified.
Definition: coins.cpp:278
virtual uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:13
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:25
bool BatchWrite(CoinsViewCacheCursor &cursor, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: coins.cpp:185
static const size_t MAX_OUTPUTS_PER_BLOCK
Definition: coins.cpp:353
size_t cachedCoinsUsage
Definition: coins.h:376
CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const
Definition: coins.cpp:45
virtual std::unique_ptr< CCoinsViewCursor > Cursor() const
Get a cursor to iterate over the whole state.
Definition: coins.cpp:16
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:295
void SanityCheck() const
Run an internal sanity check on the cache data structure. */.
Definition: coins.cpp:319
CCoinsView backed by another CCoinsView.
Definition: coins.h:340
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
Definition: coins.cpp:32
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:359
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: coins.cpp:388
static const size_t MIN_TRANSACTION_OUTPUT_WEIGHT
Definition: coins.cpp:352
bilingual_str _(ConstevalStringLiteral str)
Translation function.
Definition: translation.h:80
bool Sync()
Push the modifications applied to this cache to its base while retaining the contents of this cache (...
Definition: coins.cpp:265
const Txid & GetHash() const LIFETIMEBOUND
Definition: transaction.h:343
Coin coin
Definition: coins.h:132
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: coins.cpp:165