Coverage Report

Created: 2026-07-08 14:14

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