Monero
Loading...
Searching...
No Matches
cryptonote::Blockchain Class Reference

#include <blockchain.h>

Collaboration diagram for cryptonote::Blockchain:

Classes

struct  block_extended_info
 container for passing a block and metadata about it on the blockchain More...

Public Member Functions

 Blockchain (tx_memory_pool &tx_pool)
 Blockchain constructor.
 ~Blockchain ()
 Blockchain destructor.
bool init (BlockchainDB *db, const network_type nettype=MAINNET, bool offline=false, const cryptonote::test_options *test_options=NULL, difficulty_type fixed_difficulty=0, const GetCheckpointsCallback &get_checkpoints=nullptr)
 Initialize the Blockchain state.
bool init (BlockchainDB *db, HardFork *&hf, const network_type nettype=MAINNET, bool offline=false)
 Initialize the Blockchain state.
bool deinit ()
 Uninitializes the blockchain state.
const checkpointsget_checkpoints () const
 get a set of blockchain checkpoint hashes
void set_checkpoints (checkpoints &&chk_pts)
 assign a set of blockchain checkpoint hashes
bool get_blocks (uint64_t start_offset, size_t count, std::vector< std::pair< cryptonote::blobdata, block > > &blocks, std::vector< cryptonote::blobdata > &txs) const
 get blocks and transactions from blocks based on start height and count
bool get_blocks (uint64_t start_offset, size_t count, std::vector< std::pair< cryptonote::blobdata, block > > &blocks) const
 get blocks from blocks based on start height and count
bool get_alternative_blocks (std::vector< block > &blocks) const
 compiles a list of all blocks stored as alternative chains
size_t get_alternative_blocks_count () const
 returns the number of alternative blocks stored
crypto::hash get_block_id_by_height (uint64_t height) const
 gets a block's hash given a height
crypto::hash get_pending_block_id_by_height (uint64_t height) const
 gets a block's hash given a height
bool get_block_by_hash (const crypto::hash &h, block &blk, bool *orphan=NULL) const
 gets the block with a given hash
bool prepare_handle_incoming_blocks (const std::vector< block_complete_entry > &blocks_entry, std::vector< block > &blocks)
 performs some preprocessing on a group of incoming blocks to speed up verification
void prepare_handle_incoming_block_no_preprocess (const size_t block_byte_estimate)
 prepare the blockchain for handling an incoming block, without performing preprocessing
bool cleanup_handle_incoming_blocks (bool force_sync=false)
 incoming blocks post-processing, cleanup, and disk sync
bool have_tx (const crypto::hash &id) const
 search the blockchain for a transaction by hash
bool have_tx_keyimges_as_spent (const transaction &tx) const
 check if any key image in a transaction has already been spent
bool have_tx_keyimg_as_spent (const crypto::key_image &key_im) const
 check if a key image is already spent on the blockchain
uint64_t get_current_blockchain_height () const
 get the current height of the blockchain
crypto::hash get_tail_id () const
 get the hash of the most recent block on the blockchain
crypto::hash get_tail_id (uint64_t &height) const
 get the height and hash of the most recent block on the blockchain
difficulty_type get_difficulty_for_next_block ()
 returns the difficulty target the next block to be added must meet
std::pair< bool, uint64_tcheck_difficulty_checkpoints () const
 check currently stored difficulties against difficulty checkpoints
size_t recalculate_difficulties (boost::optional< uint64_t > start_height=boost::none)
 recalculate difficulties for blocks after the last difficulty checkpoints to circumvent the annoying 'difficulty drift' bug
bool add_new_block (const block &bl_, block_verification_context &bvc)
 adds a block to the blockchain
bool add_new_block (const block &bl_, block_verification_context &bvc, pool_supplement &extra_block_txs)
bool reset_and_set_genesis_block (const block &b)
 clears the blockchain and starts a new one
bool create_block_template (block &b, const account_public_address &miner_address, difficulty_type &di, uint64_t &height, uint64_t &expected_reward, const blobdata &ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
 creates a new block to mine against
bool create_block_template (block &b, const crypto::hash *from_block, const account_public_address &miner_address, difficulty_type &di, uint64_t &height, uint64_t &expected_reward, const blobdata &ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
bool get_miner_data (uint8_t &major_version, uint64_t &height, crypto::hash &prev_id, crypto::hash &seed_hash, difficulty_type &difficulty, uint64_t &median_weight, uint64_t &already_generated_coins, std::vector< tx_block_template_backlog_entry > &tx_backlog)
 gets data required to create a block template and start mining on it
bool have_block_unlocked (const crypto::hash &id, int *where=NULL) const
 checks if a block is known about with a given hash
bool have_block (const crypto::hash &id, int *where=NULL) const
size_t get_total_transactions () const
 gets the total number of transactions on the main chain
bool get_short_chain_history (std::list< crypto::hash > &ids, uint64_t &current_height) const
 gets the hashes for a subset of the blockchain
bool find_blockchain_supplement (const std::list< crypto::hash > &qblock_ids, std::vector< crypto::hash > &hashes, std::vector< uint64_t > *weights, uint64_t &start_height, uint64_t &current_height, bool clip_pruned) const
 get recent block hashes for a foreign chain
bool find_blockchain_supplement (const std::list< crypto::hash > &qblock_ids, bool clip_pruned, NOTIFY_RESPONSE_CHAIN_ENTRY::request &resp) const
 get recent block hashes for a foreign chain
bool find_blockchain_supplement (const std::list< crypto::hash > &qblock_ids, uint64_t &starter_offset) const
 find the most recent common point between ours and a foreign chain
bool find_blockchain_supplement (const uint64_t req_start_block, const std::list< crypto::hash > &qblock_ids, std::vector< std::pair< std::pair< cryptonote::blobdata, crypto::hash >, std::vector< std::pair< crypto::hash, cryptonote::blobdata > > > > &blocks, uint64_t &total_height, uint64_t &start_height, bool pruned, bool get_miner_tx_hash, size_t max_block_count, size_t max_tx_count) const
 get recent blocks for a foreign chain
bool handle_get_objects (NOTIFY_REQUEST_GET_OBJECTS::request &arg, NOTIFY_RESPONSE_GET_OBJECTS::request &rsp)
 retrieves a set of blocks and their transactions, and possibly other transactions
uint64_t get_num_mature_outputs (uint64_t amount) const
 get number of outputs of an amount past the minimum spendable age
crypto::public_key get_output_key (uint64_t amount, uint64_t global_index) const
 get the public key for an output
bool get_outs (const COMMAND_RPC_GET_OUTPUTS_BIN::request &req, COMMAND_RPC_GET_OUTPUTS_BIN::response &res) const
 gets specific outputs to mix with
void get_output_key_mask_unlocked (const uint64_t &amount, const uint64_t &index, crypto::public_key &key, rct::key &mask, bool &unlocked) const
 gets an output's key and unlocked state
bool get_output_distribution (uint64_t amount, uint64_t from_height, uint64_t to_height, uint64_t &start_height, std::vector< uint64_t > &distribution, uint64_t &base) const
 gets per block distribution of outputs of a given amount
bool get_tx_outputs_gindexs (const crypto::hash &tx_id, std::vector< uint64_t > &indexs) const
 gets the global indices for outputs from a given transaction
bool get_tx_outputs_gindexs (const crypto::hash &tx_id, size_t n_txes, std::vector< std::vector< uint64_t > > &indexs) const
bool store_blockchain ()
 stores the blockchain
bool check_tx_inputs (transaction &tx, uint64_t &pmax_used_block_height, crypto::hash &max_used_block_id, tx_verification_context &tvc, bool kept_by_block=false) const
 validates a transaction's inputs
uint64_t get_dynamic_base_fee_estimate (uint64_t grace_blocks) const
 get dynamic per kB or byte fee estimate for the next few blocks
void get_dynamic_base_fee_estimate_2021_scaling (uint64_t grace_blocks, uint64_t base_reward, uint64_t Mnw, uint64_t Mlw, std::vector< uint64_t > &fees) const
void get_dynamic_base_fee_estimate_2021_scaling (uint64_t grace_blocks, std::vector< uint64_t > &fees) const
 get four levels of dynamic per byte fee estimate for the next few blocks
bool check_fee (size_t tx_weight, uint64_t fee) const
 validate a transaction's fee
uint64_t get_current_cumulative_block_weight_limit () const
 gets the block weight limit based on recent blocks
uint64_t get_next_long_term_block_weight (uint64_t block_weight) const
 gets the long term block weight for a new block
uint64_t get_current_cumulative_block_weight_median () const
 gets the block weight median based on recent blocks (same window as for the limit)
difficulty_type block_difficulty (uint64_t i) const
 gets the difficulty of the block with a given height
template<class t_ids_container, class t_blocks_container, class t_missed_container>
bool get_blocks (const t_ids_container &block_ids, t_blocks_container &blocks, t_missed_container &missed_bs) const
 gets blocks based on a list of block hashes
bool get_transactions_blobs (const std::vector< crypto::hash > &txs_ids, std::vector< cryptonote::blobdata > &txs, std::vector< crypto::hash > &missed_txs, bool pruned=false) const
 gets transactions based on a list of transaction hashes
bool get_transactions_blobs (const std::vector< crypto::hash > &txs_ids, std::vector< tx_blob_entry > &txs, std::vector< crypto::hash > &missed_txs, bool pruned=false) const
template<class t_ids_container, class t_tx_container, class t_missed_container>
bool get_split_transactions_blobs (const t_ids_container &txs_ids, t_tx_container &txs, t_missed_container &missed_txs) const
template<class t_ids_container, class t_tx_container, class t_missed_container>
bool get_transactions (const t_ids_container &txs_ids, t_tx_container &txs, t_missed_container &missed_txs, bool pruned=false) const
void check_against_checkpoints (const checkpoints &points, bool enforce)
 check the blockchain against a set of checkpoints
void set_enforce_dns_checkpoints (bool enforce)
 configure whether or not to enforce DNS-based checkpoints
bool update_checkpoints (const std::string &file_path, bool check_dns)
 loads new checkpoints from a file and optionally from DNS
void set_user_options (uint64_t maxthreads, bool sync_on_blocks, uint64_t sync_threshold, blockchain_db_sync_mode sync_mode, bool fast_sync)
 sets various performance options
void set_txpool_notify (TxpoolNotifyCallback &&notify)
 sets a txpool notify object to call for every new tx used to add a new block
void add_block_notify (BlockNotifyCallback &&notify)
 sets a block notify object to call for every new block
void add_miner_notify (MinerNotifyCallback &&notify)
 sets a miner notify object to call for every new block
void set_reorg_notify (const std::shared_ptr< tools::Notify > &notify)
 sets a reorg notify object to call for every reorg
void notify_txpool_event (std::vector< txpool_event > &&event) const
 Notify this Blockchain's txpool notifier about a txpool event.
void safesyncmode (const bool onoff)
 Put DB in safe sync mode.
void set_show_time_stats (bool stats)
 set whether or not to show/print time statistics
HardFork::State get_hard_fork_state () const
 gets the hardfork voting state object
uint8_t get_current_hard_fork_version () const
 gets the current hardfork version in use/voted for
uint8_t get_ideal_hard_fork_version () const
 returns the newest hardfork version known to the blockchain
uint8_t get_next_hard_fork_version () const
 returns the next hardfork version
uint8_t get_ideal_hard_fork_version (uint64_t height) const
 returns the newest hardfork version voted to be enabled as of a certain height
uint8_t get_hard_fork_version (uint64_t height) const
 returns the actual hardfork version for a given block height
uint64_t get_earliest_ideal_height_for_version (uint8_t version) const
 returns the earliest block a given version may activate
const std::vector< hardfork_t > & get_hardforks () const
 returns info for all known hard forks
bool get_hard_fork_voting_info (uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint64_t &earliest_height, uint8_t &voting) const
 get information about hardfork voting for a version
uint64_t get_difficulty_target () const
 get difficulty target based on chain and hardfork version
bool flush_txes_from_pool (const std::vector< crypto::hash > &txids)
 remove transactions from the transaction pool (if present)
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=0) const
 return a histogram of outputs on the blockchain
bool for_all_key_images (std::function< bool(const crypto::key_image &)>) const
 perform a check on all key images in the blockchain
bool for_blocks_range (const uint64_t &h1, const uint64_t &h2, std::function< bool(uint64_t, const crypto::hash &, const block &)>) const
 perform a check on all blocks in the blockchain in the given range
bool for_all_transactions (std::function< bool(const crypto::hash &, const cryptonote::transaction &)>, bool pruned) const
 perform a check on all transactions in the blockchain
bool for_all_outputs (std::function< bool(uint64_t amount, const crypto::hash &tx_hash, uint64_t height, size_t tx_idx)>) const
 perform a check on all outputs in the blockchain
bool for_all_outputs (uint64_t amount, std::function< bool(uint64_t height)>) const
 perform a check on all outputs of a given amount in the blockchain
const BlockchainDBget_db () const
 get a reference to the BlockchainDB in use by Blockchain
BlockchainDBget_db ()
 get a reference to the BlockchainDB in use by Blockchain
void output_scan_worker (const uint64_t amount, const std::vector< uint64_t > &offsets, std::vector< output_data_t > &outputs) const
 get a number of outputs of a specific amount
void block_longhash_worker (uint64_t height, const epee::span< const block > &blocks, std::unordered_map< crypto::hash, crypto::hash > &map) const
 computes the "short" and "long" hashes for a set of blocks
std::vector< std::pair< block_extended_info, std::vector< crypto::hash > > > get_alternative_chains () const
 returns a set of known alternate chains
void add_txpool_tx (const crypto::hash &txid, const cryptonote::blobdata &blob, const txpool_tx_meta_t &meta)
void update_txpool_tx (const crypto::hash &txid, const txpool_tx_meta_t &meta)
void remove_txpool_tx (const crypto::hash &txid)
uint64_t get_txpool_tx_count (bool include_sensitive=false) const
bool get_txpool_tx_meta (const crypto::hash &txid, txpool_tx_meta_t &meta) const
bool get_txpool_tx_blob (const crypto::hash &txid, cryptonote::blobdata &bd, relay_category tx_category) const
cryptonote::blobdata get_txpool_tx_blob (const crypto::hash &txid, relay_category tx_category) const
bool for_all_txpool_txes (std::function< bool(const crypto::hash &, const txpool_tx_meta_t &, const cryptonote::blobdata_ref *)>, bool include_blob=false, relay_category tx_category=relay_category::broadcasted) const
bool txpool_tx_matches_category (const crypto::hash &tx_hash, relay_category category)
bool is_within_compiled_block_hash_area () const
uint64_t prevalidate_block_hashes (uint64_t height, const std::vector< crypto::hash > &hashes, const std::vector< uint64_t > &weights)
uint32_t get_blockchain_pruning_seed () const
bool prune_blockchain (uint32_t pruning_seed=0)
bool update_blockchain_pruning ()
bool check_blockchain_pruning ()
void lock ()
void unlock ()
void cancel ()
std::vector< time_t > get_last_block_timestamps (unsigned int blocks) const
 returns the timestamps of the last N blocks
void pop_blocks (uint64_t nblocks)
 removes blocks from the top of the blockchain
bool is_within_compiled_block_hash_area (uint64_t height) const
 checks whether a given block height is included in the precompiled block hash area
bool has_block_weights (uint64_t height, uint64_t nblocks) const
 checks whether we have known weights for the given block heights
void flush_invalid_blocks ()
 flush the invalid blocks set
uint64_t get_adjusted_time (uint64_t height) const
 get the "adjusted time"
template<class t_ids_container, class t_tx_container, class t_missed_container>
bool get_transactions (const t_ids_container &txs_ids, t_tx_container &txs, t_missed_container &missed_txs, bool pruned) const

Static Public Member Functions

static bool expand_transaction_2 (transaction &tx, const crypto::hash &tx_prefix_hash, const std::vector< std::vector< rct::ctkey > > &pubkeys)
 expands v2 transaction data from blockchain
static uint64_t get_fee_quantization_mask ()
 get fee quantization mask
static uint64_t get_dynamic_base_fee (uint64_t block_reward, size_t median_block_weight, uint8_t version)
 get dynamic per kB or byte fee for a given block weight
static bool check_tx_outputs (const transaction &tx, tx_verification_context &tvc, std::uint8_t hf_version)
 check that a transaction's outputs conform to current standards

Private Types

typedef std::unordered_set< crypto::key_imagekey_images_container
typedef std::vector< block_extended_infoblocks_container
typedef std::unordered_map< crypto::hash, block_extended_infoblocks_ext_by_hash

Private Member Functions

template<class visitor_t>
bool scan_outputkeys_for_indexes (size_t tx_version, const txin_to_key &tx_in_to_key, visitor_t &vis, const crypto::hash &tx_prefix_hash, uint64_t *pmax_related_block_height=NULL) const
 collects the keys for all outputs being "spent" as an input
bool check_tx_input (size_t tx_version, const txin_to_key &txin, const crypto::hash &tx_prefix_hash, const std::vector< crypto::signature > &sig, const rct::rctSig &rct_signatures, std::vector< rct::ctkey > &output_keys, uint64_t *pmax_related_block_height, uint8_t hf_version) const
 collect output public keys of a transaction input set
bool check_tx_inputs (transaction &tx, tx_verification_context &tvc, uint64_t *pmax_used_block_height=NULL) const
 validate a transaction's inputs and their keys
bool switch_to_alternative_blockchain (std::list< block_extended_info > &alt_chain, bool discard_disconnected_chain)
 performs a blockchain reorganization according to the longest chain rule
block pop_block_from_blockchain ()
 removes the most recent block from the blockchain
bool handle_block_to_main_chain (const block &bl, block_verification_context &bvc)
 validate and add a new block to the end of the blockchain
bool handle_block_to_main_chain (const block &bl, const crypto::hash &id, block_verification_context &bvc, pool_supplement &extra_block_txs)
 validate and add a new block to the end of the blockchain
bool handle_alternative_block (const block &b, const crypto::hash &id, block_verification_context &bvc, pool_supplement &extra_block_txs)
 validate and add a new block to an alternate blockchain
bool build_alt_chain (const crypto::hash &prev_id, std::list< block_extended_info > &alt_chain, std::vector< uint64_t > &timestamps, block_verification_context &bvc) const
 builds a list of blocks connecting a block to the main chain
difficulty_type get_next_difficulty_for_alternative_chain (const std::list< block_extended_info > &alt_chain, block_extended_info &bei) const
 gets the difficulty requirement for a new block on an alternate chain
bool prevalidate_miner_transaction (const block &b, uint64_t height, uint8_t hf_version)
 sanity checks a miner transaction before validating an entire block
bool validate_miner_transaction (const block &b, size_t cumulative_block_weight, uint64_t fee, uint64_t &base_reward, uint64_t already_generated_coins, bool &partial_block_reward, uint8_t version)
 validates a miner (coinbase) transaction
bool rollback_blockchain_switching (std::list< block > &original_chain, uint64_t rollback_height)
 reverts the blockchain to its previous state following a failed switch
void get_last_n_blocks_weights (std::vector< uint64_t > &weights, size_t count) const
 gets recent block weights for median calculation
uint64_t get_long_term_block_weight_median (uint64_t start_height, size_t count) const
 gets block long term weight median
bool is_tx_spendtime_unlocked (uint64_t unlock_time, uint8_t hf_version) const
 checks if a transaction is unlocked (its outputs spendable)
bool add_block_as_invalid (const block &bl, const crypto::hash &h)
 stores an invalid block in a separate container
bool add_block_as_invalid (const block_extended_info &bei, const crypto::hash &h)
 stores an invalid block in a separate container
bool check_block_timestamp (const block &b, uint64_t &median_ts) const
 checks a block's timestamp
bool check_block_timestamp (const block &b) const
bool check_block_timestamp (std::vector< uint64_t > &timestamps, const block &b, uint64_t &median_ts) const
 checks a block's timestamp
bool check_block_timestamp (std::vector< uint64_t > &timestamps, const block &b) const
bool complete_timestamps_vector (uint64_t start_height, std::vector< uint64_t > &timestamps) const
 finish an alternate chain's timestamp window from the main chain
bool update_next_cumulative_weight_limit (uint64_t *long_term_effective_median_block_weight=NULL)
 calculate the block weight limit for the next block to be added
bool check_for_double_spend (const transaction &tx, key_images_container &keys_this_block) const
 make sure a transaction isn't attempting a double-spend
void check_ring_signature (const crypto::hash &tx_prefix_hash, const crypto::key_image &key_image, const std::vector< rct::ctkey > &pubkeys, const std::vector< crypto::signature > &sig, uint64_t &result) const
 validates a transaction input's ring signature
void load_compiled_in_block_hashes (const GetCheckpointsCallback &get_checkpoints)
 loads block hashes from compiled-in data set
void invalidate_block_template_cache ()
 invalidates any cached block template
void cache_block_template (const block &b, const cryptonote::account_public_address &address, const blobdata &nonce, const difficulty_type &diff, uint64_t height, uint64_t expected_reward, uint64_t seed_height, const crypto::hash &seed_hash, uint64_t pool_cookie)
 stores a new cached block template
void send_miner_notifications (uint64_t height, const crypto::hash &seed_hash, const crypto::hash &prev_id, uint64_t already_generated_coins)
 sends new block notifications to ZMQ miner_data subscribers

Private Attributes

BlockchainDBm_db
tx_memory_poolm_tx_pool
epee::critical_section m_blockchain_lock
size_t m_current_block_cumul_weight_limit
size_t m_current_block_cumul_weight_median
std::unordered_map< crypto::hash, std::unordered_map< crypto::key_image, std::vector< output_data_t > > > m_scan_table
std::unordered_map< crypto::hash, crypto::hashm_blocks_longhash_table
std::vector< std::pair< crypto::hash, crypto::hash > > m_blocks_hash_of_hashes
std::vector< std::pair< crypto::hash, uint64_t > > m_blocks_hash_check
blockchain_db_sync_mode m_db_sync_mode
bool m_fast_sync
bool m_show_time_stats
bool m_db_default_sync
bool m_db_sync_on_blocks
uint64_t m_db_sync_threshold
uint64_t m_max_prepare_blocks_threads
uint64_t m_fake_pow_calc_time
uint64_t m_fake_scan_time
uint64_t m_sync_counter
uint64_t m_bytes_to_sync
std::vector< uint64_tm_timestamps
std::vector< difficulty_typem_difficulties
uint64_t m_timestamps_and_difficulties_height
bool m_reset_timestamps_and_difficulties_height
uint64_t m_long_term_block_weights_window
uint64_t m_long_term_effective_median_block_weight
crypto::hash m_long_term_block_weights_cache_tip_hash
epee::misc_utils::rolling_median_t< uint64_tm_long_term_block_weights_cache_rolling_median
epee::critical_section m_difficulty_lock
crypto::hash m_difficulty_for_next_block_top_hash
difficulty_type m_difficulty_for_next_block
boost::asio::io_context m_async_service
boost::thread_group m_async_pool
std::unique_ptr< boost::asio::executor_work_guard< boost::asio::io_context::executor_type > > m_async_work_idle
blocks_ext_by_hash m_invalid_blocks
checkpoints m_checkpoints
bool m_enforce_dns_checkpoints
HardForkm_hardfork
network_type m_nettype
bool m_offline
difficulty_type m_fixed_difficulty
std::atomic< bool > m_cancel
block m_btc
account_public_address m_btc_address
blobdata m_btc_nonce
difficulty_type m_btc_difficulty
uint64_t m_btc_height
uint64_t m_btc_pool_cookie
uint64_t m_btc_expected_reward
crypto::hash m_btc_seed_hash
uint64_t m_btc_seed_height
bool m_btc_valid
bool m_batch_success
TxpoolNotifyCallback m_txpool_notifier
std::mutex m_txpool_notifier_mutex
std::vector< BlockNotifyCallbackm_block_notifiers
std::vector< MinerNotifyCallbackm_miner_notifiers
std::shared_ptr< tools::Notifym_reorg_notify
uint64_t m_prepare_height
uint64_t m_prepare_nblocks
std::vector< block > * m_prepare_blocks
rct_ver_cache_t m_rct_ver_cache

Member Typedef Documentation

◆ blocks_container

◆ blocks_ext_by_hash

◆ key_images_container

Constructor & Destructor Documentation

◆ Blockchain()

Blockchain::Blockchain ( tx_memory_pool & tx_pool)

Blockchain constructor.

Parameters
tx_poola reference to the transaction pool to be kept by the Blockchain

◆ ~Blockchain()

Blockchain::~Blockchain ( )

Blockchain destructor.

Member Function Documentation

◆ add_block_as_invalid() [1/2]

bool Blockchain::add_block_as_invalid ( const block & bl,
const crypto::hash & h )
private

stores an invalid block in a separate container

Storing invalid blocks allows quick dismissal of the same block if it is seen again.

Parameters
blthe invalid block
hthe block's hash
Returns
false if the block cannot be stored for some reason, otherwise true

◆ add_block_as_invalid() [2/2]

bool Blockchain::add_block_as_invalid ( const block_extended_info & bei,
const crypto::hash & h )
private

stores an invalid block in a separate container

Storing invalid blocks allows quick dismissal of the same block if it is seen again.

Parameters
beithe invalid block (see ::block_extended_info)
hthe block's hash
Returns
false if the block cannot be stored for some reason, otherwise true

◆ add_block_notify()

void Blockchain::add_block_notify ( BlockNotifyCallback && notify)

sets a block notify object to call for every new block

Parameters
notifythe notify object to call at every new block

◆ add_miner_notify()

void Blockchain::add_miner_notify ( MinerNotifyCallback && notify)

sets a miner notify object to call for every new block

Parameters
notifythe notify object to call at every new block

◆ add_new_block() [1/2]

bool Blockchain::add_new_block ( const block & bl_,
block_verification_context & bvc )

adds a block to the blockchain

Adds a new block to the blockchain. If the block's parent is not the current top of the blockchain, the block may be added to an alternate chain. If the block does not belong, is already in the blockchain or an alternate chain, or is invalid, return false.

Parameters
bl_the block to be added
bvcmetadata about the block addition's success/failure
extra_block_txstxs belonging to this block that may not be in the mempool
Returns
true on successful addition to the blockchain, else false

◆ add_new_block() [2/2]

bool Blockchain::add_new_block ( const block & bl_,
block_verification_context & bvc,
pool_supplement & extra_block_txs )

◆ add_txpool_tx()

void Blockchain::add_txpool_tx ( const crypto::hash & txid,
const cryptonote::blobdata & blob,
const txpool_tx_meta_t & meta )

◆ block_difficulty()

difficulty_type Blockchain::block_difficulty ( uint64_t i) const

gets the difficulty of the block with a given height

Parameters
ithe height
Returns
the difficulty

◆ block_longhash_worker()

void Blockchain::block_longhash_worker ( uint64_t height,
const epee::span< const block > & blocks,
std::unordered_map< crypto::hash, crypto::hash > & map ) const

computes the "short" and "long" hashes for a set of blocks

Parameters
heightthe height of the first block
blocksthe blocks to be hashed
mapreturn-by-reference the hashes for each block

◆ build_alt_chain()

bool Blockchain::build_alt_chain ( const crypto::hash & prev_id,
std::list< block_extended_info > & alt_chain,
std::vector< uint64_t > & timestamps,
block_verification_context & bvc ) const
private

builds a list of blocks connecting a block to the main chain

Parameters
prev_idthe block hash of the tip of the alt chain
alt_chainthe chain to be added to
timestampsreturns the timestamps of previous blocks
bvcthe block verification context for error return
Returns
true on success, false otherwise

◆ cache_block_template()

void Blockchain::cache_block_template ( const block & b,
const cryptonote::account_public_address & address,
const blobdata & nonce,
const difficulty_type & diff,
uint64_t height,
uint64_t expected_reward,
uint64_t seed_height,
const crypto::hash & seed_hash,
uint64_t pool_cookie )
private

stores a new cached block template

At some point, may be used to push an update to miners

◆ cancel()

void Blockchain::cancel ( )

◆ check_against_checkpoints()

void Blockchain::check_against_checkpoints ( const checkpoints & points,
bool enforce )

check the blockchain against a set of checkpoints

If a block fails a checkpoint and enforce is enabled, the blockchain will be rolled back to two blocks prior to that block. If enforce is disabled, as is currently the default case with DNS-based checkpoints, an error will be printed to the user but no other action will be taken.

Parameters
pointsthe checkpoints to check against
enforcewhether or not to take action on failure

◆ check_block_timestamp() [1/4]

bool cryptonote::Blockchain::check_block_timestamp ( const block & b) const
inlineprivate

◆ check_block_timestamp() [2/4]

bool Blockchain::check_block_timestamp ( const block & b,
uint64_t & median_ts ) const
private

checks a block's timestamp

This function grabs the timestamps from the most recent <n> blocks, where n = BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW. If there are not those many blocks in the blockchain, the timestap is assumed to be valid. If there are, this function returns: true if the block's timestamp is not less than the timestamp of the median of the selected blocks false otherwise

Parameters
bthe block to be checked
median_tsreturn-by-reference the median of timestamps
Returns
true if the block's timestamp is valid, otherwise false

◆ check_block_timestamp() [3/4]

bool cryptonote::Blockchain::check_block_timestamp ( std::vector< uint64_t > & timestamps,
const block & b ) const
inlineprivate

◆ check_block_timestamp() [4/4]

bool Blockchain::check_block_timestamp ( std::vector< uint64_t > & timestamps,
const block & b,
uint64_t & median_ts ) const
private

checks a block's timestamp

If the block is not more recent than the median of the recent timestamps passed here, it is considered invalid.

Parameters
timestampsa list of the most recent timestamps to check against
bthe block to be checked
Returns
true if the block's timestamp is valid, otherwise false

◆ check_blockchain_pruning()

bool Blockchain::check_blockchain_pruning ( )

◆ check_difficulty_checkpoints()

std::pair< bool, uint64_t > Blockchain::check_difficulty_checkpoints ( ) const

check currently stored difficulties against difficulty checkpoints

Returns
{flag, height} flag: true if all difficulty checkpoints pass, height: the last checkpoint height before the difficulty drift bug starts

◆ check_fee()

bool Blockchain::check_fee ( size_t tx_weight,
uint64_t fee ) const

validate a transaction's fee

This function validates the fee is enough for the transaction. This is based on the weight of the transaction, and, after a height threshold, on the average weight of transaction in a past window

Parameters
tx_weightthe transaction weight
feethe fee
Returns
true if the fee is enough, false otherwise

◆ check_for_double_spend()

bool Blockchain::check_for_double_spend ( const transaction & tx,
key_images_container & keys_this_block ) const
private

make sure a transaction isn't attempting a double-spend

Parameters
txthe transaction to check
keys_this_blocka cumulative list of spent keys for the current block
Returns
false if a double spend was detected, otherwise true

◆ check_ring_signature()

void Blockchain::check_ring_signature ( const crypto::hash & tx_prefix_hash,
const crypto::key_image & key_image,
const std::vector< rct::ctkey > & pubkeys,
const std::vector< crypto::signature > & sig,
uint64_t & result ) const
private

validates a transaction input's ring signature

Parameters
tx_prefix_hashthe transaction prefix' hash
key_imagethe key image generated from the true input
pubkeysthe public keys for each input in the ring signature
sigthe signature generated for each input in the ring signature
resultfalse if the ring signature is invalid, otherwise true

◆ check_tx_input()

bool Blockchain::check_tx_input ( size_t tx_version,
const txin_to_key & txin,
const crypto::hash & tx_prefix_hash,
const std::vector< crypto::signature > & sig,
const rct::rctSig & rct_signatures,
std::vector< rct::ctkey > & output_keys,
uint64_t * pmax_related_block_height,
uint8_t hf_version ) const
private

collect output public keys of a transaction input set

This function locates all outputs associated with a given input set (mixins) and validates that they exist and are usable (unlocked, unspent is checked elsewhere).

If pmax_related_block_height is not NULL, its value is set to the height of the most recent block which contains an output used in the input set

Parameters
tx_versionthe transaction version
txinthe transaction input
tx_prefix_hashthe transaction prefix hash, for caching organization
sigthe input signature
output_keysreturn-by-reference the public keys of the outputs in the input set
rct_signaturesthe ringCT signatures, which are only valid if tx version > 1
pmax_related_block_heightreturn-by-pointer the height of the most recent block in the input set
hf_versionthe consensus rules version to use
Returns
false if any output is not yet unlocked, or is missing, otherwise true

◆ check_tx_inputs() [1/2]

bool Blockchain::check_tx_inputs ( transaction & tx,
tx_verification_context & tvc,
uint64_t * pmax_used_block_height = NULL ) const
private

validate a transaction's inputs and their keys

This function validates transaction inputs and their keys. Previously it also performed double spend checking, but that has been moved to its own function. The transaction's rct signatures, if any, are expanded.

If pmax_related_block_height is not NULL, its value is set to the height of the most recent block which contains an output used in any input set

Currently this function calls ring signature validation for each transaction.

Parameters
txthe transaction to validate
tvcreturned information about tx verification
pmax_related_block_heightreturn-by-pointer the height of the most recent block in the input set
Returns
false if any validation step fails, otherwise true

◆ check_tx_inputs() [2/2]

bool cryptonote::Blockchain::check_tx_inputs ( transaction & tx,
uint64_t & pmax_used_block_height,
crypto::hash & max_used_block_id,
tx_verification_context & tvc,
bool kept_by_block = false ) const

validates a transaction's inputs

validates a transaction's inputs as correctly used and not previously spent. also returns the hash and height of the most recent block which contains an output that was used as an input to the transaction. The transaction's rct signatures, if any, are expanded.

Parameters
txthe transaction to validate
pmax_used_block_heightreturn-by-reference block height of most recent input
max_used_block_idreturn-by-reference block hash of most recent input
tvcreturned information about tx verification
kept_by_blockwhether or not the transaction is from a previously-verified block
Returns
false if any input is invalid, otherwise true

◆ check_tx_outputs()

bool Blockchain::check_tx_outputs ( const transaction & tx,
tx_verification_context & tvc,
std::uint8_t hf_version )
static

check that a transaction's outputs conform to current standards

This function checks, for example at the time of this writing, that each output is of the form a * 10^b (phrased differently, that if written out would have only one non-zero digit in base 10).

Parameters
txthe transaction to check the outputs of
tvcreturned info about tx verification
hf_versionhard fork version
Returns
false if any outputs do not conform, otherwise true

◆ cleanup_handle_incoming_blocks()

bool Blockchain::cleanup_handle_incoming_blocks ( bool force_sync = false)

incoming blocks post-processing, cleanup, and disk sync

Parameters
force_syncif true, and Blockchain is handling syncing to disk, always sync
Returns
true

◆ complete_timestamps_vector()

bool Blockchain::complete_timestamps_vector ( uint64_t start_height,
std::vector< uint64_t > & timestamps ) const
private

finish an alternate chain's timestamp window from the main chain

for an alternate chain, get the timestamps from the main chain to complete the needed number of timestamps for the BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW.

Parameters
start_heightthe alternate chain's attachment height to the main chain
timestampsreturn-by-value the timestamps set to be populated
Returns
true unless start_height is greater than the current blockchain height

◆ create_block_template() [1/2]

bool Blockchain::create_block_template ( block & b,
const account_public_address & miner_address,
difficulty_type & di,
uint64_t & height,
uint64_t & expected_reward,
const blobdata & ex_nonce,
uint64_t & seed_height,
crypto::hash & seed_hash )

creates a new block to mine against

Parameters
breturn-by-reference block to be filled in
from_blockoptional block hash to start mining from (main chain tip if NULL)
miner_addressaddress new coins for the block will go to
direturn-by-reference tells the miner what the difficulty target is
heightreturn-by-reference tells the miner what height it's mining against
expected_rewardreturn-by-reference the total reward awarded to the miner finding this block, including transaction fees
ex_nonceextra data to be added to the miner transaction's extra
Returns
true if block template filled in successfully, else false

◆ create_block_template() [2/2]

bool Blockchain::create_block_template ( block & b,
const crypto::hash * from_block,
const account_public_address & miner_address,
difficulty_type & di,
uint64_t & height,
uint64_t & expected_reward,
const blobdata & ex_nonce,
uint64_t & seed_height,
crypto::hash & seed_hash )

◆ deinit()

bool Blockchain::deinit ( )

Uninitializes the blockchain state.

Saves to disk any state that needs to be maintained

Returns
true on success, false if any uninitialization steps fail

◆ expand_transaction_2()

bool Blockchain::expand_transaction_2 ( transaction & tx,
const crypto::hash & tx_prefix_hash,
const std::vector< std::vector< rct::ctkey > > & pubkeys )
static

expands v2 transaction data from blockchain

RingCT transactions do not transmit some of their data if it can be reconstituted by the receiver. This function expands that implicit data.

◆ find_blockchain_supplement() [1/4]

bool Blockchain::find_blockchain_supplement ( const std::list< crypto::hash > & qblock_ids,
bool clip_pruned,
NOTIFY_RESPONSE_CHAIN_ENTRY::request & resp ) const

get recent block hashes for a foreign chain

Find the split point between us and foreign blockchain and return (by reference) the most recent common block hash along with up to BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT additional (more recent) hashes.

Parameters
qblock_idsthe foreign chain's "short history" (see get_short_chain_history)
clip_prunedclip pruned blocks if true, include them otherwise
respreturn-by-reference the split height and subsequent blocks' hashes
Returns
true if a block found in common, else false

◆ find_blockchain_supplement() [2/4]

bool Blockchain::find_blockchain_supplement ( const std::list< crypto::hash > & qblock_ids,
std::vector< crypto::hash > & hashes,
std::vector< uint64_t > * weights,
uint64_t & start_height,
uint64_t & current_height,
bool clip_pruned ) const

get recent block hashes for a foreign chain

Find the split point between us and foreign blockchain and return (by reference) the most recent common block hash along with up to BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT additional (more recent) hashes.

Parameters
qblock_idsthe foreign chain's "short history" (see get_short_chain_history)
hashesthe hashes to be returned, return-by-reference
weightsthe block weights to be returned, return-by-reference
start_heightthe start height, return-by-reference
current_heightthe current blockchain height, return-by-reference
clip_prunedwhether to constrain results to unpruned data
Returns
true if a block found in common, else false

◆ find_blockchain_supplement() [3/4]

bool Blockchain::find_blockchain_supplement ( const std::list< crypto::hash > & qblock_ids,
uint64_t & starter_offset ) const

find the most recent common point between ours and a foreign chain

This function takes a list of block hashes from another node on the network to find where the split point is between us and them. This is used to see what to send another node that needs to sync.

Parameters
qblock_idsthe foreign chain's "short history" (see get_short_chain_history)
starter_offsetreturn-by-reference the most recent common block's height
Returns
true if a block found in common, else false

◆ find_blockchain_supplement() [4/4]

bool Blockchain::find_blockchain_supplement ( const uint64_t req_start_block,
const std::list< crypto::hash > & qblock_ids,
std::vector< std::pair< std::pair< cryptonote::blobdata, crypto::hash >, std::vector< std::pair< crypto::hash, cryptonote::blobdata > > > > & blocks,
uint64_t & total_height,
uint64_t & start_height,
bool pruned,
bool get_miner_tx_hash,
size_t max_block_count,
size_t max_tx_count ) const

get recent blocks for a foreign chain

This function gets recent blocks relative to a foreign chain, starting either at a requested height or whatever height is the most recent ours and the foreign chain have in common.

Parameters
req_start_blockif non-zero, specifies a start point (otherwise find most recent commonality)
qblock_idsthe foreign chain's "short history" (see get_short_chain_history)
blocksreturn-by-reference the blocks and their transactions
total_heightreturn-by-reference our current blockchain height
start_heightreturn-by-reference the height of the first block returned
prunedwhether to return full or pruned tx blobs
max_block_countthe max number of blocks to get
max_tx_countthe max number of txes to get (it can get overshot by the last block's number of txes minus 1)
Returns
true if a block found in common or req_start_block specified, else false

◆ flush_invalid_blocks()

void Blockchain::flush_invalid_blocks ( )

flush the invalid blocks set

◆ flush_txes_from_pool()

bool Blockchain::flush_txes_from_pool ( const std::vector< crypto::hash > & txids)

remove transactions from the transaction pool (if present)

Parameters
txidsa list of hashes of transactions to be removed
Returns
false if any removals fail, otherwise true

◆ for_all_key_images()

bool Blockchain::for_all_key_images ( std::function< bool(const crypto::key_image &)> ) const

perform a check on all key images in the blockchain

Parameters
std::functionthe check to perform, pass/fail
Returns
false if any key image fails the check, otherwise true

◆ for_all_outputs() [1/2]

bool cryptonote::Blockchain::for_all_outputs ( std::function< bool(uint64_t amount, const crypto::hash &tx_hash, uint64_t height, size_t tx_idx)> ) const

perform a check on all outputs in the blockchain

Parameters
std::functionthe check to perform, pass/fail
Returns
false if any output fails the check, otherwise true

◆ for_all_outputs() [2/2]

bool cryptonote::Blockchain::for_all_outputs ( uint64_t amount,
std::function< bool(uint64_t height)>  ) const

perform a check on all outputs of a given amount in the blockchain

Parameters
amountthe amount to iterate through
std::functionthe check to perform, pass/fail
Returns
false if any output fails the check, otherwise true

◆ for_all_transactions()

bool Blockchain::for_all_transactions ( std::function< bool(const crypto::hash &, const cryptonote::transaction &)> ,
bool pruned ) const

perform a check on all transactions in the blockchain

Parameters
std::functionthe check to perform, pass/fail
boolpruned whether to return pruned txes only
Returns
false if any transaction fails the check, otherwise true

◆ for_all_txpool_txes()

bool Blockchain::for_all_txpool_txes ( std::function< bool(const crypto::hash &, const txpool_tx_meta_t &, const cryptonote::blobdata_ref *)> ,
bool include_blob = false,
relay_category tx_category = relay_category::broadcasted ) const

◆ for_blocks_range()

bool Blockchain::for_blocks_range ( const uint64_t & h1,
const uint64_t & h2,
std::function< bool(uint64_t, const crypto::hash &, const block &)>  ) const

perform a check on all blocks in the blockchain in the given range

Parameters
h1the start height
h2the end height
std::functionthe check to perform, pass/fail
Returns
false if any block fails the check, otherwise true

◆ get_adjusted_time()

uint64_t Blockchain::get_adjusted_time ( uint64_t height) const

get the "adjusted time"

Computes the median timestamp of the previous 60 blocks, projects it onto the current block to get an 'adjusted median time' which approximates what the current block's timestamp should be. Also projects the previous block's timestamp to estimate the current block's timestamp.

Returns the minimum of the two projections, or the current local time on the machine if less than 60 blocks are available.

Returns
current time approximated from chain data

◆ get_alternative_blocks()

bool Blockchain::get_alternative_blocks ( std::vector< block > & blocks) const

compiles a list of all blocks stored as alternative chains

Parameters
blocksreturn-by-reference container to put result blocks in
Returns
true

◆ get_alternative_blocks_count()

size_t Blockchain::get_alternative_blocks_count ( ) const

returns the number of alternative blocks stored

Returns
the number of alternative blocks stored

◆ get_alternative_chains()

std::vector< std::pair< Blockchain::block_extended_info, std::vector< crypto::hash > > > Blockchain::get_alternative_chains ( ) const

returns a set of known alternate chains

Returns
a vector of chains

◆ get_block_by_hash()

bool Blockchain::get_block_by_hash ( const crypto::hash & h,
block & blk,
bool * orphan = NULL ) const

gets the block with a given hash

Parameters
hthe hash to look for
blkreturn-by-reference variable to put result block in
orphanif non-NULL, will be set to true if not in the main chain, false otherwise
Returns
true if the block was found, else false

◆ get_block_id_by_height()

crypto::hash Blockchain::get_block_id_by_height ( uint64_t height) const

gets a block's hash given a height

Parameters
heightthe height of the block
Returns
the hash of the block at the requested height, or a zeroed hash if there is no such block

◆ get_blockchain_pruning_seed()

uint32_t cryptonote::Blockchain::get_blockchain_pruning_seed ( ) const
inline

◆ get_blocks() [1/3]

template<class t_ids_container, class t_blocks_container, class t_missed_container>
bool Blockchain::get_blocks ( const t_ids_container & block_ids,
t_blocks_container & blocks,
t_missed_container & missed_bs ) const

gets blocks based on a list of block hashes

Template Parameters
t_ids_containera standard-iterable container
t_blocks_containera standard-iterable container
t_missed_containera standard-iterable container
Parameters
block_idsa container of block hashes for which to get the corresponding blocks
blocksreturn-by-reference a container to store result blocks in
missed_bsreturn-by-reference a container to store missed blocks in
Returns
false if an unexpected exception occurs, else true

◆ get_blocks() [2/3]

bool Blockchain::get_blocks ( uint64_t start_offset,
size_t count,
std::vector< std::pair< cryptonote::blobdata, block > > & blocks ) const

get blocks from blocks based on start height and count

Parameters
start_offsetthe height on the blockchain to start at
countthe number of blocks to get, if there are as many after start_offset
blocksreturn-by-reference container to put result blocks in
Returns
false if start_offset > blockchain height, else true

◆ get_blocks() [3/3]

bool Blockchain::get_blocks ( uint64_t start_offset,
size_t count,
std::vector< std::pair< cryptonote::blobdata, block > > & blocks,
std::vector< cryptonote::blobdata > & txs ) const

get blocks and transactions from blocks based on start height and count

Parameters
start_offsetthe height on the blockchain to start at
countthe number of blocks to get, if there are as many after start_offset
blocksreturn-by-reference container to put result blocks in
txsreturn-by-reference container to put result transactions in
Returns
false if start_offset > blockchain height, else true

◆ get_checkpoints()

const checkpoints & cryptonote::Blockchain::get_checkpoints ( ) const
inline

get a set of blockchain checkpoint hashes

Returns
set of blockchain checkpoint hashes

◆ get_current_blockchain_height()

uint64_t Blockchain::get_current_blockchain_height ( ) const

get the current height of the blockchain

Returns
the height

◆ get_current_cumulative_block_weight_limit()

uint64_t Blockchain::get_current_cumulative_block_weight_limit ( ) const

gets the block weight limit based on recent blocks

Returns
the limit

◆ get_current_cumulative_block_weight_median()

uint64_t Blockchain::get_current_cumulative_block_weight_median ( ) const

gets the block weight median based on recent blocks (same window as for the limit)

Returns
the median

◆ get_current_hard_fork_version()

uint8_t cryptonote::Blockchain::get_current_hard_fork_version ( ) const
inline

gets the current hardfork version in use/voted for

Returns
the version

◆ get_db() [1/2]

BlockchainDB & cryptonote::Blockchain::get_db ( )
inline

get a reference to the BlockchainDB in use by Blockchain

Returns
a reference to the BlockchainDB instance

◆ get_db() [2/2]

const BlockchainDB & cryptonote::Blockchain::get_db ( ) const
inline

get a reference to the BlockchainDB in use by Blockchain

Returns
a reference to the BlockchainDB instance

◆ get_difficulty_for_next_block()

difficulty_type Blockchain::get_difficulty_for_next_block ( )

returns the difficulty target the next block to be added must meet

Returns
the target

◆ get_difficulty_target()

uint64_t Blockchain::get_difficulty_target ( ) const

get difficulty target based on chain and hardfork version

Returns
difficulty target

◆ get_dynamic_base_fee()

uint64_t Blockchain::get_dynamic_base_fee ( uint64_t block_reward,
size_t median_block_weight,
uint8_t version )
static

get dynamic per kB or byte fee for a given block weight

The dynamic fee is based on the block weight in a past window, and the current block reward. It is expressed by kB before v8, and per byte from v8.

Parameters
block_rewardthe current block reward
median_block_weightthe median block weight in the past window
versionhard fork version for rules and constants to use
Returns
the fee

◆ get_dynamic_base_fee_estimate()

uint64_t Blockchain::get_dynamic_base_fee_estimate ( uint64_t grace_blocks) const

get dynamic per kB or byte fee estimate for the next few blocks

The dynamic fee is based on the block weight in a past window, and the current block reward. It is expressed by kB before v8, and per byte from v8. This function calculates an estimate for a dynamic fee which will be valid for the next grace_blocks

Parameters
grace_blocksnumber of blocks we want the fee to be valid for
Returns
the fee estimate

◆ get_dynamic_base_fee_estimate_2021_scaling() [1/2]

void Blockchain::get_dynamic_base_fee_estimate_2021_scaling ( uint64_t grace_blocks,
std::vector< uint64_t > & fees ) const

get four levels of dynamic per byte fee estimate for the next few blocks

The dynamic fee is based on the block weight in a past window, and the current block reward. It is expressed per byte, and is based on https://github.com/ArticMine/Monero-Documents/blob/master/MoneroScaling2021-02.pdf This function calculates an estimate for a dynamic fee which will be valid for the next grace_blocks

Parameters
grace_blocksnumber of blocks we want the fee to be valid for
Returns
the fee estimates (4 of them)

◆ get_dynamic_base_fee_estimate_2021_scaling() [2/2]

void Blockchain::get_dynamic_base_fee_estimate_2021_scaling ( uint64_t grace_blocks,
uint64_t base_reward,
uint64_t Mnw,
uint64_t Mlw,
std::vector< uint64_t > & fees ) const

◆ get_earliest_ideal_height_for_version()

uint64_t cryptonote::Blockchain::get_earliest_ideal_height_for_version ( uint8_t version) const
inline

returns the earliest block a given version may activate

Returns
the height

◆ get_fee_quantization_mask()

uint64_t cryptonote::Blockchain::get_fee_quantization_mask ( )
inlinestatic

get fee quantization mask

The dynamic fee may be quantized, to mask out the last decimal places

Returns
the fee quantized mask

◆ get_hard_fork_state()

HardFork::State Blockchain::get_hard_fork_state ( ) const

gets the hardfork voting state object

Returns
the HardFork object

◆ get_hard_fork_version()

uint8_t cryptonote::Blockchain::get_hard_fork_version ( uint64_t height) const
inline

returns the actual hardfork version for a given block height

Parameters
heightthe height for which to check version info
Returns
the version

◆ get_hard_fork_voting_info()

bool Blockchain::get_hard_fork_voting_info ( uint8_t version,
uint32_t & window,
uint32_t & votes,
uint32_t & threshold,
uint64_t & earliest_height,
uint8_t & voting ) const

get information about hardfork voting for a version

Parameters
versionthe version in question
windowthe size of the voting window
votesthe number of votes to enable <version>
thresholdthe number of votes required to enable <version>
earliest_heightthe earliest height at which <version> is allowed
votingwhich version this node is voting for/using
Returns
whether the version queried is enabled

◆ get_hardforks()

const std::vector< hardfork_t > & cryptonote::Blockchain::get_hardforks ( ) const
inline

returns info for all known hard forks

Returns
the hardforks

◆ get_ideal_hard_fork_version() [1/2]

uint8_t cryptonote::Blockchain::get_ideal_hard_fork_version ( ) const
inline

returns the newest hardfork version known to the blockchain

Returns
the version

◆ get_ideal_hard_fork_version() [2/2]

uint8_t cryptonote::Blockchain::get_ideal_hard_fork_version ( uint64_t height) const
inline

returns the newest hardfork version voted to be enabled as of a certain height

Parameters
heightthe height for which to check version info
Returns
the version

◆ get_last_block_timestamps()

std::vector< time_t > Blockchain::get_last_block_timestamps ( unsigned int blocks) const

returns the timestamps of the last N blocks

◆ get_last_n_blocks_weights()

void Blockchain::get_last_n_blocks_weights ( std::vector< uint64_t > & weights,
size_t count ) const
private

gets recent block weights for median calculation

get the block weights of the last <count> blocks, and return by reference <weights>.

Parameters
weightsreturn-by-reference the list of weights
countthe number of blocks to get weights for

◆ get_long_term_block_weight_median()

uint64_t Blockchain::get_long_term_block_weight_median ( uint64_t start_height,
size_t count ) const
private

gets block long term weight median

get the block long term weight median of <count> blocks starting at <start_height>

Parameters
start_heightthe block height of the first block to query
countthe number of blocks to get weights for
Returns
the long term median block weight

◆ get_miner_data()

bool Blockchain::get_miner_data ( uint8_t & major_version,
uint64_t & height,
crypto::hash & prev_id,
crypto::hash & seed_hash,
difficulty_type & difficulty,
uint64_t & median_weight,
uint64_t & already_generated_coins,
std::vector< tx_block_template_backlog_entry > & tx_backlog )

gets data required to create a block template and start mining on it

Parameters
major_versioncurrent hardfork version
heightcurrent blockchain height
prev_idhash of the top block
seed_hashseed hash used for RandomX initialization
difficultycurrent mining difficulty
median_weightcurrent median block weight
already_generated_coinscurrent emission
tx_backlogtransactions in mempool ready to be mined
Returns
true if block template filled in successfully, else false

◆ get_next_difficulty_for_alternative_chain()

difficulty_type Blockchain::get_next_difficulty_for_alternative_chain ( const std::list< block_extended_info > & alt_chain,
block_extended_info & bei ) const
private

gets the difficulty requirement for a new block on an alternate chain

Parameters
alt_chainthe chain to be added to
beithe block being added (and metadata, see ::block_extended_info)
Returns
the difficulty requirement

◆ get_next_hard_fork_version()

uint8_t cryptonote::Blockchain::get_next_hard_fork_version ( ) const
inline

returns the next hardfork version

Returns
the version

◆ get_next_long_term_block_weight()

uint64_t Blockchain::get_next_long_term_block_weight ( uint64_t block_weight) const

gets the long term block weight for a new block

Returns
the long term block weight

◆ get_num_mature_outputs()

uint64_t Blockchain::get_num_mature_outputs ( uint64_t amount) const

get number of outputs of an amount past the minimum spendable age

Parameters
amountthe output amount
Returns
the number of mature outputs

◆ get_output_distribution()

bool Blockchain::get_output_distribution ( uint64_t amount,
uint64_t from_height,
uint64_t to_height,
uint64_t & start_height,
std::vector< uint64_t > & distribution,
uint64_t & base ) const

gets per block distribution of outputs of a given amount

Parameters
amountthe amount to get a ditribution for
from_heightthe height before which we do not care about the data
to_heightthe height after which we do not care about the data
return-by-referencestart_height the height of the first rct output
return-by-referencedistribution the start offset of the first rct output in this block (same as previous if none)
return-by-referencebase how many outputs of that amount are before the stated distribution

◆ get_output_histogram()

std::map< uint64_t, std::tuple< uint64_t, uint64_t, uint64_t > > Blockchain::get_output_histogram ( const std::vector< uint64_t > & amounts,
bool unlocked,
uint64_t recent_cutoff,
uint64_t min_count = 0 ) const

return a histogram of outputs on the blockchain

Parameters
amountsoptional set of amounts to lookup
unlockedwhether to restrict instances to unlocked ones
recent_cutofftimestamp to consider outputs as recent
min_countreturn only amounts with at least that many instances
Returns
a set of amount/instances

◆ get_output_key()

crypto::public_key Blockchain::get_output_key ( uint64_t amount,
uint64_t global_index ) const

get the public key for an output

Parameters
amountthe output amount
global_indexthe output amount-global index
Returns
the public key

◆ get_output_key_mask_unlocked()

void Blockchain::get_output_key_mask_unlocked ( const uint64_t & amount,
const uint64_t & index,
crypto::public_key & key,
rct::key & mask,
bool & unlocked ) const

gets an output's key and unlocked state

Parameters
amountin - the output amount
indexin - the output global amount index
maskout - the output's RingCT mask
keyout - the output's key
unlockedout - the output's unlocked state

◆ get_outs()

gets specific outputs to mix with

This function takes an RPC request for outputs to mix with and creates an RPC response with the resultant output indices.

Outputs to mix with are specified in the request.

Parameters
reqthe outputs to return
resreturn-by-reference the resultant output indices and keys
Returns
true

◆ get_pending_block_id_by_height()

crypto::hash Blockchain::get_pending_block_id_by_height ( uint64_t height) const

gets a block's hash given a height

Used only by prepare_handle_incoming_blocks. Will look in the list of incoming blocks if the height is contained there.

Parameters
heightthe height of the block
Returns
the hash of the block at the requested height, or a zeroed hash if there is no such block

◆ get_short_chain_history()

bool Blockchain::get_short_chain_history ( std::list< crypto::hash > & ids,
uint64_t & current_height ) const

gets the hashes for a subset of the blockchain

puts into list <ids> a list of hashes representing certain blocks from the blockchain in reverse chronological order

the blocks chosen, at the time of this writing, are: the most recent 11 powers of 2 less recent from there, so 13, 17, 25, etc...

Parameters
idsreturn-by-reference list to put the resulting hashes in
current_heightthe current blockchain height, return-by-reference
Returns
true

◆ get_split_transactions_blobs()

template<class t_ids_container, class t_tx_container, class t_missed_container>
template bool cryptonote::Blockchain::get_split_transactions_blobs ( const t_ids_container & txs_ids,
t_tx_container & txs,
t_missed_container & missed_txs ) const

◆ get_tail_id() [1/2]

crypto::hash Blockchain::get_tail_id ( ) const

get the hash of the most recent block on the blockchain

Returns
the hash

◆ get_tail_id() [2/2]

crypto::hash Blockchain::get_tail_id ( uint64_t & height) const

get the height and hash of the most recent block on the blockchain

Parameters
heightreturn-by-reference variable to store the height in
Returns
the hash

◆ get_total_transactions()

size_t Blockchain::get_total_transactions ( ) const

gets the total number of transactions on the main chain

Returns
the number of transactions on the main chain

◆ get_transactions() [1/2]

template<class t_ids_container, class t_tx_container, class t_missed_container>
bool cryptonote::Blockchain::get_transactions ( const t_ids_container & txs_ids,
t_tx_container & txs,
t_missed_container & missed_txs,
bool pruned ) const

◆ get_transactions() [2/2]

template<class t_ids_container, class t_tx_container, class t_missed_container>
bool cryptonote::Blockchain::get_transactions ( const t_ids_container & txs_ids,
t_tx_container & txs,
t_missed_container & missed_txs,
bool pruned = false ) const

◆ get_transactions_blobs() [1/2]

bool Blockchain::get_transactions_blobs ( const std::vector< crypto::hash > & txs_ids,
std::vector< cryptonote::blobdata > & txs,
std::vector< crypto::hash > & missed_txs,
bool pruned = false ) const

gets transactions based on a list of transaction hashes

Template Parameters
t_ids_containera standard-iterable container
t_tx_containera standard-iterable container
t_missed_containera standard-iterable container
Parameters
txs_idsa container of hashes for which to get the corresponding transactions
txsreturn-by-reference a container to store result transactions in
missed_txsreturn-by-reference a container to store missed transactions in
prunedwhether to return full or pruned blobs
Returns
false if an unexpected exception occurs, else true

◆ get_transactions_blobs() [2/2]

bool Blockchain::get_transactions_blobs ( const std::vector< crypto::hash > & txs_ids,
std::vector< tx_blob_entry > & txs,
std::vector< crypto::hash > & missed_txs,
bool pruned = false ) const

◆ get_tx_outputs_gindexs() [1/2]

bool Blockchain::get_tx_outputs_gindexs ( const crypto::hash & tx_id,
size_t n_txes,
std::vector< std::vector< uint64_t > > & indexs ) const

◆ get_tx_outputs_gindexs() [2/2]

bool Blockchain::get_tx_outputs_gindexs ( const crypto::hash & tx_id,
std::vector< uint64_t > & indexs ) const

gets the global indices for outputs from a given transaction

This function gets the global indices for all outputs belonging to a specific transaction.

Parameters
tx_idthe hash of the transaction to fetch indices for
indexsreturn-by-reference the global indices for the transaction's outputs
n_txeshow many txes in a row to get results for
Returns
false if the transaction does not exist, or if no indices are found, otherwise true

◆ get_txpool_tx_blob() [1/2]

bool Blockchain::get_txpool_tx_blob ( const crypto::hash & txid,
cryptonote::blobdata & bd,
relay_category tx_category ) const

◆ get_txpool_tx_blob() [2/2]

cryptonote::blobdata Blockchain::get_txpool_tx_blob ( const crypto::hash & txid,
relay_category tx_category ) const

◆ get_txpool_tx_count()

uint64_t Blockchain::get_txpool_tx_count ( bool include_sensitive = false) const

◆ get_txpool_tx_meta()

bool Blockchain::get_txpool_tx_meta ( const crypto::hash & txid,
txpool_tx_meta_t & meta ) const

◆ handle_alternative_block()

bool Blockchain::handle_alternative_block ( const block & b,
const crypto::hash & id,
block_verification_context & bvc,
pool_supplement & extra_block_txs )
private

validate and add a new block to an alternate blockchain

If a block to be added does not belong to the main chain, but there is an alternate chain to which it should be added, that is handled here.

Parameters
bthe block to be added
idthe hash of the block
bvcmetadata concerning the block's validity
extra_block_txstxs belonging to this block that may not be in the mempool
Returns
true if the block was added successfully, otherwise false

◆ handle_block_to_main_chain() [1/2]

bool Blockchain::handle_block_to_main_chain ( const block & bl,
block_verification_context & bvc )
private

validate and add a new block to the end of the blockchain

This function is merely a convenience wrapper around the other of the same name. This one passes the block's hash to the other as well as the block and verification context.

Parameters
blthe block to be added
bvcmetadata concerning the block's validity
Returns
true if the block was added successfully, otherwise false

◆ handle_block_to_main_chain() [2/2]

bool Blockchain::handle_block_to_main_chain ( const block & bl,
const crypto::hash & id,
block_verification_context & bvc,
pool_supplement & extra_block_txs )
private

validate and add a new block to the end of the blockchain

When a block is given to Blockchain to be added to the blockchain, it is passed here if it is determined to belong at the end of the current chain.

Parameters
blthe block to be added
idthe hash of the block
bvcmetadata concerning the block's validity
extra_block_txstxs belonging to this block that may not be in the mempool
Returns
true if the block was added successfully, otherwise false

◆ handle_get_objects()

bool Blockchain::handle_get_objects ( NOTIFY_REQUEST_GET_OBJECTS::request & arg,
NOTIFY_RESPONSE_GET_OBJECTS::request & rsp )

retrieves a set of blocks and their transactions, and possibly other transactions

the request object encapsulates a list of block hashes and a (possibly empty) list of transaction hashes. for each block hash, the block is fetched along with all of that block's transactions. Any transactions requested separately are fetched afterwards.

Parameters
argthe request
rspreturn-by-reference the response to fill in
Returns
true unless any blocks or transactions are missing

◆ has_block_weights()

bool Blockchain::has_block_weights ( uint64_t height,
uint64_t nblocks ) const

checks whether we have known weights for the given block heights

Parameters
heightthe start height to check for
nblockshow many blocks to check from that height

◆ have_block()

bool Blockchain::have_block ( const crypto::hash & id,
int * where = NULL ) const

◆ have_block_unlocked()

bool Blockchain::have_block_unlocked ( const crypto::hash & id,
int * where = NULL ) const

checks if a block is known about with a given hash

This function checks the main chain, alternate chains, and invalid blocks for a block with the given hash

Parameters
idthe hash to search for
wherethe type of block, if non NULL
Returns
true if the block is known, else false

◆ have_tx()

bool Blockchain::have_tx ( const crypto::hash & id) const

search the blockchain for a transaction by hash

Parameters
idthe hash to search for
Returns
true if the tx exists, else false

◆ have_tx_keyimg_as_spent()

bool Blockchain::have_tx_keyimg_as_spent ( const crypto::key_image & key_im) const

check if a key image is already spent on the blockchain

Whenever a transaction output is used as an input for another transaction (a true input, not just one of a mixing set), a key image is generated and stored in the transaction in order to prevent double spending. If this key image is seen again, the transaction using it is rejected.

Parameters
key_imthe key image to search for
Returns
true if the key image is already spent in the blockchain, else false

◆ have_tx_keyimges_as_spent()

bool Blockchain::have_tx_keyimges_as_spent ( const transaction & tx) const

check if any key image in a transaction has already been spent

Parameters
txthe transaction to check
Returns
true if any key image is already spent in the blockchain, else false

◆ init() [1/2]

bool Blockchain::init ( BlockchainDB * db,
const network_type nettype = MAINNET,
bool offline = false,
const cryptonote::test_options * test_options = NULL,
difficulty_type fixed_difficulty = 0,
const GetCheckpointsCallback & get_checkpoints = nullptr )

Initialize the Blockchain state.

Parameters
dba pointer to the backing store to use for the blockchain
nettypenetwork type
offlinetrue if running offline, else false
test_optionstest parameters
fixed_difficultyfixed difficulty for testing purposes; 0 means disabled
get_checkpointsif set, will be called to get checkpoints data
Returns
true on success, false if any initialization steps fail

◆ init() [2/2]

bool Blockchain::init ( BlockchainDB * db,
HardFork *& hf,
const network_type nettype = MAINNET,
bool offline = false )

Initialize the Blockchain state.

Parameters
dba pointer to the backing store to use for the blockchain
hfa structure containing hardfork information
nettypenetwork type
offlinetrue if running offline, else false
Returns
true on success, false if any initialization steps fail

◆ invalidate_block_template_cache()

void Blockchain::invalidate_block_template_cache ( )
private

invalidates any cached block template

◆ is_tx_spendtime_unlocked()

bool Blockchain::is_tx_spendtime_unlocked ( uint64_t unlock_time,
uint8_t hf_version ) const
private

checks if a transaction is unlocked (its outputs spendable)

This function checks to see if a transaction is unlocked. unlock_time is either a block index or a unix time.

Parameters
unlock_timethe unlock parameter (height or time)
hf_versionthe consensus rules version to use
Returns
true if spendable, otherwise false

◆ is_within_compiled_block_hash_area() [1/2]

bool cryptonote::Blockchain::is_within_compiled_block_hash_area ( ) const
inline

◆ is_within_compiled_block_hash_area() [2/2]

bool Blockchain::is_within_compiled_block_hash_area ( uint64_t height) const

checks whether a given block height is included in the precompiled block hash area

Parameters
heightthe height to check for

◆ load_compiled_in_block_hashes()

void cryptonote::Blockchain::load_compiled_in_block_hashes ( const GetCheckpointsCallback & get_checkpoints)
private

loads block hashes from compiled-in data set

A (possibly empty) set of block hashes can be compiled into the monero daemon binary. This function loads those hashes into a useful state.

Parameters
get_checkpointsif set, will be called to get checkpoints data

◆ lock()

void Blockchain::lock ( )

◆ notify_txpool_event()

void Blockchain::notify_txpool_event ( std::vector< txpool_event > && event) const

Notify this Blockchain's txpool notifier about a txpool event.

◆ output_scan_worker()

void Blockchain::output_scan_worker ( const uint64_t amount,
const std::vector< uint64_t > & offsets,
std::vector< output_data_t > & outputs ) const

get a number of outputs of a specific amount

Parameters
amountthe amount
offsetsthe indices (indexed to the amount) of the outputs
outputsreturn-by-reference the outputs collected

◆ pop_block_from_blockchain()

block Blockchain::pop_block_from_blockchain ( )
private

removes the most recent block from the blockchain

Returns
the block removed

◆ pop_blocks()

void Blockchain::pop_blocks ( uint64_t nblocks)

removes blocks from the top of the blockchain

Parameters
nblocksnumber of blocks to be removed

◆ prepare_handle_incoming_block_no_preprocess()

void Blockchain::prepare_handle_incoming_block_no_preprocess ( const size_t block_byte_estimate)

prepare the blockchain for handling an incoming block, without performing preprocessing

Parameters
block_byte_estimatean estimate of the byte size of the block & its transactions

This function should always be followed up by a call to cleanup_handle_incoming_blocks() later in the same thread.

◆ prepare_handle_incoming_blocks()

bool Blockchain::prepare_handle_incoming_blocks ( const std::vector< block_complete_entry > & blocks_entry,
std::vector< block > & blocks )

performs some preprocessing on a group of incoming blocks to speed up verification

Parameters
blocks_entrya list of incoming blocks
blocksthe parsed blocks
Returns
false on erroneous blocks, else true

◆ prevalidate_block_hashes()

uint64_t Blockchain::prevalidate_block_hashes ( uint64_t height,
const std::vector< crypto::hash > & hashes,
const std::vector< uint64_t > & weights )

◆ prevalidate_miner_transaction()

bool Blockchain::prevalidate_miner_transaction ( const block & b,
uint64_t height,
uint8_t hf_version )
private

sanity checks a miner transaction before validating an entire block

This function merely checks basic things like the structure of the miner transaction, the unlock time, and that the amount doesn't overflow.

Parameters
bthe block containing the miner transaction
heightthe height at which the block will be added
hf_versionthe consensus rules to apply
Returns
false if anything is found wrong with the miner transaction, otherwise true

◆ prune_blockchain()

bool Blockchain::prune_blockchain ( uint32_t pruning_seed = 0)

◆ recalculate_difficulties()

size_t Blockchain::recalculate_difficulties ( boost::optional< uint64_t > start_height = boost::none)

recalculate difficulties for blocks after the last difficulty checkpoints to circumvent the annoying 'difficulty drift' bug

Parameters
start_heightif omitted, starts recalculation from the last difficulty checkpoint
Returns
number of blocks whose difficulties got corrected

◆ remove_txpool_tx()

void Blockchain::remove_txpool_tx ( const crypto::hash & txid)

◆ reset_and_set_genesis_block()

bool Blockchain::reset_and_set_genesis_block ( const block & b)

clears the blockchain and starts a new one

Parameters
bthe first block in the new chain (the genesis block)
Returns
true on success, else false

◆ rollback_blockchain_switching()

bool Blockchain::rollback_blockchain_switching ( std::list< block > & original_chain,
uint64_t rollback_height )
private

reverts the blockchain to its previous state following a failed switch

If Blockchain fails to switch to an alternate chain when it means to do so, this function reverts the blockchain to how it was before the attempted switch.

Parameters
original_chainthe chain to switch back to
rollback_heightthe height to revert to before appending the original chain
Returns
false if something goes wrong with reverting (very bad), otherwise true

◆ safesyncmode()

void Blockchain::safesyncmode ( const bool onoff)

Put DB in safe sync mode.

◆ scan_outputkeys_for_indexes()

template<class visitor_t>
bool Blockchain::scan_outputkeys_for_indexes ( size_t tx_version,
const txin_to_key & tx_in_to_key,
visitor_t & vis,
const crypto::hash & tx_prefix_hash,
uint64_t * pmax_related_block_height = NULL ) const
inlineprivate

collects the keys for all outputs being "spent" as an input

This function makes sure that each "input" in an input (mixins) exists and collects the public key for each from the transaction it was included in via the visitor passed to it.

If pmax_related_block_height is not NULL, its value is set to the height of the most recent block which contains an output used in the input set

Template Parameters
visitor_ta class encapsulating tx is unlocked and collect tx key
Parameters
tx_in_to_keya transaction input instance
visan instance of the visitor to use
tx_prefix_hashthe hash of the associated transaction_prefix
pmax_related_block_heightreturn-by-pointer the height of the most recent block in the input set
tx_versionversion of the tx, if > 1 we also get commitments
Returns
false if any keys are not found or any inputs are not unlocked, otherwise true

◆ send_miner_notifications()

void Blockchain::send_miner_notifications ( uint64_t height,
const crypto::hash & seed_hash,
const crypto::hash & prev_id,
uint64_t already_generated_coins )
private

sends new block notifications to ZMQ miner_data subscribers

Parameters
heightcurrent blockchain height
seed_hashseed hash to use for mining
prev_idhash of new blockchain tip
already_generated_coinstotal coins mined by the network so far

◆ set_checkpoints()

void cryptonote::Blockchain::set_checkpoints ( checkpoints && chk_pts)
inline

assign a set of blockchain checkpoint hashes

Parameters
chk_ptsthe set of checkpoints to assign

◆ set_enforce_dns_checkpoints()

void Blockchain::set_enforce_dns_checkpoints ( bool enforce)

configure whether or not to enforce DNS-based checkpoints

Parameters
enforcethe new enforcement setting

◆ set_reorg_notify()

void cryptonote::Blockchain::set_reorg_notify ( const std::shared_ptr< tools::Notify > & notify)
inline

sets a reorg notify object to call for every reorg

Parameters
notifythe notify object to call at every reorg

◆ set_show_time_stats()

void cryptonote::Blockchain::set_show_time_stats ( bool stats)
inline

set whether or not to show/print time statistics

Parameters
statsthe new time stats setting

◆ set_txpool_notify()

void Blockchain::set_txpool_notify ( TxpoolNotifyCallback && notify)

sets a txpool notify object to call for every new tx used to add a new block

Parameters
notifythe notify object to call at every new tx used to add a new block

◆ set_user_options()

void Blockchain::set_user_options ( uint64_t maxthreads,
bool sync_on_blocks,
uint64_t sync_threshold,
blockchain_db_sync_mode sync_mode,
bool fast_sync )

sets various performance options

Parameters
maxthreadsmax number of threads when preparing blocks for addition
sync_on_blockswhether to sync based on blocks or bytes
sync_thresholdnumber of blocks/bytes to cache before syncing to database
sync_modethe ::blockchain_db_sync_mode to use
fast_syncsync using built-in block hashes as trusted

◆ store_blockchain()

bool Blockchain::store_blockchain ( )

stores the blockchain

If Blockchain is handling storing of the blockchain (rather than BlockchainDB), this initiates a blockchain save.

Returns
true unless saving the blockchain fails

◆ switch_to_alternative_blockchain()

bool Blockchain::switch_to_alternative_blockchain ( std::list< block_extended_info > & alt_chain,
bool discard_disconnected_chain )
private

performs a blockchain reorganization according to the longest chain rule

This function aggregates all the actions necessary to switch to a newly-longer chain. If any step in the reorganization process fails, the blockchain is reverted to its previous state.

Parameters
alt_chainthe chain to switch to
discard_disconnected_chainwhether or not to keep the old chain as an alternate
Returns
false if the reorganization fails, otherwise true

◆ txpool_tx_matches_category()

bool Blockchain::txpool_tx_matches_category ( const crypto::hash & tx_hash,
relay_category category )

◆ unlock()

void Blockchain::unlock ( )

◆ update_blockchain_pruning()

bool Blockchain::update_blockchain_pruning ( )

◆ update_checkpoints()

bool Blockchain::update_checkpoints ( const std::string & file_path,
bool check_dns )

loads new checkpoints from a file and optionally from DNS

Parameters
file_paththe path of the file to look for and load checkpoints from
check_dnswhether or not to check for new DNS-based checkpoints
Returns
false if any enforced checkpoint type fails to load, otherwise true

◆ update_next_cumulative_weight_limit()

bool Blockchain::update_next_cumulative_weight_limit ( uint64_t * long_term_effective_median_block_weight = NULL)
private

calculate the block weight limit for the next block to be added

Parameters
long_term_effective_median_block_weightoptionally return that value
Returns
true

◆ update_txpool_tx()

void Blockchain::update_txpool_tx ( const crypto::hash & txid,
const txpool_tx_meta_t & meta )

◆ validate_miner_transaction()

bool Blockchain::validate_miner_transaction ( const block & b,
size_t cumulative_block_weight,
uint64_t fee,
uint64_t & base_reward,
uint64_t already_generated_coins,
bool & partial_block_reward,
uint8_t version )
private

validates a miner (coinbase) transaction

This function makes sure that the miner calculated his reward correctly and that his miner transaction totals reward + fee.

Parameters
bthe block containing the miner transaction to be validated
cumulative_block_weightthe block's weight
feethe total fees collected in the block
base_rewardreturn-by-reference the new block's generated coins
already_generated_coinsthe amount of currency generated prior to this block
partial_block_rewardreturn-by-reference true if miner accepted only partial reward
versionhard fork version for that transaction
Returns
false if anything is found wrong with the miner transaction, otherwise true

Member Data Documentation

◆ m_async_pool

boost::thread_group cryptonote::Blockchain::m_async_pool
private

◆ m_async_service

boost::asio::io_context cryptonote::Blockchain::m_async_service
private

◆ m_async_work_idle

std::unique_ptr<boost::asio::executor_work_guard<boost::asio::io_context::executor_type> > cryptonote::Blockchain::m_async_work_idle
private

◆ m_batch_success

bool cryptonote::Blockchain::m_batch_success
private

◆ m_block_notifiers

std::vector<BlockNotifyCallback> cryptonote::Blockchain::m_block_notifiers
private

◆ m_blockchain_lock

epee::critical_section cryptonote::Blockchain::m_blockchain_lock
mutableprivate

◆ m_blocks_hash_check

std::vector<std::pair<crypto::hash, uint64_t> > cryptonote::Blockchain::m_blocks_hash_check
private

◆ m_blocks_hash_of_hashes

std::vector<std::pair<crypto::hash, crypto::hash> > cryptonote::Blockchain::m_blocks_hash_of_hashes
private

◆ m_blocks_longhash_table

std::unordered_map<crypto::hash, crypto::hash> cryptonote::Blockchain::m_blocks_longhash_table
private

◆ m_btc

block cryptonote::Blockchain::m_btc
private

◆ m_btc_address

account_public_address cryptonote::Blockchain::m_btc_address
private

◆ m_btc_difficulty

difficulty_type cryptonote::Blockchain::m_btc_difficulty
private

◆ m_btc_expected_reward

uint64_t cryptonote::Blockchain::m_btc_expected_reward
private

◆ m_btc_height

uint64_t cryptonote::Blockchain::m_btc_height
private

◆ m_btc_nonce

blobdata cryptonote::Blockchain::m_btc_nonce
private

◆ m_btc_pool_cookie

uint64_t cryptonote::Blockchain::m_btc_pool_cookie
private

◆ m_btc_seed_hash

crypto::hash cryptonote::Blockchain::m_btc_seed_hash
private

◆ m_btc_seed_height

uint64_t cryptonote::Blockchain::m_btc_seed_height
private

◆ m_btc_valid

bool cryptonote::Blockchain::m_btc_valid
private

◆ m_bytes_to_sync

uint64_t cryptonote::Blockchain::m_bytes_to_sync
private

◆ m_cancel

std::atomic<bool> cryptonote::Blockchain::m_cancel
private

◆ m_checkpoints

checkpoints cryptonote::Blockchain::m_checkpoints
private

◆ m_current_block_cumul_weight_limit

size_t cryptonote::Blockchain::m_current_block_cumul_weight_limit
private

◆ m_current_block_cumul_weight_median

size_t cryptonote::Blockchain::m_current_block_cumul_weight_median
private

◆ m_db

BlockchainDB* cryptonote::Blockchain::m_db
private

◆ m_db_default_sync

bool cryptonote::Blockchain::m_db_default_sync
private

◆ m_db_sync_mode

blockchain_db_sync_mode cryptonote::Blockchain::m_db_sync_mode
private

◆ m_db_sync_on_blocks

bool cryptonote::Blockchain::m_db_sync_on_blocks
private

◆ m_db_sync_threshold

uint64_t cryptonote::Blockchain::m_db_sync_threshold
private

◆ m_difficulties

std::vector<difficulty_type> cryptonote::Blockchain::m_difficulties
private

◆ m_difficulty_for_next_block

difficulty_type cryptonote::Blockchain::m_difficulty_for_next_block
private

◆ m_difficulty_for_next_block_top_hash

crypto::hash cryptonote::Blockchain::m_difficulty_for_next_block_top_hash
private

◆ m_difficulty_lock

epee::critical_section cryptonote::Blockchain::m_difficulty_lock
private

◆ m_enforce_dns_checkpoints

bool cryptonote::Blockchain::m_enforce_dns_checkpoints
private

◆ m_fake_pow_calc_time

uint64_t cryptonote::Blockchain::m_fake_pow_calc_time
private

◆ m_fake_scan_time

uint64_t cryptonote::Blockchain::m_fake_scan_time
private

◆ m_fast_sync

bool cryptonote::Blockchain::m_fast_sync
private

◆ m_fixed_difficulty

difficulty_type cryptonote::Blockchain::m_fixed_difficulty
private

◆ m_hardfork

HardFork* cryptonote::Blockchain::m_hardfork
private

◆ m_invalid_blocks

blocks_ext_by_hash cryptonote::Blockchain::m_invalid_blocks
private

◆ m_long_term_block_weights_cache_rolling_median

epee::misc_utils::rolling_median_t<uint64_t> cryptonote::Blockchain::m_long_term_block_weights_cache_rolling_median
mutableprivate

◆ m_long_term_block_weights_cache_tip_hash

crypto::hash cryptonote::Blockchain::m_long_term_block_weights_cache_tip_hash
mutableprivate

◆ m_long_term_block_weights_window

uint64_t cryptonote::Blockchain::m_long_term_block_weights_window
private

◆ m_long_term_effective_median_block_weight

uint64_t cryptonote::Blockchain::m_long_term_effective_median_block_weight
private

◆ m_max_prepare_blocks_threads

uint64_t cryptonote::Blockchain::m_max_prepare_blocks_threads
private

◆ m_miner_notifiers

std::vector<MinerNotifyCallback> cryptonote::Blockchain::m_miner_notifiers
private

◆ m_nettype

network_type cryptonote::Blockchain::m_nettype
private

◆ m_offline

bool cryptonote::Blockchain::m_offline
private

◆ m_prepare_blocks

std::vector<block>* cryptonote::Blockchain::m_prepare_blocks
private

◆ m_prepare_height

uint64_t cryptonote::Blockchain::m_prepare_height
private

◆ m_prepare_nblocks

uint64_t cryptonote::Blockchain::m_prepare_nblocks
private

◆ m_rct_ver_cache

rct_ver_cache_t cryptonote::Blockchain::m_rct_ver_cache
mutableprivate

◆ m_reorg_notify

std::shared_ptr<tools::Notify> cryptonote::Blockchain::m_reorg_notify
private

◆ m_reset_timestamps_and_difficulties_height

bool cryptonote::Blockchain::m_reset_timestamps_and_difficulties_height
private

◆ m_scan_table

std::unordered_map<crypto::hash, std::unordered_map<crypto::key_image, std::vector<output_data_t> > > cryptonote::Blockchain::m_scan_table
private

◆ m_show_time_stats

bool cryptonote::Blockchain::m_show_time_stats
private

◆ m_sync_counter

uint64_t cryptonote::Blockchain::m_sync_counter
private

◆ m_timestamps

std::vector<uint64_t> cryptonote::Blockchain::m_timestamps
private

◆ m_timestamps_and_difficulties_height

uint64_t cryptonote::Blockchain::m_timestamps_and_difficulties_height
private

◆ m_tx_pool

tx_memory_pool& cryptonote::Blockchain::m_tx_pool
private

◆ m_txpool_notifier

TxpoolNotifyCallback cryptonote::Blockchain::m_txpool_notifier
private

◆ m_txpool_notifier_mutex

std::mutex cryptonote::Blockchain::m_txpool_notifier_mutex
mutableprivate

The documentation for this class was generated from the following files: