29 #ifndef BLOCKCHAIN_DB_H 30 #define BLOCKCHAIN_DB_H 37 #include <boost/program_options.hpp> 111 #pragma pack(push, 1) 125 #pragma pack(push, 1) 157 #define DBF_FASTEST 4 159 #define DBF_SALVAGE 0x10 179 const char*
what()
const throw()
366 ,
const size_t& block_size
368 ,
const uint64_t& coins_generated
548 static void init_options(boost::program_options::options_description& desc);
586 virtual void open(
const std::string& filename,
const int db_flags = 0) = 0;
605 virtual void close() = 0;
618 virtual void sync() = 0;
637 virtual void reset() = 0;
681 virtual bool lock() = 0;
694 virtual void unlock() = 0;
715 virtual bool batch_start(uint64_t batch_num_blocks=0, uint64_t batch_bytes=0) = 0;
777 ,
const size_t& block_size
779 ,
const uint64_t& coins_generated
780 ,
const std::vector<transaction>& txs
994 virtual std::vector<block>
get_blocks_range(
const uint64_t& h1,
const uint64_t& h2)
const = 0;
1011 virtual std::vector<crypto::hash>
get_hashes_range(
const uint64_t& h1,
const uint64_t& h2)
const = 0;
1038 virtual uint64_t
height()
const = 0;
1061 virtual void pop_block(
block& blk, std::vector<transaction>& txs);
1156 virtual std::vector<transaction>
get_tx_list(
const std::vector<crypto::hash>& hlist)
const = 0;
1268 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;
1281 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;
1507 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;
1535 #endif // BLOCKCHAIN_DB_H DB_SYNC_FAILURE(const char *s)
Definition: blockchain_db.h:232
thrown when creating the BlockchainDB fails
Definition: blockchain_db.h:218
uint64_t tx_id
Definition: blockchain_db.h:128
DB_CREATE_FAILURE(const char *s)
Definition: blockchain_db.h:222
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:126
void reset_stats()
reset profiling stats
Definition: blockchain_db.cpp:302
OUTPUT_EXISTS(const char *s)
Definition: blockchain_db.h:312
virtual uint64_t get_indexing_base() const
return index of the first element (should be hidden, but isn't)
Definition: blockchain_db.h:1194
const char * what() const
Definition: blockchain_db.h:179
virtual void set_validator_list(std::string, uint32_t expiration_date)=0
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:117
thrown when a transaction exists, but shouldn't, namely when adding a block
Definition: blockchain_db.h:288
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:208
virtual std::string get_validator_list() const =0
virtual void drop_hard_fork_info()=0
delete hard fork info from database
DB_ERROR()
Definition: blockchain_db.h:191
thrown when a spent key image exists, but shouldn't, namely when adding a block
Definition: blockchain_db.h:318
virtual crypto::hash get_block_hash_from_height(const uint64_t &height) const =0
fetch a block's hash
DB_ERROR(const char *s)
Definition: blockchain_db.h:192
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:382
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:168
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
thrown when a requested block does not exist
Definition: blockchain_db.h:238
const command_line::arg_descriptor< std::string > arg_db_sync_mode
Definition: blockchain_db.cpp:88
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:202
BLOCK_EXISTS(const char *s)
Definition: blockchain_db.h:262
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:308
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:241
virtual transaction get_tx(const crypto::hash &h) const
fetches the transaction with the given hash
Definition: blockchain_db.cpp:294
virtual bool batch_start(uint64_t batch_num_blocks=0, uint64_t batch_bytes=0)=0
tells the BlockchainDB to start a new "batch" of blocks
uint64_t block_id
Definition: blockchain_db.h:130
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:251
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:188
virtual bool get_txpool_tx_blob(const crypto::hash &txid, cryptonote::blobdata &bd) const =0
get a txpool transaction's blob
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:512
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:321
TX_EXISTS()
Definition: blockchain_db.h:291
Holds cryptonote related classes and helpers.
Definition: db_bdb.cpp:225
virtual uint64_t get_block_already_generated_coins(const uint64_t &height) const =0
fetch a block's already generated coins
virtual void block_txn_abort()=0
virtual void set_hard_fork(HardFork *hf)
Definition: blockchain_db.cpp:223
BLOCK_INVALID()
Definition: blockchain_db.h:271
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:99
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:124
virtual ~BlockchainDB()
An empty destructor.
Definition: blockchain_db.h:543
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:515
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:212
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:242
crypto::public_key pubkey
the output's public key (for spend verification)
Definition: blockchain_db.h:118
void set_auto_remove_logs(bool auto_remove)
set whether or not to automatically remove logs
Definition: blockchain_db.h:1524
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 unlock_time
Definition: blockchain_db.h:129
uint64_t height
the height of the block which created the output
Definition: blockchain_db.h:120
std::string m
Definition: blockchain_db.h:171
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:198
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:263
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
const command_line::arg_descriptor< std::string > arg_db_type
Definition: blockchain_db.cpp:83
POD_CLASS public_key
Definition: crypto.h:65
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:121
virtual void batch_stop()=0
ends a batch transaction
DB_OPEN_FAILURE()
Definition: blockchain_db.h:211
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:177
std::string blobdata
Definition: blobdatatype.h:36
thrown when a requested transaction does not exist
Definition: blockchain_db.h:278
BLOCK_DNE(const char *s)
Definition: blockchain_db.h:242
OUTPUT_EXISTS()
Definition: blockchain_db.h:311
virtual bool can_thread_bulk_indices() const =0
OUTPUT_DNE(const char *s)
Definition: blockchain_db.h:302
DB_EXCEPTION(const char *s)
Definition: blockchain_db.h:174
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:322
virtual void remove_block()=0
remove data about the top block
BLOCK_INVALID(const char *s)
Definition: blockchain_db.h:272
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:247
virtual uint64_t get_txpool_tx_count() const =0
get the number of transactions in the txpool
static void init_options(boost::program_options::options_description &desc)
init command line options
Definition: blockchain_db.cpp:110
virtual void set_block_cumulative_difficulty(uint64_t height, difficulty_type diff)=0
sets a block's cumulative difficulty
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:93
DB_SYNC_FAILURE()
Definition: blockchain_db.h:231
TX_DNE(const char *s)
Definition: blockchain_db.h:282
TX_DNE()
Definition: blockchain_db.h:281
thrown when a block's parent does not exist (and it needed to)
Definition: blockchain_db.h:248
void show_stats()
show profiling stats
Definition: blockchain_db.cpp:312
bool m_auto_remove_logs
whether or not to automatically remove old logs
Definition: blockchain_db.h:534
DB_CREATE_FAILURE()
Definition: blockchain_db.h:221
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:292
const command_line::arg_descriptor< bool > arg_db_salvage
Definition: blockchain_db.cpp:93
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:1527
The BlockchainDB backing store interface declaration/contract.
Definition: blockchain_db.h:342
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:536
virtual bool get_txpool_tx_meta(const crypto::hash &txid, txpool_tx_meta_t &meta) const =0
get a txpool transaction's metadata
uint64_t time_tx_exists
a performance metric
Definition: blockchain_db.h:532
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:513
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:273
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:105
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:514
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:301
Definition: cryptonote_basic.h:149
BLOCK_PARENT_DNE(const char *s)
Definition: blockchain_db.h:252
uint64_t unlock_time
the output's unlock time (or height)
Definition: blockchain_db.h:119
thrown when a requested output does not exist
Definition: blockchain_db.h:298
thrown when a block exists, but shouldn't, namely when adding a block
Definition: blockchain_db.h:258
thrown when something is wrong with the block to be added
Definition: blockchain_db.h:268
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:228
virtual block get_top_block() const =0
fetch the top block
a struct containing output metadata
Definition: blockchain_db.h:116
Definition: cryptonote_basic.h:198
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:1526
BLOCK_EXISTS()
Definition: blockchain_db.h:261
virtual void block_txn_stop()=0
uint64_t time_commit1
a performance metric
Definition: blockchain_db.h:533
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:201