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