Electroneum
db_bdb.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2020, The Electroneum Project
2 // Copyrights(c) 2014-2019, The Monero Project
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #include <db_cxx.h>
30 
32 #include "cryptonote_basic/blobdatatype.h" // for type blobdata
33 
34 #include <unordered_map>
35 #include <condition_variable>
36 
37 // ND: Enables multi-threaded bulk reads for when getting indices.
38 // TODO: Disabled for now, as it doesn't seem to provide noticeable improvements (??. Reason: TBD.
39 // #define BDB_BULK_CAN_THREAD
40 namespace cryptonote
41 {
42 
44 {
45  bdb_txn_safe() : m_txn(NULL) { }
47  {
48  LOG_PRINT_L3("bdb_txn_safe: destructor");
49 
50  if (m_txn != NULL)
51  abort();
52  }
53 
54  void commit(std::string message = "")
55  {
56  if (message.size() == 0)
57  {
58  message = "Failed to commit a transaction to the db";
59  }
60 
61  if (m_txn->commit(0))
62  {
63  m_txn = NULL;
64  LOG_PRINT_L0(message);
65  throw DB_ERROR(message.c_str());
66  }
67  m_txn = NULL;
68  }
69 
70  void abort()
71  {
72  LOG_PRINT_L3("bdb_txn_safe: abort()");
73  if(m_txn != NULL)
74  {
75  m_txn->abort();
76  m_txn = NULL;
77  }
78  else
79  {
80  LOG_PRINT_L0("WARNING: bdb_txn_safe: abort() called, but m_txn is NULL");
81  }
82  }
83 
84  operator DbTxn*()
85  {
86  return m_txn;
87  }
88 
89  operator DbTxn**()
90  {
91  return &m_txn;
92  }
93 private:
94  DbTxn* m_txn;
95 };
96 
97 // ND: Class to handle buffer management when doing bulk queries
98 // (DB_MULTIPLE). Allocates buffers then handles thread queuing
99 // so a fixed set of buffers can be used (instead of allocating
100 // every time a bulk query is needed).
101 template <typename T>
103 {
104  // limit the number of buffers to 8
105  const size_t MaxAllowedBuffers = 8;
106 public:
107  bdb_safe_buffer(size_t num_buffers, size_t count)
108  {
109  if(num_buffers > MaxAllowedBuffers)
110  num_buffers = MaxAllowedBuffers;
111 
112  set_count(num_buffers);
113  for (size_t i = 0; i < num_buffers; i++)
114  m_buffers.push_back((T) malloc(sizeof(T) * count));
116  }
117 
119  {
120  for (size_t i = 0; i < m_buffers.size(); i++)
121  {
122  if (m_buffers[i])
123  {
124  free(m_buffers[i]);
125  m_buffers[i] = nullptr;
126  }
127  }
128 
129  m_buffers.resize(0);
130  }
131 
133  {
134  boost::unique_lock<boost::mutex> lock(m_lock);
135  m_cv.wait(lock, [&]{ return m_count > 0; });
136 
137  --m_count;
138  size_t index = -1;
139  for (size_t i = 0; i < m_open_slot.size(); i++)
140  {
141  if (m_open_slot[i])
142  {
143  m_open_slot[i] = false;
144  index = i;
145  break;
146  }
147  }
148 
149  assert(index >= 0);
150 
151  T buffer = m_buffers[index];
152  m_buffer_map.emplace(buffer, index);
153  return buffer;
154  }
155 
156  void release_buffer(T buffer)
157  {
158  boost::unique_lock<boost::mutex> lock(m_lock);
159 
160  assert(buffer != nullptr);
161  auto it = m_buffer_map.find(buffer);
162  if (it != m_buffer_map.end())
163  {
164  auto index = it->second;
165 
166  assert(index < m_open_slot.size());
167  assert(m_open_slot[index] == false);
168  assert(m_count < m_open_slot.size());
169 
170  ++m_count;
171  m_open_slot[index] = true;
172  m_buffer_map.erase(it);
173  m_cv.notify_one();
174  }
175  }
176 
177  size_t get_buffer_size() const
178  {
179  return m_buffer_count * sizeof(T);
180  }
181 
182  size_t get_buffer_count() const
183  {
184  return m_buffer_count;
185  }
186 
187  typedef T type;
188 
189 private:
190  void set_count(size_t count)
191  {
192  assert(count > 0);
193  m_open_slot.resize(count, true);
194  m_count = count;
195  }
196 
197  std::vector<T> m_buffers;
198  std::unordered_map<T, size_t> m_buffer_map;
199 
200  boost::condition_variable m_cv;
201  std::vector<bool> m_open_slot;
202  size_t m_count;
203  boost::mutex m_lock;
204 
206 };
207 
208 template <typename T>
210 {
211 public:
212  bdb_safe_buffer_autolock(T &safe_buffer, typename T::type &buffer) :
213  m_safe_buffer(safe_buffer), m_buffer(nullptr)
214  {
215  m_buffer = m_safe_buffer.acquire_buffer();
216  buffer = m_buffer;
217  }
218 
220  {
221  if (m_buffer != nullptr)
222  {
223  m_safe_buffer.release_buffer(m_buffer);
224  m_buffer = nullptr;
225  }
226  }
227 private:
229  typename T::type m_buffer;
230 };
231 
233 {
234 public:
235  BlockchainBDB(bool batch_transactions=false);
236  ~BlockchainBDB();
237 
238  virtual void open(const std::string& filename, const int db_flags);
239 
240  virtual void close();
241 
242  virtual void sync();
243 
244  virtual void reset();
245 
246  virtual std::vector<std::string> get_filenames() const;
247 
248  virtual bool remove_data_file(const std::string& folder);
249 
250  virtual std::string get_db_name() const;
251 
252  virtual bool lock();
253 
254  virtual void unlock();
255 
256  virtual bool block_exists(const crypto::hash& h, uint64_t *height = NULL) const;
257 
258  virtual block get_block(const crypto::hash& h) const;
259 
260  virtual uint64_t get_block_height(const crypto::hash& h) const;
261 
262  virtual block_header get_block_header(const crypto::hash& h) const;
263 
264  virtual block get_block_from_height(const uint64_t& height) const;
265 
266  virtual uint64_t get_block_timestamp(const uint64_t& height) const;
267 
268  virtual uint64_t get_top_block_timestamp() const;
269 
270  virtual size_t get_block_weight(const uint64_t& height) const;
271 
273 
274  virtual difficulty_type get_block_cumulative_difficulty(const uint64_t& height) const;
275 
276  virtual difficulty_type get_block_difficulty(const uint64_t& height) const;
277 
278  virtual uint64_t get_block_already_generated_coins(const uint64_t& height) const;
279 
280  virtual crypto::hash get_block_hash_from_height(const uint64_t& height) const;
281 
282  virtual std::vector<block> get_blocks_range(const uint64_t& h1, const uint64_t& h2) const;
283 
284  virtual std::vector<crypto::hash> get_hashes_range(const uint64_t& h1, const uint64_t& h2) const;
285 
286  virtual crypto::hash top_block_hash() const;
287 
288  virtual block get_top_block() const;
289 
290  virtual uint64_t height() const;
291 
292  virtual bool tx_exists(const crypto::hash& h) const;
293 
294  virtual uint64_t get_tx_unlock_time(const crypto::hash& h) const;
295 
296  virtual transaction get_tx(const crypto::hash& h) const;
297 
298  virtual uint64_t get_tx_count() const;
299 
300  virtual std::vector<transaction> get_tx_list(const std::vector<crypto::hash>& hlist) const;
301 
302  virtual uint64_t get_tx_block_height(const crypto::hash& h) const;
303 
304  virtual uint64_t get_num_outputs(const uint64_t& amount) const;
305 
306  virtual uint64_t get_indexing_base() const { return 1; }
307 
308  virtual output_data_t get_output_key(const uint64_t& amount, const uint64_t& index);
309  virtual void get_output_key(const uint64_t &amount, const std::vector<uint64_t> &offsets, std::vector<output_data_t> &outputs);
310 
311  virtual tx_out_index get_output_tx_and_index_from_global(const uint64_t& index) const;
312  virtual void get_output_tx_and_index_from_global(const std::vector<uint64_t> &global_indices,
313  std::vector<tx_out_index> &tx_out_indices) const;
314 
315  virtual tx_out_index get_output_tx_and_index(const uint64_t& amount, const uint64_t& index);
316  virtual void get_output_tx_and_index(const uint64_t& amount, const std::vector<uint64_t> &offsets, std::vector<tx_out_index> &indices);
317 
318  virtual std::vector<uint64_t> get_tx_amount_output_indices(const crypto::hash& h) const;
319 
320  virtual bool has_key_image(const crypto::key_image& img) const;
321 
322  virtual uint64_t add_block( const block& blk
323  , size_t block_weight
324  , const difficulty_type& cumulative_difficulty
325  , const uint64_t& coins_generated
326  , const std::vector<transaction>& txs
327  );
328 
329  virtual void set_batch_transactions(bool batch_transactions);
330  virtual bool batch_start(uint64_t batch_num_blocks=0);
331  virtual void batch_commit();
332  virtual void batch_stop();
333  virtual void batch_abort();
334 
335  virtual void block_txn_start(bool readonly);
336  virtual void block_txn_stop();
337  virtual void block_txn_abort();
338 
339  virtual void pop_block(block& blk, std::vector<transaction>& txs);
340 
341 #if defined(BDB_BULK_CAN_THREAD)
342  virtual bool can_thread_bulk_indices() const { return true; }
343 #else
344  virtual bool can_thread_bulk_indices() const { return false; }
345 #endif
346 
354  std::map<uint64_t, uint64_t> get_output_histogram(const std::vector<uint64_t> &amounts) const;
355 
356 private:
357  virtual void add_block( const block& blk
358  , size_t block_weight
359  , const difficulty_type& cumulative_difficulty
360  , const uint64_t& coins_generated
361  , const crypto::hash& block_hash
362  );
363 
364  virtual void remove_block();
365 
366  virtual void add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prunable_hash);
367 
368  virtual void remove_transaction_data(const crypto::hash& tx_hash, const transaction& tx);
369 
370  virtual void add_output(const crypto::hash& tx_hash, const tx_out& tx_output, const uint64_t& local_index, const uint64_t unlock_time, const rct::key *commitment);
371 
372  virtual void remove_output(const tx_out& tx_output);
373 
374  void remove_tx_outputs(const crypto::hash& tx_hash, const transaction& tx);
375 
376  void remove_output(const uint64_t& out_index, const uint64_t amount);
377  void remove_amount_output_index(const uint64_t amount, const uint64_t global_output_index);
378 
379  virtual void add_spent_key(const crypto::key_image& k_image);
380 
381  virtual void remove_spent_key(const crypto::key_image& k_image);
382 
383  void get_output_global_indices(const uint64_t& amount, const std::vector<uint64_t> &offsets, std::vector<uint64_t> &global_indices);
384 
385  virtual bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const;
386  virtual bool for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const;
387  virtual bool for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)>, bool pruned) const;
388  virtual bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const;
389 
390  // Hard fork related storage
391  virtual void set_hard_fork_version(uint64_t height, uint8_t version);
392  virtual uint8_t get_hard_fork_version(uint64_t height) const;
393  virtual void check_hard_fork_info();
394  virtual void drop_hard_fork_info();
395 
404  uint64_t get_output_global_index(const uint64_t& amount, const uint64_t& index);
405  output_data_t get_output_key(const uint64_t& global_index) const;
406  void checkpoint_worker() const;
407  void check_open() const;
408 
409  virtual bool is_read_only() const;
410 
412  std::unique_ptr<boost::thread> m_checkpoint_thread;
415 
416  DbEnv* m_env;
417 
418  Db* m_blocks;
425 
426  Db* m_txs;
430 
435 
437 
440 
442 
443  uint64_t m_height;
444  uint64_t m_num_outputs;
445  std::string m_folder;
447 
448  bool m_batch_transactions; // support for batch transactions
449 };
450 
451 } // namespace cryptonote
uint8_t version
Definition: blockchain.cpp:90
static uint64_t db_flags
Definition: blockchain_blackball.cpp:57
Definition: db_bdb.h:233
virtual void add_transaction_data(const crypto::hash &blk_hash, const transaction &tx, const crypto::hash &tx_hash, const crypto::hash &tx_prunable_hash)
Definition: db_bdb.cpp:317
Db * m_output_keys
Definition: db_bdb.h:434
Db * m_block_diffs
Definition: db_bdb.h:423
virtual void drop_hard_fork_info()
delete hard fork info from database
Definition: db_bdb.cpp:2200
uint64_t get_output_global_index(const uint64_t &amount, const uint64_t &index)
get the global index of the index-th output of the given amount
Definition: db_bdb.cpp:718
virtual uint64_t get_indexing_base() const
return index of the first element (should be hidden, but isn't)
Definition: db_bdb.h:306
virtual crypto::hash get_block_hash_from_height(const uint64_t &height) const
fetch a block's hash
Definition: db_bdb.cpp:1405
Db * m_properties
Definition: db_bdb.h:441
uint64_t m_height
Definition: db_bdb.h:443
virtual bool for_all_blocks(std::function< bool(uint64_t, const crypto::hash &, const cryptonote::block &)>) const
Definition: db_bdb.cpp:624
virtual void check_hard_fork_info()
verify hard fork info in database
Definition: db_bdb.cpp:2146
Db * m_tx_heights
Definition: db_bdb.h:428
bdb_safe_buffer< void * > bdb_safe_buffer_t
Definition: db_bdb.h:413
Db * m_blocks
Definition: db_bdb.h:418
virtual void set_hard_fork_version(uint64_t height, uint8_t version)
sets which hardfork version a height is on
Definition: db_bdb.cpp:2235
Db * m_tx_unlocks
Definition: db_bdb.h:427
virtual bool lock()
acquires the BlockchainDB lock
Definition: db_bdb.cpp:1207
virtual uint8_t get_hard_fork_version(uint64_t height) const
checks which hardfork version a height is on
Definition: db_bdb.cpp:2246
virtual block_header get_block_header(const crypto::hash &h) const
fetch a block header
Definition: db_bdb.cpp:1268
virtual block get_block(const crypto::hash &h) const
fetches the block with the given hash
Definition: db_bdb.cpp:1243
virtual uint64_t get_tx_block_height(const crypto::hash &h) const
fetches the height of a transaction's block
Definition: db_bdb.cpp:1577
DbEnv * m_env
Definition: db_bdb.h:416
virtual void unlock()
This function releases the BlockchainDB lock.
Definition: db_bdb.cpp:1215
virtual void set_batch_transactions(bool batch_transactions)
sets whether or not to batch transactions
Definition: db_bdb.cpp:1790
virtual uint64_t get_num_outputs(const uint64_t &amount) const
fetches the number of outputs of a given amount
Definition: db_bdb.cpp:1595
Db * m_txs
Definition: db_bdb.h:426
Db * m_tx_outputs
Definition: db_bdb.h:429
virtual uint64_t get_block_already_generated_coins(const uint64_t &height) const
fetch a block's already generated coins
Definition: db_bdb.cpp:1387
virtual uint64_t get_top_block_timestamp() const
fetch the top block's timestamp
Definition: db_bdb.cpp:1320
virtual void remove_spent_key(const crypto::key_image &k_image)
remove a spent key
Definition: db_bdb.cpp:587
virtual std::vector< transaction > get_tx_list(const std::vector< crypto::hash > &hlist) const
fetches a list of transactions based on their hashes
Definition: db_bdb.cpp:1563
bool m_run_checkpoint
Definition: db_bdb.h:411
virtual tx_out_index get_output_tx_and_index(const uint64_t &amount, const uint64_t &index)
virtual bool batch_start(uint64_t batch_num_blocks=0)
Definition: db_bdb.cpp:1769
virtual void open(const std::string &filename, const int db_flags)
open a db, or create it if necessary.
Definition: db_bdb.cpp:766
virtual difficulty_type get_block_cumulative_difficulty(const uint64_t &height) const
fetch a block's cumulative difficulty
Definition: db_bdb.cpp:1352
virtual uint64_t height() const
fetch the current blockchain height
Definition: db_bdb.cpp:1477
Db * m_block_timestamps
Definition: db_bdb.h:421
virtual bool tx_exists(const crypto::hash &h) const
check if a transaction with a given hash exists
Definition: db_bdb.cpp:1485
virtual uint64_t get_tx_count() const
fetches the total number of transactions ever
Definition: db_bdb.cpp:1546
Db * m_block_hashes
Definition: db_bdb.h:420
void remove_tx_outputs(const crypto::hash &tx_hash, const transaction &tx)
Definition: db_bdb.cpp:405
virtual void batch_commit()
Definition: db_bdb.cpp:1775
virtual std::vector< uint64_t > get_tx_amount_output_indices(const crypto::hash &h) const
Definition: db_bdb.cpp:1658
Db * m_output_amounts
Definition: db_bdb.h:433
virtual bool for_all_transactions(std::function< bool(const crypto::hash &, const cryptonote::transaction &)>, bool pruned) const
runs a function over all transactions stored
Definition: db_bdb.cpp:659
void check_open() const
Definition: db_bdb.cpp:733
bool m_batch_transactions
Definition: db_bdb.h:448
Db * m_block_coins
Definition: db_bdb.h:424
virtual void block_txn_abort()
Definition: db_bdb.cpp:1807
virtual uint64_t get_block_height(const crypto::hash &h) const
gets the height of the block with a given hash
Definition: db_bdb.cpp:1251
virtual void close()
close the BlockchainDB
Definition: db_bdb.cpp:979
virtual void add_spent_key(const crypto::key_image &k_image)
store a spent key
Definition: db_bdb.cpp:573
bdb_safe_buffer_t m_buffer
Definition: db_bdb.h:414
virtual size_t get_block_weight(const uint64_t &height) const
fetch a block's weight
Definition: db_bdb.cpp:1334
virtual std::vector< std::string > get_filenames() const
get all files used by the BlockchainDB (if any)
Definition: db_bdb.cpp:1112
virtual void batch_stop()
ends a batch transaction
Definition: db_bdb.cpp:1780
virtual void block_txn_stop()
Definition: db_bdb.cpp:1802
virtual void remove_block()
remove data about the top block
Definition: db_bdb.cpp:282
virtual std::string get_db_name() const
gets the name of the folder the BlockchainDB's file(s) should be in
Definition: db_bdb.cpp:1199
virtual transaction get_tx(const crypto::hash &h) const
fetches the transaction with the given hash
Definition: db_bdb.cpp:1523
Db * m_hf_versions
Definition: db_bdb.h:439
std::map< uint64_t, uint64_t > get_output_histogram(const std::vector< uint64_t > &amounts) const
return a histogram of outputs on the blockchain
virtual uint64_t add_block(const block &blk, size_t block_weight, const difficulty_type &cumulative_difficulty, const uint64_t &coins_generated, const std::vector< transaction > &txs)
Definition: db_bdb.cpp:1812
Db * m_output_indices
Definition: db_bdb.h:432
std::unique_ptr< boost::thread > m_checkpoint_thread
Definition: db_bdb.h:412
virtual bool for_all_outputs(std::function< bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const
Definition: db_bdb.cpp:690
uint64_t m_num_outputs
Definition: db_bdb.h:444
bdb_txn_safe * m_write_txn
Definition: db_bdb.h:446
virtual uint64_t get_tx_unlock_time(const crypto::hash &h) const
fetch a transaction's unlock time/height
Definition: db_bdb.cpp:1507
virtual void remove_transaction_data(const crypto::hash &tx_hash, const transaction &tx)
remove data about a transaction
Definition: db_bdb.cpp:340
virtual bool remove_data_file(const std::string &folder)
Definition: db_bdb.cpp:1194
virtual void set_block_cumulative_difficulty(uint64_t height, difficulty_type diff)
sets a block's cumulative difficulty
virtual void batch_abort()
aborts a batch transaction
Definition: db_bdb.cpp:1785
virtual tx_out_index get_output_tx_and_index_from_global(const uint64_t &index) const
gets an output's tx hash and index
Definition: db_bdb.cpp:1726
virtual block get_top_block() const
fetch the top block
Definition: db_bdb.cpp:1463
Db * m_block_sizes
Definition: db_bdb.h:422
Db * m_spent_keys
Definition: db_bdb.h:436
void remove_amount_output_index(const uint64_t amount, const uint64_t global_output_index)
Definition: db_bdb.cpp:501
BlockchainBDB(bool batch_transactions=false)
Definition: db_bdb.cpp:750
virtual output_data_t get_output_key(const uint64_t &amount, const uint64_t &index)
Db * m_hf_starting_heights
Definition: db_bdb.h:438
Db * m_output_txs
Definition: db_bdb.h:431
virtual void reset()
Remove everything from the BlockchainDB.
Definition: db_bdb.cpp:1067
virtual void block_txn_start(bool readonly)
Definition: db_bdb.cpp:1797
virtual bool has_key_image(const crypto::key_image &img) const
check if a key image is stored as spent
Definition: db_bdb.cpp:1752
virtual void add_output(const crypto::hash &tx_hash, const tx_out &tx_output, const uint64_t &local_index, const uint64_t unlock_time, const rct::key *commitment)
store an output
Definition: db_bdb.cpp:365
~BlockchainBDB()
Definition: db_bdb.cpp:740
virtual bool block_exists(const crypto::hash &h, uint64_t *height=NULL) const
checks if a block exists
Definition: db_bdb.cpp:1221
virtual void remove_output(const tx_out &tx_output)
Definition: db_bdb.cpp:453
virtual void sync()
sync the BlockchainDB with disk
Definition: db_bdb.cpp:1027
virtual block get_block_from_height(const uint64_t &height) const
fetch a block by height
Definition: db_bdb.cpp:1277
virtual std::vector< crypto::hash > get_hashes_range(const uint64_t &h1, const uint64_t &h2) const
fetch a list of block hashes
Definition: db_bdb.cpp:1437
virtual uint64_t get_block_timestamp(const uint64_t &height) const
fetch a block's timestamp
Definition: db_bdb.cpp:1302
std::string m_folder
Definition: db_bdb.h:445
virtual std::vector< block > get_blocks_range(const uint64_t &h1, const uint64_t &h2) const
fetch a list of blocks
Definition: db_bdb.cpp:1423
virtual crypto::hash top_block_hash() const
Definition: db_bdb.cpp:1451
void checkpoint_worker() const
Definition: db_bdb.cpp:2263
void get_output_global_indices(const uint64_t &amount, const std::vector< uint64_t > &offsets, std::vector< uint64_t > &global_indices)
Definition: db_bdb.cpp:1901
Db * m_block_heights
Definition: db_bdb.h:419
virtual bool for_all_key_images(std::function< bool(const crypto::key_image &)>) const
runs a function over all key images stored
Definition: db_bdb.cpp:598
virtual difficulty_type get_block_difficulty(const uint64_t &height) const
fetch a block's difficulty
Definition: db_bdb.cpp:1370
virtual bool can_thread_bulk_indices() const
Definition: db_bdb.h:344
virtual bool is_read_only() const
is BlockchainDB in read-only mode?
Definition: db_bdb.cpp:2285
The BlockchainDB backing store interface declaration/contract.
Definition: blockchain_db.h:344
void pop_block()
private version of pop_block, for undoing if an add_block fails
Definition: blockchain_db.cpp:118
A generic BlockchainDB exception.
Definition: blockchain_db.h:190
Definition: db_bdb.h:210
T::type m_buffer
Definition: db_bdb.h:229
~bdb_safe_buffer_autolock()
Definition: db_bdb.h:219
T & m_safe_buffer
Definition: db_bdb.h:228
bdb_safe_buffer_autolock(T &safe_buffer, typename T::type &buffer)
Definition: db_bdb.h:212
Definition: db_bdb.h:103
bdb_safe_buffer(size_t num_buffers, size_t count)
Definition: db_bdb.h:107
size_t get_buffer_count() const
Definition: db_bdb.h:182
~bdb_safe_buffer()
Definition: db_bdb.h:118
size_t m_buffer_count
Definition: db_bdb.h:205
std::unordered_map< T, size_t > m_buffer_map
Definition: db_bdb.h:198
std::vector< bool > m_open_slot
Definition: db_bdb.h:201
T type
Definition: db_bdb.h:187
const size_t MaxAllowedBuffers
Definition: db_bdb.h:105
void set_count(size_t count)
Definition: db_bdb.h:190
size_t m_count
Definition: db_bdb.h:202
T acquire_buffer()
Definition: db_bdb.h:132
boost::mutex m_lock
Definition: db_bdb.h:203
size_t get_buffer_size() const
Definition: db_bdb.h:177
std::vector< T > m_buffers
Definition: db_bdb.h:197
void release_buffer(T buffer)
Definition: db_bdb.h:156
boost::condition_variable m_cv
Definition: db_bdb.h:200
Definition: cryptonote_basic.h:205
const uint32_t T[512]
Definition: groestl_tables.h:37
POD_CLASS key_image
Definition: crypto.h:102
POD_CLASS hash
Definition: hash.h:50
Holds cryptonote related classes and helpers.
Definition: db_bdb.cpp:226
boost::multiprecision::uint128_t difficulty_type
Definition: difficulty.h:43
std::pair< crypto::hash, uint64_t > tx_out_index
Definition: blockchain_db.h:104
mdb_size_t count(MDB_cursor *cur)
Definition: value_stream.cpp:39
Definition: db_bdb.h:44
DbTxn * m_txn
Definition: db_bdb.h:94
void commit(std::string message="")
Definition: db_bdb.h:54
~bdb_txn_safe()
Definition: db_bdb.h:46
bdb_txn_safe()
Definition: db_bdb.h:45
void abort()
Definition: db_bdb.h:70
Definition: cryptonote_basic.h:393
Definition: cryptonote_basic.h:410
a struct containing output metadata
Definition: blockchain_db.h:116
Definition: cryptonote_basic.h:144
Definition: rctTypes.h:78