Bitcoin Core  31.0.0
P2P Digital Currency
txdb.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-present The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_TXDB_H
7 #define BITCOIN_TXDB_H
8 
9 #include <coins.h>
10 #include <dbwrapper.h>
11 #include <kernel/caches.h>
12 #include <kernel/cs_main.h>
13 #include <sync.h>
14 #include <util/fs.h>
15 
16 #include <cstddef>
17 #include <cstdint>
18 #include <memory>
19 #include <optional>
20 #include <vector>
21 
22 class COutPoint;
23 class uint256;
24 
31 };
32 
34 class CCoinsViewDB final : public CCoinsView
35 {
36 protected:
39  std::unique_ptr<CDBWrapper> m_db;
40 public:
41  explicit CCoinsViewDB(DBParams db_params, CoinsViewOptions options);
42 
43  std::optional<Coin> GetCoin(const COutPoint& outpoint) const override;
44  bool HaveCoin(const COutPoint &outpoint) const override;
45  uint256 GetBestBlock() const override;
46  std::vector<uint256> GetHeadBlocks() const override;
47  void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock) override;
48  std::unique_ptr<CCoinsViewCursor> Cursor() const override;
49 
51  bool NeedsUpgrade();
52  size_t EstimateSize() const override;
53 
55  void ResizeCache(size_t new_cache_size) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
56 };
57 
58 #endif // BITCOIN_TXDB_H
std::unique_ptr< CCoinsViewCursor > Cursor() const override
Get a cursor to iterate over the whole state.
Definition: txdb.cpp:194
void ResizeCache(size_t new_cache_size) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Dynamically alter the underlying leveldb cache size.
Definition: txdb.cpp:58
User-controlled performance and debug options.
Definition: txdb.h:26
CoinsViewOptions m_options
Definition: txdb.h:38
DBParams m_db_params
Definition: txdb.h:37
bool NeedsUpgrade()
Whether an unsupported database format is used.
Definition: txdb.cpp:32
CCoinsViewDB(DBParams db_params, CoinsViewOptions options)
Definition: txdb.cpp:53
size_t batch_write_bytes
Maximum database write batch size in bytes.
Definition: txdb.h:28
Abstract view on the open txout dataset.
Definition: coins.h:307
Cursor for iterating over the linked list of flagged entries in CCoinsViewCache.
Definition: coins.h:260
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
Definition: txdb.cpp:166
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:28
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: txdb.cpp:81
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: txdb.cpp:85
256-bit opaque blob.
Definition: uint256.h:195
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
void BatchWrite(CoinsViewCacheCursor &cursor, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: txdb.cpp:100
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:34
Application-specific storage settings.
Definition: dbwrapper.h:33
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: txdb.cpp:72
int simulate_crash_ratio
If non-zero, randomly exit when the database is flushed with (1/ratio) probability.
Definition: txdb.h:30
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: cs_main.cpp:8
std::vector< uint256 > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
Definition: txdb.cpp:92
std::unique_ptr< CDBWrapper > m_db
Definition: txdb.h:39
static constexpr size_t DEFAULT_DB_CACHE_BATCH
Default LevelDB write batch size.
Definition: caches.h:15