 |
Bitcoin Core
21.99.0
P2P Digital Currency
|
Go to the documentation of this file.
47 CCoinsMap::iterator ret =
cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::forward_as_tuple(std::move(tmp))).first;
48 if (ret->second.coin.IsSpent()) {
60 coin =
it->second.coin;
68 if (coin.out.scriptPubKey.IsUnspendable())
return;
69 CCoinsMap::iterator
it;
71 std::tie(
it, inserted) =
cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());
76 if (!possible_overwrite) {
77 if (!
it->second.coin.IsSpent()) {
78 throw std::logic_error(
"Attempted to overwrite an unspent coin (when possible_overwrite is false)");
95 it->second.coin = std::move(coin);
103 std::piecewise_construct,
104 std::forward_as_tuple(std::move(outpoint)),
111 for (
size_t i = 0; i < tx.
vout.size(); ++i) {
112 bool overwrite = check_for_overwrite ? cache.
HaveCoin(
COutPoint(txid, i)) : fCoinbase;
124 *moveout = std::move(
it->second.coin);
130 it->second.coin.Clear();
138 CCoinsMap::const_iterator
it =
FetchCoin(outpoint);
142 return it->second.coin;
147 CCoinsMap::const_iterator
it =
FetchCoin(outpoint);
152 CCoinsMap::const_iterator
it =
cacheCoins.find(outpoint);
167 for (CCoinsMap::iterator
it = mapCoins.begin();
it != mapCoins.end();
it = mapCoins.erase(
it)) {
180 entry.
coin = std::move(
it->second.coin);
197 throw std::logic_error(
"FRESH flag misapplied to coin that exists in parent cache");
208 itUs->second.coin = std::move(
it->second.coin);
245 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
270 if (!alternate.
IsSpent())
return alternate;
279 }
catch(
const std::runtime_error& e) {
283 LogPrintf(
"Error reading from database: %s\n", e.what());
void SetBackend(CCoinsView &viewIn)
size_t GetSerializeSize(const T &t, int nVersion=0)
const std::vector< CTxIn > vin
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transaction outputs)
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
CCoinsViewCache(CCoinsView *baseIn)
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
void AddCoin(const COutPoint &outpoint, Coin &&coin, bool possible_overwrite)
Add a coin.
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
void EmplaceCoinInternalDANGER(COutPoint &&outpoint, Coin &&coin)
Emplace a coin into cacheCoins without performing any checks, marking the emplaced coin as dirty.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
void ReallocateCache()
Force a reallocation of the cache map.
The basic transaction that is broadcasted on the network and contained in blocks.
virtual bool HaveCoin(const COutPoint &outpoint) const
Just check whether a given outpoint is unspent.
virtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
Abstract view on the open txout dataset.
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.
Cursor for iterating over CoinsView state.
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
Do a bulk modification (multiple Coin changes + BestBlock change).
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
bool SpendCoin(const COutPoint &outpoint, Coin *moveto=nullptr)
Spend a coin.
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
An output of a transaction.
static const Coin coinEmpty
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
const std::vector< CTxOut > vout
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
virtual std::vector< uint256 > GetHeadBlocks() const
Retrieve the range of blocks that may have been only partially written.
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
uint256 hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
virtual CCoinsViewCursor * Cursor() const
Get a cursor to iterate over the whole state.
virtual size_t EstimateSize() const
Estimate database size (0 if not implemented)
CCoinsViewBacked(CCoinsView *viewIn)
CCoinsView that adds a memory cache for transactions to another CCoinsView.
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
CCoinsView backed by another CCoinsView.
void SetBestBlock(const uint256 &hashBlock)
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view.
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher > CCoinsMap
std::vector< uint256 > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
void Uncache(const COutPoint &outpoint)
Removes the UTXO with the given outpoint from the cache, if it is not modified.
size_t DynamicMemoryUsage() const
const uint256 & GetHash() const
std::vector< std::function< void()> > m_err_callbacks
A list of callbacks to execute upon leveldb read error.
An outpoint - a combination of a transaction hash and an index n into its vout.
const Coin & AccessByTxid(const CCoinsViewCache &view, const uint256 &txid)
Utility function to find any unspent output with a given txid.
static const size_t MAX_OUTPUTS_PER_BLOCK
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
bool IsSpent() const
Either this coin never existed (see e.g.
@ FRESH
FRESH means the parent cache does not have this coin or that it is a spent coin in the parent cache.
@ DIRTY
DIRTY means the CCoinsCacheEntry is potentially different from the version in the parent cache.
CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const
virtual uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
assert(std::addressof(::ChainstateActive().CoinsTip())==std::addressof(coins_cache))
static const int WITNESS_SCALE_FACTOR
A Coin in one level of the coins database caching hierarchy.
static const size_t MIN_TRANSACTION_OUTPUT_WEIGHT
bool Flush()
Push the modifications applied to this cache to its base.
static const int PROTOCOL_VERSION
network protocol versioning