Electroneum
blockchain_db.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2018, The Electroneum Project
2 // Copyrights(c) 2014-2017, The Monero Project
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without modification, are
7 // permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this list of
10 // conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 // of conditions and the following disclaimer in the documentation and/or other
14 // materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its contributors may be
17 // used to endorse or promote products derived from this software without specific
18 // prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef BLOCKCHAIN_DB_H
30 #define BLOCKCHAIN_DB_H
31 
32 #pragma once
33 
34 #include <list>
35 #include <string>
36 #include <exception>
37 #include "crypto/hash.h"
42 
99 namespace cryptonote
100 {
101 
103 typedef std::pair<crypto::hash, uint64_t> tx_out_index;
104 
105 #pragma pack(push, 1)
106 
111 {
113  uint64_t unlock_time;
114  uint64_t height;
116 };
117 #pragma pack(pop)
118 
119 #pragma pack(push, 1)
120 struct tx_data_t
121 {
122  uint64_t tx_id;
123  uint64_t unlock_time;
124  uint64_t block_id;
125 };
126 #pragma pack(pop)
127 
132 {
135  uint64_t blob_size;
136  uint64_t fee;
139  uint64_t receive_time;
141  // 112 bytes
142  uint8_t kept_by_block;
143  uint8_t relayed;
144  uint8_t do_not_relay;
145 
146  uint8_t padding[77]; // till 192 bytes
147 };
148 
149 #define DBF_SAFE 1
150 #define DBF_FAST 2
151 #define DBF_FASTEST 4
152 #define DBF_RDONLY 8
153 #define DBF_SALVAGE 0x10
154 
155 /***********************************
156  * Exception Definitions
157  ***********************************/
158 
162 class DB_EXCEPTION : public std::exception
163 {
164  private:
165  std::string m;
166 
167  protected:
168  DB_EXCEPTION(const char *s) : m(s) { }
169 
170  public:
171  virtual ~DB_EXCEPTION() { }
172 
173  const char* what() const throw()
174  {
175  return m.c_str();
176  }
177 };
178 
182 class DB_ERROR : public DB_EXCEPTION
183 {
184  public:
185  DB_ERROR() : DB_EXCEPTION("Generic DB Error") { }
186  DB_ERROR(const char* s) : DB_EXCEPTION(s) { }
187 };
188 
193 {
194  public:
195  DB_ERROR_TXN_START() : DB_EXCEPTION("DB Error in starting txn") { }
196  DB_ERROR_TXN_START(const char* s) : DB_EXCEPTION(s) { }
197 };
198 
203 {
204  public:
205  DB_OPEN_FAILURE() : DB_EXCEPTION("Failed to open the db") { }
206  DB_OPEN_FAILURE(const char* s) : DB_EXCEPTION(s) { }
207 };
208 
213 {
214  public:
215  DB_CREATE_FAILURE() : DB_EXCEPTION("Failed to create the db") { }
216  DB_CREATE_FAILURE(const char* s) : DB_EXCEPTION(s) { }
217 };
218 
223 {
224  public:
225  DB_SYNC_FAILURE() : DB_EXCEPTION("Failed to sync the db") { }
226  DB_SYNC_FAILURE(const char* s) : DB_EXCEPTION(s) { }
227 };
228 
232 class BLOCK_DNE : public DB_EXCEPTION
233 {
234  public:
235  BLOCK_DNE() : DB_EXCEPTION("The block requested does not exist") { }
236  BLOCK_DNE(const char* s) : DB_EXCEPTION(s) { }
237 };
238 
243 {
244  public:
245  BLOCK_PARENT_DNE() : DB_EXCEPTION("The parent of the block does not exist") { }
246  BLOCK_PARENT_DNE(const char* s) : DB_EXCEPTION(s) { }
247 };
248 
253 {
254  public:
255  BLOCK_EXISTS() : DB_EXCEPTION("The block to be added already exists!") { }
256  BLOCK_EXISTS(const char* s) : DB_EXCEPTION(s) { }
257 };
258 
263 {
264  public:
265  BLOCK_INVALID() : DB_EXCEPTION("The block to be added did not pass validation!") { }
266  BLOCK_INVALID(const char* s) : DB_EXCEPTION(s) { }
267 };
268 
272 class TX_DNE : public DB_EXCEPTION
273 {
274  public:
275  TX_DNE() : DB_EXCEPTION("The transaction requested does not exist") { }
276  TX_DNE(const char* s) : DB_EXCEPTION(s) { }
277 };
278 
282 class TX_EXISTS : public DB_EXCEPTION
283 {
284  public:
285  TX_EXISTS() : DB_EXCEPTION("The transaction to be added already exists!") { }
286  TX_EXISTS(const char* s) : DB_EXCEPTION(s) { }
287 };
288 
292 class OUTPUT_DNE : public DB_EXCEPTION
293 {
294  public:
295  OUTPUT_DNE() : DB_EXCEPTION("The output requested does not exist!") { }
296  OUTPUT_DNE(const char* s) : DB_EXCEPTION(s) { }
297 };
298 
303 {
304  public:
305  OUTPUT_EXISTS() : DB_EXCEPTION("The output to be added already exists!") { }
306  OUTPUT_EXISTS(const char* s) : DB_EXCEPTION(s) { }
307 };
308 
313 {
314  public:
315  KEY_IMAGE_EXISTS() : DB_EXCEPTION("The spent key image to be added already exists!") { }
316  KEY_IMAGE_EXISTS(const char* s) : DB_EXCEPTION(s) { }
317 };
318 
319 /***********************************
320  * End of Exception Definitions
321  ***********************************/
322 
323 
337 {
338 private:
339  /*********************************************************************
340  * private virtual members
341  *********************************************************************/
342 
359  virtual void add_block( const block& blk
360  , const size_t& block_size
361  , const difficulty_type& cumulative_difficulty
362  , const uint64_t& coins_generated
363  , const crypto::hash& blk_hash
364  ) = 0;
365 
376  virtual void remove_block() = 0;
377 
397  virtual uint64_t add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash) = 0;
398 
415  virtual void remove_transaction_data(const crypto::hash& tx_hash, const transaction& tx) = 0;
416 
443  virtual uint64_t 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) = 0;
444 
458  virtual void add_tx_amount_output_indices(const uint64_t tx_id, const std::vector<uint64_t>& amount_output_indices) = 0;
459 
470  virtual void add_spent_key(const crypto::key_image& k_image) = 0;
471 
482  virtual void remove_spent_key(const crypto::key_image& k_image) = 0;
483 
484 
485  /*********************************************************************
486  * private concrete members
487  *********************************************************************/
494  void pop_block();
495 
496  // helper function to remove transaction from blockchain
504  void remove_transaction(const crypto::hash& tx_hash);
505 
506  uint64_t num_calls = 0;
507  uint64_t time_blk_hash = 0;
508  uint64_t time_add_block1 = 0;
509  uint64_t time_add_transaction = 0;
510 
511 
512 protected:
513 
524  void add_transaction(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash* tx_hash_ptr = NULL);
525 
526  mutable uint64_t time_tx_exists = 0;
527  uint64_t time_commit1 = 0;
528  bool m_auto_remove_logs = true;
529 
531 
532 public:
533 
537  virtual ~BlockchainDB() { };
538 
542  void reset_stats();
543 
550  void show_stats();
551 
575  virtual void open(const std::string& filename, const int db_flags = 0) = 0;
576 
582  bool is_open() const;
583 
594  virtual void close() = 0;
595 
607  virtual void sync() = 0;
608 
614  virtual void safesyncmode(const bool onoff) = 0;
615 
626  virtual void reset() = 0;
627 
637  virtual std::vector<std::string> get_filenames() const = 0;
638 
639  // return the name of the folder the db's file(s) should reside in
648  virtual std::string get_db_name() const = 0;
649 
650 
651  // FIXME: these are just for functionality mocking, need to implement
652  // RAII-friendly and multi-read one-write friendly locking mechanism
653  //
654  // acquire db lock
670  virtual bool lock() = 0;
671 
672  // release db lock
683  virtual void unlock() = 0;
684 
704  virtual bool batch_start(uint64_t batch_num_blocks=0) = 0;
705 
719  virtual void batch_stop() = 0;
720 
736  virtual void set_batch_transactions(bool) = 0;
737 
738  virtual void block_txn_start(bool readonly=false) = 0;
739  virtual void block_txn_stop() = 0;
740  virtual void block_txn_abort() = 0;
741 
742  virtual void set_hard_fork(HardFork* hf);
743 
744  // adds a block with the given metadata to the top of the blockchain, returns the new height
765  virtual uint64_t add_block( const block& blk
766  , const size_t& block_size
767  , const difficulty_type& cumulative_difficulty
768  , const uint64_t& coins_generated
769  , const std::vector<transaction>& txs
770  );
771 
780  virtual bool block_exists(const crypto::hash& h, uint64_t *height = NULL) const = 0;
781 
793  virtual cryptonote::blobdata get_block_blob(const crypto::hash& h) const = 0;
794 
806  virtual block get_block(const crypto::hash& h) const;
807 
819  virtual uint64_t get_block_height(const crypto::hash& h) const = 0;
820 
833  virtual block_header get_block_header(const crypto::hash& h) const = 0;
834 
847  virtual cryptonote::blobdata get_block_blob_from_height(const uint64_t& height) const = 0;
848 
859  virtual block get_block_from_height(const uint64_t& height) const;
860 
873  virtual uint64_t get_block_timestamp(const uint64_t& height) const = 0;
874 
882  virtual uint64_t get_top_block_timestamp() const = 0;
883 
896  virtual size_t get_block_size(const uint64_t& height) const = 0;
897 
910  virtual difficulty_type get_block_cumulative_difficulty(const uint64_t& height) const = 0;
911 
924  virtual difficulty_type get_block_difficulty(const uint64_t& height) const = 0;
925 
938  virtual uint64_t get_block_already_generated_coins(const uint64_t& height) const = 0;
939 
952  virtual crypto::hash get_block_hash_from_height(const uint64_t& height) const = 0;
953 
969  virtual std::vector<block> get_blocks_range(const uint64_t& h1, const uint64_t& h2) const = 0;
970 
986  virtual std::vector<crypto::hash> get_hashes_range(const uint64_t& h1, const uint64_t& h2) const = 0;
987 
995  virtual crypto::hash top_block_hash() const = 0;
996 
1004  virtual block get_top_block() const = 0;
1005 
1013  virtual uint64_t height() const = 0;
1014 
1015 
1036  virtual void pop_block(block& blk, std::vector<transaction>& txs);
1037 
1038 
1050  virtual bool tx_exists(const crypto::hash& h) const = 0;
1051  virtual bool tx_exists(const crypto::hash& h, uint64_t& tx_id) const = 0;
1052 
1053  // return unlock time of tx with hash <h>
1066  virtual uint64_t get_tx_unlock_time(const crypto::hash& h) const = 0;
1067 
1068  // return tx with hash <h>
1069  // throw if no such tx exists
1079  virtual transaction get_tx(const crypto::hash& h) const;
1080 
1090  virtual bool get_tx(const crypto::hash& h, transaction &tx) const;
1091 
1104  virtual bool get_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const = 0;
1105 
1114  virtual uint64_t get_tx_count() const = 0;
1115 
1131  virtual std::vector<transaction> get_tx_list(const std::vector<crypto::hash>& hlist) const = 0;
1132 
1133  // returns height of block that contains transaction with hash <h>
1146  virtual uint64_t get_tx_block_height(const crypto::hash& h) const = 0;
1147 
1148  // returns the total number of outputs of amount <amount>
1162  virtual uint64_t get_num_outputs(const uint64_t& amount) const = 0;
1163 
1169  virtual uint64_t get_indexing_base() const { return 0; }
1170 
1187  virtual output_data_t get_output_key(const uint64_t& amount, const uint64_t& index) = 0;
1188 
1204  virtual output_data_t get_output_key(const uint64_t& global_index) const = 0;
1205 
1216  virtual tx_out_index get_output_tx_and_index_from_global(const uint64_t& index) const = 0;
1217 
1230  virtual tx_out_index get_output_tx_and_index(const uint64_t& amount, const uint64_t& index) const = 0;
1231 
1243  virtual void get_output_tx_and_index(const uint64_t& amount, const std::vector<uint64_t> &offsets, std::vector<tx_out_index> &indices) const = 0;
1244 
1256  virtual void get_output_key(const uint64_t &amount, const std::vector<uint64_t> &offsets, std::vector<output_data_t> &outputs, bool allow_partial = false) = 0;
1257 
1258  /*
1259  * FIXME: Need to check with git blame and ask what this does to
1260  * document it
1261  */
1262  virtual bool can_thread_bulk_indices() const = 0;
1263 
1278  virtual std::vector<uint64_t> get_tx_amount_output_indices(const uint64_t tx_id) const = 0;
1279 
1287  virtual bool has_key_image(const crypto::key_image& img) const = 0;
1288 
1294  virtual void add_txpool_tx(const transaction &tx, const txpool_tx_meta_t& details) = 0;
1295 
1302  virtual void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t& details) = 0;
1303 
1307  virtual uint64_t get_txpool_tx_count() const = 0;
1308 
1312  virtual bool txpool_has_tx(const crypto::hash &txid) const = 0;
1313 
1319  virtual void remove_txpool_tx(const crypto::hash& txid) = 0;
1320 
1328  virtual txpool_tx_meta_t get_txpool_tx_meta(const crypto::hash& txid) const = 0;
1329 
1338  virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const = 0;
1339 
1347  virtual cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const = 0;
1348 
1362  virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false) const = 0;
1363 
1377  virtual bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const = 0;
1378 
1397  virtual bool for_blocks_range(const uint64_t& h1, const uint64_t& h2, std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const = 0;
1398 
1415  virtual bool for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)>) const = 0;
1416 
1434  virtual bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const = 0;
1435 
1436 
1437  //
1438  // Hard fork related storage
1439  //
1440 
1447  virtual void set_hard_fork_version(uint64_t height, uint8_t version) = 0;
1448 
1456  virtual uint8_t get_hard_fork_version(uint64_t height) const = 0;
1457 
1461  virtual void check_hard_fork_info() = 0;
1462 
1466  virtual void drop_hard_fork_info() = 0;
1467 
1477  virtual std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> get_output_histogram(const std::vector<uint64_t> &amounts, bool unlocked, uint64_t recent_cutoff) const = 0;
1478 
1484  virtual bool is_read_only() const = 0;
1485 
1494  void set_auto_remove_logs(bool auto_remove) { m_auto_remove_logs = auto_remove; }
1495 
1496  bool m_open;
1497  mutable epee::critical_section m_synchronization_lock;
1498 
1499 }; // class BlockchainDB
1500 
1501 BlockchainDB *new_db(const std::string& db_type);
1502 
1503 } // namespace cryptonote
1504 
1505 #endif // BLOCKCHAIN_DB_H
DB_SYNC_FAILURE(const char *s)
Definition: blockchain_db.h:226
thrown when creating the BlockchainDB fails
Definition: blockchain_db.h:212
uint64_t tx_id
Definition: blockchain_db.h:122
DB_CREATE_FAILURE(const char *s)
Definition: blockchain_db.h:216
virtual void reset()=0
Remove everything from the BlockchainDB.
virtual std::string get_db_name() const =0
gets the name of the folder the BlockchainDB's file(s) should be in
Definition: blockchain_db.h:120
void reset_stats()
reset profiling stats
Definition: blockchain_db.cpp:292
OUTPUT_EXISTS(const char *s)
Definition: blockchain_db.h:306
virtual uint64_t get_indexing_base() const
return index of the first element (should be hidden, but isn't)
Definition: blockchain_db.h:1169
const char * what() const
Definition: blockchain_db.h:173
virtual uint64_t 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)=0
store an output
void pop_block()
private version of pop_block, for undoing if an add_block fails
Definition: blockchain_db.cpp:93
thrown when a transaction exists, but shouldn't, namely when adding a block
Definition: blockchain_db.h:282
virtual bool has_key_image(const crypto::key_image &img) const =0
check if a key image is stored as spent
virtual std::vector< uint64_t > get_tx_amount_output_indices(const uint64_t tx_id) const =0
gets output indices (amount-specific) for a transaction's outputs
thrown when opening the BlockchainDB fails
Definition: blockchain_db.h:202
virtual void drop_hard_fork_info()=0
delete hard fork info from database
DB_ERROR()
Definition: blockchain_db.h:185
thrown when a spent key image exists, but shouldn't, namely when adding a block
Definition: blockchain_db.h:312
virtual crypto::hash get_block_hash_from_height(const uint64_t &height) const =0
fetch a block's hash
crypto::hash max_used_block_id
Definition: blockchain_db.h:133
virtual txpool_tx_meta_t get_txpool_tx_meta(const crypto::hash &txid) const =0
get a txpool transaction's metadata
DB_ERROR(const char *s)
Definition: blockchain_db.h:186
virtual uint64_t get_tx_count() const =0
fetches the total number of transactions ever
virtual uint64_t get_tx_block_height(const crypto::hash &h) const =0
fetches the height of a transaction's block
virtual uint64_t get_block_height(const crypto::hash &h) const =0
gets the height of the block with a given hash
Definition: cryptonote_basic.h:372
Definition: cryptonote_basic.h:355
virtual void add_tx_amount_output_indices(const uint64_t tx_id, const std::vector< uint64_t > &amount_output_indices)=0
store amount output indices for a tx's outputs
A base class for BlockchainDB exceptions.
Definition: blockchain_db.h:162
virtual std::vector< transaction > get_tx_list(const std::vector< crypto::hash > &hlist) const =0
fetches a list of transactions based on their hashes
virtual difficulty_type get_block_cumulative_difficulty(const uint64_t &height) const =0
fetch a block's cumulative difficulty
virtual void safesyncmode(const bool onoff)=0
toggle safe syncs for the DB
virtual void add_block(const block &blk, const size_t &block_size, const difficulty_type &cumulative_difficulty, const uint64_t &coins_generated, const crypto::hash &blk_hash)=0
add the block and metadata to the db
uint64_t blob_size
Definition: blockchain_db.h:135
thrown when a requested block does not exist
Definition: blockchain_db.h:232
uint8_t do_not_relay
Definition: blockchain_db.h:144
virtual void unlock()=0
This function releases the BlockchainDB lock.
Definition: hardfork.h:39
DB_ERROR_TXN_START(const char *s)
Definition: blockchain_db.h:196
BLOCK_EXISTS(const char *s)
Definition: blockchain_db.h:256
virtual void set_hard_fork_version(uint64_t height, uint8_t version)=0
sets which hardfork version a height is on
virtual void add_spent_key(const crypto::key_image &k_image)=0
store a spent key
thrown when an output exists, but shouldn't, namely when adding a block
Definition: blockchain_db.h:302
virtual void remove_transaction_data(const crypto::hash &tx_hash, const transaction &tx)=0
remove data about a transaction
BLOCK_DNE()
Definition: blockchain_db.h:235
virtual transaction get_tx(const crypto::hash &h) const
fetches the transaction with the given hash
Definition: blockchain_db.cpp:284
uint64_t block_id
Definition: blockchain_db.h:124
virtual void sync()=0
sync the BlockchainDB with disk
virtual void remove_spent_key(const crypto::key_image &k_image)=0
remove a spent key
BLOCK_PARENT_DNE()
Definition: blockchain_db.h:245
virtual std::map< uint64_t, std::tuple< uint64_t, uint64_t, uint64_t > > get_output_histogram(const std::vector< uint64_t > &amounts, bool unlocked, uint64_t recent_cutoff) const =0
return a histogram of outputs on the blockchain
A generic BlockchainDB exception.
Definition: blockchain_db.h:182
virtual bool get_txpool_tx_blob(const crypto::hash &txid, cryptonote::blobdata &bd) const =0
get a txpool transaction's blob
uint64_t receive_time
Definition: blockchain_db.h:139
virtual crypto::hash top_block_hash() const =0
fetch the top block's hash
virtual std::vector< crypto::hash > get_hashes_range(const uint64_t &h1, const uint64_t &h2) const =0
fetch a list of block hashes
uint64_t num_calls
a performance metric
Definition: blockchain_db.h:506
virtual bool lock()=0
acquires the BlockchainDB lock
virtual bool for_all_transactions(std::function< bool(const crypto::hash &, const cryptonote::transaction &)>) const =0
runs a function over all transactions stored
KEY_IMAGE_EXISTS()
Definition: blockchain_db.h:315
TX_EXISTS()
Definition: blockchain_db.h:285
Holds cryptonote related classes and helpers.
Definition: db_bdb.cpp:225
virtual bool batch_start(uint64_t batch_num_blocks=0)=0
tells the BlockchainDB to start a new "batch" of blocks
virtual uint64_t get_block_already_generated_coins(const uint64_t &height) const =0
fetch a block's already generated coins
uint64_t fee
Definition: blockchain_db.h:136
virtual void block_txn_abort()=0
virtual void set_hard_fork(HardFork *hf)
Definition: blockchain_db.cpp:213
BLOCK_INVALID()
Definition: blockchain_db.h:265
virtual uint64_t get_top_block_timestamp() const =0
fetch the top block's timestamp
BlockchainDB * new_db(const std::string &db_type)
Definition: blockchain_db.cpp:82
virtual uint64_t height() const =0
fetch the current blockchain height
void add_transaction(const crypto::hash &blk_hash, const transaction &tx, const crypto::hash *tx_hash_ptr=NULL)
helper function for add_transactions, to add each individual transaction
Definition: blockchain_db.cpp:100
virtual ~BlockchainDB()
An empty destructor.
Definition: blockchain_db.h:537
virtual void close()=0
close the BlockchainDB
virtual void remove_txpool_tx(const crypto::hash &txid)=0
remove a txpool transaction
uint64_t time_add_transaction
a performance metric
Definition: blockchain_db.h:509
virtual bool tx_exists(const crypto::hash &h) const =0
check if a transaction with a given hash exists
virtual cryptonote::blobdata get_block_blob(const crypto::hash &h) const =0
fetches the block with the given hash
DB_OPEN_FAILURE(const char *s)
Definition: blockchain_db.h:206
virtual void set_batch_transactions(bool)=0
sets whether or not to batch transactions
bool is_open() const
Gets the current open/ready state of the BlockchainDB.
Definition: blockchain_db.cpp:232
crypto::public_key pubkey
the output's public key (for spend verification)
Definition: blockchain_db.h:112
uint64_t last_failed_height
Definition: blockchain_db.h:138
void set_auto_remove_logs(bool auto_remove)
set whether or not to automatically remove logs
Definition: blockchain_db.h:1494
Definition: rctTypes.h:82
virtual bool for_all_txpool_txes(std::function< bool(const crypto::hash &, const txpool_tx_meta_t &, const cryptonote::blobdata *)>, bool include_blob=false) const =0
runs a function over all txpool transactions
uint64_t last_relayed_time
Definition: blockchain_db.h:140
uint64_t unlock_time
Definition: blockchain_db.h:123
uint64_t height
the height of the block which created the output
Definition: blockchain_db.h:114
std::string m
Definition: blockchain_db.h:165
virtual uint64_t get_block_timestamp(const uint64_t &height) const =0
fetch a block's timestamp
thrown when there is an error starting a DB transaction
Definition: blockchain_db.h:192
virtual void block_txn_start(bool readonly=false)=0
virtual block get_block_from_height(const uint64_t &height) const
fetch a block by height
Definition: blockchain_db.cpp:253
virtual bool txpool_has_tx(const crypto::hash &txid) const =0
check whether a txid is in the txpool
virtual uint64_t add_transaction_data(const crypto::hash &blk_hash, const transaction &tx, const crypto::hash &tx_hash)=0
store the transaction and its metadata
POD_CLASS public_key
Definition: crypto.h:58
virtual uint64_t get_tx_unlock_time(const crypto::hash &h) const =0
fetch a transaction's unlock time/height
virtual uint64_t get_num_outputs(const uint64_t &amount) const =0
fetches the number of outputs of a given amount
rct::key commitment
the output's amount commitment (for spend verification)
Definition: blockchain_db.h:115
virtual void batch_stop()=0
ends a batch transaction
DB_OPEN_FAILURE()
Definition: blockchain_db.h:205
virtual output_data_t get_output_key(const uint64_t &amount, const uint64_t &index)=0
get some of an output's data
virtual bool for_blocks_range(const uint64_t &h1, const uint64_t &h2, std::function< bool(uint64_t, const crypto::hash &, const cryptonote::block &)>) const =0
runs a function over a range of blocks
uint8_t version
Definition: blockchain.cpp:86
virtual ~DB_EXCEPTION()
Definition: blockchain_db.h:171
std::string blobdata
Definition: blobdatatype.h:36
thrown when a requested transaction does not exist
Definition: blockchain_db.h:272
uint64_t max_used_block_height
Definition: blockchain_db.h:137
BLOCK_DNE(const char *s)
Definition: blockchain_db.h:236
OUTPUT_EXISTS()
Definition: blockchain_db.h:305
virtual bool can_thread_bulk_indices() const =0
OUTPUT_DNE(const char *s)
Definition: blockchain_db.h:296
DB_EXCEPTION(const char *s)
Definition: blockchain_db.h:168
virtual void open(const std::string &filename, const int db_flags=0)=0
open a db, or create it if necessary.
KEY_IMAGE_EXISTS(const char *s)
Definition: blockchain_db.h:316
virtual void remove_block()=0
remove data about the top block
BLOCK_INVALID(const char *s)
Definition: blockchain_db.h:266
std::uint64_t difficulty_type
Definition: difficulty.h:41
void remove_transaction(const crypto::hash &tx_hash)
helper function to remove transaction from the blockchain
Definition: blockchain_db.cpp:237
virtual uint64_t get_txpool_tx_count() const =0
get the number of transactions in the txpool
virtual bool get_tx_blob(const crypto::hash &h, cryptonote::blobdata &tx) const =0
fetches the transaction blob with the given hash
POD_CLASS key_image
Definition: crypto.h:86
a struct containing txpool per transaction metadata
Definition: blockchain_db.h:131
DB_SYNC_FAILURE()
Definition: blockchain_db.h:225
TX_DNE(const char *s)
Definition: blockchain_db.h:276
TX_DNE()
Definition: blockchain_db.h:275
thrown when a block's parent does not exist (and it needed to)
Definition: blockchain_db.h:242
crypto::hash last_failed_id
Definition: blockchain_db.h:134
void show_stats()
show profiling stats
Definition: blockchain_db.cpp:302
bool m_auto_remove_logs
whether or not to automatically remove old logs
Definition: blockchain_db.h:528
DB_CREATE_FAILURE()
Definition: blockchain_db.h:215
virtual void add_txpool_tx(const transaction &tx, const txpool_tx_meta_t &details)=0
add a txpool transaction
TX_EXISTS(const char *s)
Definition: blockchain_db.h:286
virtual void check_hard_fork_info()=0
verify hard fork info in database
epee::critical_section m_synchronization_lock
A lock, currently for when BlockchainLMDB needs to resize the backing db file.
Definition: blockchain_db.h:1497
The BlockchainDB backing store interface declaration/contract.
Definition: blockchain_db.h:336
virtual bool for_all_key_images(std::function< bool(const crypto::key_image &)>) const =0
runs a function over all key images stored
virtual block_header get_block_header(const crypto::hash &h) const =0
fetch a block header
HardFork * m_hardfork
Definition: blockchain_db.h:530
uint64_t time_tx_exists
a performance metric
Definition: blockchain_db.h:526
uint8_t kept_by_block
Definition: blockchain_db.h:142
virtual difficulty_type get_block_difficulty(const uint64_t &height) const =0
fetch a block's difficulty
uint64_t time_blk_hash
a performance metric
Definition: blockchain_db.h:507
POD_CLASS hash
Definition: hash.h:46
virtual block get_block(const crypto::hash &h) const
fetches the block with the given hash
Definition: blockchain_db.cpp:263
virtual cryptonote::blobdata get_block_blob_from_height(const uint64_t &height) const =0
fetch a block blob by height
std::pair< crypto::hash, uint64_t > tx_out_index
Definition: blockchain_db.h:103
virtual bool block_exists(const crypto::hash &h, uint64_t *height=NULL) const =0
checks if a block exists
uint64_t time_add_block1
a performance metric
Definition: blockchain_db.h:508
uint8_t relayed
Definition: blockchain_db.h:143
virtual size_t get_block_size(const uint64_t &height) const =0
fetch a block's size
virtual void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t &details)=0
update a txpool transaction's metadata
virtual std::vector< std::string > get_filenames() const =0
get all files used by the BlockchainDB (if any)
OUTPUT_DNE()
Definition: blockchain_db.h:295
Definition: cryptonote_basic.h:149
BLOCK_PARENT_DNE(const char *s)
Definition: blockchain_db.h:246
uint8_t padding[77]
Definition: blockchain_db.h:146
uint64_t unlock_time
the output's unlock time (or height)
Definition: blockchain_db.h:113
thrown when a requested output does not exist
Definition: blockchain_db.h:292
thrown when a block exists, but shouldn't, namely when adding a block
Definition: blockchain_db.h:252
thrown when something is wrong with the block to be added
Definition: blockchain_db.h:262
virtual tx_out_index get_output_tx_and_index_from_global(const uint64_t &index) const =0
gets an output's tx hash and index
thrown when synchronizing the BlockchainDB to disk fails
Definition: blockchain_db.h:222
virtual block get_top_block() const =0
fetch the top block
a struct containing output metadata
Definition: blockchain_db.h:110
Definition: cryptonote_basic.h:188
virtual bool is_read_only() const =0
is BlockchainDB in read-only mode?
virtual std::vector< block > get_blocks_range(const uint64_t &h1, const uint64_t &h2) const =0
fetch a list of blocks
#define s(x, c)
Definition: aesb.c:46
virtual tx_out_index get_output_tx_and_index(const uint64_t &amount, const uint64_t &index) const =0
gets an output's tx hash and index
bool m_open
Whether or not the BlockchainDB is open/ready for use.
Definition: blockchain_db.h:1496
BLOCK_EXISTS()
Definition: blockchain_db.h:255
virtual void block_txn_stop()=0
uint64_t time_commit1
a performance metric
Definition: blockchain_db.h:527
virtual bool for_all_outputs(std::function< bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const =0
runs a function over all outputs stored
virtual uint8_t get_hard_fork_version(uint64_t height) const =0
checks which hardfork version a height is on
DB_ERROR_TXN_START()
Definition: blockchain_db.h:195