29 #ifndef BLOCKCHAIN_DB_H 30 #define BLOCKCHAIN_DB_H 36 #include <boost/program_options.hpp> 114 #pragma pack(push, 1) 128 #pragma pack(push, 1) 189 #define DBF_FASTEST 4 191 #define DBF_SALVAGE 0x10 192 #define DBF_ADDR_TX_SALVAGE 0x20 212 const char*
what()
const throw()
426 virtual void add_block(
const block& blk
427 ,
size_t block_weight
445 virtual void remove_block() = 0;
528 virtual void add_tx_amount_output_indices(
const uint64_t tx_id,
const std::vector<uint64_t>& amount_output_indices) = 0;
531 virtual void remove_chainstate_utxo(
const crypto::hash tx_hash,
const uint32_t relative_out_index) = 0;
535 virtual void remove_tx_input(
const crypto::hash tx_hash,
const uint32_t relative_out_index) = 0;
627 static void init_options(boost::program_options::options_description& desc);
665 virtual void open(
const std::string& filename,
const int db_flags = 0) = 0;
684 virtual void close() = 0;
697 virtual void sync() = 0;
716 virtual void reset() = 0;
774 virtual bool lock() = 0;
787 virtual void unlock() = 0;
888 virtual uint64_t add_block(
const std::pair<block, blobdata>& blk
889 ,
size_t block_weight
893 ,
const std::vector<std::pair<transaction, blobdata>>& txs
1223 virtual void pop_block(
block& blk, std::vector<transaction>& txs);
1382 virtual std::vector<transaction>
get_tx_list(
const std::vector<crypto::hash>& hlist)
const = 0;
1767 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,
uint64_t min_count)
const = 0;
1790 virtual void fixup();
1866 #endif // BLOCKCHAIN_DB_H
virtual void check_hard_fork_info()=0
verify hard fork info in database
thrown when an output exists, but shouldn't, namely when adding a block
virtual bool update_pruning()=0
prunes recent blockchain changes as needed, iff pruning is enabled
bool is_coinbase(const transaction &tx)
virtual bool get_tx_blob(const crypto::hash &h, cryptonote::blobdata &tx) const =0
fetches the transaction blob with the given hash
virtual uint64_t get_tx_block_height(const crypto::hash &h) const =0
fetches the height of a transaction's block
virtual std::string get_db_name() const =0
gets the name of the folder the BlockchainDB's file(s) should be in
virtual void set_hard_fork_version(uint64_t height, uint8_t version)=0
sets which hardfork version a height is on
BlockchainDB()
An empty constructor.
thrown when a utxo already exists, but shouldn't, namely when adding a block
virtual cryptonote::blobdata get_block_blob_from_height(const uint64_t &height) const =0
fetch a block blob by height
DB_EXCEPTION(const char *s)
ADDR_TX_EXISTS(const char *s)
virtual std::vector< address_outputs > get_addr_output_batch(const crypto::public_key &combined_key, uint64_t start_db_index=0, uint64_t batch_size=100, bool desc=false)=0
db_wtxn_guard(BlockchainDB *db)
virtual void batch_abort()=0
aborts a batch transaction
virtual bool has_key_image(const crypto::key_image &img) const =0
check if a key image is stored as spent
virtual bool get_txpool_tx_blob(const crypto::hash &txid, cryptonote::blobdata &bd) const =0
get a txpool transaction's blob
virtual std::vector< block > get_blocks_range(const uint64_t &h1, const uint64_t &h2) const =0
fetch a list of blocks
virtual uint64_t get_block_timestamp(const uint64_t &height) const =0
fetch a block's timestamp
DB_OPEN_FAILURE(const char *s)
DB_SYNC_FAILURE(const char *s)
thrown when a block exists, but shouldn't, namely when adding a block
virtual crypto::hash get_block_hash_from_height(const uint64_t &height) const =0
fetch a block's hash
virtual void add_txpool_tx(const crypto::hash &txid, const cryptonote::blobdata &blob, const txpool_tx_meta_t &details)=0
add a txpool transaction
thrown when a transaction exists, but shouldn't, namely when adding a block
virtual uint64_t get_block_height(const crypto::hash &h) const =0
gets the height of the block with a given hash
epee::critical_section m_synchronization_lock
A lock, currently for when BlockchainLMDB needs to resize the backing db file.
virtual uint64_t get_database_size() const =0
get disk space requirements
OUTPUT_DNE(const char *s)
virtual uint64_t get_balance(const crypto::public_key &combined_key)=0
thrown when there is an error starting a DB transaction
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
const command_line::arg_descriptor< std::string > arg_db_sync_mode
virtual std::vector< address_txs > get_addr_tx_all(const crypto::public_key &combined_key)=0
virtual bool tx_exists(const crypto::hash &h) const =0
check if a transaction with a given hash exists
virtual void remove_addr_tx(const crypto::hash tx_hash, const crypto::public_key &combined_key)=0
virtual bool remove_data_file(const std::string &folder) const =0
remove file(s) storing the database
Non-owning sequence of data. Does not deep copy.
virtual difficulty_type get_block_cumulative_difficulty(const uint64_t &height) const =0
fetch a block's cumulative difficulty
uint32_t relative_out_index
virtual tx_input_t get_tx_input(const crypto::hash tx_hash, const uint32_t relative_out_index)=0
virtual bool for_all_txpool_txes(std::function< bool(const crypto::hash &, const txpool_tx_meta_t &, const cryptonote::blobdata *)>, bool include_blob=false, bool include_unrelayed_txes=true) const =0
runs a function over all txpool transactions
virtual void safesyncmode(const bool onoff)=0
toggle safe syncs for the DB
virtual std::vector< std::string > get_filenames() const =0
get all files used by the BlockchainDB (if any)
virtual void set_batch_transactions(bool)=0
sets whether or not to batch transactions
thrown when a block's parent does not exist (and it needed to)
virtual bool for_all_transactions(std::function< bool(const crypto::hash &, const cryptonote::transaction &)>, bool pruned) const =0
runs a function over all transactions stored
virtual uint64_t get_num_outputs(const uint64_t &amount) const =0
fetches the number of outputs of a given amount
virtual void add_max_block_size(uint64_t sz)=0
add a new max block size
virtual void open(const std::string &filename, const int db_flags=0)=0
open a db, or create it if necessary.
bool m_auto_remove_logs
whether or not to automatically remove old logs
virtual std::vector< address_txs > get_addr_tx_batch(const crypto::public_key &combined_key, uint64_t start_db_index=0, uint64_t batch_size=100, bool desc=false)=0
virtual bool get_pruned_tx_blob(const crypto::hash &h, cryptonote::blobdata &tx) const =0
fetches the pruned transaction blob with the given hash
void add_transaction(const crypto::hash &blk_hash, const std::pair< transaction, blobdata > &tx, const crypto::hash *tx_hash_ptr=NULL, const crypto::hash *tx_prunable_hash_ptr=NULL)
helper function for add_transactions, to add each individual transaction
virtual void block_rtxn_abort() const =0
virtual uint64_t get_max_block_size()=0
get the max block size
virtual uint64_t get_indexing_base() const
return index of the first element (should be hidden, but isn't)
virtual bool get_prunable_tx_blob(const crypto::hash &h, cryptonote::blobdata &tx) const =0
fetches the prunable transaction blob with the given hash
virtual void close()=0
close the BlockchainDB
virtual std::vector< address_outputs > get_addr_output_all(const crypto::public_key &combined_key)=0
virtual uint64_t get_txpool_tx_count(bool include_unrelayed_txes=true) const =0
get the number of transactions in the txpool
thrown when a requested transaction does not exist
thrown when a spent key image exists, but shouldn't, namely when adding a block
virtual void block_wtxn_abort()=0
Holds cryptonote related classes and helpers.
db_rtxn_guard(BlockchainDB *db)
void show_stats()
show profiling stats
virtual bool check_chainstate_utxo(const crypto::hash tx_hash, const uint32_t relative_out_index)=0
virtual void set_block_cumulative_difficulty(uint64_t height, difficulty_type diff)=0
sets a block's cumulative difficulty
ADDR_OUTPUT_EXISTS(const char *s)
virtual size_t get_block_weight(const uint64_t &height) const =0
fetch a block's weight
virtual std::vector< uint64_t > get_block_weights(uint64_t start_height, size_t count) const =0
fetch the last N blocks' weights
mdb_size_t count(MDB_cursor *cur)
DB_CREATE_FAILURE(const char *s)
virtual output_data_t get_output_key(const uint64_t &amount, const uint64_t &index, bool include_commitmemt=true) const =0
get some of an output's data
BlockchainDB * new_db(const std::string &db_type)
virtual bool for_all_outputs(std::function< bool(uint64_t amount, const crypto::hash &tx_hash, uint64_t height, size_t tx_idx)> f) const =0
runs a function over all outputs stored
thrown when something is wrong with the block to be added
virtual block get_block_from_height(const uint64_t &height) const
fetch a block by height
virtual bool get_prunable_tx_hash(const crypto::hash &tx_hash, crypto::hash &prunable_hash) const =0
fetches the prunable transaction hash
uint64_t time_tx_exists
a performance metric
virtual std::vector< std::vector< uint64_t > > get_tx_amount_output_indices(const uint64_t tx_id, size_t n_txes=1) const =0
gets output indices (amount-specific) for a transaction's outputs
virtual void prune_outputs(uint64_t amount)=0
prune output data for the given amount
virtual bool is_read_only() const =0
is BlockchainDB in read-only mode?
virtual bool can_thread_bulk_indices() const =0
A base class for BlockchainDB exceptions.
crypto::public_key pubkey
the output's public key (for spend verification)
virtual transaction get_tx(const crypto::hash &h) const
fetches the transaction with the given hash
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, uint64_t min_count) const =0
return a histogram of outputs on the blockchain
unsigned __int64 uint64_t
OUTPUT_EXISTS(const char *s)
void set_auto_remove_logs(bool auto_remove)
set whether or not to automatically remove logs
virtual block get_top_block() const =0
fetch the top block
virtual void sync()=0
sync the BlockchainDB with disk
virtual void block_rtxn_stop() const =0
uint64_t height
the height of the block which created the output
virtual uint64_t height() const =0
fetch the current blockchain height
virtual void batch_stop()=0
ends a batch transaction
virtual uint64_t get_tx_unlock_time(const crypto::hash &h) const =0
fetch a transaction's unlock time/height
virtual std::vector< uint64_t > get_long_term_block_weights(uint64_t start_height, size_t count) const =0
fetch the last N blocks' long term weights
virtual bool block_exists(const crypto::hash &h, uint64_t *height=NULL) const =0
checks if a block exists
virtual transaction get_pruned_tx(const crypto::hash &h) const
fetches the transaction base with the given hash
virtual void block_wtxn_start()=0
thrown when synchronizing the BlockchainDB to disk fails
virtual bool for_all_key_images(std::function< bool(const crypto::key_image &)>) const =0
runs a function over all key images stored
virtual void add_addr_tx(const crypto::hash tx_hash, const crypto::public_key &combined_key)=0
thrown when a requested block does not exist
virtual void remove_txpool_tx(const crypto::hash &txid)=0
remove a txpool transaction
bool m_open
Whether or not the BlockchainDB is open/ready for use.
const command_line::arg_descriptor< std::string > arg_db_type
version
Supported socks variants.
rct::key commitment
the output's amount commitment (for spend verification)
virtual bool get_output_distribution(uint64_t amount, uint64_t from_height, uint64_t to_height, std::vector< uint64_t > &distribution, uint64_t &base) const =0
bool is_open() const
Gets the current open/ready state of the BlockchainDB.
virtual void set_hard_fork(HardFork *hf)
virtual difficulty_type get_block_difficulty(const uint64_t &height) const =0
fetch a block's difficulty
KEY_IMAGE_EXISTS(const char *s)
BLOCK_INVALID(const char *s)
A generic BlockchainDB exception.
The BlockchainDB backing store interface declaration/contract.
virtual void drop_hard_fork_info()=0
delete hard fork info from database
virtual uint64_t get_utxo_unlock_time(const crypto::hash tx_hash, const uint32_t relative_out_index)=0
virtual bool prune_blockchain(uint32_t pruning_seed=0)=0
prunes the blockchain
boost::multiprecision::uint128_t difficulty_type
virtual crypto::hash top_block_hash(uint64_t *block_height=NULL) const =0
fetch the top block's hash
virtual bool lock()=0
acquires the BlockchainDB lock
virtual void set_validator_list(std::string, uint32_t expiration_date)=0
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
const command_line::arg_descriptor< bool > arg_addr_db_salvage
thrown when creating the BlockchainDB fails
virtual void unlock()=0
This function releases the BlockchainDB lock.
virtual void fixup()
fix up anything that may be wrong due to past bugs
const command_line::arg_descriptor< bool > arg_db_salvage
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
BLOCK_PARENT_DNE(const char *s)
virtual uint64_t get_tx_count() const =0
fetches the total number of transactions ever
static void init_options(boost::program_options::options_description &desc)
init command line options
virtual bool check_pruning()=0
checks pruning was done correctly, iff enabled
virtual void block_wtxn_stop()=0
virtual std::vector< transaction > get_tx_list(const std::vector< crypto::hash > &hlist) const =0
fetches a list of transactions based on their hashes
thrown when a requested output does not exist
virtual block_header get_block_header(const crypto::hash &h) const =0
fetch a block header
virtual std::vector< crypto::hash > get_hashes_range(const uint64_t &h1, const uint64_t &h2) const =0
fetch a list of block hashes
std::pair< crypto::hash, uint64_t > tx_out_index
virtual std::string get_validator_list() const =0
uint64_t time_commit1
a performance metric
virtual uint64_t get_block_already_generated_coins(const uint64_t &height) const =0
fetch a block's already generated coins
thrown when opening the BlockchainDB fails
crypto::public_key combined_key
uint64_t unlock_time
the output's unlock time (or height)
thrown when an output record for an address already exists, but shouldn't, namely when adding a block...
virtual void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t &details)=0
update a txpool transaction's metadata
virtual ~BlockchainDB()
An empty destructor.
virtual bool get_txpool_tx_meta(const crypto::hash &txid, txpool_tx_meta_t &meta) const =0
get a txpool transaction's metadata
virtual void reset()=0
Remove everything from the BlockchainDB.
db_txn_guard(BlockchainDB *db, bool readonly)
DB_ERROR_TXN_START(const char *s)
BLOCK_EXISTS(const char *s)
virtual uint32_t get_blockchain_pruning_seed() const =0
get the blockchain pruning seed
virtual block get_block(const crypto::hash &h) const
fetches the block with the given hash
virtual uint64_t get_top_block_timestamp() const =0
fetch the top block's timestamp
a struct containing output metadata
virtual bool txpool_has_tx(const crypto::hash &txid) const =0
check whether a txid is in the txpool
virtual uint64_t get_block_long_term_weight(const uint64_t &height) const =0
fetch a block's long term weight
const char * what() const
virtual cryptonote::blobdata get_block_blob(const crypto::hash &h) const =0
fetches the block with the given hash
virtual bool block_rtxn_start() const =0
void reset_stats()
reset profiling stats
virtual uint8_t get_hard_fork_version(uint64_t height) const =0
checks which hardfork version a height is on
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
virtual std::vector< uint64_t > get_block_cumulative_rct_outputs(const std::vector< uint64_t > &heights) const =0
fetch a block's cumulative number of rct outputs
UTXO_EXISTS(const char *s)