Coverage Report

Created: 2026-07-20 20:52

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
446k
    {
114
446k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
446k
        m_key_scratch << key;
116
446k
        m_value_scratch << value;
117
446k
        WriteImpl(m_key_scratch, m_value_scratch);
118
446k
    }
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
520
    {
114
520
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
520
        m_key_scratch << key;
116
520
        m_value_scratch << value;
117
520
        WriteImpl(m_key_scratch, m_value_scratch);
118
520
    }
void CDBBatch::Write<unsigned char, CBlockLocator>(unsigned char const&, CBlockLocator 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, FlatFilePos>(unsigned char const&, FlatFilePos const&)
Line
Count
Source
113
176
    {
114
176
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
176
        m_key_scratch << key;
116
176
        m_value_scratch << value;
117
176
        WriteImpl(m_key_scratch, m_value_scratch);
118
176
    }
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.18k
    {
114
4.18k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
4.18k
        m_key_scratch << key;
116
4.18k
        m_value_scratch << value;
117
4.18k
        WriteImpl(m_key_scratch, m_value_scratch);
118
4.18k
    }
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.87k
    {
114
3.87k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
3.87k
        m_key_scratch << key;
116
3.87k
        m_value_scratch << value;
117
3.87k
        WriteImpl(m_key_scratch, m_value_scratch);
118
3.87k
    }
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
292k
    {
114
292k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
115
292k
        m_key_scratch << key;
116
292k
        m_value_scratch << value;
117
292k
        WriteImpl(m_key_scratch, m_value_scratch);
118
292k
    }
119
120
    template <typename K>
121
    void Erase(const K& key)
122
44.5k
    {
123
44.5k
        ScopedDataStreamUsage scoped_key{m_key_scratch};
124
44.5k
        m_key_scratch << key;
125
44.5k
        EraseImpl(m_key_scratch);
126
44.5k
    }
void CDBBatch::Erase<unsigned char>(unsigned char const&)
Line
Count
Source
122
7.56k
    {
123
7.56k
        ScopedDataStreamUsage scoped_key{m_key_scratch};
124
7.56k
        m_key_scratch << key;
125
7.56k
        EraseImpl(m_key_scratch);
126
7.56k
    }
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
36.9k
    {
123
36.9k
        ScopedDataStreamUsage scoped_key{m_key_scratch};
124
36.9k
        m_key_scratch << key;
125
36.9k
        EraseImpl(m_key_scratch);
126
36.9k
    }
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.39k
    template<typename K> void Seek(const K& key) {
159
4.39k
        ScopedDataStreamUsage scoped_scratch{m_scratch};
160
4.39k
        m_scratch << key;
161
4.39k
        SeekImpl(m_scratch);
162
4.39k
    }
void CDBIterator::Seek<unsigned char>(unsigned char const&)
Line
Count
Source
158
1.25k
    template<typename K> void Seek(const K& key) {
159
1.25k
        ScopedDataStreamUsage scoped_scratch{m_scratch};
160
1.25k
        m_scratch << key;
161
1.25k
        SeekImpl(m_scratch);
162
1.25k
    }
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.41k
    template<typename K> void Seek(const K& key) {
159
2.41k
        ScopedDataStreamUsage scoped_scratch{m_scratch};
160
2.41k
        m_scratch << key;
161
2.41k
        SeekImpl(m_scratch);
162
2.41k
    }
163
164
    void Next();
165
166
411k
    template<typename K> bool GetKey(K& key) {
167
411k
        try {
168
411k
            SpanReader ssKey{GetKeyImpl()};
169
411k
            ssKey >> key;
170
411k
        } catch (const std::exception&) {
171
750
            return false;
172
750
        }
173
410k
        return true;
174
411k
    }
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
26
    template<typename K> bool GetKey(K& key) {
167
26
        try {
168
26
            SpanReader ssKey{GetKeyImpl()};
169
26
            ssKey >> key;
170
26
        } catch (const std::exception&) {
171
0
            return false;
172
0
        }
173
26
        return true;
174
26
    }
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
748
            return false;
172
748
        }
173
135k
        return true;
174
136k
    }
txdb.cpp:bool CDBIterator::GetKey<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry&)
Line
Count
Source
166
271k
    template<typename K> bool GetKey(K& key) {
167
271k
        try {
168
271k
            SpanReader ssKey{GetKeyImpl()};
169
271k
            ssKey >> key;
170
271k
        } catch (const std::exception&) {
171
0
            return false;
172
0
        }
173
271k
        return true;
174
271k
    }
175
176
410k
    template<typename V> bool GetValue(V& value) {
177
410k
        try {
178
410k
            ScopedDataStreamUsage scoped_scratch{m_scratch};
179
410k
            m_scratch.write(GetValueImpl());
180
410k
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
181
410k
            m_scratch >> value;
182
410k
        } catch (const std::exception&) {
183
2
            return false;
184
2
        }
185
410k
        return true;
186
410k
    }
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
271k
    template<typename V> bool GetValue(V& value) {
177
271k
        try {
178
271k
            ScopedDataStreamUsage scoped_scratch{m_scratch};
179
271k
            m_scratch.write(GetValueImpl());
180
271k
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
181
271k
            m_scratch >> value;
182
271k
        } catch (const std::exception&) {
183
0
            return false;
184
0
        }
185
271k
        return true;
186
271k
    }
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
12.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
6.08M
    {
222
6.08M
        DataStream ssKey{};
223
6.08M
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
6.08M
        ssKey << key;
225
6.08M
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
6.08M
        if (!strValue) {
227
5.97M
            return false;
228
5.97M
        }
229
107k
        try {
230
107k
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
107k
            m_obfuscation(ssValue);
232
107k
            SpanReader{ssValue} >> value;
233
107k
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
107k
        return true;
237
107k
    }
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
861
        try {
230
861
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
861
            m_obfuscation(ssValue);
232
861
            SpanReader{ssValue} >> value;
233
861
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
860
        return true;
237
861
    }
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
62
            return false;
228
62
        }
229
93
        try {
230
93
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
93
            m_obfuscation(ssValue);
232
93
            SpanReader{ssValue} >> value;
233
93
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
93
        return true;
237
93
    }
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
18
            return false;
228
18
        }
229
25
        try {
230
25
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
25
            m_obfuscation(ssValue);
232
25
            SpanReader{ssValue} >> value;
233
25
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
25
        return true;
237
25
    }
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.01k
        try {
230
1.01k
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
1.01k
            m_obfuscation(ssValue);
232
1.01k
            SpanReader{ssValue} >> value;
233
1.01k
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
1.01k
        return true;
237
1.01k
    }
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
21
            return false;
228
21
        }
229
31
        try {
230
31
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
31
            m_obfuscation(ssValue);
232
31
            SpanReader{ssValue} >> value;
233
31
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
31
        return true;
237
31
    }
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
222
    {
222
222
        DataStream ssKey{};
223
222
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
222
        ssKey << key;
225
222
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
222
        if (!strValue) {
227
1
            return false;
228
1
        }
229
221
        try {
230
221
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
221
            m_obfuscation(ssValue);
232
221
            SpanReader{ssValue} >> value;
233
221
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
221
        return true;
237
221
    }
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.41k
    {
222
2.41k
        DataStream ssKey{};
223
2.41k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
2.41k
        ssKey << key;
225
2.41k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
2.41k
        if (!strValue) {
227
1.65k
            return false;
228
1.65k
        }
229
763
        try {
230
763
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
763
            m_obfuscation(ssValue);
232
763
            SpanReader{ssValue} >> value;
233
763
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
763
        return true;
237
763
    }
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
454
            return false;
228
454
        }
229
746
        try {
230
746
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
746
            m_obfuscation(ssValue);
232
746
            SpanReader{ssValue} >> value;
233
746
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
746
        return true;
237
746
    }
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.19k
    {
222
1.19k
        DataStream ssKey{};
223
1.19k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
1.19k
        ssKey << key;
225
1.19k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
1.19k
        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
6.06M
    {
222
6.06M
        DataStream ssKey{};
223
6.06M
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
224
6.06M
        ssKey << key;
225
6.06M
        std::optional<std::string> strValue{ReadImpl(ssKey)};
226
6.06M
        if (!strValue) {
227
5.96M
            return false;
228
5.96M
        }
229
97.7k
        try {
230
97.7k
            std::span ssValue{MakeWritableByteSpan(*strValue)};
231
97.7k
            m_obfuscation(ssValue);
232
97.7k
            SpanReader{ssValue} >> value;
233
97.7k
        } catch (const std::exception&) {
234
0
            return false;
235
0
        }
236
97.7k
        return true;
237
97.7k
    }
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
520
    {
242
520
        CDBBatch batch(*this);
243
520
        batch.Write(key, value);
244
520
        WriteBatch(batch, fSync);
245
520
    }
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.18k
    {
242
4.18k
        CDBBatch batch(*this);
243
4.18k
        batch.Write(key, value);
244
4.18k
        WriteBatch(batch, fSync);
245
4.18k
    }
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.23k
    {
250
1.23k
        DataStream ssKey{};
251
1.23k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
252
1.23k
        ssKey << key;
253
1.23k
        return ExistsImpl(ssKey);
254
1.23k
    }
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