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