Coverage Report

Created: 2025-03-18 19:28

/root/bitcoin/src/dbwrapper.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2012-2022 The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_DBWRAPPER_H
6
#define BITCOIN_DBWRAPPER_H
7
8
#include <attributes.h>
9
#include <serialize.h>
10
#include <span.h>
11
#include <streams.h>
12
#include <util/check.h>
13
#include <util/fs.h>
14
15
#include <cstddef>
16
#include <exception>
17
#include <memory>
18
#include <optional>
19
#include <stdexcept>
20
#include <string>
21
#include <vector>
22
23
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64;
24
static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024;
25
static const size_t DBWRAPPER_MAX_FILE_SIZE = 32 << 20; // 32 MiB
26
27
//! User-controlled performance and debug options.
28
struct DBOptions {
29
    //! Compact database on startup.
30
    bool force_compact = false;
31
};
32
33
//! Application-specific storage settings.
34
struct DBParams {
35
    //! Location in the filesystem where leveldb data will be stored.
36
    fs::path path;
37
    //! Configures various leveldb cache settings.
38
    size_t cache_bytes;
39
    //! If true, use leveldb's memory environment.
40
    bool memory_only = false;
41
    //! If true, remove all existing data.
42
    bool wipe_data = false;
43
    //! If true, store data obfuscated via simple XOR. If false, XOR with a
44
    //! zero'd byte array.
45
    bool obfuscate = false;
46
    //! Passed-through options.
47
    DBOptions options{};
48
};
49
50
class dbwrapper_error : public std::runtime_error
51
{
52
public:
53
0
    explicit dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {}
54
};
55
56
class CDBWrapper;
57
58
/** These should be considered an implementation detail of the specific database.
59
 */
60
namespace dbwrapper_private {
61
62
/** Work around circular dependency, as well as for testing in dbwrapper_tests.
63
 * Database obfuscation should be considered an implementation detail of the
64
 * specific database.
65
 */
66
const std::vector<unsigned char>& GetObfuscateKey(const CDBWrapper &w);
67
68
}; // namespace dbwrapper_private
69
70
bool DestroyDB(const std::string& path_str);
71
72
/** Batch of changes queued to be written to a CDBWrapper */
73
class CDBBatch
74
{
75
    friend class CDBWrapper;
76
77
private:
78
    const CDBWrapper &parent;
79
80
    struct WriteBatchImpl;
81
    const std::unique_ptr<WriteBatchImpl> m_impl_batch;
82
83
    DataStream ssKey{};
84
    DataStream ssValue{};
85
86
    size_t size_estimate{0};
87
88
    void WriteImpl(Span<const std::byte> key, DataStream& ssValue);
89
    void EraseImpl(Span<const std::byte> key);
90
91
public:
92
    /**
93
     * @param[in] _parent   CDBWrapper that this batch is to be submitted to
94
     */
95
    explicit CDBBatch(const CDBWrapper& _parent);
96
    ~CDBBatch();
97
    void Clear();
98
99
    template <typename K, typename V>
100
    void Write(const K& key, const V& value)
101
48.6k
    {
102
48.6k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
103
48.6k
        ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
104
48.6k
        ssKey << key;
105
48.6k
        ssValue << value;
106
48.6k
        WriteImpl(ssKey, ssValue);
107
48.6k
        ssKey.clear();
108
48.6k
        ssValue.clear();
109
48.6k
    }
Unexecuted instantiation: void CDBBatch::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<unsigned char, std::allocator<unsigned char> > const&)
Unexecuted instantiation: void CDBBatch::Write<unsigned char, CBlockLocator>(unsigned char const&, CBlockLocator const&)
Unexecuted instantiation: void CDBBatch::Write<std::pair<unsigned char, uint256>, CDiskTxPos>(std::pair<unsigned char, uint256> const&, CDiskTxPos const&)
Unexecuted instantiation: coinstatsindex.cpp:void CDBBatch::Write<(anonymous namespace)::DBHashKey, (anonymous namespace)::DBVal>((anonymous namespace)::DBHashKey const&, (anonymous namespace)::DBVal const&)
Unexecuted instantiation: coinstatsindex.cpp:void CDBBatch::Write<(anonymous namespace)::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal> >((anonymous namespace)::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal> const&)
Unexecuted instantiation: void CDBBatch::Write<unsigned char, MuHash3072>(unsigned char const&, MuHash3072 const&)
Unexecuted instantiation: blockfilterindex.cpp:void CDBBatch::Write<(anonymous namespace)::DBHashKey, (anonymous namespace)::DBVal>((anonymous namespace)::DBHashKey const&, (anonymous namespace)::DBVal const&)
Unexecuted instantiation: void CDBBatch::Write<unsigned char, FlatFilePos>(unsigned char const&, FlatFilePos const&)
Unexecuted instantiation: blockfilterindex.cpp:void CDBBatch::Write<(anonymous namespace)::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal> >((anonymous namespace)::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal> const&)
Unexecuted instantiation: void CDBBatch::Write<unsigned char, unsigned char>(unsigned char const&, unsigned char const&)
Unexecuted instantiation: void CDBBatch::Write<std::pair<unsigned char, int>, CBlockFileInfo>(std::pair<unsigned char, int> const&, CBlockFileInfo const&)
Unexecuted instantiation: void CDBBatch::Write<unsigned char, int>(unsigned char const&, int const&)
Unexecuted instantiation: void CDBBatch::Write<std::pair<unsigned char, uint256>, CDiskBlockIndex>(std::pair<unsigned char, uint256> const&, CDiskBlockIndex const&)
Unexecuted instantiation: void CDBBatch::Write<std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, unsigned char>(std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, unsigned char const&)
void CDBBatch::Write<unsigned char, std::vector<uint256, std::allocator<uint256> > >(unsigned char const&, std::vector<uint256, std::allocator<uint256> > const&)
Line
Count
Source
101
23.5k
    {
102
23.5k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
103
23.5k
        ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
104
23.5k
        ssKey << key;
105
23.5k
        ssValue << value;
106
23.5k
        WriteImpl(ssKey, ssValue);
107
23.5k
        ssKey.clear();
108
23.5k
        ssValue.clear();
109
23.5k
    }
txdb.cpp:void CDBBatch::Write<(anonymous namespace)::CoinEntry, Coin>((anonymous namespace)::CoinEntry const&, Coin const&)
Line
Count
Source
101
1.60k
    {
102
1.60k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
103
1.60k
        ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
104
1.60k
        ssKey << key;
105
1.60k
        ssValue << value;
106
1.60k
        WriteImpl(ssKey, ssValue);
107
1.60k
        ssKey.clear();
108
1.60k
        ssValue.clear();
109
1.60k
    }
void CDBBatch::Write<unsigned char, uint256>(unsigned char const&, uint256 const&)
Line
Count
Source
101
23.5k
    {
102
23.5k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
103
23.5k
        ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
104
23.5k
        ssKey << key;
105
23.5k
        ssValue << value;
106
23.5k
        WriteImpl(ssKey, ssValue);
107
23.5k
        ssKey.clear();
108
23.5k
        ssValue.clear();
109
23.5k
    }
110
111
    template <typename K>
112
    void Erase(const K& key)
113
47.2k
    {
114
47.2k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
115
47.2k
        ssKey << key;
116
47.2k
        EraseImpl(ssKey);
117
47.2k
        ssKey.clear();
118
47.2k
    }
void CDBBatch::Erase<unsigned char>(unsigned char const&)
Line
Count
Source
113
47.0k
    {
114
47.0k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
115
47.0k
        ssKey << key;
116
47.0k
        EraseImpl(ssKey);
117
47.0k
        ssKey.clear();
118
47.0k
    }
txdb.cpp:void CDBBatch::Erase<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry const&)
Line
Count
Source
113
268
    {
114
268
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
115
268
        ssKey << key;
116
268
        EraseImpl(ssKey);
117
268
        ssKey.clear();
118
268
    }
119
120
1.87k
    size_t SizeEstimate() const { return size_estimate; }
121
};
122
123
class CDBIterator
124
{
125
public:
126
    struct IteratorImpl;
127
128
private:
129
    const CDBWrapper &parent;
130
    const std::unique_ptr<IteratorImpl> m_impl_iter;
131
132
    void SeekImpl(Span<const std::byte> key);
133
    Span<const std::byte> GetKeyImpl() const;
134
    Span<const std::byte> GetValueImpl() const;
135
136
public:
137
138
    /**
139
     * @param[in] _parent          Parent CDBWrapper instance.
140
     * @param[in] _piter           The original leveldb iterator.
141
     */
142
    CDBIterator(const CDBWrapper& _parent, std::unique_ptr<IteratorImpl> _piter);
143
    ~CDBIterator();
144
145
    bool Valid() const;
146
147
    void SeekToFirst();
148
149
1.61k
    template<typename K> void Seek(const K& key) {
150
1.61k
        DataStream ssKey{};
151
1.61k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
152
1.61k
        ssKey << key;
153
1.61k
        SeekImpl(ssKey);
154
1.61k
    }
Unexecuted instantiation: coinstatsindex.cpp:void CDBIterator::Seek<(anonymous namespace)::DBHeightKey>((anonymous namespace)::DBHeightKey const&)
Unexecuted instantiation: blockfilterindex.cpp:void CDBIterator::Seek<(anonymous namespace)::DBHeightKey>((anonymous namespace)::DBHeightKey const&)
Unexecuted instantiation: void CDBIterator::Seek<std::pair<unsigned char, uint256> >(std::pair<unsigned char, uint256> const&)
void CDBIterator::Seek<unsigned char>(unsigned char const&)
Line
Count
Source
149
1.61k
    template<typename K> void Seek(const K& key) {
150
1.61k
        DataStream ssKey{};
151
1.61k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
152
1.61k
        ssKey << key;
153
1.61k
        SeekImpl(ssKey);
154
1.61k
    }
155
156
    void Next();
157
158
348
    template<typename K> bool GetKey(K& key) {
159
348
        try {
160
348
            DataStream ssKey{GetKeyImpl()};
161
348
            ssKey >> key;
162
348
        } catch (const std::exception&) {
163
0
            return false;
164
0
        }
165
348
        return true;
166
348
    }
Unexecuted instantiation: coinstatsindex.cpp:bool CDBIterator::GetKey<(anonymous namespace)::DBHeightKey>((anonymous namespace)::DBHeightKey&)
Unexecuted instantiation: blockfilterindex.cpp:bool CDBIterator::GetKey<(anonymous namespace)::DBHeightKey>((anonymous namespace)::DBHeightKey&)
Unexecuted instantiation: bool CDBIterator::GetKey<std::pair<unsigned char, uint256> >(std::pair<unsigned char, uint256>&)
txdb.cpp:bool CDBIterator::GetKey<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry&)
Line
Count
Source
158
348
    template<typename K> bool GetKey(K& key) {
159
348
        try {
160
348
            DataStream ssKey{GetKeyImpl()};
161
348
            ssKey >> key;
162
348
        } catch (const std::exception&) {
163
0
            return false;
164
0
        }
165
348
        return true;
166
348
    }
167
168
0
    template<typename V> bool GetValue(V& value) {
169
0
        try {
170
0
            DataStream ssValue{GetValueImpl()};
171
0
            ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent));
172
0
            ssValue >> value;
173
0
        } catch (const std::exception&) {
174
0
            return false;
175
0
        }
176
0
        return true;
177
0
    }
Unexecuted instantiation: coinstatsindex.cpp:bool CDBIterator::GetValue<std::pair<uint256, (anonymous namespace)::DBVal> >(std::pair<uint256, (anonymous namespace)::DBVal>&)
Unexecuted instantiation: blockfilterindex.cpp:bool CDBIterator::GetValue<std::pair<uint256, (anonymous namespace)::DBVal> >(std::pair<uint256, (anonymous namespace)::DBVal>&)
Unexecuted instantiation: bool CDBIterator::GetValue<CDiskBlockIndex>(CDiskBlockIndex&)
Unexecuted instantiation: bool CDBIterator::GetValue<Coin>(Coin&)
178
};
179
180
struct LevelDBContext;
181
182
class CDBWrapper
183
{
184
    friend const std::vector<unsigned char>& dbwrapper_private::GetObfuscateKey(const CDBWrapper &w);
185
private:
186
    //! holds all leveldb-specific fields of this class
187
    std::unique_ptr<LevelDBContext> m_db_context;
188
189
    //! the name of this database
190
    std::string m_name;
191
192
    //! a key used for optional XOR-obfuscation of the database
193
    std::vector<unsigned char> obfuscate_key;
194
195
    //! the key under which the obfuscation key is stored
196
    static const std::string OBFUSCATE_KEY_KEY;
197
198
    //! the length of the obfuscate key in number of bytes
199
    static const unsigned int OBFUSCATE_KEY_NUM_BYTES;
200
201
    std::vector<unsigned char> CreateObfuscateKey() const;
202
203
    //! path to filesystem storage
204
    const fs::path m_path;
205
206
    //! whether or not the database resides in memory
207
    bool m_is_memory;
208
209
    std::optional<std::string> ReadImpl(Span<const std::byte> key) const;
210
    bool ExistsImpl(Span<const std::byte> key) const;
211
    size_t EstimateSizeImpl(Span<const std::byte> key1, Span<const std::byte> key2) const;
212
172k
    auto& DBContext() const LIFETIMEBOUND { return *Assert(m_db_context); }
213
214
public:
215
    CDBWrapper(const DBParams& params);
216
    ~CDBWrapper();
217
218
    CDBWrapper(const CDBWrapper&) = delete;
219
    CDBWrapper& operator=(const CDBWrapper&) = delete;
220
221
    template <typename K, typename V>
222
    bool Read(const K& key, V& value) const
223
40.1k
    {
224
40.1k
        DataStream ssKey{};
225
40.1k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
226
40.1k
        ssKey << key;
227
40.1k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
228
40.1k
        if (!strValue) {
  Branch (228:13): [True: 1.61k, False: 0]
  Branch (228:13): [True: 0, False: 0]
  Branch (228:13): [True: 0, False: 0]
  Branch (228:13): [True: 0, False: 0]
  Branch (228:13): [True: 0, False: 0]
  Branch (228:13): [True: 0, False: 0]
  Branch (228:13): [True: 0, False: 0]
  Branch (228:13): [True: 0, False: 0]
  Branch (228:13): [True: 0, False: 0]
  Branch (228:13): [True: 0, False: 0]
  Branch (228:13): [True: 0, False: 0]
  Branch (228:13): [True: 0, False: 0]
  Branch (228:13): [True: 0, False: 0]
  Branch (228:13): [True: 6.46k, False: 940]
  Branch (228:13): [True: 2.09k, False: 24.6k]
  Branch (228:13): [True: 4.36k, False: 0]
229
14.5k
            return false;
230
14.5k
        }
231
25.5k
        try {
232
25.5k
            DataStream ssValue{MakeByteSpan(*strValue)};
233
25.5k
            ssValue.Xor(obfuscate_key);
234
25.5k
            ssValue >> value;
235
25.5k
        } catch (const std::exception&) {
236
0
            return false;
237
0
        }
238
25.5k
        return true;
239
25.5k
    }
bool CDBWrapper::Read<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<unsigned char, std::allocator<unsigned char> >&) const
Line
Count
Source
223
1.61k
    {
224
1.61k
        DataStream ssKey{};
225
1.61k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
226
1.61k
        ssKey << key;
227
1.61k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
228
1.61k
        if (!strValue) {
  Branch (228:13): [True: 1.61k, False: 0]
229
1.61k
            return false;
230
1.61k
        }
231
0
        try {
232
0
            DataStream ssValue{MakeByteSpan(*strValue)};
233
0
            ssValue.Xor(obfuscate_key);
234
0
            ssValue >> value;
235
0
        } catch (const std::exception&) {
236
0
            return false;
237
0
        }
238
0
        return true;
239
0
    }
Unexecuted instantiation: bool CDBWrapper::Read<unsigned char, CBlockLocator>(unsigned char const&, CBlockLocator&) const
Unexecuted instantiation: bool CDBWrapper::Read<std::pair<unsigned char, uint256>, CDiskTxPos>(std::pair<unsigned char, uint256> const&, CDiskTxPos&) const
Unexecuted instantiation: coinstatsindex.cpp:bool CDBWrapper::Read<(anonymous namespace)::DBHashKey, (anonymous namespace)::DBVal>((anonymous namespace)::DBHashKey const&, (anonymous namespace)::DBVal&) const
Unexecuted instantiation: coinstatsindex.cpp:bool CDBWrapper::Read<(anonymous namespace)::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal> >((anonymous namespace)::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal>&) const
Unexecuted instantiation: coinstatsindex.cpp:bool CDBWrapper::Read<(anonymous namespace)::DBHashKey, std::pair<uint256, (anonymous namespace)::DBVal> >((anonymous namespace)::DBHashKey const&, std::pair<uint256, (anonymous namespace)::DBVal>&) const
Unexecuted instantiation: bool CDBWrapper::Read<unsigned char, MuHash3072>(unsigned char const&, MuHash3072&) const
Unexecuted instantiation: blockfilterindex.cpp:bool CDBWrapper::Read<(anonymous namespace)::DBHashKey, (anonymous namespace)::DBVal>((anonymous namespace)::DBHashKey const&, (anonymous namespace)::DBVal&) const
Unexecuted instantiation: bool CDBWrapper::Read<unsigned char, FlatFilePos>(unsigned char const&, FlatFilePos&) const
Unexecuted instantiation: blockfilterindex.cpp:bool CDBWrapper::Read<(anonymous namespace)::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal> >((anonymous namespace)::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal>&) const
Unexecuted instantiation: bool CDBWrapper::Read<std::pair<unsigned char, int>, CBlockFileInfo>(std::pair<unsigned char, int> const&, CBlockFileInfo&) const
Unexecuted instantiation: bool CDBWrapper::Read<unsigned char, int>(unsigned char const&, int&) const
Unexecuted instantiation: bool CDBWrapper::Read<std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, unsigned char>(std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, unsigned char&) const
txdb.cpp:bool CDBWrapper::Read<(anonymous namespace)::CoinEntry, Coin>((anonymous namespace)::CoinEntry const&, Coin&) const
Line
Count
Source
223
7.40k
    {
224
7.40k
        DataStream ssKey{};
225
7.40k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
226
7.40k
        ssKey << key;
227
7.40k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
228
7.40k
        if (!strValue) {
  Branch (228:13): [True: 6.46k, False: 940]
229
6.46k
            return false;
230
6.46k
        }
231
940
        try {
232
940
            DataStream ssValue{MakeByteSpan(*strValue)};
233
940
            ssValue.Xor(obfuscate_key);
234
940
            ssValue >> value;
235
940
        } catch (const std::exception&) {
236
0
            return false;
237
0
        }
238
940
        return true;
239
940
    }
bool CDBWrapper::Read<unsigned char, uint256>(unsigned char const&, uint256&) const
Line
Count
Source
223
26.7k
    {
224
26.7k
        DataStream ssKey{};
225
26.7k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
226
26.7k
        ssKey << key;
227
26.7k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
228
26.7k
        if (!strValue) {
  Branch (228:13): [True: 2.09k, False: 24.6k]
229
2.09k
            return false;
230
2.09k
        }
231
24.6k
        try {
232
24.6k
            DataStream ssValue{MakeByteSpan(*strValue)};
233
24.6k
            ssValue.Xor(obfuscate_key);
234
24.6k
            ssValue >> value;
235
24.6k
        } catch (const std::exception&) {
236
0
            return false;
237
0
        }
238
24.6k
        return true;
239
24.6k
    }
bool CDBWrapper::Read<unsigned char, std::vector<uint256, std::allocator<uint256> > >(unsigned char const&, std::vector<uint256, std::allocator<uint256> >&) const
Line
Count
Source
223
4.36k
    {
224
4.36k
        DataStream ssKey{};
225
4.36k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
226
4.36k
        ssKey << key;
227
4.36k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
228
4.36k
        if (!strValue) {
  Branch (228:13): [True: 4.36k, False: 0]
229
4.36k
            return false;
230
4.36k
        }
231
0
        try {
232
0
            DataStream ssValue{MakeByteSpan(*strValue)};
233
0
            ssValue.Xor(obfuscate_key);
234
0
            ssValue >> value;
235
0
        } catch (const std::exception&) {
236
0
            return false;
237
0
        }
238
0
        return true;
239
0
    }
240
241
    template <typename K, typename V>
242
    bool Write(const K& key, const V& value, bool fSync = false)
243
0
    {
244
0
        CDBBatch batch(*this);
245
0
        batch.Write(key, value);
246
0
        return WriteBatch(batch, fSync);
247
0
    }
Unexecuted instantiation: bool CDBWrapper::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<unsigned char, std::allocator<unsigned char> > const&, bool)
Unexecuted instantiation: coinstatsindex.cpp:bool CDBWrapper::Write<(anonymous namespace)::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal> >((anonymous namespace)::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal> const&, bool)
Unexecuted instantiation: blockfilterindex.cpp:bool CDBWrapper::Write<(anonymous namespace)::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal> >((anonymous namespace)::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal> const&, bool)
Unexecuted instantiation: bool CDBWrapper::Write<unsigned char, unsigned char>(unsigned char const&, unsigned char const&, bool)
Unexecuted instantiation: bool CDBWrapper::Write<std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, unsigned char>(std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, unsigned char const&, bool)
248
249
    //! @returns filesystem path to the on-disk data.
250
0
    std::optional<fs::path> StoragePath() {
251
0
        if (m_is_memory) {
  Branch (251:13): [True: 0, False: 0]
252
0
            return {};
253
0
        }
254
0
        return m_path;
255
0
    }
256
257
    template <typename K>
258
    bool Exists(const K& key) const
259
1.61k
    {
260
1.61k
        DataStream ssKey{};
261
1.61k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
262
1.61k
        ssKey << key;
263
1.61k
        return ExistsImpl(ssKey);
264
1.61k
    }
Unexecuted instantiation: bool CDBWrapper::Exists<unsigned char>(unsigned char const&) const
txdb.cpp:bool CDBWrapper::Exists<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry const&) const
Line
Count
Source
259
1.61k
    {
260
1.61k
        DataStream ssKey{};
261
1.61k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
262
1.61k
        ssKey << key;
263
1.61k
        return ExistsImpl(ssKey);
264
1.61k
    }
265
266
    template <typename K>
267
    bool Erase(const K& key, bool fSync = false)
268
0
    {
269
0
        CDBBatch batch(*this);
270
0
        batch.Erase(key);
271
0
        return WriteBatch(batch, fSync);
272
0
    }
273
274
    bool WriteBatch(CDBBatch& batch, bool fSync = false);
275
276
    // Get an estimate of LevelDB memory usage (in bytes).
277
    size_t DynamicMemoryUsage() const;
278
279
    CDBIterator* NewIterator();
280
281
    /**
282
     * Return true if the database managed by this class contains no entries.
283
     */
284
    bool IsEmpty();
285
286
    template<typename K>
287
    size_t EstimateSize(const K& key_begin, const K& key_end) const
288
3.23k
    {
289
3.23k
        DataStream ssKey1{}, ssKey2{};
290
3.23k
        ssKey1.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
291
3.23k
        ssKey2.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
292
3.23k
        ssKey1 << key_begin;
293
3.23k
        ssKey2 << key_end;
294
3.23k
        return EstimateSizeImpl(ssKey1, ssKey2);
295
3.23k
    }
296
};
297
298
#endif // BITCOIN_DBWRAPPER_H