/root/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 | | static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64; |
24 | | static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024; |
25 | | static const size_t DBWRAPPER_MAX_FILE_SIZE{32_MiB}; |
26 | | |
27 | | //! User-controlled performance and debug options. |
28 | | struct DBOptions { |
29 | | //! Compact database on startup. |
30 | | bool force_compact = false; |
31 | | }; |
32 | | |
33 | | //! Application-specific storage settings. |
34 | | struct DBParams { |
35 | | //! Location in the filesystem where leveldb data will be stored. |
36 | | fs::path path; |
37 | | //! Configures various leveldb cache settings. |
38 | | size_t cache_bytes; |
39 | | //! If true, use leveldb's memory environment. |
40 | | bool memory_only = false; |
41 | | //! If true, remove all existing data. |
42 | | bool wipe_data = false; |
43 | | //! If true, store data obfuscated via simple XOR. If false, XOR with a |
44 | | //! zero'd byte array. |
45 | | bool obfuscate = false; |
46 | | //! Passed-through options. |
47 | | DBOptions options{}; |
48 | | }; |
49 | | |
50 | | class dbwrapper_error : public std::runtime_error |
51 | | { |
52 | | public: |
53 | 0 | explicit dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {} |
54 | | }; |
55 | | |
56 | | class CDBWrapper; |
57 | | |
58 | | /** These should be considered an implementation detail of the specific database. |
59 | | */ |
60 | | namespace dbwrapper_private { |
61 | | |
62 | | /** Work around circular dependency, as well as for testing in dbwrapper_tests. |
63 | | * Database obfuscation should be considered an implementation detail of the |
64 | | * specific database. |
65 | | */ |
66 | | const Obfuscation& GetObfuscation(const CDBWrapper&); |
67 | | }; // namespace dbwrapper_private |
68 | | |
69 | | bool DestroyDB(const std::string& path_str); |
70 | | |
71 | | /** Batch of changes queued to be written to a CDBWrapper */ |
72 | | class CDBBatch |
73 | | { |
74 | | friend class CDBWrapper; |
75 | | |
76 | | private: |
77 | | const CDBWrapper &parent; |
78 | | |
79 | | struct WriteBatchImpl; |
80 | | const std::unique_ptr<WriteBatchImpl> m_impl_batch; |
81 | | |
82 | | DataStream ssKey{}; |
83 | | DataStream ssValue{}; |
84 | | |
85 | | void WriteImpl(std::span<const std::byte> key, DataStream& ssValue); |
86 | | void EraseImpl(std::span<const std::byte> key); |
87 | | |
88 | | public: |
89 | | /** |
90 | | * @param[in] _parent CDBWrapper that this batch is to be submitted to |
91 | | */ |
92 | | explicit CDBBatch(const CDBWrapper& _parent); |
93 | | ~CDBBatch(); |
94 | | void Clear(); |
95 | | |
96 | | template <typename K, typename V> |
97 | | void Write(const K& key, const V& value) |
98 | 925 | { |
99 | 925 | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
100 | 925 | ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE); |
101 | 925 | ssKey << key; |
102 | 925 | ssValue << value; |
103 | 925 | WriteImpl(ssKey, ssValue); |
104 | 925 | ssKey.clear(); |
105 | 925 | ssValue.clear(); |
106 | 925 | } 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 | 98 | 925 | { | 99 | 925 | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 100 | 925 | ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE); | 101 | 925 | ssKey << key; | 102 | 925 | ssValue << value; | 103 | 925 | WriteImpl(ssKey, ssValue); | 104 | 925 | ssKey.clear(); | 105 | 925 | ssValue.clear(); | 106 | 925 | } |
Unexecuted instantiation: void CDBBatch::Write<unsigned char, unsigned char>(unsigned char const&, unsigned char const&) Unexecuted instantiation: void CDBBatch::Write<std::pair<unsigned char, int>, kernel::CBlockFileInfo>(std::pair<unsigned char, int> const&, kernel::CBlockFileInfo const&) Unexecuted instantiation: void CDBBatch::Write<unsigned char, int>(unsigned char const&, int const&) Unexecuted instantiation: void CDBBatch::Write<std::pair<unsigned char, uint256>, CDiskBlockIndex>(std::pair<unsigned char, uint256> const&, CDiskBlockIndex const&) Unexecuted instantiation: void CDBBatch::Write<std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, unsigned char>(std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>> const&, unsigned char const&) Unexecuted instantiation: void CDBBatch::Write<unsigned char, std::vector<uint256, std::allocator<uint256>>>(unsigned char const&, std::vector<uint256, std::allocator<uint256>> const&) Unexecuted instantiation: txdb.cpp:void CDBBatch::Write<(anonymous namespace)::CoinEntry, Coin>((anonymous namespace)::CoinEntry const&, Coin const&) Unexecuted instantiation: void CDBBatch::Write<unsigned char, uint256>(unsigned char const&, uint256 const&) Unexecuted instantiation: void CDBBatch::Write<unsigned char, CBlockLocator>(unsigned char const&, CBlockLocator const&) Unexecuted instantiation: void CDBBatch::Write<unsigned char, FlatFilePos>(unsigned char const&, FlatFilePos const&) Unexecuted instantiation: 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&) Unexecuted instantiation: blockfilterindex.cpp:void CDBBatch::Write<index_util::DBHashKey, (anonymous namespace)::DBVal>(index_util::DBHashKey const&, (anonymous namespace)::DBVal const&) Unexecuted instantiation: 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&) Unexecuted instantiation: coinstatsindex.cpp:void CDBBatch::Write<index_util::DBHashKey, (anonymous namespace)::DBVal>(index_util::DBHashKey const&, (anonymous namespace)::DBVal const&) Unexecuted instantiation: void CDBBatch::Write<unsigned char, MuHash3072>(unsigned char const&, MuHash3072 const&) Unexecuted instantiation: void CDBBatch::Write<std::pair<unsigned char, uint256>, CDiskTxPos>(std::pair<unsigned char, uint256> const&, CDiskTxPos const&) Unexecuted instantiation: void CDBBatch::Write<char [12], std::pair<unsigned long, unsigned long>>(char const (&) [12], std::pair<unsigned long, unsigned long> const&) Unexecuted instantiation: void CDBBatch::Write<DBKey, char [1]>(DBKey const&, char const (&) [1]) |
107 | | |
108 | | template <typename K> |
109 | | void Erase(const K& key) |
110 | 0 | { |
111 | 0 | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
112 | 0 | ssKey << key; |
113 | 0 | EraseImpl(ssKey); |
114 | 0 | ssKey.clear(); |
115 | 0 | } Unexecuted instantiation: void CDBBatch::Erase<unsigned char>(unsigned char const&) Unexecuted instantiation: txdb.cpp:void CDBBatch::Erase<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry const&) Unexecuted instantiation: void CDBBatch::Erase<DBKey>(DBKey const&) |
116 | | |
117 | | size_t ApproximateSize() const; |
118 | | }; |
119 | | |
120 | | class CDBIterator |
121 | | { |
122 | | public: |
123 | | struct IteratorImpl; |
124 | | |
125 | | private: |
126 | | const CDBWrapper &parent; |
127 | | const std::unique_ptr<IteratorImpl> m_impl_iter; |
128 | | |
129 | | void SeekImpl(std::span<const std::byte> key); |
130 | | std::span<const std::byte> GetKeyImpl() const; |
131 | | std::span<const std::byte> GetValueImpl() const; |
132 | | |
133 | | public: |
134 | | |
135 | | /** |
136 | | * @param[in] _parent Parent CDBWrapper instance. |
137 | | * @param[in] _piter The original leveldb iterator. |
138 | | */ |
139 | | CDBIterator(const CDBWrapper& _parent, std::unique_ptr<IteratorImpl> _piter); |
140 | | ~CDBIterator(); |
141 | | |
142 | | bool Valid() const; |
143 | | |
144 | | void SeekToFirst(); |
145 | | |
146 | 1.85k | template<typename K> void Seek(const K& key) { |
147 | 1.85k | DataStream ssKey{}; |
148 | 1.85k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
149 | 1.85k | ssKey << key; |
150 | 1.85k | SeekImpl(ssKey); |
151 | 1.85k | } void CDBIterator::Seek<std::pair<unsigned char, uint256>>(std::pair<unsigned char, uint256> const&) Line | Count | Source | 146 | 1.85k | template<typename K> void Seek(const K& key) { | 147 | 1.85k | DataStream ssKey{}; | 148 | 1.85k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 149 | 1.85k | ssKey << key; | 150 | 1.85k | SeekImpl(ssKey); | 151 | 1.85k | } |
Unexecuted instantiation: void CDBIterator::Seek<unsigned char>(unsigned char const&) Unexecuted instantiation: void CDBIterator::Seek<index_util::DBHeightKey>(index_util::DBHeightKey const&) Unexecuted instantiation: void CDBIterator::Seek<std::pair<unsigned char, unsigned long>>(std::pair<unsigned char, unsigned long> const&) |
152 | | |
153 | | void Next(); |
154 | | |
155 | 0 | template<typename K> bool GetKey(K& key) { |
156 | 0 | try { |
157 | 0 | SpanReader ssKey{GetKeyImpl()}; |
158 | 0 | ssKey >> key; |
159 | 0 | } catch (const std::exception&) { |
160 | 0 | return false; |
161 | 0 | } |
162 | 0 | return true; |
163 | 0 | } Unexecuted instantiation: bool CDBIterator::GetKey<std::pair<unsigned char, uint256>>(std::pair<unsigned char, uint256>&) Unexecuted instantiation: txdb.cpp:bool CDBIterator::GetKey<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry&) Unexecuted instantiation: bool CDBIterator::GetKey<index_util::DBHeightKey>(index_util::DBHeightKey&) Unexecuted instantiation: bool CDBIterator::GetKey<DBKey>(DBKey&) |
164 | | |
165 | 0 | template<typename V> bool GetValue(V& value) { |
166 | 0 | try { |
167 | 0 | DataStream ssValue{GetValueImpl()}; |
168 | 0 | dbwrapper_private::GetObfuscation(parent)(ssValue); |
169 | 0 | ssValue >> value; |
170 | 0 | } catch (const std::exception&) { |
171 | 0 | return false; |
172 | 0 | } |
173 | 0 | return true; |
174 | 0 | } Unexecuted instantiation: bool CDBIterator::GetValue<CDiskBlockIndex>(CDiskBlockIndex&) Unexecuted instantiation: bool CDBIterator::GetValue<Coin>(Coin&) Unexecuted instantiation: blockfilterindex.cpp:bool CDBIterator::GetValue<std::pair<uint256, (anonymous namespace)::DBVal>>(std::pair<uint256, (anonymous namespace)::DBVal>&) Unexecuted instantiation: coinstatsindex.cpp:bool CDBIterator::GetValue<std::pair<uint256, (anonymous namespace)::DBVal>>(std::pair<uint256, (anonymous namespace)::DBVal>&) |
175 | | }; |
176 | | |
177 | | struct LevelDBContext; |
178 | | |
179 | | class CDBWrapper |
180 | | { |
181 | | friend const Obfuscation& dbwrapper_private::GetObfuscation(const CDBWrapper&); |
182 | | private: |
183 | | //! holds all leveldb-specific fields of this class |
184 | | std::unique_ptr<LevelDBContext> m_db_context; |
185 | | |
186 | | //! the name of this database |
187 | | std::string m_name; |
188 | | |
189 | | //! optional XOR-obfuscation of the database |
190 | | Obfuscation m_obfuscation; |
191 | | |
192 | | //! obfuscation key storage key, null-prefixed to avoid collisions |
193 | | inline static const std::string OBFUSCATION_KEY{"\000obfuscate_key", 14}; // explicit size to avoid truncation at leading \0 |
194 | | |
195 | | std::optional<std::string> ReadImpl(std::span<const std::byte> key) const; |
196 | | bool ExistsImpl(std::span<const std::byte> key) const; |
197 | | size_t EstimateSizeImpl(std::span<const std::byte> key1, std::span<const std::byte> key2) const; |
198 | 1.57M | auto& DBContext() const LIFETIMEBOUND { return *Assert(m_db_context); }Line | Count | Source | 116 | 1.57M | #define Assert(val) inline_assertion_check<true>(val, std::source_location::current(), #val) |
|
199 | | |
200 | | public: |
201 | | CDBWrapper(const DBParams& params); |
202 | | ~CDBWrapper(); |
203 | | |
204 | | CDBWrapper(const CDBWrapper&) = delete; |
205 | | CDBWrapper& operator=(const CDBWrapper&) = delete; |
206 | | |
207 | | template <typename K, typename V> |
208 | | bool Read(const K& key, V& value) const |
209 | 761k | { |
210 | 761k | DataStream ssKey{}; |
211 | 761k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
212 | 761k | ssKey << key; |
213 | 761k | std::optional<std::string> strValue{ReadImpl(ssKey)}; |
214 | 761k | if (!strValue) { |
215 | 761k | return false; |
216 | 761k | } |
217 | 0 | try { |
218 | 0 | std::span ssValue{MakeWritableByteSpan(*strValue)}; |
219 | 0 | m_obfuscation(ssValue); |
220 | 0 | SpanReader{ssValue} >> value; |
221 | 0 | } catch (const std::exception&) { |
222 | 0 | return false; |
223 | 0 | } |
224 | 0 | return true; |
225 | 0 | } 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 | 209 | 1.85k | { | 210 | 1.85k | DataStream ssKey{}; | 211 | 1.85k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 212 | 1.85k | ssKey << key; | 213 | 1.85k | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 214 | 1.85k | if (!strValue) { | 215 | 1.85k | return false; | 216 | 1.85k | } | 217 | 0 | try { | 218 | 0 | std::span ssValue{MakeWritableByteSpan(*strValue)}; | 219 | 0 | m_obfuscation(ssValue); | 220 | 0 | SpanReader{ssValue} >> value; | 221 | 0 | } catch (const std::exception&) { | 222 | 0 | return false; | 223 | 0 | } | 224 | 0 | return true; | 225 | 0 | } |
bool CDBWrapper::Read<std::pair<unsigned char, int>, kernel::CBlockFileInfo>(std::pair<unsigned char, int> const&, kernel::CBlockFileInfo&) const Line | Count | Source | 209 | 1.85k | { | 210 | 1.85k | DataStream ssKey{}; | 211 | 1.85k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 212 | 1.85k | ssKey << key; | 213 | 1.85k | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 214 | 1.85k | if (!strValue) { | 215 | 1.85k | return false; | 216 | 1.85k | } | 217 | 0 | try { | 218 | 0 | std::span ssValue{MakeWritableByteSpan(*strValue)}; | 219 | 0 | m_obfuscation(ssValue); | 220 | 0 | SpanReader{ssValue} >> value; | 221 | 0 | } catch (const std::exception&) { | 222 | 0 | return false; | 223 | 0 | } | 224 | 0 | return true; | 225 | 0 | } |
bool CDBWrapper::Read<unsigned char, int>(unsigned char const&, int&) const Line | Count | Source | 209 | 925 | { | 210 | 925 | DataStream ssKey{}; | 211 | 925 | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 212 | 925 | ssKey << key; | 213 | 925 | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 214 | 925 | if (!strValue) { | 215 | 925 | return false; | 216 | 925 | } | 217 | 0 | try { | 218 | 0 | std::span ssValue{MakeWritableByteSpan(*strValue)}; | 219 | 0 | m_obfuscation(ssValue); | 220 | 0 | SpanReader{ssValue} >> value; | 221 | 0 | } catch (const std::exception&) { | 222 | 0 | return false; | 223 | 0 | } | 224 | 0 | return true; | 225 | 0 | } |
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 | 209 | 925 | { | 210 | 925 | DataStream ssKey{}; | 211 | 925 | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 212 | 925 | ssKey << key; | 213 | 925 | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 214 | 925 | if (!strValue) { | 215 | 925 | return false; | 216 | 925 | } | 217 | 0 | try { | 218 | 0 | std::span ssValue{MakeWritableByteSpan(*strValue)}; | 219 | 0 | m_obfuscation(ssValue); | 220 | 0 | SpanReader{ssValue} >> value; | 221 | 0 | } catch (const std::exception&) { | 222 | 0 | return false; | 223 | 0 | } | 224 | 0 | return true; | 225 | 0 | } |
txdb.cpp:bool CDBWrapper::Read<(anonymous namespace)::CoinEntry, Coin>((anonymous namespace)::CoinEntry const&, Coin&) const Line | Count | Source | 209 | 752k | { | 210 | 752k | DataStream ssKey{}; | 211 | 752k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 212 | 752k | ssKey << key; | 213 | 752k | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 214 | 752k | if (!strValue) { | 215 | 752k | return false; | 216 | 752k | } | 217 | 0 | try { | 218 | 0 | std::span ssValue{MakeWritableByteSpan(*strValue)}; | 219 | 0 | m_obfuscation(ssValue); | 220 | 0 | SpanReader{ssValue} >> value; | 221 | 0 | } catch (const std::exception&) { | 222 | 0 | return false; | 223 | 0 | } | 224 | 0 | return true; | 225 | 0 | } |
bool CDBWrapper::Read<unsigned char, uint256>(unsigned char const&, uint256&) const Line | Count | Source | 209 | 2.77k | { | 210 | 2.77k | DataStream ssKey{}; | 211 | 2.77k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 212 | 2.77k | ssKey << key; | 213 | 2.77k | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 214 | 2.77k | if (!strValue) { | 215 | 2.77k | return false; | 216 | 2.77k | } | 217 | 0 | try { | 218 | 0 | std::span ssValue{MakeWritableByteSpan(*strValue)}; | 219 | 0 | m_obfuscation(ssValue); | 220 | 0 | SpanReader{ssValue} >> value; | 221 | 0 | } catch (const std::exception&) { | 222 | 0 | return false; | 223 | 0 | } | 224 | 0 | return true; | 225 | 0 | } |
bool CDBWrapper::Read<unsigned char, std::vector<uint256, std::allocator<uint256>>>(unsigned char const&, std::vector<uint256, std::allocator<uint256>>&) const Line | Count | Source | 209 | 925 | { | 210 | 925 | DataStream ssKey{}; | 211 | 925 | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 212 | 925 | ssKey << key; | 213 | 925 | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 214 | 925 | if (!strValue) { | 215 | 925 | return false; | 216 | 925 | } | 217 | 0 | try { | 218 | 0 | std::span ssValue{MakeWritableByteSpan(*strValue)}; | 219 | 0 | m_obfuscation(ssValue); | 220 | 0 | SpanReader{ssValue} >> value; | 221 | 0 | } catch (const std::exception&) { | 222 | 0 | return false; | 223 | 0 | } | 224 | 0 | return true; | 225 | 0 | } |
Unexecuted instantiation: bool CDBWrapper::Read<unsigned char, CBlockLocator>(unsigned char const&, CBlockLocator&) const Unexecuted instantiation: blockfilterindex.cpp:bool CDBWrapper::Read<index_util::DBHashKey, (anonymous namespace)::DBVal>(index_util::DBHashKey const&, (anonymous namespace)::DBVal&) const Unexecuted instantiation: bool CDBWrapper::Read<unsigned char, FlatFilePos>(unsigned char const&, FlatFilePos&) const Unexecuted instantiation: blockfilterindex.cpp:bool CDBWrapper::Read<index_util::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal>&) const Unexecuted instantiation: coinstatsindex.cpp:bool CDBWrapper::Read<index_util::DBHashKey, (anonymous namespace)::DBVal>(index_util::DBHashKey const&, (anonymous namespace)::DBVal&) const Unexecuted instantiation: bool CDBWrapper::Read<unsigned char, MuHash3072>(unsigned char const&, MuHash3072&) const Unexecuted instantiation: 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 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 Unexecuted instantiation: bool CDBWrapper::Read<std::pair<unsigned char, uint256>, CDiskTxPos>(std::pair<unsigned char, uint256> const&, CDiskTxPos&) const Unexecuted instantiation: bool CDBWrapper::Read<char [12], std::pair<unsigned long, unsigned long>>(char const (&) [12], std::pair<unsigned long, unsigned long>&) const |
226 | | |
227 | | template <typename K, typename V> |
228 | | void Write(const K& key, const V& value, bool fSync = false) |
229 | 925 | { |
230 | 925 | CDBBatch batch(*this); |
231 | 925 | batch.Write(key, value); |
232 | 925 | WriteBatch(batch, fSync); |
233 | 925 | } 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 | 229 | 925 | { | 230 | 925 | CDBBatch batch(*this); | 231 | 925 | batch.Write(key, value); | 232 | 925 | WriteBatch(batch, fSync); | 233 | 925 | } |
Unexecuted instantiation: void CDBWrapper::Write<unsigned char, unsigned char>(unsigned char const&, unsigned char const&, bool) Unexecuted instantiation: 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) Unexecuted instantiation: 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) Unexecuted instantiation: 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) Unexecuted instantiation: void CDBWrapper::Write<char [12], std::pair<unsigned long, unsigned long>>(char const (&) [12], std::pair<unsigned long, unsigned long> const&, bool) |
234 | | |
235 | | template <typename K> |
236 | | bool Exists(const K& key) const |
237 | 925 | { |
238 | 925 | DataStream ssKey{}; |
239 | 925 | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
240 | 925 | ssKey << key; |
241 | 925 | return ExistsImpl(ssKey); |
242 | 925 | } bool CDBWrapper::Exists<unsigned char>(unsigned char const&) const Line | Count | Source | 237 | 925 | { | 238 | 925 | DataStream ssKey{}; | 239 | 925 | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 240 | 925 | ssKey << key; | 241 | 925 | return ExistsImpl(ssKey); | 242 | 925 | } |
Unexecuted instantiation: txdb.cpp:bool CDBWrapper::Exists<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry const&) const |
243 | | |
244 | | template <typename K> |
245 | | void Erase(const K& key, bool fSync = false) |
246 | 0 | { |
247 | 0 | CDBBatch batch(*this); |
248 | 0 | batch.Erase(key); |
249 | 0 | WriteBatch(batch, fSync); |
250 | 0 | } |
251 | | |
252 | | void WriteBatch(CDBBatch& batch, bool fSync = false); |
253 | | |
254 | | // Get an estimate of LevelDB memory usage (in bytes). |
255 | | size_t DynamicMemoryUsage() const; |
256 | | |
257 | | CDBIterator* NewIterator(); |
258 | | |
259 | | /** |
260 | | * Return true if the database managed by this class contains no entries. |
261 | | */ |
262 | | bool IsEmpty(); |
263 | | |
264 | | template<typename K> |
265 | | size_t EstimateSize(const K& key_begin, const K& key_end) const |
266 | 0 | { |
267 | 0 | DataStream ssKey1{}, ssKey2{}; |
268 | 0 | ssKey1.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
269 | 0 | ssKey2.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
270 | 0 | ssKey1 << key_begin; |
271 | 0 | ssKey2 << key_end; |
272 | 0 | return EstimateSizeImpl(ssKey1, ssKey2); |
273 | 0 | } |
274 | | }; |
275 | | |
276 | | #endif // BITCOIN_DBWRAPPER_H |