19 return std::vector<BlockHash>();
60 : k0(
GetRand(
std::numeric_limits<uint64_t>::max())),
72 CCoinsMap::iterator it =
cacheCoins.find(outpoint);
80 CCoinsMap::iterator ret =
82 .emplace(std::piecewise_construct, std::forward_as_tuple(outpoint),
83 std::forward_as_tuple(std::move(tmp)))
85 if (ret->second.coin.IsSpent()) {
95 CCoinsMap::const_iterator it =
FetchCoin(outpoint);
99 coin = it->second.coin;
104 bool possible_overwrite) {
109 CCoinsMap::iterator it;
111 std::tie(it, inserted) =
113 std::forward_as_tuple(outpoint), std::tuple<>());
118 if (!possible_overwrite) {
119 if (!it->second.coin.IsSpent()) {
120 throw std::logic_error(
"Attempted to overwrite an unspent coin " 121 "(when possible_overwrite is false)");
138 it->second.coin = std::move(coin);
145 bool check_for_overwrite) {
148 for (
size_t i = 0; i < tx.
vout.size(); ++i) {
151 check_for_overwrite ? cache.
HaveCoin(outpoint) : fCoinbase;
161 CCoinsMap::iterator it =
FetchCoin(outpoint);
167 *moveout = std::move(it->second.coin);
173 it->second.coin.Clear();
181 CCoinsMap::const_iterator it =
FetchCoin(outpoint);
185 return it->second.coin;
189 CCoinsMap::const_iterator it =
FetchCoin(outpoint);
190 return it !=
cacheCoins.end() && !it->second.coin.IsSpent();
194 CCoinsMap::const_iterator it =
cacheCoins.find(outpoint);
195 return (it !=
cacheCoins.end() && !it->second.coin.IsSpent());
211 for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();
212 it = mapCoins.erase(it)) {
217 CCoinsMap::iterator itUs =
cacheCoins.find(it->first);
222 it->second.coin.IsSpent())) {
226 entry.
coin = std::move(it->second.coin);
239 !itUs->second.coin.IsSpent()) {
244 throw std::logic_error(
"FRESH flag misapplied to coin that " 245 "exists in parent cache");
249 it->second.coin.IsSpent()) {
257 itUs->second.coin = std::move(it->second.coin);
279 CCoinsMap::iterator it =
cacheCoins.find(outpoint);
280 if (it !=
cacheCoins.end() && it->second.flags == 0) {
295 for (
size_t i = 0; i < tx.
vin.size(); i++) {
323 }
catch (
const std::runtime_error &e) {
324 for (
auto f : m_err_callbacks) {
327 LogPrintf(
"Error reading from database: %s\n", e.what());
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
uint64_t GetRand(uint64_t nMax) noexcept
CCoinsViewCache(CCoinsView *baseIn)
std::vector< BlockHash > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
A Coin in one level of the coins database caching hierarchy.
virtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
bool Flush()
Push the modifications applied to this cache to its base.
void SetBackend(CCoinsView &viewIn)
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
static const uint64_t MAX_TX_SIZE
The maximum allowed size for a transaction, in bytes.
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
static const size_t MAX_OUTPUTS_PER_TX
static void LogPrintf(const char *fmt, const Args &... args)
virtual CCoinsViewCursor * Cursor() const
Get a cursor to iterate over the whole state.
virtual bool HaveCoin(const COutPoint &outpoint) const
Just check whether a given outpoint is unspent.
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
static const Coin coinEmpty
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view...
bool SpendCoin(const COutPoint &outpoint, Coin *moveto=nullptr)
Spend a coin.
const std::vector< CTxIn > vin
size_t GetSerializeSize(const T &t, int nVersion=0)
DIRTY means the CCoinsCacheEntry is potentially different from the version in the parent cache...
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack...
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.
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transaction outputs)
virtual std::vector< BlockHash > GetHeadBlocks() const
Retrieve the range of blocks that may have been only partially written.
Abstract view on the open txout dataset.
void AddCoin(const COutPoint &outpoint, Coin coin, bool possible_overwrite)
Add a coin.
virtual bool BatchWrite(CCoinsMap &mapCoins, const BlockHash &hashBlock)
Do a bulk modification (multiple Coin changes + BestBlock change).
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher > CCoinsMap
const std::vector< CTxOut > vout
An output of a transaction.
An outpoint - a combination of a transaction hash and an index n into its vout.
static const uint8_t k1[32]
CCoinsViewBacked(CCoinsView *viewIn)
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
BlockHash hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
FRESH means the parent cache does not have this coin or that it is a spent coin in the parent cache...
bool BatchWrite(CCoinsMap &mapCoins, const BlockHash &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
A BlockHash is a unqiue identifier for a block.
virtual size_t EstimateSize() const
Estimate database size (0 if not implemented)
A TxId is the identifier of a transaction.
void SetBestBlock(const BlockHash &hashBlock)
static const int PROTOCOL_VERSION
network protocol versioning
void Uncache(const COutPoint &outpoint)
Removes the UTXO with the given outpoint from the cache, if it is not modified.
bool BatchWrite(CCoinsMap &mapCoins, const BlockHash &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
size_t DynamicMemoryUsage() const
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
virtual BlockHash GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
BlockHash GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const
const Coin & AccessByTxid(const CCoinsViewCache &view, const TxId &txid)
Utility function to find any unspent output with a given txid.
BlockHash GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView backed by another CCoinsView.
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
CCoinsView that adds a memory cache for transactions to another CCoinsView.
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Cursor for iterating over CoinsView state.