Bitcoin Core 31.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
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 <future>
19#include <memory>
20#include <optional>
21#include <string>
22#include <vector>
23
24class COutPoint;
25class uint256;
26
34
36class CCoinsViewDB final : public CCoinsView
37{
38protected:
43 std::unique_ptr<CDBWrapper> m_db;
44 std::shared_future<void> m_compaction;
45public:
46 explicit CCoinsViewDB(DBParams db_params, CoinsViewOptions options);
47 ~CCoinsViewDB() override;
48
49 std::optional<Coin> GetCoin(const COutPoint& outpoint) const override;
50 bool HaveCoin(const COutPoint &outpoint) const override;
51 uint256 GetBestBlock() const override;
52 std::vector<uint256> GetHeadBlocks() const override;
53 void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock) override;
54 std::unique_ptr<CCoinsViewCursor> Cursor() const override;
55
57 bool NeedsUpgrade();
58 size_t EstimateSize() const override;
59
62
65
67 std::optional<std::string> GetDBProperty(const std::string& property);
68};
69
70#endif // BITCOIN_TXDB_H
Mutex m_db_mutex
Prevents CompactFull() from using m_db while ResizeCache() replaces it.
Definition txdb.h:42
std::shared_future< void > m_compaction
Definition txdb.h:44
bool HaveCoin(const COutPoint &outpoint) const override
Definition txdb.cpp:96
std::unique_ptr< CDBWrapper > m_db
Definition txdb.h:43
~CCoinsViewDB() override
Definition txdb.cpp:62
CCoinsViewDB(DBParams db_params, CoinsViewOptions options)
Definition txdb.cpp:57
std::optional< std::string > GetDBProperty(const std::string &property)
Return an underlying LevelDB property value, if available.
Definition txdb.cpp:186
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
Definition txdb.cpp:100
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
Definition txdb.cpp:87
void ResizeCache(size_t new_cache_size) EXCLUSIVE_LOCKS_REQUIRED(cs_main
Dynamically alter the underlying leveldb cache size.
Definition txdb.cpp:72
void BatchWrite(CoinsViewCacheCursor &cursor, const uint256 &hashBlock) override
Definition txdb.cpp:115
std::unique_ptr< CCoinsViewCursor > Cursor() const override
Get a cursor to iterate over the whole state.
Definition txdb.cpp:233
std::shared_future< void > CompactFull() EXCLUSIVE_LOCKS_REQUIRED(cs_main
Perform a full compaction of the underlying LevelDB on a one-shot background thread.
Definition txdb.cpp:191
CoinsViewOptions m_options
Definition txdb.h:40
std::vector< uint256 > GetHeadBlocks() const override
Definition txdb.cpp:107
bool NeedsUpgrade()
Whether an unsupported database format is used.
Definition txdb.cpp:36
size_t EstimateSize() const override
Estimate database size (0 if not implemented).
Definition txdb.cpp:181
DBParams m_db_params
Definition txdb.h:39
Abstract view on the open txout dataset.
Definition coins.h:308
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition transaction.h:29
256-bit opaque blob.
Definition uint256.h:195
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition cs_main.cpp:8
static constexpr size_t DEFAULT_DB_CACHE_BATCH
Default LevelDB write batch size.
Definition caches.h:15
Definition common.h:29
Cursor for iterating over the linked list of flagged entries in CCoinsViewCache.
Definition coins.h:261
User-controlled performance and debug options.
Definition txdb.h:28
int simulate_crash_ratio
If non-zero, randomly exit when the database is flushed with (1/ratio) probability.
Definition txdb.h:32
size_t batch_write_bytes
Maximum database write batch size in bytes.
Definition txdb.h:30
Application-specific storage settings.
Definition dbwrapper.h:33
AnnotatedMixin< std::mutex > Mutex
Wrapped mutex: supports waiting but not recursive locking.
Definition sync.h:123
#define EXCLUSIVE_LOCKS_REQUIRED(...)