fuzz coverage

Coverage Report

Created: 2025-09-17 22:41

/Users/eugenesiegel/btc/bitcoin/src/dbwrapper.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2012-present 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
22
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64;
23
static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024;
24
static const size_t DBWRAPPER_MAX_FILE_SIZE = 32 << 20; // 32 MiB
25
26
//! User-controlled performance and debug options.
27
struct DBOptions {
28
    //! Compact database on startup.
29
    bool force_compact = false;
30
};
31
32
//! Application-specific storage settings.
33
struct DBParams {
34
    //! Location in the filesystem where leveldb data will be stored.
35
    fs::path path;
36
    //! Configures various leveldb cache settings.
37
    size_t cache_bytes;
38
    //! If true, use leveldb's memory environment.
39
    bool memory_only = false;
40
    //! If true, remove all existing data.
41
    bool wipe_data = false;
42
    //! If true, store data obfuscated via simple XOR. If false, XOR with a
43
    //! zero'd byte array.
44
    bool obfuscate = false;
45
    //! Passed-through options.
46
    DBOptions options{};
47
};
48
49
class dbwrapper_error : public std::runtime_error
50
{
51
public:
52
0
    explicit dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {}
53
};
54
55
class CDBWrapper;
56
57
/** These should be considered an implementation detail of the specific database.
58
 */
59
namespace dbwrapper_private {
60
61
/** Work around circular dependency, as well as for testing in dbwrapper_tests.
62
 * Database obfuscation should be considered an implementation detail of the
63
 * specific database.
64
 */
65
const Obfuscation& GetObfuscation(const CDBWrapper&);
66
}; // namespace dbwrapper_private
67
68
bool DestroyDB(const std::string& path_str);
69
70
/** Batch of changes queued to be written to a CDBWrapper */
71
class CDBBatch
72
{
73
    friend class CDBWrapper;
74
75
private:
76
    const CDBWrapper &parent;
77
78
    struct WriteBatchImpl;
79
    const std::unique_ptr<WriteBatchImpl> m_impl_batch;
80
81
    DataStream ssKey{};
82
    DataStream ssValue{};
83
84
    void WriteImpl(std::span<const std::byte> key, DataStream& ssValue);
85
    void EraseImpl(std::span<const std::byte> key);
86
87
public:
88
    /**
89
     * @param[in] _parent   CDBWrapper that this batch is to be submitted to
90
     */
91
    explicit CDBBatch(const CDBWrapper& _parent);
92
    ~CDBBatch();
93
    void Clear();
94
95
    template <typename K, typename V>
96
    void Write(const K& key, const V& value)
97
111k
    {
98
111k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
99
111k
        ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
100
111k
        ssKey << key;
101
111k
        ssValue << value;
102
111k
        WriteImpl(ssKey, ssValue);
103
111k
        ssKey.clear();
104
111k
        ssValue.clear();
105
111k
    }
Unexecuted instantiation: _ZN8CDBBatch5WriteINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE11ObfuscationEEvRKT_RKT0_
Unexecuted instantiation: _ZN8CDBBatch5WriteIh13CBlockLocatorEEvRKT_RKT0_
Unexecuted instantiation: blockfilterindex.cpp:_ZN8CDBBatch5WriteIN12_GLOBAL__N_19DBHashKeyENS1_5DBValEEEvRKT_RKT0_
Unexecuted instantiation: _ZN8CDBBatch5WriteIh11FlatFilePosEEvRKT_RKT0_
Unexecuted instantiation: blockfilterindex.cpp:_ZN8CDBBatch5WriteIN12_GLOBAL__N_111DBHeightKeyENSt3__14pairI7uint256NS1_5DBValEEEEEvRKT_RKT0_
Unexecuted instantiation: coinstatsindex.cpp:_ZN8CDBBatch5WriteIN12_GLOBAL__N_19DBHashKeyENS1_5DBValEEEvRKT_RKT0_
Unexecuted instantiation: coinstatsindex.cpp:_ZN8CDBBatch5WriteIN12_GLOBAL__N_111DBHeightKeyENSt3__14pairI7uint256NS1_5DBValEEEEEvRKT_RKT0_
Unexecuted instantiation: _ZN8CDBBatch5WriteIh10MuHash3072EEvRKT_RKT0_
Unexecuted instantiation: _ZN8CDBBatch5WriteINSt3__14pairIh7uint256EE10CDiskTxPosEEvRKT_RKT0_
Unexecuted instantiation: _ZN8CDBBatch5WriteIhhEEvRKT_RKT0_
_ZN8CDBBatch5WriteINSt3__14pairIhiEE14CBlockFileInfoEEvRKT_RKT0_
Line
Count
Source
97
2.09k
    {
98
2.09k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
99
2.09k
        ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
100
2.09k
        ssKey << key;
101
2.09k
        ssValue << value;
102
2.09k
        WriteImpl(ssKey, ssValue);
103
2.09k
        ssKey.clear();
104
2.09k
        ssValue.clear();
105
2.09k
    }
_ZN8CDBBatch5WriteIhiEEvRKT_RKT0_
Line
Count
Source
97
14.2k
    {
98
14.2k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
99
14.2k
        ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
100
14.2k
        ssKey << key;
101
14.2k
        ssValue << value;
102
14.2k
        WriteImpl(ssKey, ssValue);
103
14.2k
        ssKey.clear();
104
14.2k
        ssValue.clear();
105
14.2k
    }
_ZN8CDBBatch5WriteINSt3__14pairIh7uint256EE15CDiskBlockIndexEEvRKT_RKT0_
Line
Count
Source
97
62.7k
    {
98
62.7k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
99
62.7k
        ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
100
62.7k
        ssKey << key;
101
62.7k
        ssValue << value;
102
62.7k
        WriteImpl(ssKey, ssValue);
103
62.7k
        ssKey.clear();
104
62.7k
        ssValue.clear();
105
62.7k
    }
Unexecuted instantiation: _ZN8CDBBatch5WriteINSt3__14pairIhNS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEEhEEvRKT_RKT0_
_ZN8CDBBatch5WriteIhNSt3__16vectorI7uint256NS1_9allocatorIS3_EEEEEEvRKT_RKT0_
Line
Count
Source
97
14.2k
    {
98
14.2k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
99
14.2k
        ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
100
14.2k
        ssKey << key;
101
14.2k
        ssValue << value;
102
14.2k
        WriteImpl(ssKey, ssValue);
103
14.2k
        ssKey.clear();
104
14.2k
        ssValue.clear();
105
14.2k
    }
txdb.cpp:_ZN8CDBBatch5WriteIN12_GLOBAL__N_19CoinEntryE4CoinEEvRKT_RKT0_
Line
Count
Source
97
4.14k
    {
98
4.14k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
99
4.14k
        ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
100
4.14k
        ssKey << key;
101
4.14k
        ssValue << value;
102
4.14k
        WriteImpl(ssKey, ssValue);
103
4.14k
        ssKey.clear();
104
4.14k
        ssValue.clear();
105
4.14k
    }
_ZN8CDBBatch5WriteIh7uint256EEvRKT_RKT0_
Line
Count
Source
97
14.2k
    {
98
14.2k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
99
14.2k
        ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
100
14.2k
        ssKey << key;
101
14.2k
        ssValue << value;
102
14.2k
        WriteImpl(ssKey, ssValue);
103
14.2k
        ssKey.clear();
104
14.2k
        ssValue.clear();
105
14.2k
    }
106
107
    template <typename K>
108
    void Erase(const K& key)
109
29.8k
    {
110
29.8k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
111
29.8k
        ssKey << key;
112
29.8k
        EraseImpl(ssKey);
113
29.8k
        ssKey.clear();
114
29.8k
    }
_ZN8CDBBatch5EraseIhEEvRKT_
Line
Count
Source
109
28.4k
    {
110
28.4k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
111
28.4k
        ssKey << key;
112
28.4k
        EraseImpl(ssKey);
113
28.4k
        ssKey.clear();
114
28.4k
    }
txdb.cpp:_ZN8CDBBatch5EraseIN12_GLOBAL__N_19CoinEntryEEEvRKT_
Line
Count
Source
109
1.42k
    {
110
1.42k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
111
1.42k
        ssKey << key;
112
1.42k
        EraseImpl(ssKey);
113
1.42k
        ssKey.clear();
114
1.42k
    }
115
116
    size_t ApproximateSize() const;
117
};
118
119
class CDBIterator
120
{
121
public:
122
    struct IteratorImpl;
123
124
private:
125
    const CDBWrapper &parent;
126
    const std::unique_ptr<IteratorImpl> m_impl_iter;
127
128
    void SeekImpl(std::span<const std::byte> key);
129
    std::span<const std::byte> GetKeyImpl() const;
130
    std::span<const std::byte> GetValueImpl() const;
131
132
public:
133
134
    /**
135
     * @param[in] _parent          Parent CDBWrapper instance.
136
     * @param[in] _piter           The original leveldb iterator.
137
     */
138
    CDBIterator(const CDBWrapper& _parent, std::unique_ptr<IteratorImpl> _piter);
139
    ~CDBIterator();
140
141
    bool Valid() const;
142
143
    void SeekToFirst();
144
145
77.7k
    template<typename K> void Seek(const K& key) {
146
77.7k
        DataStream ssKey{};
147
77.7k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
148
77.7k
        ssKey << key;
149
77.7k
        SeekImpl(ssKey);
150
77.7k
    }
Unexecuted instantiation: blockfilterindex.cpp:_ZN11CDBIterator4SeekIN12_GLOBAL__N_111DBHeightKeyEEEvRKT_
Unexecuted instantiation: coinstatsindex.cpp:_ZN11CDBIterator4SeekIN12_GLOBAL__N_111DBHeightKeyEEEvRKT_
_ZN11CDBIterator4SeekINSt3__14pairIh7uint256EEEEvRKT_
Line
Count
Source
145
77.7k
    template<typename K> void Seek(const K& key) {
146
77.7k
        DataStream ssKey{};
147
77.7k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
148
77.7k
        ssKey << key;
149
77.7k
        SeekImpl(ssKey);
150
77.7k
    }
Unexecuted instantiation: _ZN11CDBIterator4SeekIhEEvRKT_
151
152
    void Next();
153
154
7.85M
    template<typename K> bool GetKey(K& key) {
155
7.85M
        try {
156
7.85M
            DataStream ssKey{GetKeyImpl()};
157
7.85M
            ssKey >> key;
158
7.85M
        } catch (const std::exception&) {
159
38.8k
            return false;
160
38.8k
        }
161
7.81M
        return true;
162
7.85M
    }
Unexecuted instantiation: blockfilterindex.cpp:_ZN11CDBIterator6GetKeyIN12_GLOBAL__N_111DBHeightKeyEEEbRT_
Unexecuted instantiation: coinstatsindex.cpp:_ZN11CDBIterator6GetKeyIN12_GLOBAL__N_111DBHeightKeyEEEbRT_
_ZN11CDBIterator6GetKeyINSt3__14pairIh7uint256EEEEbRT_
Line
Count
Source
154
7.85M
    template<typename K> bool GetKey(K& key) {
155
7.85M
        try {
156
7.85M
            DataStream ssKey{GetKeyImpl()};
157
7.85M
            ssKey >> key;
158
7.85M
        } catch (const std::exception&) {
159
38.8k
            return false;
160
38.8k
        }
161
7.81M
        return true;
162
7.85M
    }
Unexecuted instantiation: txdb.cpp:_ZN11CDBIterator6GetKeyIN12_GLOBAL__N_19CoinEntryEEEbRT_
163
164
7.81M
    template<typename V> bool GetValue(V& value) {
165
7.81M
        try {
166
7.81M
            DataStream ssValue{GetValueImpl()};
167
7.81M
            dbwrapper_private::GetObfuscation(parent)(ssValue);
168
7.81M
            ssValue >> value;
169
7.81M
        } catch (const std::exception&) {
170
0
            return false;
171
0
        }
172
7.81M
        return true;
173
7.81M
    }
Unexecuted instantiation: blockfilterindex.cpp:_ZN11CDBIterator8GetValueINSt3__14pairI7uint256N12_GLOBAL__N_15DBValEEEEEbRT_
Unexecuted instantiation: coinstatsindex.cpp:_ZN11CDBIterator8GetValueINSt3__14pairI7uint256N12_GLOBAL__N_15DBValEEEEEbRT_
_ZN11CDBIterator8GetValueI15CDiskBlockIndexEEbRT_
Line
Count
Source
164
7.81M
    template<typename V> bool GetValue(V& value) {
165
7.81M
        try {
166
7.81M
            DataStream ssValue{GetValueImpl()};
167
7.81M
            dbwrapper_private::GetObfuscation(parent)(ssValue);
168
7.81M
            ssValue >> value;
169
7.81M
        } catch (const std::exception&) {
170
0
            return false;
171
0
        }
172
7.81M
        return true;
173
7.81M
    }
Unexecuted instantiation: _ZN11CDBIterator8GetValueI4CoinEEbRT_
174
};
175
176
struct LevelDBContext;
177
178
class CDBWrapper
179
{
180
    friend const Obfuscation& dbwrapper_private::GetObfuscation(const CDBWrapper&);
181
private:
182
    //! holds all leveldb-specific fields of this class
183
    std::unique_ptr<LevelDBContext> m_db_context;
184
185
    //! the name of this database
186
    std::string m_name;
187
188
    //! optional XOR-obfuscation of the database
189
    Obfuscation m_obfuscation;
190
191
    //! obfuscation key storage key, null-prefixed to avoid collisions
192
    inline static const std::string OBFUSCATION_KEY{"\000obfuscate_key", 14}; // explicit size to avoid truncation at leading \0
193
194
    //! path to filesystem storage
195
    const fs::path m_path;
196
197
    //! whether or not the database resides in memory
198
    bool m_is_memory;
199
200
    std::optional<std::string> ReadImpl(std::span<const std::byte> key) const;
201
    bool ExistsImpl(std::span<const std::byte> key) const;
202
    size_t EstimateSizeImpl(std::span<const std::byte> key1, std::span<const std::byte> key2) const;
203
5.35M
    auto& DBContext() const LIFETIMEBOUND { return *Assert(m_db_context); }
Line
Count
Source
106
5.35M
#define Assert(val) inline_assertion_check<true>(val, __FILE__, __LINE__, __func__, #val)
204
205
public:
206
    CDBWrapper(const DBParams& params);
207
    ~CDBWrapper();
208
209
    CDBWrapper(const CDBWrapper&) = delete;
210
    CDBWrapper& operator=(const CDBWrapper&) = delete;
211
212
    template <typename K, typename V>
213
    bool Read(const K& key, V& value) const
214
1.79M
    {
215
1.79M
        DataStream ssKey{};
216
1.79M
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
217
1.79M
        ssKey << key;
218
1.79M
        std::optional<std::string> strValue{ReadImpl(ssKey)};
219
1.79M
        if (!strValue) {
220
1.03M
            return false;
221
1.03M
        }
222
753k
        try {
223
753k
            DataStream ssValue{MakeByteSpan(*strValue)};
224
753k
            m_obfuscation(ssValue);
225
753k
            ssValue >> value;
226
753k
        } catch (const std::exception&) {
227
0
            return false;
228
0
        }
229
753k
        return true;
230
753k
    }
_ZNK10CDBWrapper4ReadINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE11ObfuscationEEbRKT_RT0_
Line
Count
Source
214
77.7k
    {
215
77.7k
        DataStream ssKey{};
216
77.7k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
217
77.7k
        ssKey << key;
218
77.7k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
219
77.7k
        if (!strValue) {
220
38.8k
            return false;
221
38.8k
        }
222
38.8k
        try {
223
38.8k
            DataStream ssValue{MakeByteSpan(*strValue)};
224
38.8k
            m_obfuscation(ssValue);
225
38.8k
            ssValue >> value;
226
38.8k
        } catch (const std::exception&) {
227
0
            return false;
228
0
        }
229
38.8k
        return true;
230
38.8k
    }
Unexecuted instantiation: _ZNK10CDBWrapper4ReadIh13CBlockLocatorEEbRKT_RT0_
Unexecuted instantiation: blockfilterindex.cpp:_ZNK10CDBWrapper4ReadIN12_GLOBAL__N_19DBHashKeyENS1_5DBValEEEbRKT_RT0_
Unexecuted instantiation: _ZNK10CDBWrapper4ReadIh11FlatFilePosEEbRKT_RT0_
Unexecuted instantiation: blockfilterindex.cpp:_ZNK10CDBWrapper4ReadIN12_GLOBAL__N_111DBHeightKeyENSt3__14pairI7uint256NS1_5DBValEEEEEbRKT_RT0_
Unexecuted instantiation: coinstatsindex.cpp:_ZNK10CDBWrapper4ReadIN12_GLOBAL__N_19DBHashKeyENS1_5DBValEEEbRKT_RT0_
Unexecuted instantiation: coinstatsindex.cpp:_ZNK10CDBWrapper4ReadIN12_GLOBAL__N_111DBHeightKeyENSt3__14pairI7uint256NS1_5DBValEEEEEbRKT_RT0_
Unexecuted instantiation: coinstatsindex.cpp:_ZNK10CDBWrapper4ReadIN12_GLOBAL__N_19DBHashKeyENSt3__14pairI7uint256NS1_5DBValEEEEEbRKT_RT0_
Unexecuted instantiation: _ZNK10CDBWrapper4ReadIh10MuHash3072EEbRKT_RT0_
Unexecuted instantiation: _ZNK10CDBWrapper4ReadINSt3__14pairIh7uint256EE10CDiskTxPosEEbRKT_RT0_
_ZNK10CDBWrapper4ReadINSt3__14pairIhiEE14CBlockFileInfoEEbRKT_RT0_
Line
Count
Source
214
77.7k
    {
215
77.7k
        DataStream ssKey{};
216
77.7k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
217
77.7k
        ssKey << key;
218
77.7k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
219
77.7k
        if (!strValue) {
220
38.8k
            return false;
221
38.8k
        }
222
38.8k
        try {
223
38.8k
            DataStream ssValue{MakeByteSpan(*strValue)};
224
38.8k
            m_obfuscation(ssValue);
225
38.8k
            ssValue >> value;
226
38.8k
        } catch (const std::exception&) {
227
0
            return false;
228
0
        }
229
38.8k
        return true;
230
38.8k
    }
_ZNK10CDBWrapper4ReadIhiEEbRKT_RT0_
Line
Count
Source
214
38.8k
    {
215
38.8k
        DataStream ssKey{};
216
38.8k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
217
38.8k
        ssKey << key;
218
38.8k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
219
38.8k
        if (!strValue) {
220
0
            return false;
221
0
        }
222
38.8k
        try {
223
38.8k
            DataStream ssValue{MakeByteSpan(*strValue)};
224
38.8k
            m_obfuscation(ssValue);
225
38.8k
            ssValue >> value;
226
38.8k
        } catch (const std::exception&) {
227
0
            return false;
228
0
        }
229
38.8k
        return true;
230
38.8k
    }
_ZNK10CDBWrapper4ReadINSt3__14pairIhNS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEEhEEbRKT_RT0_
Line
Count
Source
214
38.8k
    {
215
38.8k
        DataStream ssKey{};
216
38.8k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
217
38.8k
        ssKey << key;
218
38.8k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
219
38.8k
        if (!strValue) {
220
38.8k
            return false;
221
38.8k
        }
222
0
        try {
223
0
            DataStream ssValue{MakeByteSpan(*strValue)};
224
0
            m_obfuscation(ssValue);
225
0
            ssValue >> value;
226
0
        } catch (const std::exception&) {
227
0
            return false;
228
0
        }
229
0
        return true;
230
0
    }
txdb.cpp:_ZNK10CDBWrapper4ReadIN12_GLOBAL__N_19CoinEntryE4CoinEEbRKT_RT0_
Line
Count
Source
214
1.42M
    {
215
1.42M
        DataStream ssKey{};
216
1.42M
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
217
1.42M
        ssKey << key;
218
1.42M
        std::optional<std::string> strValue{ReadImpl(ssKey)};
219
1.42M
        if (!strValue) {
220
882k
            return false;
221
882k
        }
222
544k
        try {
223
544k
            DataStream ssValue{MakeByteSpan(*strValue)};
224
544k
            m_obfuscation(ssValue);
225
544k
            ssValue >> value;
226
544k
        } catch (const std::exception&) {
227
0
            return false;
228
0
        }
229
544k
        return true;
230
544k
    }
_ZNK10CDBWrapper4ReadIh7uint256EEbRKT_RT0_
Line
Count
Source
214
92.0k
    {
215
92.0k
        DataStream ssKey{};
216
92.0k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
217
92.0k
        ssKey << key;
218
92.0k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
219
92.0k
        if (!strValue) {
220
0
            return false;
221
0
        }
222
92.0k
        try {
223
92.0k
            DataStream ssValue{MakeByteSpan(*strValue)};
224
92.0k
            m_obfuscation(ssValue);
225
92.0k
            ssValue >> value;
226
92.0k
        } catch (const std::exception&) {
227
0
            return false;
228
0
        }
229
92.0k
        return true;
230
92.0k
    }
_ZNK10CDBWrapper4ReadIhNSt3__16vectorI7uint256NS1_9allocatorIS3_EEEEEEbRKT_RT0_
Line
Count
Source
214
38.8k
    {
215
38.8k
        DataStream ssKey{};
216
38.8k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
217
38.8k
        ssKey << key;
218
38.8k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
219
38.8k
        if (!strValue) {
220
38.8k
            return false;
221
38.8k
        }
222
0
        try {
223
0
            DataStream ssValue{MakeByteSpan(*strValue)};
224
0
            m_obfuscation(ssValue);
225
0
            ssValue >> value;
226
0
        } catch (const std::exception&) {
227
0
            return false;
228
0
        }
229
0
        return true;
230
0
    }
231
232
    template <typename K, typename V>
233
    bool Write(const K& key, const V& value, bool fSync = false)
234
0
    {
235
0
        CDBBatch batch(*this);
236
0
        batch.Write(key, value);
237
0
        return WriteBatch(batch, fSync);
238
0
    }
Unexecuted instantiation: _ZN10CDBWrapper5WriteINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE11ObfuscationEEbRKT_RKT0_b
Unexecuted instantiation: blockfilterindex.cpp:_ZN10CDBWrapper5WriteIN12_GLOBAL__N_111DBHeightKeyENSt3__14pairI7uint256NS1_5DBValEEEEEbRKT_RKT0_b
Unexecuted instantiation: coinstatsindex.cpp:_ZN10CDBWrapper5WriteIN12_GLOBAL__N_111DBHeightKeyENSt3__14pairI7uint256NS1_5DBValEEEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN10CDBWrapper5WriteIhhEEbRKT_RKT0_b
Unexecuted instantiation: _ZN10CDBWrapper5WriteINSt3__14pairIhNS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEEhEEbRKT_RKT0_b
239
240
    //! @returns filesystem path to the on-disk data.
241
0
    std::optional<fs::path> StoragePath() {
242
0
        if (m_is_memory) {
243
0
            return {};
244
0
        }
245
0
        return m_path;
246
0
    }
247
248
    template <typename K>
249
    bool Exists(const K& key) const
250
38.8k
    {
251
38.8k
        DataStream ssKey{};
252
38.8k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
253
38.8k
        ssKey << key;
254
38.8k
        return ExistsImpl(ssKey);
255
38.8k
    }
_ZNK10CDBWrapper6ExistsIhEEbRKT_
Line
Count
Source
250
38.8k
    {
251
38.8k
        DataStream ssKey{};
252
38.8k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
253
38.8k
        ssKey << key;
254
38.8k
        return ExistsImpl(ssKey);
255
38.8k
    }
Unexecuted instantiation: txdb.cpp:_ZNK10CDBWrapper6ExistsIN12_GLOBAL__N_19CoinEntryEEEbRKT_
256
257
    template <typename K>
258
    bool Erase(const K& key, bool fSync = false)
259
0
    {
260
0
        CDBBatch batch(*this);
261
0
        batch.Erase(key);
262
0
        return WriteBatch(batch, fSync);
263
0
    }
264
265
    bool WriteBatch(CDBBatch& batch, bool fSync = false);
266
267
    // Get an estimate of LevelDB memory usage (in bytes).
268
    size_t DynamicMemoryUsage() const;
269
270
    CDBIterator* NewIterator();
271
272
    /**
273
     * Return true if the database managed by this class contains no entries.
274
     */
275
    bool IsEmpty();
276
277
    template<typename K>
278
    size_t EstimateSize(const K& key_begin, const K& key_end) const
279
0
    {
280
0
        DataStream ssKey1{}, ssKey2{};
281
0
        ssKey1.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
282
0
        ssKey2.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
283
0
        ssKey1 << key_begin;
284
0
        ssKey2 << key_end;
285
0
        return EstimateSizeImpl(ssKey1, ssKey2);
286
0
    }
287
};
288
289
#endif // BITCOIN_DBWRAPPER_H