Electroneum
Loading...
Searching...
No Matches
cryptonote::core Class Reference

handles core cryptonote functionality More...

#include <cryptonote_core.h>

Inheritance diagram for cryptonote::core:
Collaboration diagram for cryptonote::core:

Public Member Functions

 core (i_cryptonote_protocol *pprotocol)
 constructor
bool handle_get_objects (NOTIFY_REQUEST_GET_OBJECTS::request &arg, NOTIFY_RESPONSE_GET_OBJECTS::request &rsp, cryptonote_connection_context &context)
 retrieves a set of blocks and their transactions, and possibly other transactions
bool on_idle ()
 calls various idle routines
bool handle_incoming_tx (const blobdata &tx_blob, tx_verification_context &tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
 handles an incoming transaction
bool handle_incoming_txs (const std::vector< blobdata > &tx_blobs, std::vector< tx_verification_context > &tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
 handles a list of incoming transactions
bool handle_incoming_block (const blobdata &block_blob, const block *b, block_verification_context &bvc, bool update_miner_blocktemplate=true)
 handles an incoming block
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
bool cleanup_handle_incoming_blocks (bool force_sync=false)
 incoming blocks post-processing, cleanup, and disk sync
bool check_incoming_block_size (const blobdata &block_blob) const
 check the size of a block against the current maximum
i_cryptonote_protocolget_protocol ()
 get the cryptonote protocol instance
virtual bool handle_block_found (block &b, block_verification_context &bvc)
 stores and relays a block found by a miner
virtual bool get_block_template (block &b, const account_public_address &adr, difficulty_type &diffic, uint64_t &height, uint64_t &expected_reward, const blobdata &ex_nonce)
 creates a new block to mine against
virtual bool get_block_template (block &b, const crypto::hash *prev_block, const account_public_address &adr, difficulty_type &diffic, uint64_t &height, uint64_t &expected_reward, const blobdata &ex_nonce)
virtual void on_transaction_relayed (const cryptonote::blobdata &tx)
 called when a transaction is relayed
minerget_miner ()
 gets the miner instance
const minerget_miner () const
 gets the miner instance (const)
bool init (const boost::program_options::variables_map &vm, const test_options *test_options=NULL, const GetCheckpointsCallback &get_checkpoints=nullptr)
 initializes the core as needed
bool set_genesis_block (const block &b)
 clears the blockchain and starts a new one
bool deinit ()
 performs safe shutdown steps for core and core components
void test_drop_download ()
 sets to drop blocks downloaded (for testing)
void test_drop_download_height (uint64_t height)
 sets to drop blocks downloaded below a certain height
bool get_test_drop_download () const
 gets whether or not to drop blocks (for testing)
bool get_test_drop_download_height () const
 gets whether or not to drop blocks
uint64_t get_current_blockchain_height () const
 get the current height of the blockchain
void get_blockchain_top (uint64_t &height, crypto::hash &top_id) const
 get the hash and height of the most recent block
bool get_blocks (uint64_t start_offset, size_t count, std::vector< std::pair< cryptonote::blobdata, block > > &blocks, std::vector< cryptonote::blobdata > &txs) const
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_blocks (uint64_t start_offset, size_t count, std::vector< block > &blocks) const
 get blocks from blocks based on start height and count
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
crypto::hash get_block_id_by_height (uint64_t height) const
 gets a block's hash given a height
bool get_transactions (const std::vector< crypto::hash > &txs_ids, std::vector< cryptonote::blobdata > &txs, std::vector< crypto::hash > &missed_txs) const
bool get_split_transactions_blobs (const std::vector< crypto::hash > &txs_ids, std::vector< std::tuple< crypto::hash, cryptonote::blobdata, crypto::hash, cryptonote::blobdata > > &txs, std::vector< crypto::hash > &missed_txs) const
bool get_transactions (const std::vector< crypto::hash > &txs_ids, std::vector< transaction > &txs, std::vector< crypto::hash > &missed_txs) const
bool get_block_by_hash (const crypto::hash &h, block &blk, bool *orphan=NULL) const
 gets the block with a given hash
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
void set_cryptonote_protocol (i_cryptonote_protocol *pprotocol)
 set the pointer to the cryptonote protocol object to use
void set_checkpoints (checkpoints &&chk_pts)
 assign a set of blockchain checkpoint hashes
void set_checkpoints_file_path (const std::string &path)
 set the file path to read from when loading checkpoints
void set_enforce_dns_checkpoints (bool enforce_dns)
 set whether or not we enforce DNS checkpoints
void disable_dns_checkpoints (bool disable=true)
 set whether or not to enable or disable DNS checkpoints
bool pool_has_utxo_as_spent (const txin_to_key_public &in) const
 get a summary statistics of all transaction hashes in the pool
bool pool_has_tx (const crypto::hash &txid) const
 checks if the pool has a transaction with the given hash
bool get_pool_transactions (std::vector< transaction > &txs, bool include_unrelayed_txes=true) const
 get a list of all transactions in the pool
bool get_txpool_backlog (std::vector< tx_backlog_entry > &backlog) const
bool get_pool_transaction_hashes (std::vector< crypto::hash > &txs, bool include_unrelayed_txes=true) const
 get a list of all transactions in the pool
bool get_pool_transaction_stats (struct txpool_stats &stats, bool include_unrelayed_txes=true) const
 get a list of all transactions in the pool
bool get_pool_transaction (const crypto::hash &id, cryptonote::blobdata &tx) const
 get a specific transaction from the pool
bool get_pool_transactions_and_spent_keys_info (std::vector< tx_info > &tx_infos, std::vector< spent_key_image_info > &key_image_infos, bool include_unrelayed_txes=true) const
bool get_pool_for_rpc (std::vector< cryptonote::rpc::tx_in_pool > &tx_infos, cryptonote::rpc::key_images_with_tx_hashes &key_image_infos) const
 get information about all transactions and key images in the pool
size_t get_pool_transactions_count () const
 get the total number of transactions in the pool
size_t get_blockchain_total_transactions () const
 gets the total number of transactions on the main chain
bool have_block (const crypto::hash &id) const
 checks if a block is known about with a given hash
bool get_short_chain_history (std::list< crypto::hash > &ids) const
 gets the hashes for a subset of the blockchain
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
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
bool get_stat_info (core_stat_info &st_inf) const
 gets some stats about the daemon
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
crypto::hash get_tail_id () const
 get the hash of the most recent block on the blockchain
void set_block_cumulative_difficulty (uint64_t height, difficulty_type diff)
difficulty_type get_block_cumulative_difficulty (uint64_t height) const
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
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
void pause_mine ()
void resume_mine ()
Blockchainget_blockchain_storage ()
 gets the Blockchain instance
const Blockchainget_blockchain_storage () const
 gets the Blockchain instance (const)
std::string print_pool (bool short_format) const
 get a string containing human-readable pool information
void on_synchronized ()
void safesyncmode (const bool onoff)
 Put DB in safe sync mode.
void set_target_blockchain_height (uint64_t target_blockchain_height)
 sets the target blockchain height
uint64_t get_target_blockchain_height () const
 gets the target blockchain height
uint8_t get_ideal_hard_fork_version () const
 returns the newest hardfork version known to the blockchain
uint8_t get_ideal_hard_fork_version (uint64_t height) const
 return the ideal hard fork version for a given block height
uint8_t get_hard_fork_version (uint64_t height) const
 return the hard fork version for a given block height
uint64_t get_earliest_ideal_height_for_version (uint8_t version) const
 return the earliest block a given version may activate
std::time_t get_start_time () const
 gets start_time
bool update_checkpoints ()
 tells the Blockchain to update its checkpoints
std::string get_validators_list ()
 Get a serialized representation of the list of validators.
electroneum::basic::list_update_outcome set_validators_list (std::string v_list, bool isEmergencyUpdate)
 set the list of validators according to the serialized string passed in as parameter
bool isValidatorsListValid ()
 get Validators List state
void graceful_exit ()
 tells the daemon to wind down operations and stop running
void stop ()
 stops the daemon running
bool is_key_image_spent (const crypto::key_image &key_im) const
 check if a key image is already spent on the blockchain
bool are_key_images_spent (const std::vector< crypto::key_image > &key_im, std::vector< bool > &spent) const
 check if multiple key images are spent
bool utxo_nonexistant (const std::vector< txin_to_key_public > &public_outputs, std::vector< bool > &spent) const
 check if multiple public outputs are found in the utxo database or not
bool are_key_images_spent_in_pool (const std::vector< crypto::key_image > &key_im, std::vector< bool > &spent) const
 check if multiple key images are spent in the transaction pool
size_t get_block_sync_size (uint64_t height) const
 get the number of blocks to sync in one go
std::pair< uint64_t, uint64_tget_coinbase_tx_sum (const uint64_t start_offset, const size_t count)
 get the sum of coinbase tx amounts between blocks
network_type get_nettype () const
 get the network type we're on
bool is_update_available () const
 check whether an update is known to be available or not
bool fluffy_blocks_enabled () const
 get whether fluffy blocks are enabled
bool pad_transactions () const
 get whether transaction relay should be padded
uint64_t get_free_space () const
 get free disk space on the blockchain partition
bool offline () const
 get whether the core is running offline
uint32_t get_blockchain_pruning_seed () const
 get the blockchain pruning seed
bool prune_blockchain (uint32_t pruning_seed=0)
 prune the blockchain
bool update_blockchain_pruning ()
 incrementally prunes blockchain
bool check_blockchain_pruning ()
 checks the blockchain pruning if enabled
bool set_validator_key (std::string key)
 set validator key
std::vector< std::string > generate_ed25519_keypair ()
std::string sign_message (std::string sk, std::string msg)
uint64_t get_balance (const address_parse_info &addr)
std::vector< address_outputsget_address_batch_history (const address_parse_info &addr, const uint64_t &start_tx_id=0, const uint64_t &batch_size=100, bool desc=false)
std::vector< address_txsget_addr_tx_batch_history (const address_parse_info &addr, const uint64_t &start_tx_id=0, const uint64_t &batch_size=100, bool desc=false)

Static Public Member Functions

static void init_options (boost::program_options::options_description &desc)
 adds command line options to the given options set

Additional Inherited Members

Protected Member Functions inherited from cryptonote::i_miner_handler
 ~i_miner_handler ()

Detailed Description

handles core cryptonote functionality

This class coordinates cryptonote functionality including, but not limited to, communication among the Blockchain, the transaction pool, any miners, and the network.

Definition at line 85 of file cryptonote_core.h.

Constructor & Destructor Documentation

◆ core()

cryptonote::core::core ( i_cryptonote_protocol * pprotocol)

constructor

sets member variables into a usable state

Parameters
pprotocolpre-constructed protocol object to store and use

Definition at line 248 of file cryptonote_core.cpp.

248 :
249 m_mempool(m_blockchain_storage),
250 m_blockchain_storage(m_mempool),
251 m_miner(this),
252 m_miner_address(boost::value_initialized<account_public_address>()),
253 m_starter_message_showed(false),
254 m_target_blockchain_height(0),
255 m_checkpoints_path(""),
256 m_last_dns_checkpoints_update(0),
257 m_last_json_checkpoints_update(0),
258 m_disable_dns_checkpoints(false),
259 m_update_download(0),
260 m_nettype(UNDEFINED),
261 m_update_available(false),
262 m_pad_transactions(false)
263 {
264 m_checkpoints_updating.clear();
265 set_cryptonote_protocol(pprotocol);
266 }
void set_cryptonote_protocol(i_cryptonote_protocol *pprotocol)
set the pointer to the cryptonote protocol object to use
Here is the call graph for this function:

Member Function Documentation

◆ are_key_images_spent()

bool cryptonote::core::are_key_images_spent ( const std::vector< crypto::key_image > & key_im,
std::vector< bool > & spent ) const

check if multiple key images are spent

plural version of is_key_image_spent()

Parameters
key_imlist of key images to check
spentreturn-by-reference result for each image checked
Returns
true

Definition at line 1174 of file cryptonote_core.cpp.

1175 {
1176 spent.clear();
1177 for(auto& ki: key_im)
1178 {
1179 spent.push_back(m_blockchain_storage.have_tx_keyimg_as_spent(ki));
1180 }
1181 return true;
1182 }

◆ are_key_images_spent_in_pool()

bool cryptonote::core::are_key_images_spent_in_pool ( const std::vector< crypto::key_image > & key_im,
std::vector< bool > & spent ) const

check if multiple key images are spent in the transaction pool

Parameters
key_imlist of key images to check
spentreturn-by-reference result for each image checked
Returns
true

Definition at line 1204 of file cryptonote_core.cpp.

1205 {
1206 spent.clear();
1207 return m_mempool.check_for_key_images(key_im, spent);
1208 }

◆ check_blockchain_pruning()

bool cryptonote::core::check_blockchain_pruning ( )

checks the blockchain pruning if enabled

Returns
true on success, false otherwise

Definition at line 2006 of file cryptonote_core.cpp.

2007 {
2008 return m_blockchain_storage.check_blockchain_pruning();
2009 }

◆ check_incoming_block_size()

bool cryptonote::core::check_incoming_block_size ( const blobdata & block_blob) const

check the size of a block against the current maximum

Parameters
block_blobthe block to check
Returns
whether or not the block is too big

Definition at line 1565 of file cryptonote_core.cpp.

1566 {
1567 // note: we assume block weight is always >= block blob size, so we check incoming
1568 // blob size against the block weight limit, which acts as a sanity check without
1569 // having to parse/weigh first; in fact, since the block blob is the block header
1570 // plus the tx hashes, the weight will typically be much larger than the blob size
1571 if(block_blob.size() > m_blockchain_storage.get_current_cumulative_block_weight_limit() + BLOCK_SIZE_SANITY_LEEWAY)
1572 {
1573 LOG_PRINT_L1("WRONG BLOCK BLOB, sanity check failed on size " << block_blob.size() << ", rejected");
1574 return false;
1575 }
1576 return true;
1577 }
#define BLOCK_SIZE_SANITY_LEEWAY
#define LOG_PRINT_L1(x)
Here is the caller graph for this function:

◆ cleanup_handle_incoming_blocks()

bool cryptonote::core::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
Note
see Blockchain::cleanup_handle_incoming_blocks

Definition at line 1505 of file cryptonote_core.cpp.

1506 {
1507 bool success = false;
1508 try {
1509 success = m_blockchain_storage.cleanup_handle_incoming_blocks(force_sync);
1510 }
1511 catch (...) {}
1512 m_incoming_tx_lock.unlock();
1513 return success;
1514 }
Here is the caller graph for this function:

◆ deinit()

bool cryptonote::core::deinit ( )

performs safe shutdown steps for core and core components

Uninitializes the miner instance, transaction pool, and Blockchain

Returns
true

Definition at line 787 of file cryptonote_core.cpp.

788 {
789 m_miner.stop();
790 m_mempool.deinit();
791 m_blockchain_storage.deinit();
792 return true;
793 }
Here is the caller graph for this function:

◆ disable_dns_checkpoints()

void cryptonote::core::disable_dns_checkpoints ( bool disable = true)
inline

set whether or not to enable or disable DNS checkpoints

Parameters
disblewhether to disable DNS checkpoints

Definition at line 436 of file cryptonote_core.h.

436{ m_disable_dns_checkpoints = disable; }
Here is the caller graph for this function:

◆ find_blockchain_supplement() [1/2]

bool cryptonote::core::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.

Parameters
qblock_idsthe foreign chain's "short history" (see get_short_chain_history)
respreturn-by-reference the split height and subsequent blocks' hashes
Returns
true if a block found in common, else false
Note
see Blockchain::find_blockchain_supplement(const std::list<crypto::hash>&, NOTIFY_RESPONSE_CHAIN_ENTRY::request&) const

Definition at line 1366 of file cryptonote_core.cpp.

1367 {
1368 return m_blockchain_storage.find_blockchain_supplement(qblock_ids, resp);
1369 }

◆ find_blockchain_supplement() [2/2]

bool cryptonote::core::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

Note
see Blockchain::find_blockchain_supplement(const uint64_t, const std::list<crypto::hash>&, std::vector<std::pair<cryptonote::blobdata, std::vector<transaction> > >&, uint64_t&, uint64_t&, size_t) const

Definition at line 1371 of file cryptonote_core.cpp.

1372 {
1373 return m_blockchain_storage.find_blockchain_supplement(req_start_block, qblock_ids, blocks, total_height, start_height, pruned, get_miner_tx_hash, max_count);
1374 }

◆ fluffy_blocks_enabled()

bool cryptonote::core::fluffy_blocks_enabled ( ) const
inline

get whether fluffy blocks are enabled

Returns
whether fluffy blocks are enabled

Definition at line 824 of file cryptonote_core.h.

824{ return m_fluffy_blocks_enabled; }

◆ generate_ed25519_keypair()

std::vector< std::string > cryptonote::core::generate_ed25519_keypair ( )

Definition at line 2056 of file cryptonote_core.cpp.

2056 {
2058 }
std::vector< std::string > create_ed25519_keypair()
Definition crypto.h:388
Here is the call graph for this function:

◆ get_addr_tx_batch_history()

std::vector< address_txs > cryptonote::core::get_addr_tx_batch_history ( const address_parse_info & addr,
const uint64_t & start_tx_id = 0,
const uint64_t & batch_size = 100,
bool desc = false )

Definition at line 2078 of file cryptonote_core.cpp.

2079 {
2080 crypto::public_key combined_key = crypto::addKeys(addr.address.m_view_public_key, addr.address.m_spend_public_key);
2081 return m_blockchain_storage.get_db().get_addr_tx_batch(combined_key, start_tx_id, batch_size, desc);
2082 }
public_key addKeys(const public_key &A, const public_key &B)
Definition crypto.h:339
POD_CLASS public_key
Definition crypto.h:79
Here is the call graph for this function:

◆ get_address_batch_history()

std::vector< address_outputs > cryptonote::core::get_address_batch_history ( const address_parse_info & addr,
const uint64_t & start_tx_id = 0,
const uint64_t & batch_size = 100,
bool desc = false )

Definition at line 2072 of file cryptonote_core.cpp.

2073 {
2074 crypto::public_key combined_key = crypto::addKeys(addr.address.m_view_public_key, addr.address.m_spend_public_key);
2075 return m_blockchain_storage.get_db().get_addr_output_batch(combined_key, start_tx_id, batch_size, desc);
2076 }
Here is the call graph for this function:

◆ get_alternative_blocks()

bool cryptonote::core::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
Note
see Blockchain::get_alternative_blocks(std::vector<block>&) const

Definition at line 487 of file cryptonote_core.cpp.

488 {
489 return m_blockchain_storage.get_alternative_blocks(blocks);
490 }
Here is the caller graph for this function:

◆ get_alternative_blocks_count()

size_t cryptonote::core::get_alternative_blocks_count ( ) const

returns the number of alternative blocks stored

Returns
the number of alternative blocks stored
Note
see Blockchain::get_alternative_blocks_count() const

Definition at line 492 of file cryptonote_core.cpp.

493 {
494 return m_blockchain_storage.get_alternative_blocks_count();
495 }
Here is the caller graph for this function:

◆ get_balance()

uint64_t cryptonote::core::get_balance ( const address_parse_info & addr)

Definition at line 2066 of file cryptonote_core.cpp.

2067 {
2068 crypto::public_key combined_key = crypto::addKeys(addr.address.m_view_public_key, addr.address.m_spend_public_key);
2069 return m_blockchain_storage.get_db().get_balance(combined_key);
2070 }
Here is the call graph for this function:

◆ get_block_by_hash()

bool cryptonote::core::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
Note
see Blockchain::get_block_by_hash

Definition at line 1672 of file cryptonote_core.cpp.

1673 {
1674 return m_blockchain_storage.get_block_by_hash(h, blk, orphan);
1675 }

◆ get_block_cumulative_difficulty()

difficulty_type cryptonote::core::get_block_cumulative_difficulty ( uint64_t height) const

Note
see Blockchain::get_block_cumulative_difficulty

Definition at line 1589 of file cryptonote_core.cpp.

1590 {
1591 return m_blockchain_storage.get_db().get_block_cumulative_difficulty(height);
1592 }
uint64_t height

◆ get_block_id_by_height()

crypto::hash cryptonote::core::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
Note
see Blockchain::get_block_id_by_height

Definition at line 1667 of file cryptonote_core.cpp.

1668 {
1669 return m_blockchain_storage.get_block_id_by_height(height);
1670 }

◆ get_block_sync_size()

size_t cryptonote::core::get_block_sync_size ( uint64_t height) const

get the number of blocks to sync in one go

Returns
the number of blocks to sync in one go

Definition at line 1194 of file cryptonote_core.cpp.

1195 {
1196 static const uint64_t quick_height = m_nettype == TESTNET ? 801219 : m_nettype == MAINNET ? 1220516 : 0;
1197 if (block_sync_size > 0)
1198 return block_sync_size;
1199 if (height >= quick_height)
1202 }
#define BLOCKS_SYNCHRONIZING_DEFAULT_COUNT
#define BLOCKS_SYNCHRONIZING_DEFAULT_COUNT_PRE_V4
unsigned __int64 uint64_t
Definition stdint.h:136

◆ get_block_template() [1/2]

bool cryptonote::core::get_block_template ( block & b,
const account_public_address & adr,
difficulty_type & diffic,
uint64_t & height,
uint64_t & expected_reward,
const blobdata & ex_nonce )
virtual

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
Note
see Blockchain::create_block_template

Implements cryptonote::i_miner_handler.

Definition at line 1356 of file cryptonote_core.cpp.

1357 {
1358 return m_blockchain_storage.create_block_template(b, adr, diffic, height, expected_reward, ex_nonce);
1359 }

◆ get_block_template() [2/2]

bool cryptonote::core::get_block_template ( block & b,
const crypto::hash * prev_block,
const account_public_address & adr,
difficulty_type & diffic,
uint64_t & height,
uint64_t & expected_reward,
const blobdata & ex_nonce )
virtual

Definition at line 1361 of file cryptonote_core.cpp.

1362 {
1363 return m_blockchain_storage.create_block_template(b, prev_block, adr, diffic, height, expected_reward, ex_nonce);
1364 }

◆ get_blockchain_pruning_seed()

uint32_t cryptonote::core::get_blockchain_pruning_seed ( ) const

get the blockchain pruning seed

Returns
the blockchain pruning seed

Definition at line 2028 of file cryptonote_core.cpp.

2029 {
2031 }
uint32_t get_blockchain_pruning_seed() const
Blockchain & get_blockchain_storage()
gets the Blockchain instance
Here is the call graph for this function:

◆ get_blockchain_storage() [1/2]

Blockchain & cryptonote::core::get_blockchain_storage ( )
inline

gets the Blockchain instance

Returns
a reference to the Blockchain instance

Definition at line 620 of file cryptonote_core.h.

620{return m_blockchain_storage;}
Here is the caller graph for this function:

◆ get_blockchain_storage() [2/2]

const Blockchain & cryptonote::core::get_blockchain_storage ( ) const
inline

gets the Blockchain instance (const)

Returns
a const reference to the Blockchain instance

Definition at line 627 of file cryptonote_core.h.

627{return m_blockchain_storage;}

◆ get_blockchain_top()

void cryptonote::core::get_blockchain_top ( uint64_t & height,
crypto::hash & top_id ) const

get the hash and height of the most recent block

Parameters
heightreturn-by-reference height of the block
top_idreturn-by-reference hash of the block

Definition at line 441 of file cryptonote_core.cpp.

442 {
443 top_id = m_blockchain_storage.get_tail_id(height);
444 }

◆ get_blockchain_total_transactions()

size_t cryptonote::core::get_blockchain_total_transactions ( ) const

gets the total number of transactions on the main chain

Returns
the number of transactions on the main chain
Note
see Blockchain::get_total_transactions

Definition at line 1299 of file cryptonote_core.cpp.

1300 {
1301 return m_blockchain_storage.get_total_transactions();
1302 }
Here is the caller graph for this function:

◆ get_blocks() [1/4]

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

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
Note
see Blockchain::get_blocks(const t_ids_container&, t_blocks_container&, t_missed_container&) const

Definition at line 349 of file cryptonote_core.h.

350 {
351 return m_blockchain_storage.get_blocks(block_ids, blocks, missed_bs);
352 }

◆ get_blocks() [2/4]

bool cryptonote::core::get_blocks ( uint64_t start_offset,
size_t count,
std::vector< 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
Note
see Blockchain::get_blocks(uint64_t, size_t, std::vector<std::pair<cryptonote::blobdata,block>>&) const

Definition at line 456 of file cryptonote_core.cpp.

457 {
458 std::vector<std::pair<cryptonote::blobdata, cryptonote::block>> bs;
459 if (!m_blockchain_storage.get_blocks(start_offset, count, bs))
460 return false;
461 for (const auto &b: bs)
462 blocks.push_back(b.second);
463 return true;
464 }

◆ get_blocks() [3/4]

bool cryptonote::core::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
Note
see Blockchain::get_blocks(uint64_t, size_t, std::vector<std::pair<cryptonote::blobdata,block>>&) const

Definition at line 451 of file cryptonote_core.cpp.

452 {
453 return m_blockchain_storage.get_blocks(start_offset, count, blocks);
454 }

◆ get_blocks() [4/4]

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

Note
see Blockchain::get_blocks(uint64_t, size_t, std::vector<std::pair<cryptonote::blobdata,block>>&, std::vector<transaction>&) const

Definition at line 446 of file cryptonote_core.cpp.

447 {
448 return m_blockchain_storage.get_blocks(start_offset, count, blocks, txs);
449 }
Here is the caller graph for this function:

◆ get_coinbase_tx_sum()

std::pair< uint64_t, uint64_t > cryptonote::core::get_coinbase_tx_sum ( const uint64_t start_offset,
const size_t count )

get the sum of coinbase tx amounts between blocks

Returns
the number of blocks to sync in one go

Definition at line 1210 of file cryptonote_core.cpp.

1211 {
1212 uint64_t emission_amount = 0;
1213 uint64_t total_fee_amount = 0;
1214 if (count)
1215 {
1216 const uint64_t end = start_offset + count - 1;
1217 m_blockchain_storage.for_blocks_range(start_offset, end,
1218 [this, &emission_amount, &total_fee_amount](uint64_t, const crypto::hash& hash, const block& b){
1219 std::vector<transaction> txs;
1220 std::vector<crypto::hash> missed_txs;
1221 uint64_t coinbase_amount = get_outs_etn_amount(b.miner_tx);
1222 this->get_transactions(b.tx_hashes, txs, missed_txs);
1223 uint64_t tx_fee_amount = 0;
1224 for(const auto& tx: txs)
1225 {
1226 tx_fee_amount += get_tx_fee(tx);
1227 }
1228
1229 emission_amount += coinbase_amount - tx_fee_amount;
1230 total_fee_amount += tx_fee_amount;
1231 return true;
1232 });
1233 }
1234
1235 return std::pair<uint64_t, uint64_t>(emission_amount, total_fee_amount);
1236 }
bool get_transactions(const std::vector< crypto::hash > &txs_ids, std::vector< cryptonote::blobdata > &txs, std::vector< crypto::hash > &missed_txs) const
POD_CLASS hash
Definition hash.h:50
uint64_t get_outs_etn_amount(const transaction &tx)
bool get_tx_fee(const transaction &tx, uint64_t &fee)
mdb_size_t count(MDB_cursor *cur)
Here is the call graph for this function:

◆ get_current_blockchain_height()

uint64_t cryptonote::core::get_current_blockchain_height ( ) const

get the current height of the blockchain

Returns
the height
Note
see Blockchain::get_current_blockchain_height()

Definition at line 436 of file cryptonote_core.cpp.

437 {
438 return m_blockchain_storage.get_current_blockchain_height();
439 }
Here is the caller graph for this function:

◆ get_earliest_ideal_height_for_version()

uint64_t cryptonote::core::get_earliest_ideal_height_for_version ( uint8_t version) const

return the earliest block a given version may activate

Returns
what it says above

Definition at line 1765 of file cryptonote_core.cpp.

1766 {
1768 }
uint8_t version
uint64_t get_earliest_ideal_height_for_version(uint8_t version) const
returns the earliest block a given version may activate
Definition blockchain.h:865
Here is the call graph for this function:

◆ get_free_space()

uint64_t cryptonote::core::get_free_space ( ) const

get free disk space on the blockchain partition

Returns
free space in bytes

Definition at line 2021 of file cryptonote_core.cpp.

2022 {
2023 boost::filesystem::path path(m_config_folder);
2024 boost::filesystem::space_info si = boost::filesystem::space(path);
2025 return si.available;
2026 }

◆ get_hard_fork_version()

uint8_t cryptonote::core::get_hard_fork_version ( uint64_t height) const

return the hard fork version for a given block height

Returns
what it says above

Definition at line 1760 of file cryptonote_core.cpp.

1761 {
1763 }
uint8_t get_hard_fork_version(uint64_t height) const
returns the actual hardfork version for a given block height
Definition blockchain.h:858
Here is the call graph for this function:

◆ get_ideal_hard_fork_version() [1/2]

uint8_t cryptonote::core::get_ideal_hard_fork_version ( ) const

returns the newest hardfork version known to the blockchain

Returns
the version

Definition at line 1750 of file cryptonote_core.cpp.

1751 {
1753 }
uint8_t get_ideal_hard_fork_version() const
returns the newest hardfork version known to the blockchain
Definition blockchain.h:832
Here is the call graph for this function:

◆ get_ideal_hard_fork_version() [2/2]

uint8_t cryptonote::core::get_ideal_hard_fork_version ( uint64_t height) const

return the ideal hard fork version for a given block height

Returns
what it says above

Definition at line 1755 of file cryptonote_core.cpp.

Here is the call graph for this function:

◆ get_miner() [1/2]

miner & cryptonote::core::get_miner ( )
inline

gets the miner instance

Returns
a reference to the miner instance

Definition at line 229 of file cryptonote_core.h.

229{return m_miner;}

◆ get_miner() [2/2]

const miner & cryptonote::core::get_miner ( ) const
inline

gets the miner instance (const)

Returns
a const reference to the miner instance

Definition at line 236 of file cryptonote_core.h.

236{return m_miner;}

◆ get_nettype()

network_type cryptonote::core::get_nettype ( ) const
inline

get the network type we're on

Returns
which network are we on?

Definition at line 807 of file cryptonote_core.h.

807{ return m_nettype; };

◆ get_output_distribution()

bool cryptonote::core::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 per block distribution of outputs of a given amount

Definition at line 1381 of file cryptonote_core.cpp.

1382 {
1383 return m_blockchain_storage.get_output_distribution(amount, from_height, to_height, start_height, distribution, base);
1384 }

◆ get_outs()

bool cryptonote::core::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.

Parameters
reqthe outputs to return
resreturn-by-reference the resultant output indices and keys
Returns
true
Note
see Blockchain::get_outs

Definition at line 1376 of file cryptonote_core.cpp.

1377 {
1378 return m_blockchain_storage.get_outs(req, res);
1379 }
const char * res

◆ get_pool_for_rpc()

bool cryptonote::core::get_pool_for_rpc ( std::vector< cryptonote::rpc::tx_in_pool > & tx_infos,
cryptonote::rpc::key_images_with_tx_hashes & key_image_infos ) const

get information about all transactions and key images in the pool

see documentation on tx_in_pool and key_images_with_tx_hashes for more details

Parameters
tx_infos[out] the transactions' information
key_image_infos[out] the spent key images' information
Returns
true
Note
see tx_memory_pool::get_pool_for_rpc

Definition at line 1652 of file cryptonote_core.cpp.

1653 {
1654 return m_mempool.get_pool_for_rpc(tx_infos, key_image_infos);
1655 }

◆ get_pool_transaction()

bool cryptonote::core::get_pool_transaction ( const crypto::hash & id,
cryptonote::blobdata & tx ) const

get a specific transaction from the pool

Parameters
hthe hash of the transaction to get
txreturn-by-reference the transaction blob requested
Returns
true if the transaction is found, otherwise false
Note
see tx_memory_pool::get_transaction

Definition at line 1632 of file cryptonote_core.cpp.

1633 {
1634 return m_mempool.get_transaction(id, tx);
1635 }

◆ get_pool_transaction_hashes()

bool cryptonote::core::get_pool_transaction_hashes ( std::vector< crypto::hash > & txs,
bool include_unrelayed_txes = true ) const

get a list of all transactions in the pool

Parameters
txsreturn-by-reference the list of transactions
include_unrelayed_txesinclude unrelayed txes in the result
include_unrelayed_txesinclude unrelayed txes in result
Note
see tx_memory_pool::get_transactions

Definition at line 1620 of file cryptonote_core.cpp.

1621 {
1622 m_mempool.get_transaction_hashes(txs, include_sensitive_data);
1623 return true;
1624 }
Here is the caller graph for this function:

◆ get_pool_transaction_stats()

bool cryptonote::core::get_pool_transaction_stats ( struct txpool_stats & stats,
bool include_unrelayed_txes = true ) const

get a list of all transactions in the pool

Parameters
txsreturn-by-reference the list of transactions
include_unrelayed_txesinclude unrelayed txes in the result
include_unrelayed_txesinclude unrelayed txes in result
Note
see tx_memory_pool::get_transactions

Definition at line 1626 of file cryptonote_core.cpp.

1627 {
1628 m_mempool.get_transaction_stats(stats, include_sensitive_data);
1629 return true;
1630 }

◆ get_pool_transactions()

bool cryptonote::core::get_pool_transactions ( std::vector< transaction > & txs,
bool include_unrelayed_txes = true ) const

get a list of all transactions in the pool

Parameters
txsreturn-by-reference the list of transactions
include_unrelayed_txesinclude unrelayed txes in the result
include_unrelayed_txesinclude unrelayed txes in result
Note
see tx_memory_pool::get_transactions

Definition at line 1614 of file cryptonote_core.cpp.

1615 {
1616 m_mempool.get_transactions(txs, include_sensitive_data);
1617 return true;
1618 }
Here is the caller graph for this function:

◆ get_pool_transactions_and_spent_keys_info()

bool cryptonote::core::get_pool_transactions_and_spent_keys_info ( std::vector< tx_info > & tx_infos,
std::vector< spent_key_image_info > & key_image_infos,
bool include_unrelayed_txes = true ) const

Parameters
include_unrelayed_txesinclude unrelayed txes in result
Note
see tx_memory_pool::get_pool_transactions_and_spent_keys_info

Definition at line 1647 of file cryptonote_core.cpp.

1648 {
1649 return m_mempool.get_transactions_and_spent_keys_info(tx_infos, key_image_infos, include_sensitive_data);
1650 }

◆ get_pool_transactions_count()

size_t cryptonote::core::get_pool_transactions_count ( ) const

get the total number of transactions in the pool

Returns
the number of transactions in the pool
Note
see tx_memory_pool::get_transactions_count

Definition at line 1594 of file cryptonote_core.cpp.

1595 {
1596 return m_mempool.get_transactions_count();
1597 }
Here is the caller graph for this function:

◆ get_protocol()

i_cryptonote_protocol * cryptonote::core::get_protocol ( )
inline

get the cryptonote protocol instance

Returns
the instance

Definition at line 192 of file cryptonote_core.h.

192{return m_pprotocol;}

◆ get_short_chain_history()

bool cryptonote::core::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...

Parameters
idsreturn-by-reference list to put the resulting hashes in
Returns
true
Note
see Blockchain::get_short_chain_history

Definition at line 1657 of file cryptonote_core.cpp.

1658 {
1659 return m_blockchain_storage.get_short_chain_history(ids);
1660 }

◆ get_split_transactions_blobs()

bool cryptonote::core::get_split_transactions_blobs ( const std::vector< crypto::hash > & txs_ids,
std::vector< std::tuple< crypto::hash, cryptonote::blobdata, crypto::hash, cryptonote::blobdata > > & txs,
std::vector< crypto::hash > & missed_txs ) const

Note
see Blockchain::get_transactions

Definition at line 471 of file cryptonote_core.cpp.

472 {
473 return m_blockchain_storage.get_split_transactions_blobs(txs_ids, txs, missed_txs);
474 }

◆ get_start_time()

std::time_t cryptonote::core::get_start_time ( ) const

gets start_time

Definition at line 2038 of file cryptonote_core.cpp.

2039 {
2040 return start_time;
2041 }

◆ get_stat_info()

bool cryptonote::core::get_stat_info ( core_stat_info & st_inf) const

gets some stats about the daemon

Parameters
st_infreturn-by-reference container for the stats requested
Returns
true

Definition at line 1052 of file cryptonote_core.cpp.

1053 {
1054 st_inf.mining_speed = m_miner.get_speed();
1055 st_inf.alternative_blocks = m_blockchain_storage.get_alternative_blocks_count();
1056 st_inf.blockchain_height = m_blockchain_storage.get_current_blockchain_height();
1057 st_inf.tx_pool_size = m_mempool.get_transactions_count();
1058 st_inf.top_block_id_str = epee::string_tools::pod_to_hex(m_blockchain_storage.get_tail_id());
1059 return true;
1060 }
std::string pod_to_hex(const t_pod_type &s)
Here is the call graph for this function:

◆ get_tail_id()

crypto::hash cryptonote::core::get_tail_id ( ) const

get the hash of the most recent block on the blockchain

Returns
the hash
Note
see Blockchain::get_tail_id

Definition at line 1579 of file cryptonote_core.cpp.

1580 {
1581 return m_blockchain_storage.get_tail_id();
1582 }
Here is the caller graph for this function:

◆ get_target_blockchain_height()

uint64_t cryptonote::core::get_target_blockchain_height ( ) const

gets the target blockchain height

Parameters
target_blockchain_heightthe target height

Definition at line 2016 of file cryptonote_core.cpp.

2017 {
2018 return m_target_blockchain_height;
2019 }

◆ get_test_drop_download()

bool cryptonote::core::get_test_drop_download ( ) const

gets whether or not to drop blocks (for testing)

Returns
whether or not to drop blocks

Definition at line 805 of file cryptonote_core.cpp.

806 {
807 return m_test_drop_download;
808 }

◆ get_test_drop_download_height()

bool cryptonote::core::get_test_drop_download_height ( ) const

gets whether or not to drop blocks

If the current blockchain height <= our block drop threshold and test drop blocks is set, return true

Returns
see above

Definition at line 810 of file cryptonote_core.cpp.

811 {
812 if (m_test_drop_download_height == 0)
813 return true;
814
815 if (get_blockchain_storage().get_current_blockchain_height() <= m_test_drop_download_height)
816 return true;
817
818 return false;
819 }
uint64_t get_current_blockchain_height() const
get the current height of the blockchain
Here is the call graph for this function:

◆ get_transactions() [1/2]

bool cryptonote::core::get_transactions ( const std::vector< crypto::hash > & txs_ids,
std::vector< cryptonote::blobdata > & txs,
std::vector< crypto::hash > & missed_txs ) const

Note
see Blockchain::get_transactions

Definition at line 466 of file cryptonote_core.cpp.

467 {
468 return m_blockchain_storage.get_transactions_blobs(txs_ids, txs, missed_txs);
469 }
Here is the caller graph for this function:

◆ get_transactions() [2/2]

bool cryptonote::core::get_transactions ( const std::vector< crypto::hash > & txs_ids,
std::vector< transaction > & txs,
std::vector< crypto::hash > & missed_txs ) const

Note
see Blockchain::get_transactions

Definition at line 482 of file cryptonote_core.cpp.

483 {
484 return m_blockchain_storage.get_transactions(txs_ids, txs, missed_txs);
485 }

◆ get_tx_outputs_gindexs() [1/2]

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

Definition at line 1391 of file cryptonote_core.cpp.

1392 {
1393 return m_blockchain_storage.get_tx_outputs_gindexs(tx_id, n_txes, indexs);
1394 }

◆ get_tx_outputs_gindexs() [2/2]

bool cryptonote::core::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
Note
see Blockchain::get_tx_outputs_gindexs

Definition at line 1386 of file cryptonote_core.cpp.

1387 {
1388 return m_blockchain_storage.get_tx_outputs_gindexs(tx_id, indexs);
1389 }

◆ get_txpool_backlog()

bool cryptonote::core::get_txpool_backlog ( std::vector< tx_backlog_entry > & backlog) const

Note
see tx_memory_pool::get_txpool_backlog

Definition at line 476 of file cryptonote_core.cpp.

477 {
478 m_mempool.get_transaction_backlog(backlog);
479 return true;
480 }

◆ get_validators_list()

std::string cryptonote::core::get_validators_list ( )

Get a serialized representation of the list of validators.

Returns
serialized string

Definition at line 319 of file cryptonote_core.cpp.

319 {
320 return m_validators->getSerializedValidatorList();
321 }

◆ graceful_exit()

void cryptonote::core::graceful_exit ( )

tells the daemon to wind down operations and stop running

Currently this function raises SIGTERM, allowing the installed signal handlers to do the actual stopping.

Definition at line 2084 of file cryptonote_core.cpp.

2085 {
2086 raise(SIGTERM);
2087 }
Here is the caller graph for this function:

◆ handle_block_found()

bool cryptonote::core::handle_block_found ( block & b,
block_verification_context & bvc )
virtual

stores and relays a block found by a miner

Updates the miner's target block, attempts to store the found block in Blockchain, and – on success – relays that block to the network.

Parameters
bthe block found
bvcreturns the block verification flags
Returns
true if the block was added to the main chain, otherwise false

Implements cryptonote::i_miner_handler.

Definition at line 1419 of file cryptonote_core.cpp.

1420 {
1421 bvc = boost::value_initialized<block_verification_context>();
1422 m_miner.pause();
1423 std::vector<block_complete_entry> blocks;
1424 try
1425 {
1426 blocks.push_back(get_block_complete_entry(b, m_mempool));
1427 }
1428 catch (const std::exception &e)
1429 {
1430 m_miner.resume();
1431 return false;
1432 }
1433 std::vector<block> pblocks;
1434 if (!prepare_handle_incoming_blocks(blocks, pblocks))
1435 {
1436 MERROR("Block found, but failed to prepare to add");
1437 m_miner.resume();
1438 return false;
1439 }
1440 m_blockchain_storage.add_new_block(b, bvc);
1442
1443 CHECK_AND_ASSERT_MES(!bvc.m_verification_failed, false, "Mined block failed verification");
1444 if(bvc.m_added_to_main_chain)
1445 {
1446 cryptonote_connection_context exclude_context = boost::value_initialized<cryptonote_connection_context>();
1448 arg.current_blockchain_height = m_blockchain_storage.get_current_blockchain_height();
1449 std::vector<crypto::hash> missed_txs;
1450 std::vector<cryptonote::blobdata> txs;
1451 m_blockchain_storage.get_transactions_blobs(b.tx_hashes, txs, missed_txs);
1452 if(missed_txs.size() && m_blockchain_storage.get_block_id_by_height(get_block_height(b)) != get_block_hash(b))
1453 {
1454 LOG_PRINT_L1("Block found but, seems that reorganize just happened after that, do not relay this block");
1455 return true;
1456 }
1457 CHECK_AND_ASSERT_MES(txs.size() == b.tx_hashes.size() && !missed_txs.size(), false, "can't find some transactions in found block:" << get_block_hash(b) << " txs.size()=" << txs.size()
1458 << ", b.tx_hashes.size()=" << b.tx_hashes.size() << ", missed_txs.size()" << missed_txs.size());
1459
1460 block_to_blob(b, arg.b.block);
1461 //pack transactions
1462 for(auto& tx: txs)
1463 arg.b.txs.push_back(tx);
1464
1465 m_pprotocol->relay_block(arg, exclude_context);
1466
1467 if(m_fallback_to_pow) {
1468 m_miner.resume();
1469 }
1470 } else {
1471 update_miner_block_template();
1472 m_miner.resume();
1473 }
1474 return true;
1475 }
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
bool cleanup_handle_incoming_blocks(bool force_sync=false)
incoming blocks post-processing, cleanup, and disk sync
#define AUTO_VAL_INIT(v)
#define MERROR(x)
Definition misc_log_ex.h:73
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
block_complete_entry get_block_complete_entry(block &b, tx_memory_pool &pool)
bool get_block_hash(const block &b, crypto::hash &res)
uint64_t get_block_height(const block &b)
blobdata block_to_blob(const block &b)
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

◆ handle_get_objects()

bool cryptonote::core::handle_get_objects ( NOTIFY_REQUEST_GET_OBJECTS::request & arg,
NOTIFY_RESPONSE_GET_OBJECTS::request & rsp,
cryptonote_connection_context & context )

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
Note
see Blockchain::handle_get_objects()
Parameters
contextconnection context associated with the request

Definition at line 1662 of file cryptonote_core.cpp.

1663 {
1664 return m_blockchain_storage.handle_get_objects(arg, rsp);
1665 }

◆ handle_incoming_block()

bool cryptonote::core::handle_incoming_block ( const blobdata & block_blob,
const block * b,
block_verification_context & bvc,
bool update_miner_blocktemplate = true )

handles an incoming block

periodic update to checkpoints is triggered here Attempts to add the block to the Blockchain and, on success, optionally updates the miner's block template.

Parameters
block_blobthe block to be added
blockthe block to be added, or NULL
bvcreturn-by-reference metadata context about the block's validity
update_miner_blocktemplatewhether or not to update the miner's block template
Returns
false if loading new checkpoints fails, or the block is not added, otherwise true

Definition at line 1517 of file cryptonote_core.cpp.

1518 {
1519 TRY_ENTRY();
1520
1521 bvc = boost::value_initialized<block_verification_context>();
1522
1523 if (!check_incoming_block_size(block_blob))
1524 {
1525 bvc.m_verification_failed = true;
1526 return false;
1527 }
1528
1529 if (((size_t)-1) <= 0xffffffff && block_blob.size() >= 0x3fffffff)
1530 MWARNING("This block's size is " << block_blob.size() << ", closing on the 32 bit limit");
1531
1532 // load json & DNS checkpoints every 10min/hour respectively,
1533 // and verify them with respect to what blocks we already have
1534 CHECK_AND_ASSERT_MES(update_checkpoints(), false, "One or more checkpoints loaded from json or dns conflicted with existing checkpoints.");
1535
1536 block lb;
1537 if (!b)
1538 {
1539 crypto::hash block_hash;
1540 if(!parse_and_validate_block_from_blob(block_blob, lb, block_hash))
1541 {
1542 LOG_PRINT_L1("Failed to parse and validate new block");
1543 bvc.m_verification_failed = true;
1544 return false;
1545 }
1546 b = &lb;
1547 }
1548
1549 add_new_block(*b, bvc);
1550
1551 if(bvc.m_added_to_main_chain) {
1552 m_miner.resume();
1553
1554 if(update_miner_blocktemplate)
1555 update_miner_block_template();
1556 }
1557
1558 return true;
1559
1560 CATCH_ENTRY_L0("core::handle_incoming_block()", false);
1561 }
bool update_checkpoints()
tells the Blockchain to update its checkpoints
bool check_incoming_block_size(const blobdata &block_blob) const
check the size of a block against the current maximum
#define MWARNING(x)
Definition misc_log_ex.h:74
#define CATCH_ENTRY_L0(lacation, return_val)
#define TRY_ENTRY()
bool parse_and_validate_block_from_blob(const blobdata &b_blob, block &b, crypto::hash *block_hash)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_incoming_tx()

bool cryptonote::core::handle_incoming_tx ( const blobdata & tx_blob,
tx_verification_context & tvc,
bool keeped_by_block,
bool relayed,
bool do_not_relay )

handles an incoming transaction

Parses an incoming transaction and, if nothing is obviously wrong, passes it along to the transaction pool

Parameters
tx_blobthe tx to handle
tvcmetadata about the transaction's validity
keeped_by_blockif the transaction has been in a block
relayedwhether or not the transaction was relayed to us
do_not_relaywhether to prevent the transaction from being relayed
Returns
true if the transaction was accepted, false otherwise

Definition at line 1042 of file cryptonote_core.cpp.

1043 {
1044 std::vector<cryptonote::blobdata> tx_blobs;
1045 tx_blobs.push_back(tx_blob);
1046 std::vector<tx_verification_context> tvcv(1);
1047 bool r = handle_incoming_txs(tx_blobs, tvcv, keeped_by_block, relayed, do_not_relay);
1048 tvc = tvcv[0];
1049 return r;
1050 }
bool handle_incoming_txs(const std::vector< blobdata > &tx_blobs, std::vector< tx_verification_context > &tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
handles a list of incoming transactions
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_incoming_txs()

bool cryptonote::core::handle_incoming_txs ( const std::vector< blobdata > & tx_blobs,
std::vector< tx_verification_context > & tvc,
bool keeped_by_block,
bool relayed,
bool do_not_relay )

handles a list of incoming transactions

Parses incoming transactions and, if nothing is obviously wrong, passes them along to the transaction pool

Parameters
tx_blobsthe txs to handle
tvcmetadata about the transactions' validity
keeped_by_blockif the transactions have been in a block
relayedwhether or not the transactions were relayed to us
do_not_relaywhether to prevent the transactions from being relayed
Returns
true if the transactions were accepted, false otherwise

Definition at line 944 of file cryptonote_core.cpp.

945 {
946 TRY_ENTRY();
947 CRITICAL_REGION_LOCAL(m_incoming_tx_lock);
948
949 struct result { bool res; cryptonote::transaction tx; crypto::hash hash; };
950 std::vector<result> results(tx_blobs.size());
951
952 tvc.resize(tx_blobs.size());
953 tools::threadpool& tpool = tools::threadpool::getInstance();
954 tools::threadpool::waiter waiter;
955 std::vector<blobdata>::const_iterator it = tx_blobs.begin();
956 for (size_t i = 0; i < tx_blobs.size(); i++, ++it) {
957 tpool.submit(&waiter, [&, i, it] {
958 try
959 {
960 results[i].res = handle_incoming_tx_pre(*it, tvc[i], results[i].tx, results[i].hash, keeped_by_block, relayed, do_not_relay);
961 }
962 catch (const std::exception &e)
963 {
964 MERROR_VER("Exception in handle_incoming_tx_pre: " << e.what());
965 tvc[i].m_verification_failed = true;
966 results[i].res = false;
967 }
968 });
969 }
970 waiter.wait(&tpool);
971 it = tx_blobs.begin();
972 std::vector<bool> already_have(tx_blobs.size(), false);
973 for (size_t i = 0; i < tx_blobs.size(); i++, ++it) {
974 if (!results[i].res)
975 continue;
976 if(m_mempool.have_tx(results[i].hash))
977 {
978 LOG_PRINT_L2("tx " << results[i].hash << "already have transaction in tx_pool");
979 already_have[i] = true;
980 }
981 else if(m_blockchain_storage.have_tx(results[i].hash))
982 {
983 LOG_PRINT_L2("tx " << results[i].hash << " already have transaction in blockchain");
984 already_have[i] = true;
985 }
986 else
987 {
988 tpool.submit(&waiter, [&, i, it] {
989 try
990 {
991 results[i].res = handle_incoming_tx_post(*it, tvc[i], results[i].tx, results[i].hash, keeped_by_block, relayed, do_not_relay);
992 }
993 catch (const std::exception &e)
994 {
995 MERROR_VER("Exception in handle_incoming_tx_post: " << e.what());
996 tvc[i].m_verification_failed = true;
997 results[i].res = false;
998 }
999 });
1000 }
1001 }
1002 waiter.wait(&tpool);
1003
1004 std::vector<tx_verification_batch_info> tx_info;
1005 tx_info.reserve(tx_blobs.size());
1006 for (size_t i = 0; i < tx_blobs.size(); i++) {
1007 if (!results[i].res || already_have[i])
1008 continue;
1009 tx_info.push_back({&results[i].tx, results[i].hash, tvc[i], results[i].res});
1010 }
1011 if (!tx_info.empty())
1012 handle_incoming_tx_accumulated_batch(tx_info, keeped_by_block);
1013
1014 bool ok = true;
1015 it = tx_blobs.begin();
1016 for (size_t i = 0; i < tx_blobs.size(); i++, ++it) {
1017 if (!results[i].res)
1018 {
1019 ok = false;
1020 continue;
1021 }
1022 if (keeped_by_block)
1024 if (already_have[i])
1025 continue;
1026
1027 const size_t weight = get_transaction_weight(results[i].tx, it->size());
1028 ok &= add_new_tx(results[i].tx, results[i].hash, tx_blobs[i], weight, tvc[i], keeped_by_block, relayed, do_not_relay);
1029 if(tvc[i].m_verification_failed)
1030 {MERROR_VER("Transaction verification failed: " << results[i].hash);}
1031 else if(tvc[i].m_verification_impossible)
1032 {MERROR_VER("Transaction verification impossible: " << results[i].hash);}
1033
1034 if(tvc[i].m_added_to_pool)
1035 MDEBUG("tx added: " << results[i].hash);
1036 }
1037 return ok;
1038
1039 CATCH_ENTRY_L0("core::handle_incoming_txs()", false);
1040 }
#define MERROR_VER(x)
void on_new_tx_from_block(const cryptonote::transaction &tx)
called when we see a tx originating from a block
void wait(threadpool *tpool)
void submit(waiter *waiter, std::function< void()> f, bool leaf=false)
static threadpool & getInstance()
Definition threadpool.h:46
#define MDEBUG(x)
Definition misc_log_ex.h:76
#define LOG_PRINT_L2(x)
uint64_t get_transaction_weight(const transaction &tx, size_t blob_size)
#define CRITICAL_REGION_LOCAL(x)
Definition syncobj.h:228
Here is the call graph for this function:
Here is the caller graph for this function:

◆ have_block()

bool cryptonote::core::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

Parameters
idthe hash to search for
Returns
true if the block is known, else false
Note
see Blockchain::have_block

Definition at line 1599 of file cryptonote_core.cpp.

1600 {
1601 return m_blockchain_storage.have_block(id);
1602 }

◆ init()

bool cryptonote::core::init ( const boost::program_options::variables_map & vm,
const test_options * test_options = NULL,
const GetCheckpointsCallback & get_checkpoints = nullptr )

initializes the core as needed

This function initializes the transaction pool, the Blockchain, and a miner instance with parameters given on the command line (or defaults)

Parameters
vmcommand line parameters
test_optionsconfiguration options for testing
get_checkpointsif set, will be called to get checkpoints data, must return checkpoints data pointer and size or nullptr if there ain't any checkpoints for specific network type
Returns
false if one of the init steps fails, otherwise true

Definition at line 497 of file cryptonote_core.cpp.

498 {
499 start_time = std::time(nullptr);
500
501 const bool regtest = command_line::get_arg(vm, arg_regtest_on);
502 if (test_options != NULL || regtest)
503 {
504 m_nettype = FAKECHAIN;
505 }
506
507 m_fallback_to_pow = command_line::get_arg(vm, arg_fallback_to_pow);
508 m_fallback_to_pow_checkpoint_height = command_line::get_arg(vm, arg_fallback_to_pow_checkpoint_height);
509 m_fallback_to_pow_checkpoint_hash = command_line::get_arg(vm, arg_fallback_to_pow_checkpoint_hash);
510
511 bool r = handle_command_line(vm);
512
513 std::string db_type = command_line::get_arg(vm, cryptonote::arg_db_type);
514 std::string db_sync_mode = command_line::get_arg(vm, cryptonote::arg_db_sync_mode);
515 bool db_salvage = command_line::get_arg(vm, cryptonote::arg_db_salvage) != 0;
516 bool addr_db_salvage = command_line::get_arg(vm, cryptonote::arg_addr_db_salvage) != 0;
517 bool fast_sync = command_line::get_arg(vm, arg_fast_block_sync) != 0;
518 uint64_t blocks_threads = command_line::get_arg(vm, arg_prep_blocks_threads);
519 std::string check_updates_string = command_line::get_arg(vm, arg_check_updates);
520 size_t max_txpool_weight = command_line::get_arg(vm, arg_max_txpool_weight);
521 bool prune_blockchain = command_line::get_arg(vm, arg_prune_blockchain);
522 std::string validator_key = command_line::get_arg(vm, arg_validator_key);
523
524 bool is_validator_key_valid = std::count_if(validator_key.begin(), validator_key.end(), [](int c) {return !std::isxdigit(c);}) == 0;
525 if(!is_validator_key_valid || validator_key.size() % 2 != 0) {
526 validator_key.clear();
527 }
528
529 boost::filesystem::path folder(m_config_folder);
530 if (m_nettype == FAKECHAIN)
531 folder /= "fake";
532
533 // make sure the data directory exists, and try to lock it
534 CHECK_AND_ASSERT_MES (boost::filesystem::exists(folder) || boost::filesystem::create_directories(folder), false,
535 std::string("Failed to create directory ").append(folder.string()).c_str());
536
537 // check for blockchain.bin
538 try
539 {
540 const boost::filesystem::path old_files = folder;
541 if (boost::filesystem::exists(old_files / "blockchain.bin"))
542 {
543 MWARNING("Found old-style blockchain.bin in " << old_files.string());
544 MWARNING("Electroneum now uses a new format. You can either remove blockchain.bin to start syncing");
545 MWARNING("the blockchain anew, or use electroneum-blockchain-export and electroneum-blockchain-import to");
546 MWARNING("convert your existing blockchain.bin to the new format. See README.md for instructions.");
547 return false;
548 }
549 }
550 // folder might not be a directory, etc, etc
551 catch (...) { }
552
553 std::unique_ptr<BlockchainDB> db(new_db(db_type));
554 if (db == NULL)
555 {
556 LOG_ERROR("Attempted to use non-existent database type");
557 return false;
558 }
559
560 folder /= db->get_db_name();
561 MGINFO("Loading blockchain from folder " << folder.string() << " ...");
562
563 const std::string filename = folder.string();
564 // default to fast:async:1 if overridden
566 bool sync_on_blocks = true;
567 uint64_t sync_threshold = 1;
568
569 if (m_nettype == FAKECHAIN)
570 {
571 // reset the db by removing the database file before opening it
572 if (!db->remove_data_file(filename))
573 {
574 MERROR("Failed to remove data file in " << filename);
575 return false;
576 }
577 }
578
579 try
580 {
581 uint64_t db_flags = 0;
582
583 std::vector<std::string> options;
584 boost::trim(db_sync_mode);
585 boost::split(options, db_sync_mode, boost::is_any_of(" :"));
586 const bool db_sync_mode_is_default = command_line::is_arg_defaulted(vm, cryptonote::arg_db_sync_mode);
587
588 for(const auto &option : options)
589 MDEBUG("option: " << option);
590
591 // default to fast:async:1
592 uint64_t DEFAULT_FLAGS = DBF_FAST;
593
594 if(options.size() == 0)
595 {
596 // default to fast:async:1
597 db_flags = DEFAULT_FLAGS;
598 }
599
600 bool safemode = false;
601 if(options.size() >= 1)
602 {
603 if(options[0] == "safe")
604 {
605 safemode = true;
606 db_flags = DBF_SAFE;
607 sync_mode = db_sync_mode_is_default ? db_defaultsync : db_nosync;
608 }
609 else if(options[0] == "fast")
610 {
611 db_flags = DBF_FAST;
612 sync_mode = db_sync_mode_is_default ? db_defaultsync : db_async;
613 }
614 else if(options[0] == "fastest")
615 {
616 db_flags = DBF_FASTEST;
617 sync_threshold = 1000; // default to fastest:async:1000
618 sync_mode = db_sync_mode_is_default ? db_defaultsync : db_async;
619 }
620 else
621 db_flags = DEFAULT_FLAGS;
622 }
623
624 if(options.size() >= 2 && !safemode)
625 {
626 if(options[1] == "sync")
627 sync_mode = db_sync_mode_is_default ? db_defaultsync : db_sync;
628 else if(options[1] == "async")
629 sync_mode = db_sync_mode_is_default ? db_defaultsync : db_async;
630 }
631
632 if(options.size() >= 3 && !safemode)
633 {
634 char *endptr;
635 uint64_t threshold = strtoull(options[2].c_str(), &endptr, 0);
636 if (*endptr == '\0' || !strcmp(endptr, "blocks"))
637 {
638 sync_on_blocks = true;
639 sync_threshold = threshold;
640 }
641 else if (!strcmp(endptr, "bytes"))
642 {
643 sync_on_blocks = false;
644 sync_threshold = threshold;
645 }
646 else
647 {
648 LOG_ERROR("Invalid db sync mode: " << options[2]);
649 return false;
650 }
651 }
652
653 if (db_salvage)
654 db_flags |= DBF_SALVAGE;
655
656 if(addr_db_salvage)
657 db_flags |= DBF_ADDR_TX_SALVAGE;
658
659 db->open(filename, db_flags);
660 if(!db->m_open)
661 return false;
662 }
663 catch (const DB_ERROR& e)
664 {
665 LOG_ERROR("Error opening database: " << e.what());
666 return false;
667 }
668
669 m_blockchain_storage.set_user_options(blocks_threads,
670 sync_on_blocks, sync_threshold, sync_mode, fast_sync, validator_key);
671
672 try
673 {
674 if (!command_line::is_arg_defaulted(vm, arg_block_notify))
675 m_blockchain_storage.set_block_notify(std::shared_ptr<tools::Notify>(new tools::Notify(command_line::get_arg(vm, arg_block_notify).c_str())));
676 }
677 catch (const std::exception &e)
678 {
679 MERROR("Failed to parse block notify spec: " << e.what());
680 }
681
682 try
683 {
684 if (!command_line::is_arg_defaulted(vm, arg_reorg_notify))
685 m_blockchain_storage.set_reorg_notify(std::shared_ptr<tools::Notify>(new tools::Notify(command_line::get_arg(vm, arg_reorg_notify).c_str())));
686 }
687 catch (const std::exception &e)
688 {
689 MERROR("Failed to parse reorg notify spec: " << e.what());
690 }
691
692 try
693 {
694 if (!command_line::is_arg_defaulted(vm, arg_block_rate_notify))
695 m_block_rate_notify.reset(new tools::Notify(command_line::get_arg(vm, arg_block_rate_notify).c_str()));
696 }
697 catch (const std::exception &e)
698 {
699 MERROR("Failed to parse block rate notify spec: " << e.what());
700 }
701
702 const std::pair<uint8_t, uint64_t> regtest_hard_forks[3] = {std::make_pair(1, 0), std::make_pair(Blockchain::get_hard_fork_heights(MAINNET).back().version, 1), std::make_pair(0, 0)};
703 const cryptonote::test_options regtest_test_options = {
704 regtest_hard_forks,
705 0
706 };
707 const difficulty_type fixed_difficulty = command_line::get_arg(vm, arg_fixed_difficulty);
708 const bool ignore_bsig = command_line::get_arg(vm, arg_skip_block_sig_verification);
709
710 r = m_blockchain_storage.init(db.release(), m_nettype, m_offline, regtest ? &regtest_test_options : test_options, fixed_difficulty, get_checkpoints, ignore_bsig, m_fallback_to_pow);
711
712 r = m_mempool.init(max_txpool_weight);
713 CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool");
714
715 // now that we have a valid m_blockchain_storage, we can clean out any
716 // transactions in the pool that do not conform to the current fork
717 m_mempool.validate(m_blockchain_storage.get_current_hard_fork_version());
718
719 bool show_time_stats = command_line::get_arg(vm, arg_show_time_stats) != 0;
720 m_blockchain_storage.set_show_time_stats(show_time_stats);
721 CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage");
722
723 block_sync_size = command_line::get_arg(vm, arg_block_sync_size);
724
725 MGINFO("Loading checkpoints");
726
727 // load json & DNS checkpoints, and verify them
728 // with respect to what blocks we already have
729 CHECK_AND_ASSERT_MES(update_checkpoints(), false, "One or more checkpoints loaded from json or dns conflicted with existing checkpoints.");
730
731 // DNS versions checking
732 if (check_updates_string == "disabled")
733 check_updates_level = UPDATES_DISABLED;
734 else if (check_updates_string == "notify")
735 check_updates_level = UPDATES_NOTIFY;
736 else if (check_updates_string == "download")
737 check_updates_level = UPDATES_DOWNLOAD;
738 else if (check_updates_string == "update")
739 check_updates_level = UPDATES_UPDATE;
740 else {
741 MERROR("Invalid argument to --dns-versions-check: " << check_updates_string);
742 return false;
743 }
744
745 check_updates_level = UPDATES_DISABLED;
746
747 r = m_miner.init(vm, m_nettype, m_fallback_to_pow);
748 CHECK_AND_ASSERT_MES(r, false, "Failed to initialize miner instance");
749
751 {
752 // display a message if the blockchain is not pruned yet
753 if (!m_blockchain_storage.get_blockchain_pruning_seed())
754 {
755 MGINFO("Pruning blockchain...");
756 CHECK_AND_ASSERT_MES(m_blockchain_storage.prune_blockchain(), false, "Failed to prune blockchain");
757 }
758 else
759 {
760 CHECK_AND_ASSERT_MES(m_blockchain_storage.update_blockchain_pruning(), false, "Failed to update blockchain pruning");
761 }
762 }
763
764 if(!m_fallback_to_pow) {
765 m_validators = std::unique_ptr<electroneum::basic::Validators>(new electroneum::basic::Validators(m_blockchain_storage.get_db(), m_pprotocol, m_nettype == TESTNET));
766 m_blockchain_storage.set_validators_list_instance(m_validators);
767
768 if(m_blockchain_storage.get_current_blockchain_height() >= ((m_nettype == TESTNET ? 446674 : 589169) - 720 )) { //V8 Height - 1 day
769 m_validators->enable();
770 }
771 }
772
773 return load_state_data();
774 }
uint8_t threshold
#define DBF_SAFE
#define DBF_FAST
#define DBF_FASTEST
#define DBF_ADDR_TX_SALVAGE
#define DBF_SALVAGE
static const std::vector< HardFork::Params > & get_hard_fork_heights(network_type nettype)
gets the hardfork heights of given network
bool prune_blockchain(uint32_t pruning_seed=0)
prune the blockchain
#define LOG_ERROR(x)
Definition misc_log_ex.h:98
#define MGINFO(x)
Definition misc_log_ex.h:80
bool is_arg_defaulted(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
boost::multiprecision::uint128_t difficulty_type
Definition difficulty.h:43
const command_line::arg_descriptor< bool > arg_db_salvage
const command_line::arg_descriptor< bool > arg_regtest_on
const command_line::arg_descriptor< difficulty_type > arg_fixed_difficulty
const command_line::arg_descriptor< bool > arg_addr_db_salvage
const command_line::arg_descriptor< bool > arg_fallback_to_pow
BlockchainDB * new_db(const std::string &db_type)
blockchain_db_sync_mode
Definition blockchain.h:78
@ db_async
handle syncing calls instead of the backing db, asynchronously
Definition blockchain.h:81
@ db_nosync
Leave syncing up to the backing db (safest, but slowest because of disk I/O).
Definition blockchain.h:82
@ db_sync
handle syncing calls instead of the backing db, synchronously
Definition blockchain.h:80
@ db_defaultsync
user didn't specify, use db_async
Definition blockchain.h:79
const command_line::arg_descriptor< std::string > arg_fallback_to_pow_checkpoint_hash
const command_line::arg_descriptor< std::string > arg_db_type
const command_line::arg_descriptor< uint64_t > arg_fallback_to_pow_checkpoint_height
const command_line::arg_descriptor< bool > arg_skip_block_sig_verification
const command_line::arg_descriptor< std::string > arg_db_sync_mode
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_options()

void cryptonote::core::init_options ( boost::program_options::options_description & desc)
static

adds command line options to the given options set

As of now, there are no command line options specific to core, so this function simply returns.

Parameters
descreturn-by-reference the command line options set to add to

Definition at line 346 of file cryptonote_core.cpp.

347 {
349
350 command_line::add_arg(desc, arg_test_drop_download);
351 command_line::add_arg(desc, arg_test_drop_download_height);
352
358 command_line::add_arg(desc, arg_dns_checkpoints);
359 command_line::add_arg(desc, arg_prep_blocks_threads);
360 command_line::add_arg(desc, arg_fast_block_sync);
361 command_line::add_arg(desc, arg_show_time_stats);
362 command_line::add_arg(desc, arg_block_sync_size);
363 command_line::add_arg(desc, arg_check_updates);
364 command_line::add_arg(desc, arg_fluffy_blocks);
365 command_line::add_arg(desc, arg_no_fluffy_blocks);
366 command_line::add_arg(desc, arg_test_dbg_lock_sleep);
370 command_line::add_arg(desc, arg_max_txpool_weight);
371 command_line::add_arg(desc, arg_pad_transactions);
372 command_line::add_arg(desc, arg_block_notify);
373 command_line::add_arg(desc, arg_prune_blockchain);
374 command_line::add_arg(desc, arg_reorg_notify);
375 command_line::add_arg(desc, arg_block_rate_notify);
376 command_line::add_arg(desc, arg_validator_key);
380
383 }
static void init_options(boost::program_options::options_description &desc)
init command line options
static void init_options(boost::program_options::options_description &desc)
Definition miner.cpp:280
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
const command_line::arg_descriptor< std::string, false, true, 2 > arg_data_dir
const command_line::arg_descriptor< bool > arg_offline
const command_line::arg_descriptor< bool, false > arg_testnet_on
const command_line::arg_descriptor< bool, false > arg_stagenet_on
const command_line::arg_descriptor< bool > arg_disable_dns_checkpoints
const command_line::arg_descriptor< size_t > arg_block_download_max_size
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_key_image_spent()

bool cryptonote::core::is_key_image_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
Note
see Blockchain::have_tx_keyimg_as_spent

Definition at line 1169 of file cryptonote_core.cpp.

1170 {
1171 return m_blockchain_storage.have_tx_keyimg_as_spent(key_image);
1172 }

◆ is_update_available()

bool cryptonote::core::is_update_available ( ) const
inline

check whether an update is known to be available or not

This does not actually trigger a check, but returns the result of the last check

Returns
whether an update is known to be available or not

Definition at line 817 of file cryptonote_core.h.

817{ return m_update_available; }

◆ isValidatorsListValid()

bool cryptonote::core::isValidatorsListValid ( )

get Validators List state

Returns
true if valid, false if invalid or expired

Definition at line 327 of file cryptonote_core.cpp.

327 {
328 return m_validators->isValid();
329 }

◆ offline()

bool cryptonote::core::offline ( ) const
inline

get whether the core is running offline

Returns
whether the core is running offline

Definition at line 845 of file cryptonote_core.h.

845{ return m_offline; }

◆ on_idle()

bool cryptonote::core::on_idle ( )

calls various idle routines

Note
see miner::on_idle and tx_memory_pool::on_idle
Returns
true

Definition at line 1688 of file cryptonote_core.cpp.

1689 {
1690 if(!m_starter_message_showed)
1691 {
1692 std::string main_message;
1693 if (m_offline)
1694 main_message = "The daemon is running offline and will not attempt to sync to the Electroneum network.";
1695 else
1696 main_message = "The daemon will start synchronizing with the network. This may take a long time to complete.";
1697 MGINFO_YELLOW(ENDL << "**********************************************************************" << ENDL
1698 << main_message << ENDL
1699 << ENDL
1700 << "You can set the level of process detailization through \"set_log <level|categories>\" command," << ENDL
1701 << "where <level> is between 0 (no details) and 4 (very verbose), or custom category based levels (eg, *:WARNING)." << ENDL
1702 << ENDL
1703 << "Use the \"help\" command to see the list of available commands." << ENDL
1704 << "Use \"help <command>\" to see a command's documentation." << ENDL
1705 << "**********************************************************************" << ENDL);
1706 m_starter_message_showed = true;
1707 }
1708 //Don't moan about forks for now, but keep implementation around incase we need to use it at a later stage
1709 //m_fork_moaner.do_call(boost::bind(&core::check_fork_time, this));
1710 m_txpool_auto_relayer.do_call(boost::bind(&core::relay_txpool_transactions, this));
1711 m_check_updates_interval.do_call(boost::bind(&core::check_updates, this));
1712 m_check_disk_space_interval.do_call(boost::bind(&core::check_disk_space, this));
1713 m_block_rate_interval.do_call(boost::bind(&core::check_block_rate, this));
1714 m_blockchain_pruning_interval.do_call(boost::bind(&core::update_blockchain_pruning, this));
1715 m_miner.on_idle();
1716 m_mempool.on_idle();
1717
1718 if(!m_fallback_to_pow) {
1719 m_validators->on_idle();
1720 }
1721
1722 return true;
1723 }
bool update_blockchain_pruning()
incrementally prunes blockchain
#define MGINFO_YELLOW(x)
Definition misc_log_ex.h:83
#define ENDL
Here is the call graph for this function:

◆ on_synchronized()

void cryptonote::core::on_synchronized ( )

Note
see miner::on_synchronized

Definition at line 1477 of file cryptonote_core.cpp.

1478 {
1479 m_miner.on_synchronized();
1480 }

◆ on_transaction_relayed()

void cryptonote::core::on_transaction_relayed ( const cryptonote::blobdata & tx)
virtual

called when a transaction is relayed

Definition at line 1342 of file cryptonote_core.cpp.

1343 {
1344 std::vector<std::pair<crypto::hash, cryptonote::blobdata>> txs;
1345 cryptonote::transaction tx;
1346 crypto::hash tx_hash;
1347 if (!parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash))
1348 {
1349 LOG_ERROR("Failed to parse relayed transaction");
1350 return;
1351 }
1352 txs.push_back(std::make_pair(tx_hash, std::move(tx_blob)));
1353 m_mempool.set_relayed(txs);
1354 }
bool parse_and_validate_tx_from_blob(const blobdata &tx_blob, transaction &tx)
Here is the call graph for this function:

◆ pad_transactions()

bool cryptonote::core::pad_transactions ( ) const
inline

get whether transaction relay should be padded

Returns
whether transaction relay should be padded

Definition at line 831 of file cryptonote_core.h.

831{ return m_pad_transactions; }

◆ pause_mine()

void cryptonote::core::pause_mine ( )

Note
see miner::pause

Definition at line 1396 of file cryptonote_core.cpp.

1397 {
1398 m_miner.pause();
1399 }

◆ pool_has_tx()

bool cryptonote::core::pool_has_tx ( const crypto::hash & txid) const

checks if the pool has a transaction with the given hash

Parameters
idthe hash to look for
Returns
true if the transaction is in the pool, otherwise false
Note
see tx_memory_pool::have_tx

Definition at line 1637 of file cryptonote_core.cpp.

1638 {
1639 return m_mempool.have_tx(id);
1640 }

◆ pool_has_utxo_as_spent()

bool cryptonote::core::pool_has_utxo_as_spent ( const txin_to_key_public & in) const

get a summary statistics of all transaction hashes in the pool

Parameters
ininput to check the pool spent status of
Note
see tx_memory_pool::utxo_spent_in_pool

Definition at line 1642 of file cryptonote_core.cpp.

1643 {
1644 return m_mempool.utxo_spent_in_pool(in);
1645 }

◆ prepare_handle_incoming_blocks()

bool cryptonote::core::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
Note
see Blockchain::prepare_handle_incoming_blocks

Definition at line 1493 of file cryptonote_core.cpp.

1494 {
1495 m_incoming_tx_lock.lock();
1496 if (!m_blockchain_storage.prepare_handle_incoming_blocks(blocks_entry, blocks))
1497 {
1499 return false;
1500 }
1501 return true;
1502 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_pool()

std::string cryptonote::core::print_pool ( bool short_format) const

get a string containing human-readable pool information

Parameters
short_formatwhether to use a shortened format for the info
Returns
the string
Note
see tx_memory_pool::print_pool

Definition at line 1677 of file cryptonote_core.cpp.

1678 {
1679 return m_mempool.print_pool(short_format);
1680 }

◆ prune_blockchain()

bool cryptonote::core::prune_blockchain ( uint32_t pruning_seed = 0)

prune the blockchain

Parameters
pruning_seedthe seed to use to prune the chain (0 for default, highly recommended)
Returns
true iff success

Definition at line 2033 of file cryptonote_core.cpp.

2034 {
2035 return get_blockchain_storage().prune_blockchain(pruning_seed);
2036 }
bool prune_blockchain(uint32_t pruning_seed=0)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resume_mine()

void cryptonote::core::resume_mine ( )

Note
see miner::resume

Definition at line 1401 of file cryptonote_core.cpp.

1402 {
1403 m_miner.resume();
1404 }

◆ safesyncmode()

void cryptonote::core::safesyncmode ( const bool onoff)

Put DB in safe sync mode.

2note see Blockchain::safesyncmode

Definition at line 1482 of file cryptonote_core.cpp.

1483 {
1484 m_blockchain_storage.safesyncmode(onoff);
1485 }

◆ set_block_cumulative_difficulty()

void cryptonote::core::set_block_cumulative_difficulty ( uint64_t height,
difficulty_type diff )

Note
see Blockchain::set_block_cumulative_difficulty

Definition at line 1584 of file cryptonote_core.cpp.

1585 {
1586 return m_blockchain_storage.get_db().set_block_cumulative_difficulty(height, diff);
1587 }

◆ set_checkpoints()

void cryptonote::core::set_checkpoints ( checkpoints && chk_pts)

assign a set of blockchain checkpoint hashes

Parameters
chk_ptsthe set of checkpoints to assign
Note
see Blockchain::set_checkpoints()

Definition at line 275 of file cryptonote_core.cpp.

276 {
277 m_blockchain_storage.set_checkpoints(std::move(chk_pts));
278 }

◆ set_checkpoints_file_path()

void cryptonote::core::set_checkpoints_file_path ( const std::string & path)

set the file path to read from when loading checkpoints

Parameters
paththe path to set ours as

Definition at line 280 of file cryptonote_core.cpp.

281 {
282 m_checkpoints_path = path;
283 }

◆ set_cryptonote_protocol()

void cryptonote::core::set_cryptonote_protocol ( i_cryptonote_protocol * pprotocol)

set the pointer to the cryptonote protocol object to use

Parameters
pprotocolthe pointer to set ours as

Definition at line 267 of file cryptonote_core.cpp.

268 {
269 if(pprotocol)
270 m_pprotocol = pprotocol;
271 else
272 m_pprotocol = &m_protocol_stub;
273 }
Here is the caller graph for this function:

◆ set_enforce_dns_checkpoints()

void cryptonote::core::set_enforce_dns_checkpoints ( bool enforce_dns)

set whether or not we enforce DNS checkpoints

Parameters
enforce_dnsenforce DNS checkpoints or not

Definition at line 285 of file cryptonote_core.cpp.

286 {
287 m_blockchain_storage.set_enforce_dns_checkpoints(enforce_dns);
288 }

◆ set_genesis_block()

bool cryptonote::core::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
Note
see Blockchain::reset_and_set_genesis_block

Definition at line 776 of file cryptonote_core.cpp.

777 {
778 return m_blockchain_storage.reset_and_set_genesis_block(b);
779 }
Here is the caller graph for this function:

◆ set_target_blockchain_height()

void cryptonote::core::set_target_blockchain_height ( uint64_t target_blockchain_height)

sets the target blockchain height

Parameters
target_blockchain_heightthe height to set

Definition at line 2011 of file cryptonote_core.cpp.

2012 {
2013 m_target_blockchain_height = target_blockchain_height;
2014 }

◆ set_validator_key()

bool cryptonote::core::set_validator_key ( std::string key)

set validator key

Parameters
keykey to set as new validator key
Returns
whether this new key was set or not

Definition at line 2043 of file cryptonote_core.cpp.

2043 {
2044 bool is_validator_key_valid = std::count_if(key.begin(), key.end(), [](int c) {return !std::isxdigit(c);}) == 0;
2045 if(!is_validator_key_valid || key.size() % 2 != 0) {
2046 return false;
2047 }
2048
2049 m_miner.pause();
2050 m_blockchain_storage.set_validator_key(key);
2051 m_miner.resume();
2052
2053 return true;
2054 }
const char * key

◆ set_validators_list()

electroneum::basic::list_update_outcome cryptonote::core::set_validators_list ( std::string v_list,
bool isEmergencyUpdate )

set the list of validators according to the serialized string passed in as parameter

Parameters
v_listserialized validators list string
Returns
true if successfull

Definition at line 323 of file cryptonote_core.cpp.

323 {
324 return m_validators->setValidatorsList(v_list, true, isEmergencyUpdate);
325 }

◆ sign_message()

std::string cryptonote::core::sign_message ( std::string sk,
std::string msg )

Definition at line 2061 of file cryptonote_core.cpp.

2061 {
2062 std::string b_str = crypto::sign_message(msg, sk);
2063 return boost::algorithm::hex(b_str);
2064 }
std::string sign_message(const std::string &message, const std::string &privateKey)
Definition crypto.h:376
Here is the call graph for this function:

◆ stop()

void cryptonote::core::stop ( )

stops the daemon running

Note
see graceful_exit()

Definition at line 331 of file cryptonote_core.cpp.

332 {
333 m_miner.stop();
334 m_blockchain_storage.cancel();
335
337 {
338 boost::lock_guard<boost::mutex> lock(m_update_mutex);
339 handle = m_update_download;
340 m_update_download = 0;
341 }
342 if (handle)
344 }
std::shared_ptr< download_thread_control > download_async_handle
Definition download.h:37
bool download_cancel(const download_async_handle &control)
Definition download.cpp:299
Here is the call graph for this function:

◆ test_drop_download()

void cryptonote::core::test_drop_download ( )

sets to drop blocks downloaded (for testing)

Definition at line 795 of file cryptonote_core.cpp.

796 {
797 m_test_drop_download = false;
798 }

◆ test_drop_download_height()

void cryptonote::core::test_drop_download_height ( uint64_t height)

sets to drop blocks downloaded below a certain height

Parameters
heightheight below which to drop blocks

Definition at line 800 of file cryptonote_core.cpp.

801 {
802 m_test_drop_download_height = height;
803 }

◆ update_blockchain_pruning()

bool cryptonote::core::update_blockchain_pruning ( )

incrementally prunes blockchain

Returns
true on success, false otherwise

Definition at line 2001 of file cryptonote_core.cpp.

2002 {
2003 return m_blockchain_storage.update_blockchain_pruning();
2004 }
Here is the caller graph for this function:

◆ update_checkpoints()

bool cryptonote::core::update_checkpoints ( )

tells the Blockchain to update its checkpoints

This function will check if enough time has passed since the last time checkpoints were updated and tell the Blockchain to update its checkpoints if it is time. If updating checkpoints fails, the daemon is told to shut down.

Note
see Blockchain::update_checkpoints()

Definition at line 290 of file cryptonote_core.cpp.

291 {
292 if (m_nettype != MAINNET || m_disable_dns_checkpoints) return true;
293
294 if (m_checkpoints_updating.test_and_set()) return true;
295
296 bool res = true;
297 if (time(NULL) - m_last_dns_checkpoints_update >= 3600)
298 {
299 res = m_blockchain_storage.update_checkpoints(m_checkpoints_path, true);
300 m_last_dns_checkpoints_update = time(NULL);
301 m_last_json_checkpoints_update = time(NULL);
302 }
303 else if (time(NULL) - m_last_json_checkpoints_update >= 600)
304 {
305 res = m_blockchain_storage.update_checkpoints(m_checkpoints_path, false);
306 m_last_json_checkpoints_update = time(NULL);
307 }
308
309 m_checkpoints_updating.clear();
310
311 // if anything fishy happened getting new checkpoints, bring down the house
312 if (!res)
313 {
315 }
316 return res;
317 }
time_t time
void graceful_exit()
tells the daemon to wind down operations and stop running
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utxo_nonexistant()

bool cryptonote::core::utxo_nonexistant ( const std::vector< txin_to_key_public > & public_outputs,
std::vector< bool > & spent ) const

check if multiple public outputs are found in the utxo database or not

plural version of is_public_output_spent()

Parameters
key_imlist of public outputs to check
spentreturn-by-reference result for each public output checked
Returns
true

Definition at line 1184 of file cryptonote_core.cpp.

1185 {
1186 spent.clear();
1187 for(auto& po: public_outputs)
1188 {
1189 spent.push_back(m_blockchain_storage.utxo_nonexistence_from_output(po));
1190 }
1191 return true;
1192 }

The documentation for this class was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/cryptonote_core/cryptonote_core.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/cryptonote_core/cryptonote_core.cpp