|
Electroneum
|
#include <blockchain.h>

Classes | |
| struct | block_extended_info |
| container for passing a block and metadata about it on the blockchain More... | |
| struct | transaction_chain_entry |
| Now-defunct (TODO: remove) struct from in-memory blockchain. More... | |
Public Member Functions | |
| Blockchain (tx_memory_pool &tx_pool) | |
| Blockchain constructor. More... | |
| ~Blockchain () | |
| Blockchain destructor. More... | |
| 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, bool ignore_bsig=false, bool fallback_to_pow=false) |
| Initialize the Blockchain state. More... | |
| bool | init (BlockchainDB *db, HardFork *&hf, const network_type nettype=MAINNET, bool offline=false) |
| Initialize the Blockchain state. More... | |
| bool | deinit () |
| Uninitializes the blockchain state. More... | |
| void | set_checkpoints (checkpoints &&chk_pts) |
| assign a set of blockchain checkpoint hashes More... | |
| 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 More... | |
| 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 More... | |
| bool | get_alternative_blocks (std::vector< block > &blocks) const |
| compiles a list of all blocks stored as alternative chains More... | |
| size_t | get_alternative_blocks_count () const |
| returns the number of alternative blocks stored More... | |
| crypto::hash | get_block_id_by_height (uint64_t height) const |
| gets a block's hash given a height More... | |
| bool | get_block_by_hash (const crypto::hash &h, block &blk, bool *orphan=NULL) const |
| gets the block with a given hash More... | |
| 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 More... | |
| bool | cleanup_handle_incoming_blocks (bool force_sync=false) |
| incoming blocks post-processing, cleanup, and disk sync More... | |
| bool | have_tx (const crypto::hash &id) const |
| search the blockchain for a transaction by hash More... | |
| bool | have_tx_keyimges_as_spent (const transaction &tx) const |
| check if any key image in a transaction has already been spent More... | |
| bool | have_tx_keyimg_as_spent (const crypto::key_image &key_im) const |
| check if a key image is already spent on the blockchain More... | |
| uint64_t | get_current_blockchain_height () const |
| get the current height of the blockchain More... | |
| crypto::hash | get_tail_id () const |
| get the hash of the most recent block on the blockchain More... | |
| crypto::hash | get_tail_id (uint64_t &height) const |
| get the height and hash of the most recent block on the blockchain More... | |
| difficulty_type | get_difficulty_for_next_block () |
| returns the difficulty target the next block to be added must meet More... | |
| void | normalize_v7_difficulties () |
| Normalize the cumulative difficulty for V7 blocks, fixing the differing difficulty among nodes. More... | |
| bool | add_new_block (const block &bl_, block_verification_context &bvc) |
| adds a block to the blockchain More... | |
| bool | reset_and_set_genesis_block (const block &b) |
| clears the blockchain and starts a new one More... | |
| 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) |
| creates a new block to mine against More... | |
| 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) |
| bool | have_block (const crypto::hash &id) const |
| checks if a block is known about with a given hash More... | |
| size_t | get_total_transactions () const |
| gets the total number of transactions on the main chain More... | |
| bool | get_short_chain_history (std::list< crypto::hash > &ids) const |
| gets the hashes for a subset of the blockchain More... | |
| bool | find_blockchain_supplement (const std::list< crypto::hash > &qblock_ids, std::vector< crypto::hash > &hashes, uint64_t &start_height, uint64_t ¤t_height, bool clip_pruned) const |
| get recent block hashes for a foreign chain More... | |
| bool | find_blockchain_supplement (const std::list< crypto::hash > &qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request &resp) const |
| get recent block hashes for a foreign chain More... | |
| 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 More... | |
| 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_count) const |
| get recent blocks for a foreign chain More... | |
| 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 More... | |
| uint64_t | get_num_mature_outputs (uint64_t amount) const |
| get number of outputs of an amount past the minimum spendable age More... | |
| crypto::public_key | get_output_key (uint64_t amount, uint64_t global_index) const |
| get the public key for an output More... | |
| 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 More... | |
| 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 More... | |
| 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 More... | |
| 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 More... | |
| 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 More... | |
| 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) |
| validates a transaction's inputs More... | |
| 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 More... | |
| bool | check_fee (size_t tx_weight, uint64_t fee) const |
| validate a transaction's fee More... | |
| bool | check_tx_outputs (const transaction &tx, tx_verification_context &tvc) |
| check that a transaction's outputs conform to current standards More... | |
| uint64_t | get_current_cumulative_block_weight_limit () const |
| gets the block weight limit based on recent blocks More... | |
| uint64_t | get_next_long_term_block_weight (uint64_t block_weight) const |
| gets the long term block weight for a new block More... | |
| uint64_t | get_current_cumulative_block_weight_median () const |
| gets the block weight median based on recent blocks (same window as for the limit) More... | |
| difficulty_type | block_difficulty (uint64_t i) const |
| gets the difficulty of the block with a given height More... | |
| 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 More... | |
| template<class t_ids_container , class t_tx_container , class t_missed_container > | |
| bool | get_transactions_blobs (const t_ids_container &txs_ids, t_tx_container &txs, t_missed_container &missed_txs, bool pruned=false) const |
| gets transactions based on a list of transaction hashes More... | |
| 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) const |
| void | check_against_checkpoints (const checkpoints &points, bool enforce) |
| check the blockchain against a set of checkpoints More... | |
| void | set_enforce_dns_checkpoints (bool enforce) |
| configure whether or not to enforce DNS-based checkpoints More... | |
| bool | update_checkpoints (const std::string &file_path, bool check_dns) |
| loads new checkpoints from a file and optionally from DNS More... | |
| void | set_user_options (uint64_t maxthreads, bool sync_on_blocks, uint64_t sync_threshold, blockchain_db_sync_mode sync_mode, bool fast_sync, std::string validator_key) |
| Update the validators public key by fetching data from electroneum's endpoint. More... | |
| void | set_block_notify (const std::shared_ptr< tools::Notify > ¬ify) |
| sets a block notify object to call for every new block More... | |
| void | set_reorg_notify (const std::shared_ptr< tools::Notify > ¬ify) |
| sets a reorg notify object to call for every reorg More... | |
| void | safesyncmode (const bool onoff) |
| Put DB in safe sync mode. More... | |
| void | set_show_time_stats (bool stats) |
| set whether or not to show/print time statistics More... | |
| HardFork::State | get_hard_fork_state () const |
| gets the hardfork voting state object More... | |
| uint8_t | get_current_hard_fork_version () const |
| gets the current hardfork version in use/voted for More... | |
| uint8_t | get_ideal_hard_fork_version () const |
| returns the newest hardfork version known to the blockchain More... | |
| uint8_t | get_next_hard_fork_version () const |
| returns the next hardfork version More... | |
| 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 More... | |
| uint8_t | get_hard_fork_version (uint64_t height) const |
| returns the actual hardfork version for a given block height More... | |
| uint64_t | get_earliest_ideal_height_for_version (uint8_t version) const |
| returns the earliest block a given version may activate More... | |
| 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 More... | |
| uint64_t | get_difficulty_target () const |
| get difficulty target based on chain and hardfork version More... | |
| bool | flush_txes_from_pool (const std::vector< crypto::hash > &txids) |
| remove transactions from the transaction pool (if present) More... | |
| 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 More... | |
| bool | for_all_key_images (std::function< bool(const crypto::key_image &)>) const |
| perform a check on all key images in the blockchain More... | |
| 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 More... | |
| 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 More... | |
| 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 More... | |
| 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 More... | |
| const BlockchainDB & | get_db () const |
| get a reference to the BlockchainDB in use by Blockchain More... | |
| BlockchainDB & | get_db () |
| get a reference to the BlockchainDB in use by Blockchain More... | |
| 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 More... | |
| 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 More... | |
| std::list< std::pair< block_extended_info, std::vector< crypto::hash > > > | get_alternative_chains () const |
| returns a set of known alternate chains More... | |
| 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_unrelayed_txes=true) 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) const |
| cryptonote::blobdata | get_txpool_tx_blob (const crypto::hash &txid) const |
| bool | for_all_txpool_txes (std::function< bool(const crypto::hash &, const txpool_tx_meta_t &, const cryptonote::blobdata *)>, bool include_blob=false, bool include_unrelayed_txes=true) const |
| uint32_t | get_mempool_tx_livetime () const |
| bool | is_within_compiled_block_hash_area (uint64_t height) const |
| bool | is_within_compiled_block_hash_area () const |
| 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 () |
| void | on_new_tx_from_block (const cryptonote::transaction &tx) |
| called when we see a tx originating from a block More... | |
| std::vector< time_t > | get_last_block_timestamps (unsigned int blocks) const |
| returns the timestamps of the last N blocks More... | |
| void | pop_blocks (uint64_t nblocks) |
| removes blocks from the top of the blockchain More... | |
| void | set_validator_key (std::string key) |
| set validator key More... | |
| void | set_validators_list_instance (std::unique_ptr< electroneum::basic::Validators > &v) |
| electroneum::basic::Validator | get_validator_by_height (uint64_t height) |
| network_type | get_nettype () const |
| get blockchain nettype More... | |
Static Public Member Functions | |
| static uint64_t | get_fee_quantization_mask () |
| get fee quantization mask More... | |
| 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 More... | |
| static const std::vector< HardFork::Params > & | get_hard_fork_heights (network_type nettype) |
| gets the hardfork heights of given network More... | |
Private Types | |
| typedef std::unordered_map< crypto::hash, size_t > | blocks_by_id_index |
| typedef std::unordered_map< crypto::hash, transaction_chain_entry > | transactions_container |
| typedef std::unordered_set< crypto::key_image > | key_images_container |
| typedef std::vector< block_extended_info > | blocks_container |
| typedef std::unordered_map< crypto::hash, block_extended_info > | blocks_ext_by_hash |
| typedef std::unordered_map< crypto::hash, block > | blocks_by_hash |
| typedef std::map< uint64_t, std::vector< std::pair< crypto::hash, size_t > > > | outputs_container |
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 More... | |
| 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) |
| collect output public keys of a transaction input set More... | |
| bool | check_tx_inputs (transaction &tx, tx_verification_context &tvc, uint64_t *pmax_used_block_height=NULL) |
| validate a transaction's inputs and their keys More... | |
| bool | switch_to_alternative_blockchain (std::list< blocks_ext_by_hash::const_iterator > &alt_chain, bool discard_disconnected_chain) |
| performs a blockchain reorganization according to the longest chain rule More... | |
| block | pop_block_from_blockchain () |
| removes the most recent block from the blockchain More... | |
| 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 More... | |
| bool | handle_block_to_main_chain (const block &bl, const crypto::hash &id, block_verification_context &bvc) |
| validate and add a new block to the end of the blockchain More... | |
| bool | handle_alternative_block (const block &b, const crypto::hash &id, block_verification_context &bvc) |
| validate and add a new block to an alternate blockchain More... | |
| bool | build_alt_chain (const crypto::hash &prev_id, std::list< blocks_ext_by_hash::const_iterator > &alt_chain, std::vector< uint64_t > ×tamps, block_verification_context &bvc) const |
| builds a list of blocks connecting a block to the main chain More... | |
| difficulty_type | get_next_difficulty_for_alternative_chain (const std::list< blocks_ext_by_hash::const_iterator > &alt_chain, block_extended_info &bei) const |
| gets the difficulty requirement for a new block on an alternate chain More... | |
| bool | prevalidate_miner_transaction (const block &b, uint64_t height) |
| sanity checks a miner transaction before validating an entire block More... | |
| 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 More... | |
| bool | rollback_blockchain_switching (std::list< block > &original_chain, uint64_t rollback_height) |
| reverts the blockchain to its previous state following a failed switch More... | |
| void | get_last_n_blocks_weights (std::vector< uint64_t > &weights, size_t count) const |
| gets recent block weights for median calculation More... | |
| uint64_t | get_long_term_block_weight_median (uint64_t start_height, size_t count) const |
| gets block long term weight median More... | |
| bool | is_tx_spendtime_unlocked (uint64_t unlock_time) const |
| checks if a transaction is unlocked (its outputs spendable) More... | |
| bool | add_block_as_invalid (const block &bl, const crypto::hash &h) |
| stores an invalid block in a separate container More... | |
| bool | add_block_as_invalid (const block_extended_info &bei, const crypto::hash &h) |
| stores an invalid block in a separate container More... | |
| bool | check_block_timestamp (const block &b, uint64_t &median_ts) const |
| checks a block's timestamp More... | |
| bool | check_block_timestamp (const block &b) const |
| bool | check_block_timestamp (std::vector< uint64_t > ×tamps, const block &b, uint64_t &median_ts) const |
| checks a block's timestamp More... | |
| bool | check_block_timestamp (std::vector< uint64_t > ×tamps, const block &b) const |
| uint64_t | get_adjusted_time () const |
| get the "adjusted time" More... | |
| bool | complete_timestamps_vector (uint64_t start_height, std::vector< uint64_t > ×tamps) const |
| finish an alternate chain's timestamp window from the main chain More... | |
| 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 More... | |
| void | return_tx_to_pool (std::vector< std::pair< transaction, blobdata >> &txs) |
| 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 More... | |
| 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) |
| validates a transaction input's ring signature More... | |
| void | load_compiled_in_block_hashes (const GetCheckpointsCallback &get_checkpoints) |
| loads block hashes from compiled-in data set More... | |
| 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 More... | |
| void | invalidate_block_template_cache () |
| invalidates any cached block template More... | |
| 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 pool_cookie) |
| stores a new cached block template More... | |
| void | sign_block (block &b, std::string privateKey) |
| Digitally sign the block. More... | |
| bool | verify_block_signature (const block &b) |
| Verify block's digital signature. More... | |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
| Blockchain::Blockchain | ( | tx_memory_pool & | tx_pool | ) |
Blockchain constructor.
| tx_pool | a reference to the transaction pool to be kept by the Blockchain |
| Blockchain::~Blockchain | ( | ) |
Blockchain destructor.
|
private |
stores an invalid block in a separate container
Storing invalid blocks allows quick dismissal of the same block if it is seen again.
| bl | the invalid block |
| h | the block's hash |
|
private |
stores an invalid block in a separate container
Storing invalid blocks allows quick dismissal of the same block if it is seen again.
| bei | the invalid block (see ::block_extended_info) |
| h | the block's hash |
| 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.
| bl_ | the block to be added |
| bvc | metadata about the block addition's success/failure |
| void Blockchain::add_txpool_tx | ( | const crypto::hash & | txid, |
| const cryptonote::blobdata & | blob, | ||
| const txpool_tx_meta_t & | meta | ||
| ) |
| difficulty_type Blockchain::block_difficulty | ( | uint64_t | i | ) | const |
gets the difficulty of the block with a given height
| i | the height |
| 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
| height | the height of the first block |
| blocks | the blocks to be hashed |
| map | return-by-reference the hashes for each block |
|
private |
builds a list of blocks connecting a block to the main chain
| prev_id | the block hash of the tip of the alt chain |
| alt_chain | the chain to be added to |
| timestamps | returns the timestamps of previous blocks |
| bvc | the block verification context for error return |
|
private |
stores a new cached block template
At some point, may be used to push an update to miners
| void Blockchain::cancel | ( | ) |
| 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.
| points | the checkpoints to check against |
| enforce | whether or not to take action on failure |
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
| b | the block to be checked |
| median_ts | return-by-reference the median of timestamps |
|
inlineprivate |
|
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.
| timestamps | a list of the most recent timestamps to check against |
| b | the block to be checked |
| bool Blockchain::check_blockchain_pruning | ( | ) |
| 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
| tx_weight | the transaction weight |
| fee | the fee |
|
private |
make sure a transaction isn't attempting a double-spend
| tx | the transaction to check |
| keys_this_block | a cumulative list of spent keys for the current block |
|
private |
validates a transaction input's ring signature
| tx_prefix_hash | the transaction prefix' hash |
| key_image | the key image generated from the true input |
| pubkeys | the public keys for each input in the ring signature |
| sig | the signature generated for each input in the ring signature |
| result | false if the ring signature is invalid, otherwise true |
|
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
| tx_version | the transaction version |
| txin | the transaction input |
| tx_prefix_hash | the transaction prefix hash, for caching organization |
| sig | the input signature |
| output_keys | return-by-reference the public keys of the outputs in the input set |
| rct_signatures | the ringCT signatures, which are only valid if tx version > 1 |
| pmax_related_block_height | return-by-pointer the height of the most recent block in the input set |
|
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.
| tx | the transaction to validate |
| tvc | returned information about tx verification |
| pmax_related_block_height | return-by-pointer the height of the most recent block in the input set |
| bool 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 |
||
| ) |
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.
| tx | the transaction to validate |
| pmax_used_block_height | return-by-reference block height of most recent input |
| max_used_block_id | return-by-reference block hash of most recent input |
| tvc | returned information about tx verification |
| kept_by_block | whether or not the transaction is from a previously-verified block |
| bool Blockchain::check_tx_outputs | ( | const transaction & | tx, |
| tx_verification_context & | tvc | ||
| ) |
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).
| tx | the transaction to check the outputs of |
| tvc | returned info about tx verification |
incoming blocks post-processing, cleanup, and disk sync
| force_sync | if true, and Blockchain is handling syncing to disk, always sync |
|
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.
| start_height | the alternate chain's attachment height to the main chain |
| timestamps | return-by-value the timestamps set to be populated |
| 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 | ||
| ) |
creates a new block to mine against
| b | return-by-reference block to be filled in |
| from_block | optional block hash to start mining from (main chain tip if NULL) |
| miner_address | address new coins for the block will go to |
| di | return-by-reference tells the miner what the difficulty target is |
| height | return-by-reference tells the miner what height it's mining against |
| expected_reward | return-by-reference the total reward awarded to the miner finding this block, including transaction fees |
| ex_nonce | extra data to be added to the miner transaction's extra |
| 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 | ||
| ) |
| bool Blockchain::deinit | ( | ) |
Uninitializes the blockchain state.
Saves to disk any state that needs to be maintained
|
private |
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.
| bool Blockchain::find_blockchain_supplement | ( | const std::list< crypto::hash > & | qblock_ids, |
| 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.
| qblock_ids | the foreign chain's "short history" (see get_short_chain_history) |
| resp | return-by-reference the split height and subsequent blocks' hashes |
| bool Blockchain::find_blockchain_supplement | ( | const std::list< crypto::hash > & | qblock_ids, |
| std::vector< crypto::hash > & | hashes, | ||
| 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.
| qblock_ids | the foreign chain's "short history" (see get_short_chain_history) |
| hashes | the hashes to be returned, return-by-reference |
| start_height | the start height, return-by-reference |
| current_height | the current blockchain height, return-by-reference |
| clip_pruned | whether to constrain results to unpruned data |
| 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.
| qblock_ids | the foreign chain's "short history" (see get_short_chain_history) |
| starter_offset | return-by-reference the most recent common block's height |
| 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_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.
| req_start_block | if non-zero, specifies a start point (otherwise find most recent commonality) |
| qblock_ids | the foreign chain's "short history" (see get_short_chain_history) |
| blocks | return-by-reference the blocks and their transactions |
| total_height | return-by-reference our current blockchain height |
| start_height | return-by-reference the height of the first block returned |
| pruned | whether to return full or pruned tx blobs |
| max_count | the max number of blocks to get |
| bool Blockchain::flush_txes_from_pool | ( | const std::vector< crypto::hash > & | txids | ) |
remove transactions from the transaction pool (if present)
| txids | a list of hashes of transactions to be removed |
| bool Blockchain::for_all_key_images | ( | std::function< bool(const crypto::key_image &)> | f | ) | const |
perform a check on all key images in the blockchain
| std::function | the check to perform, pass/fail |
| bool Blockchain::for_all_outputs | ( | std::function< bool(uint64_t amount, const crypto::hash &tx_hash, uint64_t height, size_t tx_idx)> | f | ) | const |
perform a check on all outputs in the blockchain
| std::function | the check to perform, pass/fail |
perform a check on all outputs of a given amount in the blockchain
| amount | the amount to iterate through |
| std::function | the check to perform, pass/fail |
| bool Blockchain::for_all_transactions | ( | std::function< bool(const crypto::hash &, const cryptonote::transaction &)> | f, |
| bool | pruned | ||
| ) | const |
perform a check on all transactions in the blockchain
| std::function | the check to perform, pass/fail |
| bool | pruned whether to return pruned txes only |
| bool Blockchain::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 |
| bool Blockchain::for_blocks_range | ( | const uint64_t & | h1, |
| const uint64_t & | h2, | ||
| std::function< bool(uint64_t, const crypto::hash &, const block &)> | f | ||
| ) | const |
perform a check on all blocks in the blockchain in the given range
| h1 | the start height |
| h2 | the end height |
| std::function | the check to perform, pass/fail |
|
private |
get the "adjusted time"
Currently this simply returns the current time according to the user's machine.
compiles a list of all blocks stored as alternative chains
| blocks | return-by-reference container to put result blocks in |
| size_t Blockchain::get_alternative_blocks_count | ( | ) | const |
returns the number of alternative blocks stored
| std::list< std::pair< Blockchain::block_extended_info, std::vector< crypto::hash > > > Blockchain::get_alternative_chains | ( | ) | const |
returns a set of known alternate chains
| bool Blockchain::get_block_by_hash | ( | const crypto::hash & | h, |
| block & | blk, | ||
| bool * | orphan = NULL |
||
| ) | const |
gets the block with a given hash
| h | the hash to look for |
| blk | return-by-reference variable to put result block in |
| orphan | if non-NULL, will be set to true if not in the main chain, false otherwise |
| crypto::hash Blockchain::get_block_id_by_height | ( | uint64_t | height | ) | const |
gets a block's hash given a height
| height | the height of the block |
|
inline |
| 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
| t_ids_container | a standard-iterable container |
| t_blocks_container | a standard-iterable container |
| t_missed_container | a standard-iterable container |
| block_ids | a container of block hashes for which to get the corresponding blocks |
| blocks | return-by-reference a container to store result blocks in |
| missed_bs | return-by-reference a container to store missed blocks in |
| 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
| start_offset | the height on the blockchain to start at |
| count | the number of blocks to get, if there are as many after start_offset |
| blocks | return-by-reference container to put result blocks in |
| 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
| start_offset | the height on the blockchain to start at |
| count | the number of blocks to get, if there are as many after start_offset |
| blocks | return-by-reference container to put result blocks in |
| txs | return-by-reference container to put result transactions in |
| uint64_t Blockchain::get_current_blockchain_height | ( | ) | const |
get the current height of the blockchain
| uint64_t Blockchain::get_current_cumulative_block_weight_limit | ( | ) | const |
gets the block weight limit based on recent blocks
| 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)
|
inline |
gets the current hardfork version in use/voted for
|
inline |
get a reference to the BlockchainDB in use by Blockchain
|
inline |
get a reference to the BlockchainDB in use by Blockchain
| difficulty_type Blockchain::get_difficulty_for_next_block | ( | ) |
returns the difficulty target the next block to be added must meet
| uint64_t Blockchain::get_difficulty_target | ( | ) | const |
get difficulty target based on chain and hardfork 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.
| block_reward | the current block reward |
| median_block_weight | the median block weight in the past window |
| version | hard fork version for rules and constants to use |
| 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
| grace_blocks | number of blocks we want the fee to be valid for |
|
inline |
returns the earliest block a given version may activate
|
static |
get fee quantization mask
The dynamic fee may be quantized, to mask out the last decimal places
|
static |
gets the hardfork heights of given network
| HardFork::State Blockchain::get_hard_fork_state | ( | ) | const |
gets the hardfork voting state object
|
inline |
returns the actual hardfork version for a given block height
| height | the height for which to check version 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
| version | the version in question |
| window | the size of the voting window |
| votes | the number of votes to enable <version> |
| threshold | the number of votes required to enable <version> |
| earliest_height | the earliest height at which <version> is allowed |
| voting | which version this node is voting for/using |
|
inline |
returns the newest hardfork version known to the blockchain
|
inline |
returns the newest hardfork version voted to be enabled as of a certain height
| height | the height for which to check version info |
| std::vector< time_t > Blockchain::get_last_block_timestamps | ( | unsigned int | blocks | ) | const |
returns the timestamps of the last N blocks
|
private |
gets recent block weights for median calculation
get the block weights of the last <count> blocks, and return by reference <weights>.
| weights | return-by-reference the list of weights |
| count | the number of blocks to get weights for |
|
private |
gets block long term weight median
get the block long term weight median of <count> blocks starting at <start_height>
| start_height | the block height of the first block to query |
| count | the number of blocks to get weights for |
| uint32_t Blockchain::get_mempool_tx_livetime | ( | ) | const |
|
inline |
get blockchain nettype
|
private |
gets the difficulty requirement for a new block on an alternate chain
| alt_chain | the chain to be added to |
| bei | the block being added (and metadata, see ::block_extended_info) |
|
inline |
returns the next hardfork version
| uint64_t Blockchain::get_next_long_term_block_weight | ( | uint64_t | block_weight | ) | const |
gets the long term block weight for a new block
| uint64_t Blockchain::get_num_mature_outputs | ( | uint64_t | amount | ) | const |
get number of outputs of an amount past the minimum spendable age
| amount | the output amount |
| 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
| amount | the amount to get a ditribution for |
| from_height | the height before which we do not care about the data |
| to_height | the height after which we do not care about the data |
| return-by-reference | start_height the height of the first rct output |
| return-by-reference | distribution the start offset of the first rct output in this block (same as previous if none) |
| return-by-reference | base how many outputs of that amount are before the stated distribution |
| 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
| amounts | optional set of amounts to lookup |
| unlocked | whether to restrict instances to unlocked ones |
| recent_cutoff | timestamp to consider outputs as recent |
| min_count | return only amounts with at least that many instances |
| crypto::public_key Blockchain::get_output_key | ( | uint64_t | amount, |
| uint64_t | global_index | ||
| ) | const |
get the public key for an output
| amount | the output amount |
| global_index | the output amount-global index |
| 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
| amount | in - the output amount |
| index | in - the output global amount index |
| mask | out - the output's RingCT mask |
| key | out - the output's key |
| unlocked | out - the output's unlocked state |
| bool Blockchain::get_outs | ( | const COMMAND_RPC_GET_OUTPUTS_BIN::request & | req, |
| COMMAND_RPC_GET_OUTPUTS_BIN::response & | res | ||
| ) | const |
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.
| req | the outputs to return |
| res | return-by-reference the resultant output indices and keys |
| bool Blockchain::get_short_chain_history | ( | std::list< crypto::hash > & | ids | ) | 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...
| ids | return-by-reference list to put the resulting hashes in |
| template bool cryptonote::Blockchain::get_split_transactions_blobs | ( | const t_ids_container & | txs_ids, |
| t_tx_container & | txs, | ||
| t_missed_container & | missed_txs | ||
| ) | const |
| crypto::hash Blockchain::get_tail_id | ( | ) | const |
get the hash of the most recent block on the blockchain
| crypto::hash Blockchain::get_tail_id | ( | uint64_t & | height | ) | const |
get the height and hash of the most recent block on the blockchain
| height | return-by-reference variable to store the height in |
| size_t Blockchain::get_total_transactions | ( | ) | const |
gets the total number of transactions on the main chain
| template bool cryptonote::Blockchain::get_transactions | ( | const t_ids_container & | txs_ids, |
| t_tx_container & | txs, | ||
| t_missed_container & | missed_txs | ||
| ) | const |
| template bool cryptonote::Blockchain::get_transactions_blobs | ( | const t_ids_container & | txs_ids, |
| t_tx_container & | txs, | ||
| t_missed_container & | missed_txs, | ||
| bool | pruned = false |
||
| ) | const |
gets transactions based on a list of transaction hashes
| t_ids_container | a standard-iterable container |
| t_tx_container | a standard-iterable container |
| t_missed_container | a standard-iterable container |
| txs_ids | a container of hashes for which to get the corresponding transactions |
| txs | return-by-reference a container to store result transactions in |
| missed_txs | return-by-reference a container to store missed transactions in |
| pruned | whether to return full or pruned blobs |
| bool Blockchain::get_tx_outputs_gindexs | ( | const crypto::hash & | tx_id, |
| size_t | n_txes, | ||
| std::vector< std::vector< uint64_t >> & | indexs | ||
| ) | const |
| 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.
| tx_id | the hash of the transaction to fetch indices for |
| indexs | return-by-reference the global indices for the transaction's outputs |
| n_txes | how many txes in a row to get results for |
| cryptonote::blobdata Blockchain::get_txpool_tx_blob | ( | const crypto::hash & | txid | ) | const |
| bool Blockchain::get_txpool_tx_blob | ( | const crypto::hash & | txid, |
| cryptonote::blobdata & | bd | ||
| ) | const |
| bool Blockchain::get_txpool_tx_meta | ( | const crypto::hash & | txid, |
| txpool_tx_meta_t & | meta | ||
| ) | const |
| electroneum::basic::Validator Blockchain::get_validator_by_height | ( | uint64_t | height | ) |
|
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.
| b | the block to be added |
| id | the hash of the block |
| bvc | metadata concerning the block's validity |
|
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.
| bl | the block to be added |
| bvc | metadata concerning the block's validity |
|
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.
| bl | the block to be added |
| id | the hash of the block |
| bvc | metadata concerning the block's validity |
| 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.
| arg | the request |
| rsp | return-by-reference the response to fill in |
| bool Blockchain::have_block | ( | const crypto::hash & | id | ) | 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
| id | the hash to search for |
| bool Blockchain::have_tx | ( | const crypto::hash & | id | ) | const |
search the blockchain for a transaction by hash
| id | the hash to search for |
| 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.
| key_im | the key image to search for |
| bool Blockchain::have_tx_keyimges_as_spent | ( | const transaction & | tx | ) | const |
check if any key image in a transaction has already been spent
| tx | the transaction to check |
| 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, |
||
| bool | ignore_bsig = false, |
||
| bool | fallback_to_pow = false |
||
| ) |
Initialize the Blockchain state.
| db | a pointer to the backing store to use for the blockchain |
| nettype | network type |
| offline | true if running offline, else false |
| test_options | test parameters |
| fixed_difficulty | fixed difficulty for testing purposes; 0 means disabled |
| get_checkpoints | if set, will be called to get checkpoints data |
| bool Blockchain::init | ( | BlockchainDB * | db, |
| HardFork *& | hf, | ||
| const network_type | nettype = MAINNET, |
||
| bool | offline = false |
||
| ) |
Initialize the Blockchain state.
| db | a pointer to the backing store to use for the blockchain |
| hf | a structure containing hardfork information |
| nettype | network type |
| offline | true if running offline, else false |
|
private |
invalidates any cached block template
|
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.
| unlock_time | the unlock parameter (height or time) |
|
inline |
| bool Blockchain::is_within_compiled_block_hash_area | ( | uint64_t | height | ) | const |
|
private |
loads block hashes from compiled-in data set
A (possibly empty) set of block hashes can be compiled into the electroneum daemon binary. This function loads those hashes into a useful state.
| get_checkpoints | if set, will be called to get checkpoints data |
| void Blockchain::lock | ( | ) |
| void Blockchain::normalize_v7_difficulties | ( | ) |
Normalize the cumulative difficulty for V7 blocks, fixing the differing difficulty among nodes.
| void Blockchain::on_new_tx_from_block | ( | const cryptonote::transaction & | tx | ) |
called when we see a tx originating from a block
Used for handling txes from historical blocks in a fast way
| 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
| amount | the amount |
| offsets | the indices (indexed to the amount) of the outputs |
| outputs | return-by-reference the outputs collected |
|
private |
removes the most recent block from the blockchain
| void Blockchain::pop_blocks | ( | uint64_t | nblocks | ) |
removes blocks from the top of the blockchain
| nblocks | number of blocks to be removed |
| 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
| blocks_entry | a list of incoming blocks |
| blocks | the parsed blocks |
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.
| b | the block containing the miner transaction |
| height | the height at which the block will be added |
| bool Blockchain::prune_blockchain | ( | uint32_t | pruning_seed = 0 | ) |
| void Blockchain::remove_txpool_tx | ( | const crypto::hash & | txid | ) |
clears the blockchain and starts a new one
| b | the first block in the new chain (the genesis block) |
|
private |
|
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.
| original_chain | the chain to switch back to |
| rollback_height | the height to revert to before appending the original chain |
| void Blockchain::safesyncmode | ( | const bool | onoff | ) |
Put DB in safe sync mode.
|
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
| visitor_t | a class encapsulating tx is unlocked and collect tx key |
| tx_in_to_key | a transaction input instance |
| vis | an instance of the visitor to use |
| tx_prefix_hash | the hash of the associated transaction_prefix |
| pmax_related_block_height | return-by-pointer the height of the most recent block in the input set |
| tx_version | version of the tx, if > 1 we also get commitments |
|
inline |
sets a block notify object to call for every new block
| notify | the notify object to call at every new block |
|
inline |
assign a set of blockchain checkpoint hashes
| chk_pts | the set of checkpoints to assign |
| void Blockchain::set_enforce_dns_checkpoints | ( | bool | enforce | ) |
configure whether or not to enforce DNS-based checkpoints
| enforce | the new enforcement setting |
|
inline |
sets a reorg notify object to call for every reorg
| notify | the notify object to call at every reorg |
|
inline |
set whether or not to show/print time statistics
| stats | the new time stats setting |
| 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, | ||
| std::string | validator_key | ||
| ) |
Update the validators public key by fetching data from electroneum's endpoint.
sets various performance options
| maxthreads | max number of threads when preparing blocks for addition |
| sync_on_blocks | whether to sync based on blocks or bytes |
| sync_threshold | number of blocks/bytes to cache before syncing to database |
| sync_mode | the blockchain_db_sync_mode to use |
| fast_sync | sync using built-in block hashes as trusted |
|
inline |
set validator key
|
inline |
|
private |
Digitally sign the block.
| b | the block to be digitally signed |
| privateKey | key to generate the signature |
| bool Blockchain::store_blockchain | ( | ) |
stores the blockchain
If Blockchain is handling storing of the blockchain (rather than BlockchainDB), this initiates a blockchain save.
|
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.
| alt_chain | the chain to switch to |
| discard_disconnected_chain | whether or not to keep the old chain as an alternate |
| void Blockchain::unlock | ( | ) |
| bool Blockchain::update_blockchain_pruning | ( | ) |
loads new checkpoints from a file and optionally from DNS
| file_path | the path of the file to look for and load checkpoints from |
| check_dns | whether or not to check for new DNS-based checkpoints |
|
private |
calculate the block weight limit for the next block to be added
| long_term_effective_median_block_weight | optionally return that value |
| void Blockchain::update_txpool_tx | ( | const crypto::hash & | txid, |
| const txpool_tx_meta_t & | meta | ||
| ) |
|
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.
| b | the block containing the miner transaction to be validated |
| cumulative_block_weight | the block's weight |
| fee | the total fees collected in the block |
| base_reward | return-by-reference the new block's generated coins |
| already_generated_coins | the amount of currency generated prior to this block |
| partial_block_reward | return-by-reference true if miner accepted only partial reward |
| version | hard fork version for that transaction |
Verify block's digital signature.
| b | block to be verified |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
mutableprivate |
|
mutableprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |