Coverage Report

Created: 2026-07-23 20:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/bitcoin/src/dbwrapper.h
Line
Count
Source
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/byte_units.h>
13
#include <util/check.h>
14
#include <util/fs.h>
15
#include <util/obfuscation.h>
16
17
#include <cstddef>
18
#include <cstdint>
19
#include <exception>
20
#include <memory>
21
#include <optional>
22
#include <span>
23
#include <stdexcept>
24
#include <string>
25
26
namespace leveldb {
27
class Env;
28
} // namespace leveldb
29
30
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64;
31
static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024;
32
static const size_t DBWRAPPER_MAX_FILE_SIZE{32_MiB};
33
34
//! User-controlled performance and debug options.
35
struct DBOptions {
36
    //! Compact database on startup.
37
    bool force_compact = false;
38
};
39
40
//! Application-specific storage settings.
41
struct DBParams {
42
    //! Location in the filesystem where leveldb data will be stored.
43
    fs::path path;
44
    //! Configures various leveldb cache settings.
45
    uint64_t cache_bytes;
46
    //! If true, use leveldb's memory environment.
47
    bool memory_only = false;
48
    //! If true, remove all existing data.
49
    bool wipe_data = false;
50
    //! If true, store data obfuscated via simple XOR. If false, XOR with a
51
    //! zero'd byte array.
52
    bool obfuscate = false;
53
    //! If true, build a LevelDB bloom filter to accelerate point lookups.
54
    bool bloom_filter = true;
55
    //! Passed-through options.
56
    DBOptions options{};
57
    //! If non-null, use this as the leveldb::Env instead of the default.
58
    //! Caller retains ownership.
59
    leveldb::Env* testing_env = nullptr;
60
    //! Maximum LevelDB SST file size. Larger values reduce the frequency
61
    //! of compactions but increase their duration.
62
    size_t max_file_size = DBWRAPPER_MAX_FILE_SIZE;
63
};
64
65
class dbwrapper_error : public std::runtime_error
66
{
67
public:
68
10
    explicit dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {}
69
};
70
71
class CDBWrapper;
72
73
/** These should be considered an implementation detail of the specific database.
74
 */
75
namespace dbwrapper_private {
76
77
/** Work around circular dependency, as well as for testing in dbwrapper_tests.
78
 * Database obfuscation should be considered an implementation detail of the
79
 * specific database.
80
 */
81
const Obfuscation& GetObfuscation(const CDBWrapper&);
82
}; // namespace dbwrapper_private
83
84
bool DestroyDB(const std::string& path_str);
85
86
/** Batch of changes queued to be written to a CDBWrapper */
87
class CDBBatch
88
{
89
    friend class CDBWrapper;
90
91
private:
92
    const CDBWrapper &parent;
93
94
    struct WriteBatchImpl;
95
    const std::unique_ptr<WriteBatchImpl> m_impl_batch;
96
97
    DataStream m_key_scratch{};
98
    DataStream m_value_scratch{};
99
100
    void WriteImpl(std::span<const std::byte> key, DataStream& value);
101
    void EraseImpl(std::span<const std::byte> key);
102
103
public:
104
    /**
105
     * @param[in] _parent   CDBWrapper that this batch is to be submitted to
106
     */
107
    explicit CDBBatch(const CDBWrapper& _parent);
108
    ~CDBBatch();
109
    void Clear();
110
111
    template <typename K, typename V>
112
    void Write(const K& key, const V& value)
113
445k
    {
114
445k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
445k
        m_key_scratch << key;
116
445k
        m_value_scratch << value;
117
445k
        WriteImpl(m_key_scratch, m_value_scratch);
118
445k
    }
void CDBBatch::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, uint256>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, uint256 const&)
Line
Count
Source
113
8
    {
114
8
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
8
        m_key_scratch << key;
116
8
        m_value_scratch << value;
117
8
        WriteImpl(m_key_scratch, m_value_scratch);
118
8
    }
void CDBBatch::Write<unsigned char, unsigned int>(unsigned char const&, unsigned int const&)
Line
Count
Source
113
258
    {
114
258
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
258
        m_key_scratch << key;
116
258
        m_value_scratch << value;
117
258
        WriteImpl(m_key_scratch, m_value_scratch);
118
258
    }
void CDBBatch::Write<unsigned char, bool>(unsigned char const&, bool const&)
Line
Count
Source
113
2
    {
114
2
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
2
        m_key_scratch << key;
116
2
        m_value_scratch << value;
117
2
        WriteImpl(m_key_scratch, m_value_scratch);
118
2
    }
void CDBBatch::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool const&)
Line
Count
Source
113
2
    {
114
2
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
2
        m_key_scratch << key;
116
2
        m_value_scratch << value;
117
2
        WriteImpl(m_key_scratch, m_value_scratch);
118
2
    }
void CDBBatch::Write<unsigned char, uint256>(unsigned char const&, uint256 const&)
Line
Count
Source
113
3.81k
    {
114
3.81k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
3.81k
        m_key_scratch << key;
116
3.81k
        m_value_scratch << value;
117
3.81k
        WriteImpl(m_key_scratch, m_value_scratch);
118
3.81k
    }
void CDBBatch::Write<dbwrapper_tests::StringContentsSerializer, unsigned int>(dbwrapper_tests::StringContentsSerializer const&, unsigned int const&)
Line
Count
Source
113
100
    {
114
100
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
100
        m_key_scratch << key;
116
100
        m_value_scratch << value;
117
100
        WriteImpl(m_key_scratch, m_value_scratch);
118
100
    }
void CDBBatch::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Obfuscation>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Obfuscation const&)
Line
Count
Source
113
521
    {
114
521
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
521
        m_key_scratch << key;
116
521
        m_value_scratch << value;
117
521
        WriteImpl(m_key_scratch, m_value_scratch);
118
521
    }
void CDBBatch::Write<unsigned char, CBlockLocator>(unsigned char const&, CBlockLocator const&)
Line
Count
Source
113
256
    {
114
256
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
256
        m_key_scratch << key;
116
256
        m_value_scratch << value;
117
256
        WriteImpl(m_key_scratch, m_value_scratch);
118
256
    }
void CDBBatch::Write<unsigned char, FlatFilePos>(unsigned char const&, FlatFilePos const&)
Line
Count
Source
113
174
    {
114
174
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
174
        m_key_scratch << key;
116
174
        m_value_scratch << value;
117
174
        WriteImpl(m_key_scratch, m_value_scratch);
118
174
    }
blockfilterindex.cpp:void CDBBatch::Write<index_util::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal> const&)
Line
Count
Source
113
7.57k
    {
114
7.57k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
7.57k
        m_key_scratch << key;
116
7.57k
        m_value_scratch << value;
117
7.57k
        WriteImpl(m_key_scratch, m_value_scratch);
118
7.57k
    }
blockfilterindex.cpp:void CDBBatch::Write<index_util::DBHashKey, (anonymous namespace)::DBVal>(index_util::DBHashKey const&, (anonymous namespace)::DBVal const&)
Line
Count
Source
113
111
    {
114
111
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
111
        m_key_scratch << key;
116
111
        m_value_scratch << value;
117
111
        WriteImpl(m_key_scratch, m_value_scratch);
118
111
    }
coinstatsindex.cpp:void CDBBatch::Write<index_util::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal> const&)
Line
Count
Source
113
4.19k
    {
114
4.19k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
4.19k
        m_key_scratch << key;
116
4.19k
        m_value_scratch << value;
117
4.19k
        WriteImpl(m_key_scratch, m_value_scratch);
118
4.19k
    }
coinstatsindex.cpp:void CDBBatch::Write<index_util::DBHashKey, (anonymous namespace)::DBVal>(index_util::DBHashKey const&, (anonymous namespace)::DBVal const&)
Line
Count
Source
113
121
    {
114
121
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
121
        m_key_scratch << key;
116
121
        m_value_scratch << value;
117
121
        WriteImpl(m_key_scratch, m_value_scratch);
118
121
    }
void CDBBatch::Write<unsigned char, MuHash3072>(unsigned char const&, MuHash3072 const&)
Line
Count
Source
113
117
    {
114
117
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
117
        m_key_scratch << key;
116
117
        m_value_scratch << value;
117
117
        WriteImpl(m_key_scratch, m_value_scratch);
118
117
    }
void CDBBatch::Write<std::pair<unsigned char, uint256>, CDiskTxPos>(std::pair<unsigned char, uint256> const&, CDiskTxPos const&)
Line
Count
Source
113
3.93k
    {
114
3.93k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
3.93k
        m_key_scratch << key;
116
3.93k
        m_value_scratch << value;
117
3.93k
        WriteImpl(m_key_scratch, m_value_scratch);
118
3.93k
    }
void CDBBatch::Write<char [12], std::pair<unsigned long, unsigned long>>(char const (&) [12], std::pair<unsigned long, unsigned long> const&)
Line
Count
Source
113
7
    {
114
7
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
7
        m_key_scratch << key;
116
7
        m_value_scratch << value;
117
7
        WriteImpl(m_key_scratch, m_value_scratch);
118
7
    }
void CDBBatch::Write<DBKey, std::span<std::byte const, 18446744073709551615ul>>(DBKey const&, std::span<std::byte const, 18446744073709551615ul> const&)
Line
Count
Source
113
38
    {
114
38
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
38
        m_key_scratch << key;
116
38
        m_value_scratch << value;
117
38
        WriteImpl(m_key_scratch, m_value_scratch);
118
38
    }
void CDBBatch::Write<unsigned char, unsigned char>(unsigned char const&, unsigned char const&)
Line
Count
Source
113
15
    {
114
15
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
15
        m_key_scratch << key;
116
15
        m_value_scratch << value;
117
15
        WriteImpl(m_key_scratch, m_value_scratch);
118
15
    }
void CDBBatch::Write<std::pair<unsigned char, int>, kernel::CBlockFileInfo>(std::pair<unsigned char, int> const&, kernel::CBlockFileInfo const&)
Line
Count
Source
113
1.65k
    {
114
1.65k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
1.65k
        m_key_scratch << key;
116
1.65k
        m_value_scratch << value;
117
1.65k
        WriteImpl(m_key_scratch, m_value_scratch);
118
1.65k
    }
void CDBBatch::Write<unsigned char, int>(unsigned char const&, int const&)
Line
Count
Source
113
3.44k
    {
114
3.44k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
3.44k
        m_key_scratch << key;
116
3.44k
        m_value_scratch << value;
117
3.44k
        WriteImpl(m_key_scratch, m_value_scratch);
118
3.44k
    }
void CDBBatch::Write<std::pair<unsigned char, uint256>, CDiskBlockIndex>(std::pair<unsigned char, uint256> const&, CDiskBlockIndex const&)
Line
Count
Source
113
124k
    {
114
124k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
124k
        m_key_scratch << key;
116
124k
        m_value_scratch << value;
117
124k
        WriteImpl(m_key_scratch, m_value_scratch);
118
124k
    }
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&)
Line
Count
Source
113
8
    {
114
8
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
8
        m_key_scratch << key;
116
8
        m_value_scratch << value;
117
8
        WriteImpl(m_key_scratch, m_value_scratch);
118
8
    }
void CDBBatch::Write<unsigned char, std::vector<uint256, std::allocator<uint256>>>(unsigned char const&, std::vector<uint256, std::allocator<uint256>> const&)
Line
Count
Source
113
3.77k
    {
114
3.77k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
3.77k
        m_key_scratch << key;
116
3.77k
        m_value_scratch << value;
117
3.77k
        WriteImpl(m_key_scratch, m_value_scratch);
118
3.77k
    }
txdb.cpp:void CDBBatch::Write<(anonymous namespace)::CoinEntry, Coin>((anonymous namespace)::CoinEntry const&, Coin const&)
Line
Count
Source
113
290k
    {
114
290k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
290k
        m_key_scratch << key;
116
290k
        m_value_scratch << value;
117
290k
        WriteImpl(m_key_scratch, m_value_scratch);
118
290k
    }
119
120
    template <typename K>
121
    void Erase(const K& key)
122
43.0k
    {
123
43.0k
        ScopedDataStreamUsage scoped_key{m_key_scratch};
124
43.0k
        m_key_scratch << key;
125
43.0k
        EraseImpl(m_key_scratch);
126
43.0k
    }
void CDBBatch::Erase<unsigned char>(unsigned char const&)
Line
Count
Source
122
7.57k
    {
123
7.57k
        ScopedDataStreamUsage scoped_key{m_key_scratch};
124
7.57k
        m_key_scratch << key;
125
7.57k
        EraseImpl(m_key_scratch);
126
7.57k
    }
void CDBBatch::Erase<DBKey>(DBKey const&)
Line
Count
Source
122
6
    {
123
6
        ScopedDataStreamUsage scoped_key{m_key_scratch};
124
6
        m_key_scratch << key;
125
6
        EraseImpl(m_key_scratch);
126
6
    }
txdb.cpp:void CDBBatch::Erase<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry const&)
Line
Count
Source
122
35.4k
    {
123
35.4k
        ScopedDataStreamUsage scoped_key{m_key_scratch};
124
35.4k
        m_key_scratch << key;
125
35.4k
        EraseImpl(m_key_scratch);
126
35.4k
    }
127
128
    size_t ApproximateSize() const;
129
};
130
131
class CDBIterator
132
{
133
public:
134
    struct IteratorImpl;
135
136
private:
137
    const CDBWrapper &parent;
138
    const std::unique_ptr<IteratorImpl> m_impl_iter;
139
    DataStream m_scratch{};
140
141
    void SeekImpl(std::span<const std::byte> key);
142
    std::span<const std::byte> GetKeyImpl() const;
143
    std::span<const std::byte> GetValueImpl() const;
144
145
public:
146
147
    /**
148
     * @param[in] _parent          Parent CDBWrapper instance.
149
     * @param[in] _piter           The original leveldb iterator.
150
     */
151
    CDBIterator(const CDBWrapper& _parent, std::unique_ptr<IteratorImpl> _piter);
152
    ~CDBIterator();
153
154
    bool Valid() const;
155
156
    void SeekToFirst();
157
158
4.38k
    template<typename K> void Seek(const K& key) {
159
4.38k
        ScopedDataStreamUsage scoped_scratch{m_scratch};
160
4.38k
        m_scratch << key;
161
4.38k
        SeekImpl(m_scratch);
162
4.38k
    }
void CDBIterator::Seek<unsigned char>(unsigned char const&)
Line
Count
Source
158
1.24k
    template<typename K> void Seek(const K& key) {
159
1.24k
        ScopedDataStreamUsage scoped_scratch{m_scratch};
160
1.24k
        m_scratch << key;
161
1.24k
        SeekImpl(m_scratch);
162
1.24k
    }
void CDBIterator::Seek<dbwrapper_tests::StringContentsSerializer>(dbwrapper_tests::StringContentsSerializer const&)
Line
Count
Source
158
2
    template<typename K> void Seek(const K& key) {
159
2
        ScopedDataStreamUsage scoped_scratch{m_scratch};
160
2
        m_scratch << key;
161
2
        SeekImpl(m_scratch);
162
2
    }
void CDBIterator::Seek<index_util::DBHeightKey>(index_util::DBHeightKey const&)
Line
Count
Source
158
680
    template<typename K> void Seek(const K& key) {
159
680
        ScopedDataStreamUsage scoped_scratch{m_scratch};
160
680
        m_scratch << key;
161
680
        SeekImpl(m_scratch);
162
680
    }
void CDBIterator::Seek<std::pair<unsigned char, unsigned long>>(std::pair<unsigned char, unsigned long> const&)
Line
Count
Source
158
35
    template<typename K> void Seek(const K& key) {
159
35
        ScopedDataStreamUsage scoped_scratch{m_scratch};
160
35
        m_scratch << key;
161
35
        SeekImpl(m_scratch);
162
35
    }
void CDBIterator::Seek<std::pair<unsigned char, uint256>>(std::pair<unsigned char, uint256> const&)
Line
Count
Source
158
2.42k
    template<typename K> void Seek(const K& key) {
159
2.42k
        ScopedDataStreamUsage scoped_scratch{m_scratch};
160
2.42k
        m_scratch << key;
161
2.42k
        SeekImpl(m_scratch);
162
2.42k
    }
163
164
    void Next();
165
166
408k
    template<typename K> bool GetKey(K& key) {
167
408k
        try {
168
408k
            SpanReader ssKey{GetKeyImpl()};
169
408k
            ssKey >> key;
170
408k
        } catch (const std::exception&) {
171
751
            return false;
172
751
        }
173
408k
        return true;
174
408k
    }
bool CDBIterator::GetKey<unsigned short>(unsigned short&)
Line
Count
Source
166
2
    template<typename K> bool GetKey(K& key) {
167
2
        try {
168
2
            SpanReader ssKey{GetKeyImpl()};
169
2
            ssKey >> key;
170
2
        } catch (const std::exception&) {
171
2
            return false;
172
2
        }
173
0
        return true;
174
2
    }
bool CDBIterator::GetKey<unsigned char>(unsigned char&)
Line
Count
Source
166
390
    template<typename K> bool GetKey(K& key) {
167
390
        try {
168
390
            SpanReader ssKey{GetKeyImpl()};
169
390
            ssKey >> key;
170
390
        } catch (const std::exception&) {
171
0
            return false;
172
0
        }
173
390
        return true;
174
390
    }
bool CDBIterator::GetKey<dbwrapper_tests::StringContentsSerializer>(dbwrapper_tests::StringContentsSerializer&)
Line
Count
Source
166
150
    template<typename K> bool GetKey(K& key) {
167
150
        try {
168
150
            SpanReader ssKey{GetKeyImpl()};
169
150
            ssKey >> key;
170
150
        } catch (const std::exception&) {
171
0
            return false;
172
0
        }
173
150
        return true;
174
150
    }
bool CDBIterator::GetKey<index_util::DBHeightKey>(index_util::DBHeightKey&)
Line
Count
Source
166
3.09k
    template<typename K> bool GetKey(K& key) {
167
3.09k
        try {
168
3.09k
            SpanReader ssKey{GetKeyImpl()};
169
3.09k
            ssKey >> key;
170
3.09k
        } catch (const std::exception&) {
171
0
            return false;
172
0
        }
173
3.09k
        return true;
174
3.09k
    }
bool CDBIterator::GetKey<DBKey>(DBKey&)
Line
Count
Source
166
25
    template<typename K> bool GetKey(K& key) {
167
25
        try {
168
25
            SpanReader ssKey{GetKeyImpl()};
169
25
            ssKey >> key;
170
25
        } catch (const std::exception&) {
171
0
            return false;
172
0
        }
173
25
        return true;
174
25
    }
bool CDBIterator::GetKey<std::pair<unsigned char, uint256>>(std::pair<unsigned char, uint256>&)
Line
Count
Source
166
136k
    template<typename K> bool GetKey(K& key) {
167
136k
        try {
168
136k
            SpanReader ssKey{GetKeyImpl()};
169
136k
            ssKey >> key;
170
136k
        } catch (const std::exception&) {
171
749
            return false;
172
749
        }
173
135k
        return true;
174
136k
    }
txdb.cpp:bool CDBIterator::GetKey<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry&)
Line
Count
Source
166
268k
    template<typename K> bool GetKey(K& key) {
167
268k
        try {
168
268k
            SpanReader ssKey{GetKeyImpl()};
169
268k
            ssKey >> key;
170
268k
        } catch (const std::exception&) {
171
0
            return false;
172
0
        }
173
268k
        return true;
174
268k
    }
175
176
407k
    template<typename V> bool GetValue(V& value) {
177
407k
        try {
178
407k
            ScopedDataStreamUsage scoped_scratch{m_scratch};
179
407k
            m_scratch.write(GetValueImpl());
180
407k
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
181
407k
            m_scratch >> value;
182
407k
        } catch (const std::exception&) {
183
2
            return false;
184
2
        }
185
407k
        return true;
186
407k
    }
bool CDBIterator::GetValue<std::pair<uint256, unsigned char>>(std::pair<uint256, unsigned char>&)
Line
Count
Source
176
2
    template<typename V> bool GetValue(V& value) {
177
2
        try {
178
2
            ScopedDataStreamUsage scoped_scratch{m_scratch};
179
2
            m_scratch.write(GetValueImpl());
180
2
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
181
2
            m_scratch >> value;
182
2
        } catch (const std::exception&) {
183
2
            return false;
184
2
        }
185
0
        return true;
186
2
    }
bool CDBIterator::GetValue<uint256>(uint256&)
Line
Count
Source
176
8
    template<typename V> bool GetValue(V& value) {
177
8
        try {
178
8
            ScopedDataStreamUsage scoped_scratch{m_scratch};
179
8
            m_scratch.write(GetValueImpl());
180
8
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
181
8
            m_scratch >> value;
182
8
        } catch (const std::exception&) {
183
0
            return false;
184
0
        }
185
8
        return true;
186
8
    }
bool CDBIterator::GetValue<unsigned int>(unsigned int&)
Line
Count
Source
176
342
    template<typename V> bool GetValue(V& value) {
177
342
        try {
178
342
            ScopedDataStreamUsage scoped_scratch{m_scratch};
179
342
            m_scratch.write(GetValueImpl());
180
342
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
181
342
            m_scratch >> value;
182
342
        } catch (const std::exception&) {
183
0
            return false;
184
0
        }
185
342
        return true;
186
342
    }
blockfilterindex.cpp:bool CDBIterator::GetValue<std::pair<uint256, (anonymous namespace)::DBVal>>(std::pair<uint256, (anonymous namespace)::DBVal>&)
Line
Count
Source
176
2.97k
    template<typename V> bool GetValue(V& value) {
177
2.97k
        try {
178
2.97k
            ScopedDataStreamUsage scoped_scratch{m_scratch};
179
2.97k
            m_scratch.write(GetValueImpl());
180
2.97k
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
181
2.97k
            m_scratch >> value;
182
2.97k
        } catch (const std::exception&) {
183
0
            return false;
184
0
        }
185
2.97k
        return true;
186
2.97k
    }
coinstatsindex.cpp:bool CDBIterator::GetValue<std::pair<uint256, (anonymous namespace)::DBVal>>(std::pair<uint256, (anonymous namespace)::DBVal>&)
Line
Count
Source
176
121
    template<typename V> bool GetValue(V& value) {
177
121
        try {
178
121
            ScopedDataStreamUsage scoped_scratch{m_scratch};
179
121
            m_scratch.write(GetValueImpl());
180
121
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
181
121
            m_scratch >> value;
182
121
        } catch (const std::exception&) {
183
0
            return false;
184
0
        }
185
121
        return true;
186
121
    }
bool CDBIterator::GetValue<CDiskBlockIndex>(CDiskBlockIndex&)
Line
Count
Source
176
135k
    template<typename V> bool GetValue(V& value) {
177
135k
        try {
178
135k
            ScopedDataStreamUsage scoped_scratch{m_scratch};
179
135k
            m_scratch.write(GetValueImpl());
180
135k
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
181
135k
            m_scratch >> value;
182
135k
        } catch (const std::exception&) {
183
0
            return false;
184
0
        }
185
135k
        return true;
186
135k
    }
bool CDBIterator::GetValue<Coin>(Coin&)
Line
Count
Source
176
268k
    template<typename V> bool GetValue(V& value) {
177
268k
        try {
178
268k
            ScopedDataStreamUsage scoped_scratch{m_scratch};
179
268k
            m_scratch.write(GetValueImpl());
180
268k
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
181
268k
            m_scratch >> value;
182
268k
        } catch (const std::exception&) {
183
0
            return false;
184
0
        }
185
268k
        return true;
186
268k
    }
187
};
188
189
struct LevelDBContext;
190
191
class CDBWrapper
192
{
193
    friend const Obfuscation& dbwrapper_private::GetObfuscation(const CDBWrapper&);
194
private:
195
    //! holds all leveldb-specific fields of this class
196
    std::unique_ptr<LevelDBContext> m_db_context;
197
198
    //! the name of this database
199
    std::string m_name;
200
201
    //! optional XOR-obfuscation of the database
202
    Obfuscation m_obfuscation;
203
204
    //! obfuscation key storage key, null-prefixed to avoid collisions
205
    inline static const std::string OBFUSCATION_KEY{"\000obfuscate_key", 14}; // explicit size to avoid truncation at leading \0
206
207
    std::optional<std::string> ReadImpl(std::span<const std::byte> key) const;
208
    bool ExistsImpl(std::span<const std::byte> key) const;
209
    size_t EstimateSizeImpl(std::span<const std::byte> key1, std::span<const std::byte> key2) const;
210
11.2M
    auto& DBContext() const LIFETIMEBOUND { return *Assert(m_db_context); }
211
212
public:
213
    CDBWrapper(const DBParams& params);
214
    ~CDBWrapper();
215
216
    CDBWrapper(const CDBWrapper&) = delete;
217
    CDBWrapper& operator=(const CDBWrapper&) = delete;
218
219
    template <typename K, typename V>
220
    bool Read(const K& key, V& value) const
221
5.58M
    {
222
5.58M
        DataStream ssKey{};
223
5.58M
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
5.58M
        ssKey << key;
225
5.58M
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
5.58M
        if (!strValue) {
227
5.47M
            return false;
228
5.47M
        }
229
106k
        try {
230
106k
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
106k
            m_obfuscation(ssValue);
232
106k
            SpanReader{ssValue} >> value;
233
106k
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
106k
        return true;
237
106k
    }
bool CDBWrapper::Read<unsigned char, uint256>(unsigned char const&, uint256&) const
Line
Count
Source
221
7.79k
    {
222
7.79k
        DataStream ssKey{};
223
7.79k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
7.79k
        ssKey << key;
225
7.79k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
7.79k
        if (!strValue) {
227
1.74k
            return false;
228
1.74k
        }
229
6.05k
        try {
230
6.05k
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
6.05k
            m_obfuscation(ssValue);
232
6.05k
            SpanReader{ssValue} >> value;
233
6.05k
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
6.05k
        return true;
237
6.05k
    }
bool CDBWrapper::Read<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, uint256>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, uint256&) const
Line
Count
Source
221
8
    {
222
8
        DataStream ssKey{};
223
8
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
8
        ssKey << key;
225
8
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
8
        if (!strValue) {
227
0
            return false;
228
0
        }
229
8
        try {
230
8
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
8
            m_obfuscation(ssValue);
232
8
            SpanReader{ssValue} >> value;
233
8
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
8
        return true;
237
8
    }
bool CDBWrapper::Read<unsigned char, unsigned int>(unsigned char const&, unsigned int&) const
Line
Count
Source
221
2
    {
222
2
        DataStream ssKey{};
223
2
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
2
        ssKey << key;
225
2
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
2
        if (!strValue) {
227
0
            return false;
228
0
        }
229
2
        try {
230
2
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
2
            m_obfuscation(ssValue);
232
2
            SpanReader{ssValue} >> value;
233
2
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
2
        return true;
237
2
    }
bool CDBWrapper::Read<unsigned char, bool>(unsigned char const&, bool&) const
Line
Count
Source
221
2
    {
222
2
        DataStream ssKey{};
223
2
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
2
        ssKey << key;
225
2
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
2
        if (!strValue) {
227
0
            return false;
228
0
        }
229
2
        try {
230
2
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
2
            m_obfuscation(ssValue);
232
2
            SpanReader{ssValue} >> value;
233
2
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
2
        return true;
237
2
    }
bool CDBWrapper::Read<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool&) const
Line
Count
Source
221
2
    {
222
2
        DataStream ssKey{};
223
2
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
2
        ssKey << key;
225
2
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
2
        if (!strValue) {
227
0
            return false;
228
0
        }
229
2
        try {
230
2
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
2
            m_obfuscation(ssValue);
232
2
            SpanReader{ssValue} >> value;
233
2
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
2
        return true;
237
2
    }
bool CDBWrapper::Read<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Obfuscation>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Obfuscation&) const
Line
Count
Source
221
2.78k
    {
222
2.78k
        DataStream ssKey{};
223
2.78k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
2.78k
        ssKey << key;
225
2.78k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
2.78k
        if (!strValue) {
227
1.92k
            return false;
228
1.92k
        }
229
862
        try {
230
862
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
862
            m_obfuscation(ssValue);
232
862
            SpanReader{ssValue} >> value;
233
862
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
861
        return true;
237
862
    }
bool CDBWrapper::Read<unsigned char, CBlockLocator>(unsigned char const&, CBlockLocator&) const
Line
Count
Source
221
155
    {
222
155
        DataStream ssKey{};
223
155
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
155
        ssKey << key;
225
155
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
155
        if (!strValue) {
227
66
            return false;
228
66
        }
229
89
        try {
230
89
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
89
            m_obfuscation(ssValue);
232
89
            SpanReader{ssValue} >> value;
233
89
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
89
        return true;
237
89
    }
blockfilterindex.cpp:bool CDBWrapper::Read<index_util::DBHashKey, (anonymous namespace)::DBVal>(index_util::DBHashKey const&, (anonymous namespace)::DBVal&) const
Line
Count
Source
221
29
    {
222
29
        DataStream ssKey{};
223
29
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
29
        ssKey << key;
225
29
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
29
        if (!strValue) {
227
0
            return false;
228
0
        }
229
29
        try {
230
29
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
29
            m_obfuscation(ssValue);
232
29
            SpanReader{ssValue} >> value;
233
29
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
29
        return true;
237
29
    }
bool CDBWrapper::Read<unsigned char, FlatFilePos>(unsigned char const&, FlatFilePos&) const
Line
Count
Source
221
43
    {
222
43
        DataStream ssKey{};
223
43
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
43
        ssKey << key;
225
43
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
43
        if (!strValue) {
227
20
            return false;
228
20
        }
229
23
        try {
230
23
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
23
            m_obfuscation(ssValue);
232
23
            SpanReader{ssValue} >> value;
233
23
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
23
        return true;
237
23
    }
blockfilterindex.cpp:bool CDBWrapper::Read<index_util::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal>&) const
Line
Count
Source
221
1.21k
    {
222
1.21k
        DataStream ssKey{};
223
1.21k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
1.21k
        ssKey << key;
225
1.21k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
1.21k
        if (!strValue) {
227
202
            return false;
228
202
        }
229
1.00k
        try {
230
1.00k
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
1.00k
            m_obfuscation(ssValue);
232
1.00k
            SpanReader{ssValue} >> value;
233
1.00k
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
1.00k
        return true;
237
1.00k
    }
coinstatsindex.cpp:bool CDBWrapper::Read<index_util::DBHashKey, (anonymous namespace)::DBVal>(index_util::DBHashKey const&, (anonymous namespace)::DBVal&) const
Line
Count
Source
221
2
    {
222
2
        DataStream ssKey{};
223
2
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
2
        ssKey << key;
225
2
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
2
        if (!strValue) {
227
0
            return false;
228
0
        }
229
2
        try {
230
2
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
2
            m_obfuscation(ssValue);
232
2
            SpanReader{ssValue} >> value;
233
2
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
2
        return true;
237
2
    }
bool CDBWrapper::Read<unsigned char, MuHash3072>(unsigned char const&, MuHash3072&) const
Line
Count
Source
221
52
    {
222
52
        DataStream ssKey{};
223
52
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
52
        ssKey << key;
225
52
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
52
        if (!strValue) {
227
22
            return false;
228
22
        }
229
30
        try {
230
30
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
30
            m_obfuscation(ssValue);
232
30
            SpanReader{ssValue} >> value;
233
30
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
30
        return true;
237
30
    }
coinstatsindex.cpp:bool CDBWrapper::Read<index_util::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal>&) const
Line
Count
Source
221
221
    {
222
221
        DataStream ssKey{};
223
221
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
221
        ssKey << key;
225
221
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
221
        if (!strValue) {
227
1
            return false;
228
1
        }
229
220
        try {
230
220
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
220
            m_obfuscation(ssValue);
232
220
            SpanReader{ssValue} >> value;
233
220
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
220
        return true;
237
220
    }
Unexecuted instantiation: coinstatsindex.cpp:bool CDBWrapper::Read<index_util::DBHashKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHashKey const&, std::pair<uint256, (anonymous namespace)::DBVal>&) const
bool CDBWrapper::Read<std::pair<unsigned char, uint256>, CDiskTxPos>(std::pair<unsigned char, uint256> const&, CDiskTxPos&) const
Line
Count
Source
221
243
    {
222
243
        DataStream ssKey{};
223
243
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
243
        ssKey << key;
225
243
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
243
        if (!strValue) {
227
101
            return false;
228
101
        }
229
142
        try {
230
142
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
142
            m_obfuscation(ssValue);
232
142
            SpanReader{ssValue} >> value;
233
142
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
142
        return true;
237
142
    }
bool CDBWrapper::Read<char [12], std::pair<unsigned long, unsigned long>>(char const (&) [12], std::pair<unsigned long, unsigned long>&) const
Line
Count
Source
221
23
    {
222
23
        DataStream ssKey{};
223
23
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
23
        ssKey << key;
225
23
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
23
        if (!strValue) {
227
7
            return false;
228
7
        }
229
16
        try {
230
16
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
16
            m_obfuscation(ssValue);
232
16
            SpanReader{ssValue} >> value;
233
16
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
16
        return true;
237
16
    }
bool CDBWrapper::Read<std::pair<unsigned char, int>, kernel::CBlockFileInfo>(std::pair<unsigned char, int> const&, kernel::CBlockFileInfo&) const
Line
Count
Source
221
2.42k
    {
222
2.42k
        DataStream ssKey{};
223
2.42k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
2.42k
        ssKey << key;
225
2.42k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
2.42k
        if (!strValue) {
227
1.65k
            return false;
228
1.65k
        }
229
764
        try {
230
764
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
764
            m_obfuscation(ssValue);
232
764
            SpanReader{ssValue} >> value;
233
764
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
764
        return true;
237
764
    }
bool CDBWrapper::Read<unsigned char, int>(unsigned char const&, int&) const
Line
Count
Source
221
1.20k
    {
222
1.20k
        DataStream ssKey{};
223
1.20k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
1.20k
        ssKey << key;
225
1.20k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
1.20k
        if (!strValue) {
227
455
            return false;
228
455
        }
229
747
        try {
230
747
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
747
            m_obfuscation(ssValue);
232
747
            SpanReader{ssValue} >> value;
233
747
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
747
        return true;
237
747
    }
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
Line
Count
Source
221
1.20k
    {
222
1.20k
        DataStream ssKey{};
223
1.20k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
1.20k
        ssKey << key;
225
1.20k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
1.20k
        if (!strValue) {
227
1.19k
            return false;
228
1.19k
        }
229
2
        try {
230
2
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
2
            m_obfuscation(ssValue);
232
2
            SpanReader{ssValue} >> value;
233
2
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
2
        return true;
237
2
    }
txdb.cpp:bool CDBWrapper::Read<(anonymous namespace)::CoinEntry, Coin>((anonymous namespace)::CoinEntry const&, Coin&) const
Line
Count
Source
221
5.56M
    {
222
5.56M
        DataStream ssKey{};
223
5.56M
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
5.56M
        ssKey << key;
225
5.56M
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
5.56M
        if (!strValue) {
227
5.46M
            return false;
228
5.46M
        }
229
96.2k
        try {
230
96.2k
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
96.2k
            m_obfuscation(ssValue);
232
96.2k
            SpanReader{ssValue} >> value;
233
96.2k
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
96.2k
        return true;
237
96.2k
    }
bool CDBWrapper::Read<unsigned char, std::vector<uint256, std::allocator<uint256>>>(unsigned char const&, std::vector<uint256, std::allocator<uint256>>&) const
Line
Count
Source
221
1.57k
    {
222
1.57k
        DataStream ssKey{};
223
1.57k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
1.57k
        ssKey << key;
225
1.57k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
1.57k
        if (!strValue) {
227
1.57k
            return false;
228
1.57k
        }
229
0
        try {
230
0
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
0
            m_obfuscation(ssValue);
232
0
            SpanReader{ssValue} >> value;
233
0
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
0
        return true;
237
0
    }
238
239
    template <typename K, typename V>
240
    void Write(const K& key, const V& value, bool fSync = false)
241
12.7k
    {
242
12.7k
        CDBBatch batch(*this);
243
12.7k
        batch.Write(key, value);
244
12.7k
        WriteBatch(batch, fSync);
245
12.7k
    }
void CDBWrapper::Write<unsigned char, uint256>(unsigned char const&, uint256 const&, bool)
Line
Count
Source
241
30
    {
242
30
        CDBBatch batch(*this);
243
30
        batch.Write(key, value);
244
30
        WriteBatch(batch, fSync);
245
30
    }
void CDBWrapper::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, uint256>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, uint256 const&, bool)
Line
Count
Source
241
8
    {
242
8
        CDBBatch batch(*this);
243
8
        batch.Write(key, value);
244
8
        WriteBatch(batch, fSync);
245
8
    }
void CDBWrapper::Write<unsigned char, unsigned int>(unsigned char const&, unsigned int const&, bool)
Line
Count
Source
241
258
    {
242
258
        CDBBatch batch(*this);
243
258
        batch.Write(key, value);
244
258
        WriteBatch(batch, fSync);
245
258
    }
void CDBWrapper::Write<unsigned char, bool>(unsigned char const&, bool const&, bool)
Line
Count
Source
241
2
    {
242
2
        CDBBatch batch(*this);
243
2
        batch.Write(key, value);
244
2
        WriteBatch(batch, fSync);
245
2
    }
void CDBWrapper::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool const&, bool)
Line
Count
Source
241
2
    {
242
2
        CDBBatch batch(*this);
243
2
        batch.Write(key, value);
244
2
        WriteBatch(batch, fSync);
245
2
    }
void CDBWrapper::Write<dbwrapper_tests::StringContentsSerializer, unsigned int>(dbwrapper_tests::StringContentsSerializer const&, unsigned int const&, bool)
Line
Count
Source
241
100
    {
242
100
        CDBBatch batch(*this);
243
100
        batch.Write(key, value);
244
100
        WriteBatch(batch, fSync);
245
100
    }
void CDBWrapper::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Obfuscation>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Obfuscation const&, bool)
Line
Count
Source
241
521
    {
242
521
        CDBBatch batch(*this);
243
521
        batch.Write(key, value);
244
521
        WriteBatch(batch, fSync);
245
521
    }
blockfilterindex.cpp:void CDBWrapper::Write<index_util::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal> const&, bool)
Line
Count
Source
241
7.57k
    {
242
7.57k
        CDBBatch batch(*this);
243
7.57k
        batch.Write(key, value);
244
7.57k
        WriteBatch(batch, fSync);
245
7.57k
    }
coinstatsindex.cpp:void CDBWrapper::Write<index_util::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal> const&, bool)
Line
Count
Source
241
4.19k
    {
242
4.19k
        CDBBatch batch(*this);
243
4.19k
        batch.Write(key, value);
244
4.19k
        WriteBatch(batch, fSync);
245
4.19k
    }
void CDBWrapper::Write<char [12], std::pair<unsigned long, unsigned long>>(char const (&) [12], std::pair<unsigned long, unsigned long> const&, bool)
Line
Count
Source
241
7
    {
242
7
        CDBBatch batch(*this);
243
7
        batch.Write(key, value);
244
7
        WriteBatch(batch, fSync);
245
7
    }
void CDBWrapper::Write<unsigned char, unsigned char>(unsigned char const&, unsigned char const&, bool)
Line
Count
Source
241
15
    {
242
15
        CDBBatch batch(*this);
243
15
        batch.Write(key, value);
244
15
        WriteBatch(batch, fSync);
245
15
    }
void 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)
Line
Count
Source
241
8
    {
242
8
        CDBBatch batch(*this);
243
8
        batch.Write(key, value);
244
8
        WriteBatch(batch, fSync);
245
8
    }
246
247
    template <typename K>
248
    bool Exists(const K& key) const
249
1.28k
    {
250
1.28k
        DataStream ssKey{};
251
1.28k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
252
1.28k
        ssKey << key;
253
1.28k
        return ExistsImpl(ssKey);
254
1.28k
    }
bool CDBWrapper::Exists<unsigned char>(unsigned char const&) const
Line
Count
Source
249
1.24k
    {
250
1.24k
        DataStream ssKey{};
251
1.24k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
252
1.24k
        ssKey << key;
253
1.24k
        return ExistsImpl(ssKey);
254
1.24k
    }
txdb.cpp:bool CDBWrapper::Exists<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry const&) const
Line
Count
Source
249
44
    {
250
44
        DataStream ssKey{};
251
44
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
252
44
        ssKey << key;
253
44
        return ExistsImpl(ssKey);
254
44
    }
255
256
    template <typename K>
257
    void Erase(const K& key, bool fSync = false)
258
14
    {
259
14
        CDBBatch batch(*this);
260
14
        batch.Erase(key);
261
14
        WriteBatch(batch, fSync);
262
14
    }
263
264
    void WriteBatch(CDBBatch& batch, bool fSync = false);
265
266
    //! Perform a blocking full compaction of the underlying LevelDB.
267
    void CompactFull();
268
269
    //! Return a LevelDB property value, if available.
270
    std::optional<std::string> GetProperty(const std::string& property) const;
271
272
    // Get an estimate of LevelDB memory usage (in bytes).
273
    size_t DynamicMemoryUsage() const;
274
275
    CDBIterator* NewIterator();
276
277
    /**
278
     * Return true if the database managed by this class contains no entries.
279
     */
280
    bool IsEmpty();
281
282
    template<typename K>
283
    size_t EstimateSize(const K& key_begin, const K& key_end) const
284
102
    {
285
102
        DataStream ssKey1{}, ssKey2{};
286
102
        ssKey1.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
287
102
        ssKey2.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
288
102
        ssKey1 << key_begin;
289
102
        ssKey2 << key_end;
290
102
        return EstimateSizeImpl(ssKey1, ssKey2);
291
102
    }
292
};
293
294
#endif // BITCOIN_DBWRAPPER_H