supply code – What’s CCoinsCacheEntry within the Bitcoin Core?

0
48410
supply code – What’s CCoinsCacheEntry within the Bitcoin Core?


CCoinsCacheEntry is applied right here.

/**
 * A Coin in a single degree of the cash database caching hierarchy.
 *
 * A coin can both be:
 * - unspent or spent (through which case the Coin object shall be nulled out - see Coin.Clear())
 * - DIRTY or not DIRTY
 * - FRESH or not FRESH
 *
 * Out of those 2^3 = 8 states, just some mixtures are legitimate:
 * - unspent, FRESH, DIRTY (e.g. a brand new coin created within the cache)
 * - unspent, not FRESH, DIRTY (e.g. a coin modified within the cache throughout a reorg)
 * - unspent, not FRESH, not DIRTY (e.g. an unspent coin fetched from the mother or father cache)
 * - spent, FRESH, not DIRTY (e.g. a spent coin fetched from the mother or father cache)
 * - spent, not FRESH, DIRTY (e.g. a coin is spent and spentness must be flushed to the mother or father)
 */
struct CCoinsCacheEntry
{
    Coin coin; // The precise cached knowledge.
    unsigned char flags;

    enum Flags {
        /**
         * DIRTY means the CCoinsCacheEntry is doubtlessly completely different from the
         * model within the mother or father cache. Failure to mark a coin as DIRTY when
         * it's doubtlessly completely different from the mother or father cache will trigger a
         * consensus failure, for the reason that coin's state will not get written to the
         * mother or father when the cache is flushed.
         */
        DIRTY = (1 << 0),
        /**
         * FRESH means the mother or father cache doesn't have this coin or that it's a
         * spent coin within the mother or father cache. If a FRESH coin within the cache is
         * later spent, it may be deleted totally and would not ever have to be
         * flushed to the mother or father. This can be a efficiency optimization. Marking a
         * coin as FRESH when it exists unspent within the mother or father cache will trigger a
         * consensus failure, because it may not be deleted from the mother or father
         * when this cache is flushed.
         */
        FRESH = (1 << 1),
    };

    CCoinsCacheEntry() : flags(0) {}
    specific CCoinsCacheEntry(Coin&& coin_) : coin(std::transfer(coin_)), flags(0) {}
    CCoinsCacheEntry(Coin&& coin_, unsigned char flag) : coin(std::transfer(coin_)), flags(flag) {}
};

And is utilized in a map right here:

typedef std::unordered_map<COutPoint, CCoinsCacheEntry, SaltedOutpointHasher> CCoinsMap;

I can not perceive what’s CCoinsCacheEntry by studying the code and feedback. What does it imply by mother or father?

DIRTY means the CCoinsCacheEntry is doubtlessly completely different from the
model within the mother or father cache.

Can somebody clarify what’s it and the way it’s used? And likewise what does DIRTY and FRESH imply?

LEAVE A REPLY

Please enter your comment!
Please enter your name here