30 std::unique_ptr<CDBIterator> cursor{
m_db->NewIterator()};
34 return cursor->Valid();
50 m_db_params{std::move(db_params)},
51 m_options{std::move(options)},
52 m_db{std::make_unique<CDBWrapper>(m_db_params)} { }
69 return m_db->Read(CoinEntry(&outpoint), coin);
73 return m_db->Exists(CoinEntry(&outpoint));
84 std::vector<uint256> vhashHeadBlocks;
86 return std::vector<uint256>();
88 return vhashHeadBlocks;
98 if (old_tip.IsNull()) {
101 if (old_heads.size() == 2) {
102 if (old_heads[0] != hashBlock) {
103 LogPrintLevel(
BCLog::COINDB,
BCLog::Level::Error,
"The coins database detected an inconsistent state, likely due to a previous crash or shutdown. You will need to restart bitcoind with the -reindex-chainstate or -reindex configuration option.\n");
105 assert(old_heads[0] == hashBlock);
106 old_tip = old_heads[1];
117 for (
auto it{cursor.
Begin()}; it != cursor.
End();) {
118 if (it->second.IsDirty()) {
119 CoinEntry entry(&it->first);
120 if (it->second.coin.IsSpent())
123 batch.
Write(entry, it->second.coin);
130 m_db->WriteBatch(batch);
135 LogPrintf(
"Simulating a crash. Goodbye.\n");
147 bool ret =
m_db->WriteBatch(batch);
148 LogPrint(
BCLog::COINDB,
"Committed %u changed transaction outputs (out of %u) to coin database...\n", (
unsigned int)changed, (
unsigned int)
count);
170 bool Valid()
const override;
171 void Next()
override;
182 auto i = std::make_unique<CCoinsViewDBCursor>(
189 if (i->pcursor->Valid()) {
190 CoinEntry entry(&i->keyTmp.second);
191 i->pcursor->GetKey(entry);
192 i->keyTmp.first = entry.key;
211 return pcursor->GetValue(coin);
222 CoinEntry entry(&
keyTmp.second);
CoinsCachePair * NextAndMaybeErase(CoinsCachePair ¤t) noexcept
Return the next entry after current, possibly erasing current.
bool GetValue(Coin &coin) const override
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
std::unique_ptr< CCoinsViewCursor > Cursor() const override
Get a cursor to iterate over the whole state.
#define LogPrint(category,...)
Specialization of CCoinsViewCursor to iterate over a CCoinsViewDB.
Batch of changes queued to be written to a CDBWrapper.
CoinsCachePair * End() const noexcept
std::unique_ptr< CDBIterator > pcursor
void ResizeCache(size_t new_cache_size) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Dynamically alter the underlying leveldb cache size.
User-controlled performance and debug options.
CoinsViewOptions m_options
static constexpr uint8_t DB_BEST_BLOCK
static constexpr uint8_t DB_HEAD_BLOCKS
bool GetKey(COutPoint &key) const override
bool NeedsUpgrade()
Whether an unsupported database format is used.
CCoinsViewDB(DBParams db_params, CoinsViewOptions options)
std::vector< typename std::common_type< Args... >::type > Vector(Args &&... args)
Construct a vector with the specified elements.
size_t batch_write_bytes
Maximum database write batch size in bytes.
Cursor for iterating over the linked list of flagged entries in CCoinsViewCache.
CDBIterator * NewIterator()
static constexpr uint8_t DB_COINS
void Write(const K &key, const V &value)
size_t SizeEstimate() const
#define LogPrintLevel(category, level,...)
CCoinsViewDBCursor(CDBIterator *pcursorIn, const uint256 &hashBlockIn)
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
An outpoint - a combination of a transaction hash and an index n into its vout.
bool wipe_data
If true, remove all existing data.
std::pair< char, COutPoint > keyTmp
constexpr bool IsNull() const
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
~CCoinsViewDBCursor()=default
#define SERIALIZE_METHODS(cls, obj)
Implement the Serialize and Unserialize methods by delegating to a single templated static method tha...
CoinsCachePair * Begin() const noexcept
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
static constexpr uint8_t DB_COIN
CCoinsView backed by the coin database (chainstate/)
Application-specific storage settings.
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
bool Valid() const override
int simulate_crash_ratio
If non-zero, randomly exit when the database is flushed with (1/ratio) probability.
size_t cache_bytes
Configures various leveldb cache settings.
std::vector< uint256 > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
bool memory_only
If true, use leveldb's memory environment.
std::unique_ptr< CDBWrapper > m_db
bool BatchWrite(CoinsViewCacheCursor &cursor, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
Cursor for iterating over CoinsView state.