mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 10:37:37 -07:00
Minor bug fixes and debug prints
Blockchain and BlockchainLMDB classes now have a debug print at the beginning of each function at log level 2. These can be removed at any time, but for now are quite useful. Blockchain runs, and adds the genesis block just fine, but for some reason isn't getting new blocks.
This commit is contained in:
parent
90f402e258
commit
006afe2172
@ -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<false> 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<std::string> BlockchainLMDB::get_filenames()
|
||||
{
|
||||
LOG_PRINT_L2("BlockchainLMDB::" << __func__);
|
||||
std::vector<std::string> filenames;
|
||||
|
||||
boost::filesystem::path datafile(m_folder);
|
||||
@ -709,6 +731,7 @@ std::vector<std::string> 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<block> BlockchainLMDB::get_blocks_range(const uint64_t& h1, const uint64_t& h2)
|
||||
{
|
||||
LOG_PRINT_L2("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
std::vector<block> v;
|
||||
|
||||
@ -1049,6 +1086,7 @@ std::vector<block> BlockchainLMDB::get_blocks_range(const uint64_t& h1, const ui
|
||||
|
||||
std::vector<crypto::hash> BlockchainLMDB::get_hashes_range(const uint64_t& h1, const uint64_t& h2)
|
||||
{
|
||||
LOG_PRINT_L2("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
std::vector<crypto::hash> v;
|
||||
|
||||
@ -1062,6 +1100,7 @@ std::vector<crypto::hash> 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<transaction> BlockchainLMDB::get_tx_list(const std::vector<crypto::hash>& hlist)
|
||||
{
|
||||
LOG_PRINT_L2("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
std::vector<transaction> v;
|
||||
|
||||
@ -1237,6 +1283,7 @@ std::vector<transaction> BlockchainLMDB::get_tx_list(const std::vector<crypto::h
|
||||
|
||||
uint64_t BlockchainLMDB::get_tx_block_height(const crypto::hash& h)
|
||||
{
|
||||
LOG_PRINT_L2("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
|
||||
txn_safe txn;
|
||||
@ -1270,6 +1317,7 @@ uint64_t BlockchainLMDB::get_tx_block_height(const crypto::hash& h)
|
||||
//FIXME: make sure the random method used here is appropriate
|
||||
uint64_t BlockchainLMDB::get_random_output(const uint64_t& amount)
|
||||
{
|
||||
LOG_PRINT_L2("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
|
||||
uint64_t num_outputs = get_num_outputs(amount);
|
||||
@ -1284,6 +1332,7 @@ uint64_t BlockchainLMDB::get_random_output(const uint64_t& amount)
|
||||
|
||||
uint64_t BlockchainLMDB::get_num_outputs(const uint64_t& amount)
|
||||
{
|
||||
LOG_PRINT_L2("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
|
||||
txn_safe txn;
|
||||
@ -1322,6 +1371,7 @@ uint64_t BlockchainLMDB::get_num_outputs(const uint64_t& amount)
|
||||
|
||||
crypto::public_key BlockchainLMDB::get_output_key(const uint64_t& amount, const uint64_t& index)
|
||||
{
|
||||
LOG_PRINT_L2("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
|
||||
uint64_t global = get_output_global_index(amount, index);
|
||||
@ -1339,6 +1389,7 @@ crypto::public_key BlockchainLMDB::get_output_key(const uint64_t& amount, const
|
||||
|
||||
tx_out BlockchainLMDB::get_output(const crypto::hash& h, const uint64_t& index)
|
||||
{
|
||||
LOG_PRINT_L2("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
|
||||
txn_safe txn;
|
||||
@ -1400,6 +1451,7 @@ tx_out BlockchainLMDB::get_output(const crypto::hash& h, const uint64_t& index)
|
||||
|
||||
tx_out BlockchainLMDB::get_output(const uint64_t& index)
|
||||
{
|
||||
LOG_PRINT_L2("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
|
||||
txn_safe txn;
|
||||
@ -1434,6 +1486,7 @@ tx_out BlockchainLMDB::get_output(const uint64_t& index)
|
||||
|
||||
tx_out_index BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, const uint64_t& index)
|
||||
{
|
||||
LOG_PRINT_L2("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
|
||||
txn_safe txn;
|
||||
@ -1523,6 +1576,7 @@ tx_out_index BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, con
|
||||
|
||||
std::vector<uint64_t> BlockchainLMDB::get_tx_output_indices(const crypto::hash& h)
|
||||
{
|
||||
LOG_PRINT_L2("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
std::vector<uint64_t> index_vec;
|
||||
|
||||
@ -1574,6 +1628,7 @@ std::vector<uint64_t> 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<transaction>& txs
|
||||
)
|
||||
{
|
||||
LOG_PRINT_L2("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
txn_safe txn;
|
||||
if (mdb_txn_begin(m_env, NULL, 0, txn))
|
||||
|
@ -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<class archive_t>
|
||||
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<class visitor_t>
|
||||
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<bool>
|
||||
{
|
||||
@ -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<crypto::hash>& 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<crypto::hash>& 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<crypto::hash> &main, std::list<crypto::hash> &alt, std::list<crypto::hash> &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<crypto::hash> &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<uint64_t> timestamps;
|
||||
std::vector<difficulty_type> 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<block>& 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<block>& original_chain,
|
||||
// boolean based on success therein.
|
||||
bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::iterator>& 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<blocks_ext_by_hash::
|
||||
// an alternate chain.
|
||||
difficulty_type Blockchain::get_next_difficulty_for_alternative_chain(const std::list<blocks_ext_by_hash::iterator>& alt_chain, block_extended_info& bei)
|
||||
{
|
||||
LOG_PRINT_L2("Blockchain::" << __func__);
|
||||
std::vector<uint64_t> timestamps;
|
||||
std::vector<difficulty_type> 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<txin_gen>(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 <sz>.
|
||||
void Blockchain::get_last_n_blocks_sizes(std::vector<size_t>& 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<size_t>& 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<uint64_t>& 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<block>& blocks, std::list<transaction>& 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<block
|
||||
//------------------------------------------------------------------
|
||||
bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list<block>& 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<block
|
||||
// but it warrants some looking into later.
|
||||
bool Blockchain::handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NOTIFY_RESPONSE_GET_OBJECTS::request& rsp)
|
||||
{
|
||||
LOG_PRINT_L2("Blockchain::" << __func__);
|
||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
rsp.current_blockchain_height = get_current_blockchain_height();
|
||||
std::list<block> blocks;
|
||||
@ -1282,6 +1314,7 @@ bool Blockchain::handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NO
|
||||
//------------------------------------------------------------------
|
||||
bool Blockchain::get_alternative_blocks(std::list<block>& 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<block>& 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<unsigned int>(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<crypto::hash>& 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<crypto::hash>& 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<class t_ids_container, class t_blocks_container, class t_missed_container>
|
||||
bool Blockchain::get_blocks(const t_ids_container& block_ids, t_blocks_container& blocks, t_missed_container& missed_bs)
|
||||
{
|
||||
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<class t_ids_container, class t_tx_container, class t_missed_container>
|
||||
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<crypto::hash>& 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<crypto::hash>& qbloc
|
||||
// blocks by reference.
|
||||
bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& 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<crypto::hash, block_extended_info>::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<bool>
|
||||
{
|
||||
@ -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<uint64_t>& 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<u
|
||||
// as a return-by-reference.
|
||||
bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t& max_used_block_height, crypto::hash& max_used_block_id)
|
||||
{
|
||||
LOG_PRINT_L2("Blockchain::" << __func__);
|
||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
bool res = check_tx_inputs(tx, &max_used_block_height);
|
||||
if(!res) return false;
|
||||
@ -1748,6 +1801,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t& max_used_block
|
||||
//------------------------------------------------------------------
|
||||
bool Blockchain::have_tx_keyimges_as_spent(const transaction &tx)
|
||||
{
|
||||
LOG_PRINT_L2("Blockchain::" << __func__);
|
||||
BOOST_FOREACH(const txin_v& in, tx.vin)
|
||||
{
|
||||
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, in_to_key, true);
|
||||
@ -1762,6 +1816,7 @@ bool Blockchain::have_tx_keyimges_as_spent(const transaction &tx)
|
||||
// own function.
|
||||
bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t* pmax_used_block_height)
|
||||
{
|
||||
LOG_PRINT_L2("Blockchain::" << __func__);
|
||||
size_t sig_index = 0;
|
||||
if(pmax_used_block_height)
|
||||
*pmax_used_block_height = 0;
|
||||
@ -1799,6 +1854,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t* pmax_used_bloc
|
||||
// a block index or a unix time.
|
||||
bool Blockchain::is_tx_spendtime_unlocked(uint64_t unlock_time)
|
||||
{
|
||||
LOG_PRINT_L2("Blockchain::" << __func__);
|
||||
if(unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER)
|
||||
{
|
||||
//interpret as block index
|
||||
@ -1823,6 +1879,7 @@ bool Blockchain::is_tx_spendtime_unlocked(uint64_t unlock_time)
|
||||
// signature for each input.
|
||||
bool Blockchain::check_tx_input(const txin_to_key& txin, const crypto::hash& tx_prefix_hash, const std::vector<crypto::signature>& 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<uint64_t>& 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<uint64_t>& 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<transaction> 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<size_t> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user