Bitcoin Core 28.99.0
P2P Digital Currency
|
A Coin in one level of the coins database caching hierarchy. More...
#include <coins.h>
Public Types | |
enum | Flags { DIRTY = (1 << 0) , FRESH = (1 << 1) } |
Public Member Functions | |
CCoinsCacheEntry () noexcept=default | |
CCoinsCacheEntry (Coin &&coin_) noexcept | |
~CCoinsCacheEntry () | |
void | SetClean () noexcept |
bool | IsDirty () const noexcept |
bool | IsFresh () const noexcept |
CoinsCachePair * | Next () const noexcept |
Only call Next when this entry is DIRTY, FRESH, or both. More... | |
CoinsCachePair * | Prev () const noexcept |
Only call Prev when this entry is DIRTY, FRESH, or both. More... | |
void | SelfRef (CoinsCachePair &pair) noexcept |
Only use this for initializing the linked list sentinel. More... | |
Static Public Member Functions | |
static void | SetDirty (CoinsCachePair &pair, CoinsCachePair &sentinel) noexcept |
static void | SetFresh (CoinsCachePair &pair, CoinsCachePair &sentinel) noexcept |
Public Attributes | |
Coin | coin |
Static Private Member Functions | |
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. More... | |
Private Attributes | |
CoinsCachePair * | m_prev {nullptr} |
These are used to create a doubly linked list of flagged entries. More... | |
CoinsCachePair * | m_next {nullptr} |
uint8_t | m_flags {0} |
A Coin in one level of the coins database caching hierarchy.
A coin can either be:
Out of these 2^3 = 8 states, only some combinations are valid:
Enumerator | |
---|---|
DIRTY | DIRTY means the CCoinsCacheEntry is potentially different from the version in the parent cache. Failure to mark a coin as DIRTY when it is potentially different from the parent cache will cause a consensus failure, since the coin's state won't get written to the parent when the cache is flushed. |
FRESH | FRESH means the parent cache does not have this coin or that it is a spent coin in the parent cache. If a FRESH coin in the cache is later spent, it can be deleted entirely and doesn't ever need to be flushed to the parent. This is a performance optimization. Marking a coin as FRESH when it exists unspent in the parent cache will cause a consensus failure, since it might not be deleted from the parent when this cache is flushed. |
|
defaultnoexcept |
|
inlineexplicitnoexcept |
|
inline |
|
inlinestaticprivatenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
private |
|
private |
These are used to create a doubly linked list of flagged entries.
They are set in SetDirty, SetFresh, and unset in SetClean. A flagged entry is any entry that is either DIRTY, FRESH, or both.
DIRTY entries are tracked so that only modified entries can be passed to the parent cache for batch writing. This is a performance optimization compared to giving all entries in the cache to the parent and having the parent scan for only modified entries.
FRESH-but-not-DIRTY coins can not occur in practice, since that would mean a spent coin exists in the parent CCoinsView and not in the child CCoinsViewCache. Nevertheless, if a spent coin is retrieved from the parent cache, the FRESH-but-not-DIRTY coin will be tracked by the linked list and deleted when Sync or Flush is called on the CCoinsViewCache.