35 #include <boost/thread/tss.hpp>
39 #define ENABLE_AUTO_RESIZE
80 #define m_cur_blocks m_cursors->m_txc_blocks
81 #define m_cur_block_heights m_cursors->m_txc_block_heights
82 #define m_cur_block_info m_cursors->m_txc_block_info
83 #define m_cur_output_txs m_cursors->m_txc_output_txs
84 #define m_cur_output_amounts m_cursors->m_txc_output_amounts
85 #define m_cur_txs m_cursors->m_txc_txs
86 #define m_cur_txs_pruned m_cursors->m_txc_txs_pruned
87 #define m_cur_txs_prunable m_cursors->m_txc_txs_prunable
88 #define m_cur_txs_prunable_hash m_cursors->m_txc_txs_prunable_hash
89 #define m_cur_txs_prunable_tip m_cursors->m_txc_txs_prunable_tip
90 #define m_cur_tx_indices m_cursors->m_txc_tx_indices
91 #define m_cur_tx_outputs m_cursors->m_txc_tx_outputs
92 #define m_cur_spent_keys m_cursors->m_txc_spent_keys
93 #define m_cur_txpool_meta m_cursors->m_txc_txpool_meta
94 #define m_cur_txpool_blob m_cursors->m_txc_txpool_blob
95 #define m_cur_hf_versions m_cursors->m_txc_hf_versions
96 #define m_cur_properties m_cursors->m_txc_properties
97 #define m_cur_validators m_cursors->m_txc_validators
98 #define m_cur_utxos m_cursors->m_txc_utxos
99 #define m_cur_addr_outputs m_cursors->m_txc_addr_outputs
100 #define m_cur_tx_inputs m_cursors->m_txc_tx_inputs
199 virtual void close();
205 virtual void reset();
273 virtual std::vector<transaction>
get_tx_list(
const std::vector<crypto::hash>& hlist)
const;
284 std::vector<tx_out_index> &tx_out_indices)
const;
315 ,
size_t block_weight
319 ,
const std::vector<std::pair<transaction, blobdata>>& txs
337 virtual void pop_block(
block& blk, std::vector<transaction>& txs);
351 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;
368 void do_resize(
uint64_t size_increase=0);
370 bool need_resize(
uint64_t threshold_size=0)
const;
371 void check_and_resize_for_batch(
uint64_t batch_num_blocks,
uint64_t batch_bytes);
375 ,
size_t block_weight
383 virtual void remove_block();
396 virtual void add_tx_amount_output_indices(
const uint64_t tx_id,
397 const std::vector<uint64_t>& amount_output_indices
404 virtual void prune_outputs(
uint64_t amount);
415 virtual void check_hard_fork_info();
416 virtual void drop_hard_fork_info();
418 inline void check_open()
const;
420 bool prune_worker(
int mode,
uint32_t pruning_seed);
422 virtual bool is_read_only()
const;
424 virtual uint64_t get_database_size()
const;
426 std::vector<uint64_t> get_block_info_64bit_fields(
uint64_t start_height,
size_t count, off_t offset)
const;
429 void add_max_block_size(
uint64_t sz);
432 virtual void fixup();
444 virtual bool check_chainstate_utxo(
const crypto::hash tx_hash,
const uint32_t relative_out_index);
446 virtual void remove_chainstate_utxo(
const crypto::hash tx_hash,
const uint32_t relative_out_index);
455 void migrate(
const uint32_t oldversion);
472 void cleanup_batch();
508 mutable unsigned int m_cum_count;
512 boost::thread::id m_writer;
514 bool m_batch_transactions;
518 mutable boost::thread_specific_ptr<mdb_threadinfo> m_tinfo;
522 constexpr
static uint64_t DEFAULT_MAPSIZE = 1LL << 31;
524 #if defined(ENABLE_AUTO_RESIZE)
525 constexpr
static uint64_t DEFAULT_MAPSIZE = 1LL << 30;
527 constexpr
static uint64_t DEFAULT_MAPSIZE = 1LL << 33;
531 constexpr
static float RESIZE_PERCENT = 0.9f;
The BlockchainDB backing store interface declaration/contract.
virtual bool update_pruning()
prunes recent blockchain changes as needed, iff pruning is enabled
virtual size_t get_block_weight(const uint64_t &height) const
fetch a block's weight
static int compare_string(const MDB_val *a, const MDB_val *b)
virtual void add_txpool_tx(const crypto::hash &txid, const cryptonote::blobdata &blob, const txpool_tx_meta_t &meta)
add a txpool transaction
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
runs a function over a range of blocks
virtual uint32_t get_blockchain_pruning_seed() const
get the blockchain pruning seed
virtual void pop_block(block &blk, std::vector< transaction > &txs)
pops the top block off the blockchain
virtual std::vector< uint64_t > get_block_cumulative_rct_outputs(const std::vector< uint64_t > &heights) const
fetch a block's cumulative number of rct outputs
virtual void batch_stop()
ends a batch transaction
virtual void open(const std::string &filename, const int mdb_flags=0)
open a db, or create it if necessary.
virtual tx_out_index get_output_tx_and_index_from_global(const uint64_t &index) const
gets an output's tx hash and index
virtual void set_batch_transactions(bool batch_transactions)
sets whether or not to batch transactions
virtual void reset()
Remove everything from the BlockchainDB.
virtual void unlock()
This function releases the BlockchainDB lock.
virtual block get_top_block() const
fetch the top block
virtual void block_rtxn_stop() const
virtual difficulty_type get_block_difficulty(const uint64_t &height) const
fetch a block's difficulty
virtual std::vector< std::vector< uint64_t > > get_tx_amount_output_indices(const uint64_t tx_id, size_t n_txes) const
gets output indices (amount-specific) for a transaction's outputs
virtual tx_input_t get_tx_input(const crypto::hash tx_hash, const uint32_t relative_out_index)
static int compare_data(const MDB_val *a, const MDB_val *b)
virtual uint64_t add_block(const std::pair< block, blobdata > &blk, size_t block_weight, uint64_t long_term_block_weight, const difficulty_type &cumulative_difficulty, const uint64_t &coins_generated, const std::vector< std::pair< transaction, blobdata >> &txs)
handles the addition of a new block to BlockchainDB
virtual block_header get_block_header(const crypto::hash &h) const
fetch a block header
virtual uint64_t get_txpool_tx_count(bool include_unrelayed_txes=true) const
get the number of transactions in the txpool
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
return a histogram of outputs on the blockchain
virtual void batch_abort()
aborts a batch transaction
virtual bool get_txpool_tx_meta(const crypto::hash &txid, txpool_tx_meta_t &meta) const
get a txpool transaction's metadata
virtual bool has_key_image(const crypto::key_image &img) const
check if a key image is stored as spent
virtual crypto::hash top_block_hash(uint64_t *block_height=NULL) const
fetch the top block's hash
virtual void block_wtxn_abort()
virtual uint64_t get_block_already_generated_coins(const uint64_t &height) const
fetch a block's already generated coins
virtual std::vector< uint64_t > get_long_term_block_weights(uint64_t start_height, size_t count) const
fetch the last N blocks' long term weights
static int compare_publickey(const MDB_val *a, const MDB_val *b)
virtual uint64_t get_tx_count() const
fetches the total number of transactions ever
virtual bool block_exists(const crypto::hash &h, uint64_t *height=NULL) const
checks if a block exists
virtual bool get_txpool_tx_blob(const crypto::hash &txid, cryptonote::blobdata &bd) const
get a txpool transaction's blob
virtual bool get_pruned_tx_blob(const crypto::hash &h, cryptonote::blobdata &tx) const
fetches the pruned transaction blob with the given hash
virtual uint64_t get_num_outputs(const uint64_t &amount) const
fetches the number of outputs of a given amount
virtual uint64_t get_block_height(const crypto::hash &h) const
gets the height of the block with a given hash
virtual std::vector< block > get_blocks_range(const uint64_t &h1, const uint64_t &h2) const
fetch a list of blocks
virtual bool tx_exists(const crypto::hash &h) const
check if a transaction with a given hash exists
virtual bool block_rtxn_start() const
virtual void block_rtxn_abort() const
virtual std::vector< uint64_t > get_block_weights(uint64_t start_height, size_t count) const
fetch the last N blocks' weights
BlockchainLMDB(bool batch_transactions=true)
virtual std::vector< transaction > get_tx_list(const std::vector< crypto::hash > &hlist) const
fetches a list of transactions based on their hashes
virtual bool batch_start(uint64_t batch_num_blocks=0, uint64_t batch_bytes=0)
tells the BlockchainDB to start a new "batch" of blocks
virtual void set_block_cumulative_difficulty(uint64_t height, difficulty_type diff)
sets a block's cumulative difficulty
virtual void remove_txpool_tx(const crypto::hash &txid)
remove a txpool transaction
virtual bool for_all_transactions(std::function< bool(const crypto::hash &, const cryptonote::transaction &)>, bool pruned) const
runs a function over all transactions stored
virtual uint64_t get_block_long_term_weight(const uint64_t &height) const
fetch a block's long term weight
virtual std::vector< address_outputs > get_addr_output_all(const crypto::public_key &combined_key)
virtual difficulty_type get_block_cumulative_difficulty(const uint64_t &height) const
fetch a block's cumulative difficulty
virtual bool txpool_has_tx(const crypto::hash &txid) const
check whether a txid is in the txpool
virtual bool check_pruning()
checks pruning was done correctly, iff enabled
virtual void batch_commit()
virtual uint64_t get_block_timestamp(const uint64_t &height) const
fetch a block's timestamp
virtual bool lock()
acquires the BlockchainDB lock
virtual bool get_tx_blob(const crypto::hash &h, cryptonote::blobdata &tx) const
fetches the transaction blob with the given hash
virtual bool get_prunable_tx_blob(const crypto::hash &h, cryptonote::blobdata &tx) const
fetches the prunable transaction blob with the given hash
virtual output_data_t get_output_key(const uint64_t &amount, const uint64_t &index, bool include_commitmemt) const
get some of an output's data
virtual uint64_t get_top_block_timestamp() const
fetch the top block's timestamp
virtual void safesyncmode(const bool onoff)
toggle safe syncs for the DB
virtual void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t &meta)
update a txpool transaction's metadata
virtual bool get_prunable_tx_hash(const crypto::hash &tx_hash, crypto::hash &prunable_hash) const
fetches the prunable transaction hash
virtual std::string get_db_name() const
gets the name of the folder the BlockchainDB's file(s) should be in
virtual void block_wtxn_start()
virtual tx_out_index get_output_tx_and_index(const uint64_t &amount, const uint64_t &index) const
gets an output's tx hash and index
virtual cryptonote::blobdata get_block_blob(const crypto::hash &h) const
fetches the block with the given hash
virtual void close()
close the BlockchainDB
virtual cryptonote::blobdata get_block_blob_from_height(const uint64_t &height) const
fetch a block blob by height
virtual uint64_t height() const
fetch the current blockchain height
virtual void block_wtxn_stop()
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
runs a function over all outputs stored
virtual std::vector< crypto::hash > get_hashes_range(const uint64_t &h1, const uint64_t &h2) const
fetch a list of block hashes
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)
bool get_output_distribution(uint64_t amount, uint64_t from_height, uint64_t to_height, std::vector< uint64_t > &distribution, uint64_t &base) const
virtual std::vector< std::string > get_filenames() const
get all files used by the BlockchainDB (if any)
virtual uint64_t get_balance(const crypto::public_key &combined_key)
virtual bool prune_blockchain(uint32_t pruning_seed=0)
prunes the blockchain
virtual bool can_thread_bulk_indices() const
virtual crypto::hash get_block_hash_from_height(const uint64_t &height) const
fetch a block's hash
static int compare_hash32(const MDB_val *a, const MDB_val *b)
virtual bool for_all_key_images(std::function< bool(const crypto::key_image &)>) const
runs a function over all key images stored
virtual uint64_t get_tx_block_height(const crypto::hash &h) const
fetches the height of a transaction's block
static int compare_uint64(const MDB_val *a, const MDB_val *b)
virtual void sync()
sync the BlockchainDB with disk
virtual uint64_t get_tx_unlock_time(const crypto::hash &h) const
fetch a transaction's unlock time/height
virtual bool for_all_txpool_txes(std::function< bool(const crypto::hash &, const txpool_tx_meta_t &, const cryptonote::blobdata *)> f, bool include_blob=false, bool include_unrelayed_txes=true) const
runs a function over all txpool transactions
virtual bool remove_data_file(const std::string &folder) const
remove file(s) storing the database
Non-owning sequence of data. Does not deep copy.
std::string message("Message requiring signing")
struct MDB_env MDB_env
Opaque structure for a database environment.
struct MDB_txn MDB_txn
Opaque structure for a transaction handle.
unsigned int MDB_dbi
A handle for an individual database in the DB environment.
struct MDB_cursor MDB_cursor
Opaque structure for navigating through a database.
Holds cryptonote related classes and helpers.
boost::multiprecision::uint128_t difficulty_type
struct cryptonote::mdb_threadinfo mdb_threadinfo
bool is_coinbase(const transaction &tx)
struct cryptonote::txindex txindex
std::pair< crypto::hash, uint64_t > tx_out_index
struct cryptonote::mdb_rflags mdb_rflags
struct cryptonote::mdb_txn_cursors mdb_txn_cursors
mdb_size_t count(MDB_cursor *cur)
version
Supported socks variants.
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
unsigned __int64 uint64_t
Generic structure used for passing keys and data in and out of the database.
bool m_rf_txs_prunable_tip
bool m_rf_txs_prunable_hash
mdb_txn_cursors m_ti_rcursors
MDB_cursor * m_txc_tx_outputs
MDB_cursor * m_txc_txs_prunable
MDB_cursor * m_txc_hf_versions
MDB_cursor * m_txc_tx_inputs
MDB_cursor * m_txc_tx_indices
MDB_cursor * m_txc_blocks
MDB_cursor * m_txc_txpool_meta
MDB_cursor * m_txc_output_amounts
MDB_cursor * m_txc_output_txs
MDB_cursor * m_txc_txs_pruned
MDB_cursor * m_txc_block_heights
MDB_cursor * m_txc_block_info
MDB_cursor * m_txc_txs_prunable_tip
MDB_cursor * m_txc_properties
MDB_cursor * m_txc_txpool_blob
MDB_cursor * m_txc_addr_outputs
MDB_cursor * m_txc_spent_keys
MDB_cursor * m_txc_txs_prunable_hash
MDB_cursor * m_txc_validators
static void prevent_new_txns()
static void allow_new_txns()
uint64_t num_active_tx() const
static void wait_no_active_txns()
static std::atomic< uint64_t > num_active_txns
mdb_txn_safe(const bool check=true)
void commit(std::string message="")
static std::atomic_flag creation_gate
a struct containing output metadata