diff --git a/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp b/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp index 3c7b1a44..731964dc 100644 --- a/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp +++ b/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp @@ -109,6 +109,7 @@ void BlockchainLMDB::add_block( const block& blk , const uint64_t& coins_generated ) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); crypto::hash h = get_block_hash(blk); @@ -217,6 +218,7 @@ void BlockchainLMDB::add_block( const block& blk void BlockchainLMDB::remove_block() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); MDB_val k; @@ -270,6 +272,7 @@ void BlockchainLMDB::remove_block() void BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const transaction& tx) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); crypto::hash h = get_transaction_hash(tx); @@ -320,6 +323,7 @@ void BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const tr void BlockchainLMDB::remove_transaction_data(const crypto::hash& tx_hash) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); crypto::hash h = tx_hash; @@ -359,6 +363,7 @@ void BlockchainLMDB::remove_transaction_data(const crypto::hash& tx_hash) void BlockchainLMDB::add_output(const crypto::hash& tx_hash, const tx_out& tx_output, const uint64_t& local_index) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); MDB_val k; @@ -417,6 +422,7 @@ void BlockchainLMDB::add_output(const crypto::hash& tx_hash, const tx_out& tx_ou void BlockchainLMDB::remove_output(const tx_out& tx_output) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); MDB_val k; @@ -474,6 +480,7 @@ void BlockchainLMDB::remove_output(const tx_out& tx_output) void BlockchainLMDB::add_spent_key(const crypto::key_image& k_image) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); crypto::key_image key = k_image; @@ -500,6 +507,7 @@ void BlockchainLMDB::add_spent_key(const crypto::key_image& k_image) void BlockchainLMDB::remove_spent_key(const crypto::key_image& k_image) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); crypto::key_image key_cpy = k_image; @@ -516,6 +524,7 @@ void BlockchainLMDB::remove_spent_key(const crypto::key_image& k_image) blobdata BlockchainLMDB::output_to_blob(const tx_out& output) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); blobdata b; if (!t_serializable_object_to_blob(output, b)) { @@ -527,6 +536,7 @@ blobdata BlockchainLMDB::output_to_blob(const tx_out& output) tx_out BlockchainLMDB::output_from_blob(const blobdata& blob) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); std::stringstream ss; ss << blob; binary_archive ba(ss); @@ -543,11 +553,13 @@ tx_out BlockchainLMDB::output_from_blob(const blobdata& blob) uint64_t BlockchainLMDB::get_output_global_index(const uint64_t& amount, const uint64_t& index) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); return 0; } void BlockchainLMDB::check_open() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); if (!m_open) { LOG_PRINT_L0("DB operation attempted on a not-open DB instance"); @@ -557,18 +569,22 @@ void BlockchainLMDB::check_open() BlockchainLMDB::~BlockchainLMDB() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); } BlockchainLMDB::BlockchainLMDB() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); // initialize folder to something "safe" just in case // someone accidentally misuses this class... m_folder = "thishsouldnotexistbecauseitisgibberish"; m_open = false; + m_height = 0; } void BlockchainLMDB::open(const std::string& filename) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); if (m_open) { @@ -652,6 +668,7 @@ void BlockchainLMDB::open(const std::string& filename) LOG_PRINT_L0("Failed to query m_blocks"); throw DB_ERROR("Failed to query m_blocks"); } + LOG_PRINT_L2("Setting m_height to: " << db_stats.ms_entries); m_height = db_stats.ms_entries; // get and keep current number of outputs @@ -672,27 +689,32 @@ void BlockchainLMDB::open(const std::string& filename) // unused for now, create will happen on open if doesn't exist void BlockchainLMDB::create(const std::string& filename) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); throw DB_CREATE_FAILURE("create() is not implemented for this BlockchainDB, open() will create files if needed."); } void BlockchainLMDB::close() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); // FIXME: not yet thread safe!!! Use with care. mdb_env_close(m_env); } void BlockchainLMDB::sync() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); // LMDB documentation leads me to believe this is unnecessary } void BlockchainLMDB::reset() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); // TODO: this } std::vector BlockchainLMDB::get_filenames() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); std::vector filenames; boost::filesystem::path datafile(m_folder); @@ -709,6 +731,7 @@ std::vector BlockchainLMDB::get_filenames() // TODO: this? bool BlockchainLMDB::lock() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); return false; } @@ -716,12 +739,14 @@ bool BlockchainLMDB::lock() // TODO: this? void BlockchainLMDB::unlock() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); } bool BlockchainLMDB::block_exists(const crypto::hash& h) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; @@ -756,6 +781,7 @@ bool BlockchainLMDB::block_exists(const crypto::hash& h) block BlockchainLMDB::get_block(const crypto::hash& h) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); return get_block_from_height(get_block_height(h)); @@ -763,6 +789,7 @@ block BlockchainLMDB::get_block(const crypto::hash& h) uint64_t BlockchainLMDB::get_block_height(const crypto::hash& h) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; @@ -796,6 +823,7 @@ uint64_t BlockchainLMDB::get_block_height(const crypto::hash& h) block_header BlockchainLMDB::get_block_header(const crypto::hash& h) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); // block_header object is automatically cast from block object @@ -804,6 +832,7 @@ block_header BlockchainLMDB::get_block_header(const crypto::hash& h) block BlockchainLMDB::get_block_from_height(const uint64_t& height) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; @@ -847,6 +876,7 @@ block BlockchainLMDB::get_block_from_height(const uint64_t& height) uint64_t BlockchainLMDB::get_block_timestamp(const uint64_t& height) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; @@ -879,6 +909,7 @@ uint64_t BlockchainLMDB::get_block_timestamp(const uint64_t& height) uint64_t BlockchainLMDB::get_top_block_timestamp() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); // if no blocks, return 0 @@ -892,6 +923,7 @@ uint64_t BlockchainLMDB::get_top_block_timestamp() size_t BlockchainLMDB::get_block_size(const uint64_t& height) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; @@ -924,6 +956,7 @@ size_t BlockchainLMDB::get_block_size(const uint64_t& height) difficulty_type BlockchainLMDB::get_block_cumulative_difficulty(const uint64_t& height) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; @@ -956,6 +989,7 @@ difficulty_type BlockchainLMDB::get_block_cumulative_difficulty(const uint64_t& difficulty_type BlockchainLMDB::get_block_difficulty(const uint64_t& height) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); difficulty_type diff1 = 0; @@ -972,6 +1006,7 @@ difficulty_type BlockchainLMDB::get_block_difficulty(const uint64_t& height) uint64_t BlockchainLMDB::get_block_already_generated_coins(const uint64_t& height) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; @@ -1004,6 +1039,7 @@ uint64_t BlockchainLMDB::get_block_already_generated_coins(const uint64_t& heigh crypto::hash BlockchainLMDB::get_block_hash_from_height(const uint64_t& height) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; @@ -1036,6 +1072,7 @@ crypto::hash BlockchainLMDB::get_block_hash_from_height(const uint64_t& height) std::vector BlockchainLMDB::get_blocks_range(const uint64_t& h1, const uint64_t& h2) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); std::vector v; @@ -1049,6 +1086,7 @@ std::vector BlockchainLMDB::get_blocks_range(const uint64_t& h1, const ui std::vector BlockchainLMDB::get_hashes_range(const uint64_t& h1, const uint64_t& h2) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); std::vector v; @@ -1062,6 +1100,7 @@ std::vector BlockchainLMDB::get_hashes_range(const uint64_t& h1, c crypto::hash BlockchainLMDB::top_block_hash() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); if (m_height != 0) { @@ -1073,6 +1112,7 @@ crypto::hash BlockchainLMDB::top_block_hash() block BlockchainLMDB::get_top_block() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); if (m_height != 0) @@ -1086,6 +1126,7 @@ block BlockchainLMDB::get_top_block() uint64_t BlockchainLMDB::height() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); return m_height; @@ -1094,6 +1135,7 @@ uint64_t BlockchainLMDB::height() bool BlockchainLMDB::tx_exists(const crypto::hash& h) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; @@ -1127,6 +1169,7 @@ bool BlockchainLMDB::tx_exists(const crypto::hash& h) uint64_t BlockchainLMDB::get_tx_unlock_time(const crypto::hash& h) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; @@ -1159,6 +1202,7 @@ uint64_t BlockchainLMDB::get_tx_unlock_time(const crypto::hash& h) transaction BlockchainLMDB::get_tx(const crypto::hash& h) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; @@ -1201,6 +1245,7 @@ transaction BlockchainLMDB::get_tx(const crypto::hash& h) uint64_t BlockchainLMDB::get_tx_count() { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; @@ -1224,6 +1269,7 @@ uint64_t BlockchainLMDB::get_tx_count() std::vector BlockchainLMDB::get_tx_list(const std::vector& hlist) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); std::vector v; @@ -1237,6 +1283,7 @@ std::vector BlockchainLMDB::get_tx_list(const std::vector BlockchainLMDB::get_tx_output_indices(const crypto::hash& h) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); std::vector index_vec; @@ -1574,6 +1628,7 @@ std::vector BlockchainLMDB::get_tx_output_indices(const crypto::hash& bool BlockchainLMDB::has_key_image(const crypto::key_image& img) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; @@ -1606,6 +1661,7 @@ uint64_t BlockchainLMDB::add_block( const block& blk , const std::vector& txs ) { + LOG_PRINT_L2("BlockchainLMDB::" << __func__); check_open(); txn_safe txn; if (mdb_txn_begin(m_env, NULL, 0, txn)) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 25d1ae33..5e1e5327 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -66,12 +66,14 @@ DISABLE_VS_WARNINGS(4267) // TODO: initialize m_db with a concrete implementation of BlockchainDB Blockchain::Blockchain(tx_memory_pool& tx_pool):m_db(), m_tx_pool(tx_pool), m_current_block_cumul_sz_limit(0), m_is_in_checkpoint_zone(false), m_is_blockchain_storing(false) { + LOG_PRINT_L2("Blockchain::" << __func__); } //------------------------------------------------------------------ //TODO: is this still needed? I don't think so - tewinget template void Blockchain::serialize(archive_t & ar, const unsigned int version) { + LOG_PRINT_L2("Blockchain::" << __func__); if(version < 11) return; CRITICAL_REGION_LOCAL(m_blockchain_lock); @@ -127,12 +129,14 @@ void Blockchain::serialize(archive_t & ar, const unsigned int version) //------------------------------------------------------------------ bool Blockchain::have_tx(const crypto::hash &id) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); return m_db->tx_exists(id); } //------------------------------------------------------------------ bool Blockchain::have_tx_keyimg_as_spent(const crypto::key_image &key_im) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); return m_db->has_key_image(key_im); } @@ -143,6 +147,7 @@ bool Blockchain::have_tx_keyimg_as_spent(const crypto::key_image &key_im) template bool Blockchain::scan_outputkeys_for_indexes(const txin_to_key& tx_in_to_key, visitor_t& vis, uint64_t* pmax_related_block_height) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); // verify that the input has key offsets (that it exists properly, really) @@ -212,6 +217,7 @@ bool Blockchain::scan_outputkeys_for_indexes(const txin_to_key& tx_in_to_key, vi //------------------------------------------------------------------ uint64_t Blockchain::get_current_blockchain_height() { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); return m_db->height(); } @@ -220,6 +226,7 @@ uint64_t Blockchain::get_current_blockchain_height() // dereferencing a null BlockchainDB pointer bool Blockchain::init(const std::string& config_folder, bool testnet) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); m_db = new BlockchainLMDB(); @@ -298,6 +305,7 @@ bool Blockchain::init(const std::string& config_folder, bool testnet) //------------------------------------------------------------------ bool Blockchain::store_blockchain() { + LOG_PRINT_L2("Blockchain::" << __func__); // TODO: make sure if this throws that it is not simply ignored higher // up the call stack try @@ -320,6 +328,7 @@ bool Blockchain::store_blockchain() //------------------------------------------------------------------ bool Blockchain::deinit() { + LOG_PRINT_L2("Blockchain::" << __func__); // as this should be called if handling a SIGSEGV, need to check // if m_db is a NULL pointer (and thus may have caused the illegal // memory operation), otherwise we may cause a loop. @@ -350,6 +359,7 @@ bool Blockchain::deinit() // from it to the tx_pool block Blockchain::pop_block_from_blockchain() { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); block popped_block; @@ -391,6 +401,7 @@ block Blockchain::pop_block_from_blockchain() //------------------------------------------------------------------ bool Blockchain::reset_and_set_genesis_block(const block& b) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); m_transactions.clear(); m_spent_keys.clear(); @@ -408,6 +419,7 @@ bool Blockchain::reset_and_set_genesis_block(const block& b) //TODO: move to BlockchainDB subclass bool Blockchain::purge_transaction_keyimages_from_blockchain(const transaction& tx, bool strict_check) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); struct purge_transaction_visitor: public boost::static_visitor { @@ -453,6 +465,7 @@ bool Blockchain::purge_transaction_keyimages_from_blockchain(const transaction& //------------------------------------------------------------------ crypto::hash Blockchain::get_tail_id(uint64_t& height) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); height = m_db->height(); return get_tail_id(); @@ -460,6 +473,7 @@ crypto::hash Blockchain::get_tail_id(uint64_t& height) //------------------------------------------------------------------ crypto::hash Blockchain::get_tail_id() { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); return m_db->top_block_hash(); } @@ -478,16 +492,17 @@ crypto::hash Blockchain::get_tail_id() */ bool Blockchain::get_short_chain_history(std::list& ids) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); uint64_t i = 0; uint64_t current_multiplier = 1; - uint64_t sz = m_db->height(); + uint64_t sz = m_db->height() - 1; if(!sz) return true; uint64_t current_back_offset = 0; - while(current_back_offset < sz) + while(current_back_offset <= sz) { ids.push_back(m_db->get_block_hash_from_height(sz-current_back_offset)); if(i < 10) @@ -507,6 +522,7 @@ bool Blockchain::get_short_chain_history(std::list& ids) //------------------------------------------------------------------ crypto::hash Blockchain::get_block_id_by_height(uint64_t height) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); try { @@ -530,6 +546,7 @@ crypto::hash Blockchain::get_block_id_by_height(uint64_t height) //------------------------------------------------------------------ bool Blockchain::get_block_by_hash(const crypto::hash &h, block &blk) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); // try to find block in main chain @@ -565,6 +582,7 @@ bool Blockchain::get_block_by_hash(const crypto::hash &h, block &blk) // if it ever is, should probably change std::list for std::vector void Blockchain::get_all_known_block_ids(std::list &main, std::list &alt, std::list &invalid) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); for (auto& a : m_db->get_hashes_range(0, m_db->height())) @@ -585,6 +603,7 @@ void Blockchain::get_all_known_block_ids(std::list &main, std::lis // less blocks than desired if there aren't enough. difficulty_type Blockchain::get_difficulty_for_next_block() { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); std::vector timestamps; std::vector cumulative_difficulties; @@ -598,7 +617,7 @@ difficulty_type Blockchain::get_difficulty_for_next_block() // makes sure we don't use the genesis block. ++offset; - for(; offset <= h; offset++) + for(; offset < h; offset++) { timestamps.push_back(m_db->get_block_timestamp(offset)); cumulative_difficulties.push_back(m_db->get_block_cumulative_difficulty(offset)); @@ -611,6 +630,7 @@ difficulty_type Blockchain::get_difficulty_for_next_block() // that had been removed. bool Blockchain::rollback_blockchain_switching(std::list& original_chain, uint64_t rollback_height) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); // remove blocks from blockchain until we get back to where we should be. @@ -639,6 +659,7 @@ bool Blockchain::rollback_blockchain_switching(std::list& original_chain, // boolean based on success therein. bool Blockchain::switch_to_alternative_blockchain(std::list& alt_chain, bool discard_disconnected_chain) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); // if empty alt chain passed (not sure how that could happen), return false @@ -729,6 +750,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list& alt_chain, block_extended_info& bei) { + LOG_PRINT_L2("Blockchain::" << __func__); std::vector timestamps; std::vector cumulative_difficulties; @@ -797,6 +819,7 @@ difficulty_type Blockchain::get_next_difficulty_for_alternative_chain(const std: // a non-overflowing tx amount (dubious necessity on this check) bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height) { + LOG_PRINT_L2("Blockchain::" << __func__); CHECK_AND_ASSERT_MES(b.miner_tx.vin.size() == 1, false, "coinbase transaction in the block has no inputs"); CHECK_AND_ASSERT_MES(b.miner_tx.vin[0].type() == typeid(txin_gen), false, "coinbase transaction in the block has the wrong type"); if(boost::get(b.miner_tx.vin[0]).height != height) @@ -824,6 +847,7 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height) // This function validates the miner transaction reward bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_block_size, uint64_t fee, uint64_t& base_reward, uint64_t already_generated_coins) { + LOG_PRINT_L2("Blockchain::" << __func__); //validate reward uint64_t money_in_use = 0; BOOST_FOREACH(auto& o, b.miner_tx.vout) @@ -853,6 +877,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl // and return by reference . void Blockchain::get_last_n_blocks_sizes(std::vector& sz, size_t count) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); auto h = m_db->height(); @@ -870,6 +895,7 @@ void Blockchain::get_last_n_blocks_sizes(std::vector& sz, size_t count) //------------------------------------------------------------------ uint64_t Blockchain::get_current_cumulative_blocksize_limit() { + LOG_PRINT_L2("Blockchain::" << __func__); return m_current_block_cumul_sz_limit; } //------------------------------------------------------------------ @@ -886,6 +912,7 @@ uint64_t Blockchain::get_current_cumulative_blocksize_limit() // necessary at all. bool Blockchain::create_block_template(block& b, const account_public_address& miner_address, difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce) { + LOG_PRINT_L2("Blockchain::" << __func__); size_t median_size; uint64_t already_generated_coins; @@ -1009,6 +1036,7 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m // the needed number of timestamps for the BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW. bool Blockchain::complete_timestamps_vector(uint64_t start_top_height, std::vector& timestamps) { + LOG_PRINT_L2("Blockchain::" << __func__); if(timestamps.size() >= BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW) return true; @@ -1033,6 +1061,7 @@ bool Blockchain::complete_timestamps_vector(uint64_t start_top_height, std::vect // a long forked chain eventually. bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id, block_verification_context& bvc) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); uint64_t block_height = get_block_height(b); @@ -1212,6 +1241,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id //------------------------------------------------------------------ bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list& blocks, std::list& txs) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); if(start_offset > m_db->height()) return false; @@ -1233,6 +1263,7 @@ bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list& blocks) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); if(start_offset > m_db->height()) return false; @@ -1249,6 +1280,7 @@ bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list blocks; @@ -1282,6 +1314,7 @@ bool Blockchain::handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NO //------------------------------------------------------------------ bool Blockchain::get_alternative_blocks(std::list& blocks) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); BOOST_FOREACH(const auto& alt_bl, m_alternative_chains) @@ -1293,6 +1326,7 @@ bool Blockchain::get_alternative_blocks(std::list& blocks) //------------------------------------------------------------------ size_t Blockchain::get_alternative_blocks_count() { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); return m_alternative_chains.size(); } @@ -1301,6 +1335,7 @@ size_t Blockchain::get_alternative_blocks_count() // unlocked and other such checks should be done by here. void Blockchain::add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& result_outs, uint64_t amount, size_t i) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry& oen = *result_outs.outs.insert(result_outs.outs.end(), COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry()); @@ -1314,6 +1349,7 @@ void Blockchain::add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_A // in some cases bool Blockchain::get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res) { + LOG_PRINT_L2("Blockchain::" << __func__); srand(static_cast(time(NULL))); CRITICAL_REGION_LOCAL(m_blockchain_lock); @@ -1386,6 +1422,7 @@ bool Blockchain::get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDOM_OUTPUT // This is used to see what to send another node that needs to sync. bool Blockchain::find_blockchain_supplement(const std::list& qblock_ids, uint64_t& starter_offset) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); // make sure the request includes at least the genesis block, otherwise @@ -1451,6 +1488,7 @@ bool Blockchain::find_blockchain_supplement(const std::list& qbloc //------------------------------------------------------------------ uint64_t Blockchain::block_difficulty(uint64_t i) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); try { @@ -1466,6 +1504,7 @@ uint64_t Blockchain::block_difficulty(uint64_t i) template bool Blockchain::get_blocks(const t_ids_container& block_ids, t_blocks_container& blocks, t_missed_container& missed_bs) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); for (const auto& block_hash : block_ids) @@ -1489,6 +1528,7 @@ bool Blockchain::get_blocks(const t_ids_container& block_ids, t_blocks_container template bool Blockchain::get_transactions(const t_ids_container& txs_ids, t_tx_container& txs, t_missed_container& missed_txs) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); for (const auto& tx_hash : txs_ids) @@ -1512,6 +1552,7 @@ bool Blockchain::get_transactions(const t_ids_container& txs_ids, t_tx_container //------------------------------------------------------------------ void Blockchain::print_blockchain(uint64_t start_index, uint64_t end_index) { + LOG_PRINT_L2("Blockchain::" << __func__); std::stringstream ss; CRITICAL_REGION_LOCAL(m_blockchain_lock); auto h = m_db->height(); @@ -1539,6 +1580,7 @@ void Blockchain::print_blockchain(uint64_t start_index, uint64_t end_index) //------------------------------------------------------------------ void Blockchain::print_blockchain_index() { + LOG_PRINT_L2("Blockchain::" << __func__); std::stringstream ss; CRITICAL_REGION_LOCAL(m_blockchain_lock); auto height = m_db->height(); @@ -1558,6 +1600,7 @@ void Blockchain::print_blockchain_index() //TODO: remove this function and references to it void Blockchain::print_blockchain_outs(const std::string& file) { + LOG_PRINT_L2("Blockchain::" << __func__); return; } //------------------------------------------------------------------ @@ -1566,6 +1609,7 @@ void Blockchain::print_blockchain_outs(const std::string& file) // BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT additional (more recent) hashes. bool Blockchain::find_blockchain_supplement(const std::list& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); // if we can't find the split point, return false @@ -1589,6 +1633,7 @@ bool Blockchain::find_blockchain_supplement(const std::list& qbloc // blocks by reference. bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, const std::list& qblock_ids, std::list > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); // if a specific start height has been requested @@ -1624,6 +1669,7 @@ bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, cons //------------------------------------------------------------------ bool Blockchain::add_block_as_invalid(const block& bl, const crypto::hash& h) { + LOG_PRINT_L2("Blockchain::" << __func__); block_extended_info bei = AUTO_VAL_INIT(bei); bei.bl = bl; return add_block_as_invalid(bei, h); @@ -1631,6 +1677,7 @@ bool Blockchain::add_block_as_invalid(const block& bl, const crypto::hash& h) //------------------------------------------------------------------ bool Blockchain::add_block_as_invalid(const block_extended_info& bei, const crypto::hash& h) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); auto i_res = m_invalid_blocks.insert(std::map::value_type(h, bei)); CHECK_AND_ASSERT_MES(i_res.second, false, "at insertion invalid by tx returned status existed"); @@ -1640,6 +1687,7 @@ bool Blockchain::add_block_as_invalid(const block_extended_info& bei, const cryp //------------------------------------------------------------------ bool Blockchain::have_block(const crypto::hash& id) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); if(m_db->block_exists(id)) @@ -1656,12 +1704,14 @@ bool Blockchain::have_block(const crypto::hash& id) //------------------------------------------------------------------ bool Blockchain::handle_block_to_main_chain(const block& bl, block_verification_context& bvc) { + LOG_PRINT_L2("Blockchain::" << __func__); crypto::hash id = get_block_hash(bl); return handle_block_to_main_chain(bl, id, bvc); } //------------------------------------------------------------------ size_t Blockchain::get_total_transactions() { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); return m_db->get_tx_count(); } @@ -1674,6 +1724,7 @@ size_t Blockchain::get_total_transactions() // remove them later if the block fails validation. bool Blockchain::check_for_double_spend(const transaction& tx, key_images_container& keys_this_block) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); struct add_transaction_input_visitor: public boost::static_visitor { @@ -1722,6 +1773,7 @@ bool Blockchain::check_for_double_spend(const transaction& tx, key_images_contai //------------------------------------------------------------------ bool Blockchain::get_tx_outputs_gindexs(const crypto::hash& tx_id, std::vector& indexs) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); if (!m_db->tx_exists(tx_id)) { @@ -1738,6 +1790,7 @@ bool Blockchain::get_tx_outputs_gindexs(const crypto::hash& tx_id, std::vector& sig, uint64_t* pmax_related_block_height) { + LOG_PRINT_L2("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); struct outputs_visitor @@ -1874,6 +1931,7 @@ bool Blockchain::check_tx_input(const txin_to_key& txin, const crypto::hash& tx_ //TODO: Is this intended to do something else? Need to look into the todo there. uint64_t Blockchain::get_adjusted_time() { + LOG_PRINT_L2("Blockchain::" << __func__); //TODO: add collecting median time return time(NULL); } @@ -1881,6 +1939,7 @@ uint64_t Blockchain::get_adjusted_time() //TODO: revisit, has changed a bit on upstream bool Blockchain::check_block_timestamp(std::vector& timestamps, const block& b) { + LOG_PRINT_L2("Blockchain::" << __func__); uint64_t median_ts = epee::misc_utils::median(timestamps); if(b.timestamp < median_ts) @@ -1901,6 +1960,7 @@ bool Blockchain::check_block_timestamp(std::vector& timestamps, const // false otherwise bool Blockchain::check_block_timestamp(const block& b) { + LOG_PRINT_L2("Blockchain::" << __func__); if(b.timestamp > get_adjusted_time() + CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT) { LOG_PRINT_L0("Timestamp of block with id: " << get_block_hash(b) << ", " << b.timestamp << ", bigger than adjusted time + 2 hours"); @@ -1933,6 +1993,7 @@ bool Blockchain::check_block_timestamp(const block& b) // m_db->add_block() bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash& id, block_verification_context& bvc) { + LOG_PRINT_L2("Blockchain::" << __func__); // if we already have the block, return false if (have_block(id)) { @@ -2027,9 +2088,6 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash& std::vector txs; key_images_container keys; - // add miner transaction to list of block's transactions. - txs.push_back(bl.miner_tx); - uint64_t fee_summary = 0; // Iterate over the block's transaction hashes, grabbing each @@ -2155,6 +2213,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash& //------------------------------------------------------------------ bool Blockchain::update_next_cumulative_size_limit() { + LOG_PRINT_L2("Blockchain::" << __func__); std::vector sz; get_last_n_blocks_sizes(sz, CRYPTONOTE_REWARD_BLOCKS_WINDOW); @@ -2168,6 +2227,7 @@ bool Blockchain::update_next_cumulative_size_limit() //------------------------------------------------------------------ bool Blockchain::add_new_block(const block& bl_, block_verification_context& bvc) { + LOG_PRINT_L2("Blockchain::" << __func__); //copy block here to let modify block.target block bl = bl_; crypto::hash id = get_block_hash(bl);