/Users/eugenesiegel/btc/bitcoin/src/dbwrapper.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2012-present The Bitcoin Core developers |
2 | | // Distributed under the MIT software license, see the accompanying |
3 | | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
4 | | |
5 | | #ifndef BITCOIN_DBWRAPPER_H |
6 | | #define BITCOIN_DBWRAPPER_H |
7 | | |
8 | | #include <attributes.h> |
9 | | #include <serialize.h> |
10 | | #include <span.h> |
11 | | #include <streams.h> |
12 | | #include <util/check.h> |
13 | | #include <util/fs.h> |
14 | | |
15 | | #include <cstddef> |
16 | | #include <exception> |
17 | | #include <memory> |
18 | | #include <optional> |
19 | | #include <stdexcept> |
20 | | #include <string> |
21 | | #include <vector> |
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 << 20; // 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 std::vector<unsigned char>& GetObfuscateKey(const CDBWrapper &w); |
67 | | |
68 | | }; // namespace dbwrapper_private |
69 | | |
70 | | bool DestroyDB(const std::string& path_str); |
71 | | |
72 | | /** Batch of changes queued to be written to a CDBWrapper */ |
73 | | class CDBBatch |
74 | | { |
75 | | friend class CDBWrapper; |
76 | | |
77 | | private: |
78 | | const CDBWrapper &parent; |
79 | | |
80 | | struct WriteBatchImpl; |
81 | | const std::unique_ptr<WriteBatchImpl> m_impl_batch; |
82 | | |
83 | | DataStream ssKey{}; |
84 | | DataStream ssValue{}; |
85 | | |
86 | | void WriteImpl(std::span<const std::byte> key, DataStream& ssValue); |
87 | | void EraseImpl(std::span<const std::byte> key); |
88 | | |
89 | | public: |
90 | | /** |
91 | | * @param[in] _parent CDBWrapper that this batch is to be submitted to |
92 | | */ |
93 | | explicit CDBBatch(const CDBWrapper& _parent); |
94 | | ~CDBBatch(); |
95 | | void Clear(); |
96 | | |
97 | | template <typename K, typename V> |
98 | | void Write(const K& key, const V& value) |
99 | 261k | { |
100 | 261k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
101 | 261k | ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE); |
102 | 261k | ssKey << key; |
103 | 261k | ssValue << value; |
104 | 261k | WriteImpl(ssKey, ssValue); |
105 | 261k | ssKey.clear(); |
106 | 261k | ssValue.clear(); |
107 | 261k | } _ZN8CDBBatch5WriteINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_6vectorIhNS5_IhEEEEEEvRKT_RKT0_ Line | Count | Source | 99 | 49.9k | { | 100 | 49.9k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 101 | 49.9k | ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE); | 102 | 49.9k | ssKey << key; | 103 | 49.9k | ssValue << value; | 104 | 49.9k | WriteImpl(ssKey, ssValue); | 105 | 49.9k | ssKey.clear(); | 106 | 49.9k | ssValue.clear(); | 107 | 49.9k | } |
Unexecuted instantiation: _ZN8CDBBatch5WriteIh13CBlockLocatorEEvRKT_RKT0_ Unexecuted instantiation: blockfilterindex.cpp:_ZN8CDBBatch5WriteIN12_GLOBAL__N_19DBHashKeyENS1_5DBValEEEvRKT_RKT0_ Unexecuted instantiation: _ZN8CDBBatch5WriteIh11FlatFilePosEEvRKT_RKT0_ Unexecuted instantiation: blockfilterindex.cpp:_ZN8CDBBatch5WriteIN12_GLOBAL__N_111DBHeightKeyENSt3__14pairI7uint256NS1_5DBValEEEEEvRKT_RKT0_ Unexecuted instantiation: coinstatsindex.cpp:_ZN8CDBBatch5WriteIN12_GLOBAL__N_19DBHashKeyENS1_5DBValEEEvRKT_RKT0_ Unexecuted instantiation: coinstatsindex.cpp:_ZN8CDBBatch5WriteIN12_GLOBAL__N_111DBHeightKeyENSt3__14pairI7uint256NS1_5DBValEEEEEvRKT_RKT0_ Unexecuted instantiation: _ZN8CDBBatch5WriteIh10MuHash3072EEvRKT_RKT0_ Unexecuted instantiation: _ZN8CDBBatch5WriteINSt3__14pairIh7uint256EE10CDiskTxPosEEvRKT_RKT0_ Unexecuted instantiation: _ZN8CDBBatch5WriteIhhEEvRKT_RKT0_ _ZN8CDBBatch5WriteINSt3__14pairIhiEE14CBlockFileInfoEEvRKT_RKT0_ Line | Count | Source | 99 | 517 | { | 100 | 517 | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 101 | 517 | ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE); | 102 | 517 | ssKey << key; | 103 | 517 | ssValue << value; | 104 | 517 | WriteImpl(ssKey, ssValue); | 105 | 517 | ssKey.clear(); | 106 | 517 | ssValue.clear(); | 107 | 517 | } |
_ZN8CDBBatch5WriteIhiEEvRKT_RKT0_ Line | Count | Source | 99 | 517 | { | 100 | 517 | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 101 | 517 | ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE); | 102 | 517 | ssKey << key; | 103 | 517 | ssValue << value; | 104 | 517 | WriteImpl(ssKey, ssValue); | 105 | 517 | ssKey.clear(); | 106 | 517 | ssValue.clear(); | 107 | 517 | } |
_ZN8CDBBatch5WriteINSt3__14pairIh7uint256EE15CDiskBlockIndexEEvRKT_RKT0_ Line | Count | Source | 99 | 104k | { | 100 | 104k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 101 | 104k | ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE); | 102 | 104k | ssKey << key; | 103 | 104k | ssValue << value; | 104 | 104k | WriteImpl(ssKey, ssValue); | 105 | 104k | ssKey.clear(); | 106 | 104k | ssValue.clear(); | 107 | 104k | } |
Unexecuted instantiation: _ZN8CDBBatch5WriteINSt3__14pairIhNS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEEhEEvRKT_RKT0_ _ZN8CDBBatch5WriteIhNSt3__16vectorI7uint256NS1_9allocatorIS3_EEEEEEvRKT_RKT0_ Line | Count | Source | 99 | 517 | { | 100 | 517 | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 101 | 517 | ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE); | 102 | 517 | ssKey << key; | 103 | 517 | ssValue << value; | 104 | 517 | WriteImpl(ssKey, ssValue); | 105 | 517 | ssKey.clear(); | 106 | 517 | ssValue.clear(); | 107 | 517 | } |
txdb.cpp:_ZN8CDBBatch5WriteIN12_GLOBAL__N_19CoinEntryE4CoinEEvRKT_RKT0_ Line | Count | Source | 99 | 103k | { | 100 | 103k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 101 | 103k | ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE); | 102 | 103k | ssKey << key; | 103 | 103k | ssValue << value; | 104 | 103k | WriteImpl(ssKey, ssValue); | 105 | 103k | ssKey.clear(); | 106 | 103k | ssValue.clear(); | 107 | 103k | } |
_ZN8CDBBatch5WriteIh7uint256EEvRKT_RKT0_ Line | Count | Source | 99 | 517 | { | 100 | 517 | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 101 | 517 | ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE); | 102 | 517 | ssKey << key; | 103 | 517 | ssValue << value; | 104 | 517 | WriteImpl(ssKey, ssValue); | 105 | 517 | ssKey.clear(); | 106 | 517 | ssValue.clear(); | 107 | 517 | } |
|
108 | | |
109 | | template <typename K> |
110 | | void Erase(const K& key) |
111 | 1.03k | { |
112 | 1.03k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
113 | 1.03k | ssKey << key; |
114 | 1.03k | EraseImpl(ssKey); |
115 | 1.03k | ssKey.clear(); |
116 | 1.03k | } _ZN8CDBBatch5EraseIhEEvRKT_ Line | Count | Source | 111 | 1.03k | { | 112 | 1.03k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 113 | 1.03k | ssKey << key; | 114 | 1.03k | EraseImpl(ssKey); | 115 | 1.03k | ssKey.clear(); | 116 | 1.03k | } |
Unexecuted instantiation: txdb.cpp:_ZN8CDBBatch5EraseIN12_GLOBAL__N_19CoinEntryEEEvRKT_ |
117 | | |
118 | | size_t ApproximateSize() const; |
119 | | }; |
120 | | |
121 | | class CDBIterator |
122 | | { |
123 | | public: |
124 | | struct IteratorImpl; |
125 | | |
126 | | private: |
127 | | const CDBWrapper &parent; |
128 | | const std::unique_ptr<IteratorImpl> m_impl_iter; |
129 | | |
130 | | void SeekImpl(std::span<const std::byte> key); |
131 | | std::span<const std::byte> GetKeyImpl() const; |
132 | | std::span<const std::byte> GetValueImpl() const; |
133 | | |
134 | | public: |
135 | | |
136 | | /** |
137 | | * @param[in] _parent Parent CDBWrapper instance. |
138 | | * @param[in] _piter The original leveldb iterator. |
139 | | */ |
140 | | CDBIterator(const CDBWrapper& _parent, std::unique_ptr<IteratorImpl> _piter); |
141 | | ~CDBIterator(); |
142 | | |
143 | | bool Valid() const; |
144 | | |
145 | | void SeekToFirst(); |
146 | | |
147 | 99.9k | template<typename K> void Seek(const K& key) { |
148 | 99.9k | DataStream ssKey{}; |
149 | 99.9k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
150 | 99.9k | ssKey << key; |
151 | 99.9k | SeekImpl(ssKey); |
152 | 99.9k | } Unexecuted instantiation: blockfilterindex.cpp:_ZN11CDBIterator4SeekIN12_GLOBAL__N_111DBHeightKeyEEEvRKT_ Unexecuted instantiation: coinstatsindex.cpp:_ZN11CDBIterator4SeekIN12_GLOBAL__N_111DBHeightKeyEEEvRKT_ _ZN11CDBIterator4SeekINSt3__14pairIh7uint256EEEEvRKT_ Line | Count | Source | 147 | 99.9k | template<typename K> void Seek(const K& key) { | 148 | 99.9k | DataStream ssKey{}; | 149 | 99.9k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 150 | 99.9k | ssKey << key; | 151 | 99.9k | SeekImpl(ssKey); | 152 | 99.9k | } |
Unexecuted instantiation: _ZN11CDBIterator4SeekIhEEvRKT_ |
153 | | |
154 | | void Next(); |
155 | | |
156 | 0 | template<typename K> bool GetKey(K& key) { |
157 | 0 | try { |
158 | 0 | DataStream ssKey{GetKeyImpl()}; |
159 | 0 | ssKey >> key; |
160 | 0 | } catch (const std::exception&) { |
161 | 0 | return false; |
162 | 0 | } |
163 | 0 | return true; |
164 | 0 | } Unexecuted instantiation: blockfilterindex.cpp:_ZN11CDBIterator6GetKeyIN12_GLOBAL__N_111DBHeightKeyEEEbRT_ Unexecuted instantiation: coinstatsindex.cpp:_ZN11CDBIterator6GetKeyIN12_GLOBAL__N_111DBHeightKeyEEEbRT_ Unexecuted instantiation: _ZN11CDBIterator6GetKeyINSt3__14pairIh7uint256EEEEbRT_ Unexecuted instantiation: txdb.cpp:_ZN11CDBIterator6GetKeyIN12_GLOBAL__N_19CoinEntryEEEbRT_ |
165 | | |
166 | 0 | template<typename V> bool GetValue(V& value) { |
167 | 0 | try { |
168 | 0 | DataStream ssValue{GetValueImpl()}; |
169 | 0 | ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent)); |
170 | 0 | ssValue >> value; |
171 | 0 | } catch (const std::exception&) { |
172 | 0 | return false; |
173 | 0 | } |
174 | 0 | return true; |
175 | 0 | } Unexecuted instantiation: blockfilterindex.cpp:_ZN11CDBIterator8GetValueINSt3__14pairI7uint256N12_GLOBAL__N_15DBValEEEEEbRT_ Unexecuted instantiation: coinstatsindex.cpp:_ZN11CDBIterator8GetValueINSt3__14pairI7uint256N12_GLOBAL__N_15DBValEEEEEbRT_ Unexecuted instantiation: _ZN11CDBIterator8GetValueI15CDiskBlockIndexEEbRT_ Unexecuted instantiation: _ZN11CDBIterator8GetValueI4CoinEEbRT_ |
176 | | }; |
177 | | |
178 | | struct LevelDBContext; |
179 | | |
180 | | class CDBWrapper |
181 | | { |
182 | | friend const std::vector<unsigned char>& dbwrapper_private::GetObfuscateKey(const CDBWrapper &w); |
183 | | private: |
184 | | //! holds all leveldb-specific fields of this class |
185 | | std::unique_ptr<LevelDBContext> m_db_context; |
186 | | |
187 | | //! the name of this database |
188 | | std::string m_name; |
189 | | |
190 | | //! a key used for optional XOR-obfuscation of the database |
191 | | std::vector<unsigned char> obfuscate_key; |
192 | | |
193 | | //! the key under which the obfuscation key is stored |
194 | | static const std::string OBFUSCATE_KEY_KEY; |
195 | | |
196 | | //! the length of the obfuscate key in number of bytes |
197 | | static const unsigned int OBFUSCATE_KEY_NUM_BYTES; |
198 | | |
199 | | std::vector<unsigned char> CreateObfuscateKey() const; |
200 | | |
201 | | //! path to filesystem storage |
202 | | const fs::path m_path; |
203 | | |
204 | | //! whether or not the database resides in memory |
205 | | bool m_is_memory; |
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 | 83.6M | auto& DBContext() const LIFETIMEBOUND { return *Assert(m_db_context); } Line | Count | Source | 106 | 83.6M | #define Assert(val) inline_assertion_check<true>(val, __FILE__, __LINE__, __func__, #val) |
|
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 | 40.4M | { |
222 | 40.4M | DataStream ssKey{}; |
223 | 40.4M | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
224 | 40.4M | ssKey << key; |
225 | 40.4M | std::optional<std::string> strValue{ReadImpl(ssKey)}; |
226 | 40.4M | if (!strValue) { |
227 | 40.4M | return false; |
228 | 40.4M | } |
229 | 0 | try { |
230 | 0 | DataStream ssValue{MakeByteSpan(*strValue)}; |
231 | 0 | ssValue.Xor(obfuscate_key); |
232 | 0 | ssValue >> value; |
233 | 0 | } catch (const std::exception&) { |
234 | 0 | return false; |
235 | 0 | } |
236 | 0 | return true; |
237 | 0 | } _ZNK10CDBWrapper4ReadINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_6vectorIhNS5_IhEEEEEEbRKT_RT0_ Line | Count | Source | 221 | 99.9k | { | 222 | 99.9k | DataStream ssKey{}; | 223 | 99.9k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 224 | 99.9k | ssKey << key; | 225 | 99.9k | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 226 | 99.9k | if (!strValue) { | 227 | 99.9k | return false; | 228 | 99.9k | } | 229 | 0 | try { | 230 | 0 | DataStream ssValue{MakeByteSpan(*strValue)}; | 231 | 0 | ssValue.Xor(obfuscate_key); | 232 | 0 | ssValue >> value; | 233 | 0 | } catch (const std::exception&) { | 234 | 0 | return false; | 235 | 0 | } | 236 | 0 | return true; | 237 | 0 | } |
Unexecuted instantiation: _ZNK10CDBWrapper4ReadIh13CBlockLocatorEEbRKT_RT0_ Unexecuted instantiation: blockfilterindex.cpp:_ZNK10CDBWrapper4ReadIN12_GLOBAL__N_19DBHashKeyENS1_5DBValEEEbRKT_RT0_ Unexecuted instantiation: _ZNK10CDBWrapper4ReadIh11FlatFilePosEEbRKT_RT0_ Unexecuted instantiation: blockfilterindex.cpp:_ZNK10CDBWrapper4ReadIN12_GLOBAL__N_111DBHeightKeyENSt3__14pairI7uint256NS1_5DBValEEEEEbRKT_RT0_ Unexecuted instantiation: coinstatsindex.cpp:_ZNK10CDBWrapper4ReadIN12_GLOBAL__N_19DBHashKeyENS1_5DBValEEEbRKT_RT0_ Unexecuted instantiation: coinstatsindex.cpp:_ZNK10CDBWrapper4ReadIN12_GLOBAL__N_111DBHeightKeyENSt3__14pairI7uint256NS1_5DBValEEEEEbRKT_RT0_ Unexecuted instantiation: coinstatsindex.cpp:_ZNK10CDBWrapper4ReadIN12_GLOBAL__N_19DBHashKeyENSt3__14pairI7uint256NS1_5DBValEEEEEbRKT_RT0_ Unexecuted instantiation: _ZNK10CDBWrapper4ReadIh10MuHash3072EEbRKT_RT0_ Unexecuted instantiation: _ZNK10CDBWrapper4ReadINSt3__14pairIh7uint256EE10CDiskTxPosEEbRKT_RT0_ _ZNK10CDBWrapper4ReadINSt3__14pairIhiEE14CBlockFileInfoEEbRKT_RT0_ Line | Count | Source | 221 | 99.9k | { | 222 | 99.9k | DataStream ssKey{}; | 223 | 99.9k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 224 | 99.9k | ssKey << key; | 225 | 99.9k | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 226 | 99.9k | if (!strValue) { | 227 | 99.9k | return false; | 228 | 99.9k | } | 229 | 0 | try { | 230 | 0 | DataStream ssValue{MakeByteSpan(*strValue)}; | 231 | 0 | ssValue.Xor(obfuscate_key); | 232 | 0 | ssValue >> value; | 233 | 0 | } catch (const std::exception&) { | 234 | 0 | return false; | 235 | 0 | } | 236 | 0 | return true; | 237 | 0 | } |
_ZNK10CDBWrapper4ReadIhiEEbRKT_RT0_ Line | Count | Source | 221 | 49.9k | { | 222 | 49.9k | DataStream ssKey{}; | 223 | 49.9k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 224 | 49.9k | ssKey << key; | 225 | 49.9k | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 226 | 49.9k | if (!strValue) { | 227 | 49.9k | return false; | 228 | 49.9k | } | 229 | 0 | try { | 230 | 0 | DataStream ssValue{MakeByteSpan(*strValue)}; | 231 | 0 | ssValue.Xor(obfuscate_key); | 232 | 0 | ssValue >> value; | 233 | 0 | } catch (const std::exception&) { | 234 | 0 | return false; | 235 | 0 | } | 236 | 0 | return true; | 237 | 0 | } |
_ZNK10CDBWrapper4ReadINSt3__14pairIhNS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEEhEEbRKT_RT0_ Line | Count | Source | 221 | 49.9k | { | 222 | 49.9k | DataStream ssKey{}; | 223 | 49.9k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 224 | 49.9k | ssKey << key; | 225 | 49.9k | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 226 | 49.9k | if (!strValue) { | 227 | 49.9k | return false; | 228 | 49.9k | } | 229 | 0 | try { | 230 | 0 | DataStream ssValue{MakeByteSpan(*strValue)}; | 231 | 0 | ssValue.Xor(obfuscate_key); | 232 | 0 | ssValue >> value; | 233 | 0 | } catch (const std::exception&) { | 234 | 0 | return false; | 235 | 0 | } | 236 | 0 | return true; | 237 | 0 | } |
txdb.cpp:_ZNK10CDBWrapper4ReadIN12_GLOBAL__N_19CoinEntryE4CoinEEbRKT_RT0_ Line | Count | Source | 221 | 39.9M | { | 222 | 39.9M | DataStream ssKey{}; | 223 | 39.9M | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 224 | 39.9M | ssKey << key; | 225 | 39.9M | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 226 | 39.9M | if (!strValue) { | 227 | 39.9M | return false; | 228 | 39.9M | } | 229 | 0 | try { | 230 | 0 | DataStream ssValue{MakeByteSpan(*strValue)}; | 231 | 0 | ssValue.Xor(obfuscate_key); | 232 | 0 | ssValue >> value; | 233 | 0 | } catch (const std::exception&) { | 234 | 0 | return false; | 235 | 0 | } | 236 | 0 | return true; | 237 | 0 | } |
_ZNK10CDBWrapper4ReadIh7uint256EEbRKT_RT0_ Line | Count | Source | 221 | 150k | { | 222 | 150k | DataStream ssKey{}; | 223 | 150k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 224 | 150k | ssKey << key; | 225 | 150k | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 226 | 150k | if (!strValue) { | 227 | 150k | return false; | 228 | 150k | } | 229 | 0 | try { | 230 | 0 | DataStream ssValue{MakeByteSpan(*strValue)}; | 231 | 0 | ssValue.Xor(obfuscate_key); | 232 | 0 | ssValue >> value; | 233 | 0 | } catch (const std::exception&) { | 234 | 0 | return false; | 235 | 0 | } | 236 | 0 | return true; | 237 | 0 | } |
_ZNK10CDBWrapper4ReadIhNSt3__16vectorI7uint256NS1_9allocatorIS3_EEEEEEbRKT_RT0_ Line | Count | Source | 221 | 50.4k | { | 222 | 50.4k | DataStream ssKey{}; | 223 | 50.4k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 224 | 50.4k | ssKey << key; | 225 | 50.4k | std::optional<std::string> strValue{ReadImpl(ssKey)}; | 226 | 50.4k | if (!strValue) { | 227 | 50.4k | return false; | 228 | 50.4k | } | 229 | 0 | try { | 230 | 0 | DataStream ssValue{MakeByteSpan(*strValue)}; | 231 | 0 | ssValue.Xor(obfuscate_key); | 232 | 0 | 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 | | bool Write(const K& key, const V& value, bool fSync = false) |
241 | 49.9k | { |
242 | 49.9k | CDBBatch batch(*this); |
243 | 49.9k | batch.Write(key, value); |
244 | 49.9k | return WriteBatch(batch, fSync); |
245 | 49.9k | } _ZN10CDBWrapper5WriteINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_6vectorIhNS5_IhEEEEEEbRKT_RKT0_b Line | Count | Source | 241 | 49.9k | { | 242 | 49.9k | CDBBatch batch(*this); | 243 | 49.9k | batch.Write(key, value); | 244 | 49.9k | return WriteBatch(batch, fSync); | 245 | 49.9k | } |
Unexecuted instantiation: blockfilterindex.cpp:_ZN10CDBWrapper5WriteIN12_GLOBAL__N_111DBHeightKeyENSt3__14pairI7uint256NS1_5DBValEEEEEbRKT_RKT0_b Unexecuted instantiation: coinstatsindex.cpp:_ZN10CDBWrapper5WriteIN12_GLOBAL__N_111DBHeightKeyENSt3__14pairI7uint256NS1_5DBValEEEEEbRKT_RKT0_b Unexecuted instantiation: _ZN10CDBWrapper5WriteIhhEEbRKT_RKT0_b Unexecuted instantiation: _ZN10CDBWrapper5WriteINSt3__14pairIhNS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEEhEEbRKT_RKT0_b |
246 | | |
247 | | //! @returns filesystem path to the on-disk data. |
248 | 0 | std::optional<fs::path> StoragePath() { |
249 | 0 | if (m_is_memory) { |
250 | 0 | return {}; |
251 | 0 | } |
252 | 0 | return m_path; |
253 | 0 | } |
254 | | |
255 | | template <typename K> |
256 | | bool Exists(const K& key) const |
257 | 49.9k | { |
258 | 49.9k | DataStream ssKey{}; |
259 | 49.9k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
260 | 49.9k | ssKey << key; |
261 | 49.9k | return ExistsImpl(ssKey); |
262 | 49.9k | } _ZNK10CDBWrapper6ExistsIhEEbRKT_ Line | Count | Source | 257 | 49.9k | { | 258 | 49.9k | DataStream ssKey{}; | 259 | 49.9k | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | 260 | 49.9k | ssKey << key; | 261 | 49.9k | return ExistsImpl(ssKey); | 262 | 49.9k | } |
Unexecuted instantiation: txdb.cpp:_ZNK10CDBWrapper6ExistsIN12_GLOBAL__N_19CoinEntryEEEbRKT_ |
263 | | |
264 | | template <typename K> |
265 | | bool Erase(const K& key, bool fSync = false) |
266 | 0 | { |
267 | 0 | CDBBatch batch(*this); |
268 | 0 | batch.Erase(key); |
269 | 0 | return WriteBatch(batch, fSync); |
270 | 0 | } |
271 | | |
272 | | bool WriteBatch(CDBBatch& batch, bool fSync = false); |
273 | | |
274 | | // Get an estimate of LevelDB memory usage (in bytes). |
275 | | size_t DynamicMemoryUsage() const; |
276 | | |
277 | | CDBIterator* NewIterator(); |
278 | | |
279 | | /** |
280 | | * Return true if the database managed by this class contains no entries. |
281 | | */ |
282 | | bool IsEmpty(); |
283 | | |
284 | | template<typename K> |
285 | | size_t EstimateSize(const K& key_begin, const K& key_end) const |
286 | 0 | { |
287 | 0 | DataStream ssKey1{}, ssKey2{}; |
288 | 0 | ssKey1.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
289 | 0 | ssKey2.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); |
290 | 0 | ssKey1 << key_begin; |
291 | 0 | ssKey2 << key_end; |
292 | 0 | return EstimateSizeImpl(ssKey1, ssKey2); |
293 | 0 | } |
294 | | }; |
295 | | |
296 | | #endif // BITCOIN_DBWRAPPER_H |