BlockchainLMDB seems to be working*!

* - Well, mostly.  Haven't let it sync too far just yet.  Currently
trying to figure out the best way to deal with LMDB/mmap virtual memory
pages.
This commit is contained in:
Thomas Winget 2014-10-30 00:58:14 -04:00 committed by warptangent
parent 1a546e3222
commit 0915913111
3 changed files with 155 additions and 141 deletions

View File

@ -119,7 +119,7 @@ void BlockchainLMDB::add_block( const block& blk
, const uint64_t& coins_generated , const uint64_t& coins_generated
) )
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
crypto::hash h = get_block_hash(blk); crypto::hash h = get_block_hash(blk);
@ -228,7 +228,7 @@ void BlockchainLMDB::add_block( const block& blk
void BlockchainLMDB::remove_block() void BlockchainLMDB::remove_block()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
MDB_val k; MDB_val k;
@ -282,7 +282,7 @@ void BlockchainLMDB::remove_block()
void BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const transaction& tx) void BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const transaction& tx)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
crypto::hash h = get_transaction_hash(tx); crypto::hash h = get_transaction_hash(tx);
@ -333,7 +333,7 @@ void BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const tr
void BlockchainLMDB::remove_transaction_data(const crypto::hash& tx_hash) void BlockchainLMDB::remove_transaction_data(const crypto::hash& tx_hash)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
crypto::hash h = tx_hash; crypto::hash h = tx_hash;
@ -373,7 +373,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) void BlockchainLMDB::add_output(const crypto::hash& tx_hash, const tx_out& tx_output, const uint64_t& local_index)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
MDB_val k; MDB_val k;
@ -407,9 +407,10 @@ void BlockchainLMDB::add_output(const crypto::hash& tx_hash, const tx_out& tx_ou
uint64_t amount = tx_output.amount; uint64_t amount = tx_output.amount;
v.mv_size = sizeof(uint64_t); v.mv_size = sizeof(uint64_t);
v.mv_data = &amount; v.mv_data = &amount;
if (mdb_put(*m_write_txn, m_output_amounts, &v, &k, 0)) if (auto result = mdb_put(*m_write_txn, m_output_amounts, &v, &k, 0))
{ {
LOG_PRINT_L0("Failed to add output amount to db transaction"); LOG_PRINT_L0("Failed to add output amount to db transaction");
LOG_PRINT_L0("E: " << mdb_strerror(result));
throw DB_ERROR("Failed to add output amount to db transaction"); throw DB_ERROR("Failed to add output amount to db transaction");
} }
@ -428,14 +429,12 @@ void BlockchainLMDB::add_output(const crypto::hash& tx_hash, const tx_out& tx_ou
throw DB_ERROR("Failed to add output global index to db transaction"); throw DB_ERROR("Failed to add output global index to db transaction");
} }
LOG_PRINT_L0(__func__ << ": amount == " << amount << ", tx_index == " << local_index << "amount_index == " << get_num_outputs(amount) << ", tx_hash == " << pod_to_hex(tx_hash));
m_num_outputs++; m_num_outputs++;
} }
void BlockchainLMDB::remove_output(const tx_out& tx_output) void BlockchainLMDB::remove_output(const tx_out& tx_output)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
MDB_val k; MDB_val k;
@ -493,7 +492,7 @@ void BlockchainLMDB::remove_output(const tx_out& tx_output)
void BlockchainLMDB::add_spent_key(const crypto::key_image& k_image) void BlockchainLMDB::add_spent_key(const crypto::key_image& k_image)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
crypto::key_image key = k_image; crypto::key_image key = k_image;
@ -520,7 +519,7 @@ void BlockchainLMDB::add_spent_key(const crypto::key_image& k_image)
void BlockchainLMDB::remove_spent_key(const crypto::key_image& k_image) void BlockchainLMDB::remove_spent_key(const crypto::key_image& k_image)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
crypto::key_image key_cpy = k_image; crypto::key_image key_cpy = k_image;
@ -537,7 +536,7 @@ void BlockchainLMDB::remove_spent_key(const crypto::key_image& k_image)
blobdata BlockchainLMDB::output_to_blob(const tx_out& output) blobdata BlockchainLMDB::output_to_blob(const tx_out& output)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
blobdata b; blobdata b;
if (!t_serializable_object_to_blob(output, b)) if (!t_serializable_object_to_blob(output, b))
{ {
@ -549,7 +548,7 @@ blobdata BlockchainLMDB::output_to_blob(const tx_out& output)
tx_out BlockchainLMDB::output_from_blob(const blobdata& blob) tx_out BlockchainLMDB::output_from_blob(const blobdata& blob)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
std::stringstream ss; std::stringstream ss;
ss << blob; ss << blob;
binary_archive<false> ba(ss); binary_archive<false> ba(ss);
@ -566,13 +565,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) uint64_t BlockchainLMDB::get_output_global_index(const uint64_t& amount, const uint64_t& index)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
return 0; return 0;
} }
void BlockchainLMDB::check_open() void BlockchainLMDB::check_open()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
if (!m_open) if (!m_open)
{ {
LOG_PRINT_L0("DB operation attempted on a not-open DB instance"); LOG_PRINT_L0("DB operation attempted on a not-open DB instance");
@ -582,12 +581,12 @@ void BlockchainLMDB::check_open()
BlockchainLMDB::~BlockchainLMDB() BlockchainLMDB::~BlockchainLMDB()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
} }
BlockchainLMDB::BlockchainLMDB() BlockchainLMDB::BlockchainLMDB()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
// initialize folder to something "safe" just in case // initialize folder to something "safe" just in case
// someone accidentally misuses this class... // someone accidentally misuses this class...
m_folder = "thishsouldnotexistbecauseitisgibberish"; m_folder = "thishsouldnotexistbecauseitisgibberish";
@ -597,7 +596,7 @@ BlockchainLMDB::BlockchainLMDB()
void BlockchainLMDB::open(const std::string& filename) void BlockchainLMDB::open(const std::string& filename)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
if (m_open) if (m_open)
{ {
@ -636,9 +635,16 @@ void BlockchainLMDB::open(const std::string& filename)
LOG_PRINT_L0("Failed to set max number of dbs"); LOG_PRINT_L0("Failed to set max number of dbs");
throw DB_ERROR("Failed to set max number of dbs"); throw DB_ERROR("Failed to set max number of dbs");
} }
if (mdb_env_open(m_env, filename.c_str(), 0, 0664)) if (auto result = mdb_env_set_mapsize(m_env, 1 << 29))
{
LOG_PRINT_L0("Failed to set max memory map size");
LOG_PRINT_L0("E: " << mdb_strerror(result));
throw DB_ERROR("Failed to set max memory map size");
}
if (auto result = mdb_env_open(m_env, filename.c_str(), 0, 0664))
{ {
LOG_PRINT_L0("Failed to open lmdb environment"); LOG_PRINT_L0("Failed to open lmdb environment");
LOG_PRINT_L0("E: " << mdb_strerror(result));
throw DB_ERROR("Failed to open lmdb environment"); throw DB_ERROR("Failed to open lmdb environment");
} }
@ -705,32 +711,32 @@ void BlockchainLMDB::open(const std::string& filename)
// unused for now, create will happen on open if doesn't exist // unused for now, create will happen on open if doesn't exist
void BlockchainLMDB::create(const std::string& filename) void BlockchainLMDB::create(const std::string& filename)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
throw DB_CREATE_FAILURE("create() is not implemented for this BlockchainDB, open() will create files if needed."); throw DB_CREATE_FAILURE("create() is not implemented for this BlockchainDB, open() will create files if needed.");
} }
void BlockchainLMDB::close() void BlockchainLMDB::close()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
// FIXME: not yet thread safe!!! Use with care. // FIXME: not yet thread safe!!! Use with care.
mdb_env_close(m_env); mdb_env_close(m_env);
} }
void BlockchainLMDB::sync() void BlockchainLMDB::sync()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
// LMDB documentation leads me to believe this is unnecessary // LMDB documentation leads me to believe this is unnecessary
} }
void BlockchainLMDB::reset() void BlockchainLMDB::reset()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
// TODO: this // TODO: this
} }
std::vector<std::string> BlockchainLMDB::get_filenames() std::vector<std::string> BlockchainLMDB::get_filenames()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
std::vector<std::string> filenames; std::vector<std::string> filenames;
boost::filesystem::path datafile(m_folder); boost::filesystem::path datafile(m_folder);
@ -747,7 +753,7 @@ std::vector<std::string> BlockchainLMDB::get_filenames()
// TODO: this? // TODO: this?
bool BlockchainLMDB::lock() bool BlockchainLMDB::lock()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
return false; return false;
} }
@ -755,14 +761,14 @@ bool BlockchainLMDB::lock()
// TODO: this? // TODO: this?
void BlockchainLMDB::unlock() void BlockchainLMDB::unlock()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
} }
bool BlockchainLMDB::block_exists(const crypto::hash& h) bool BlockchainLMDB::block_exists(const crypto::hash& h)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -797,7 +803,7 @@ bool BlockchainLMDB::block_exists(const crypto::hash& h)
block BlockchainLMDB::get_block(const crypto::hash& h) block BlockchainLMDB::get_block(const crypto::hash& h)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
return get_block_from_height(get_block_height(h)); return get_block_from_height(get_block_height(h));
@ -805,7 +811,7 @@ block BlockchainLMDB::get_block(const crypto::hash& h)
uint64_t BlockchainLMDB::get_block_height(const crypto::hash& h) uint64_t BlockchainLMDB::get_block_height(const crypto::hash& h)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -839,7 +845,7 @@ uint64_t BlockchainLMDB::get_block_height(const crypto::hash& h)
block_header BlockchainLMDB::get_block_header(const crypto::hash& h) block_header BlockchainLMDB::get_block_header(const crypto::hash& h)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
// block_header object is automatically cast from block object // block_header object is automatically cast from block object
@ -848,7 +854,7 @@ block_header BlockchainLMDB::get_block_header(const crypto::hash& h)
block BlockchainLMDB::get_block_from_height(const uint64_t& height) block BlockchainLMDB::get_block_from_height(const uint64_t& height)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -892,7 +898,7 @@ block BlockchainLMDB::get_block_from_height(const uint64_t& height)
uint64_t BlockchainLMDB::get_block_timestamp(const uint64_t& height) uint64_t BlockchainLMDB::get_block_timestamp(const uint64_t& height)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -925,7 +931,7 @@ uint64_t BlockchainLMDB::get_block_timestamp(const uint64_t& height)
uint64_t BlockchainLMDB::get_top_block_timestamp() uint64_t BlockchainLMDB::get_top_block_timestamp()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
// if no blocks, return 0 // if no blocks, return 0
@ -939,7 +945,7 @@ uint64_t BlockchainLMDB::get_top_block_timestamp()
size_t BlockchainLMDB::get_block_size(const uint64_t& height) size_t BlockchainLMDB::get_block_size(const uint64_t& height)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -972,7 +978,7 @@ size_t BlockchainLMDB::get_block_size(const uint64_t& height)
difficulty_type BlockchainLMDB::get_block_cumulative_difficulty(const uint64_t& height) difficulty_type BlockchainLMDB::get_block_cumulative_difficulty(const uint64_t& height)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -1005,7 +1011,7 @@ difficulty_type BlockchainLMDB::get_block_cumulative_difficulty(const uint64_t&
difficulty_type BlockchainLMDB::get_block_difficulty(const uint64_t& height) difficulty_type BlockchainLMDB::get_block_difficulty(const uint64_t& height)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
difficulty_type diff1 = 0; difficulty_type diff1 = 0;
@ -1022,7 +1028,7 @@ difficulty_type BlockchainLMDB::get_block_difficulty(const uint64_t& height)
uint64_t BlockchainLMDB::get_block_already_generated_coins(const uint64_t& height) uint64_t BlockchainLMDB::get_block_already_generated_coins(const uint64_t& height)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -1055,7 +1061,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) crypto::hash BlockchainLMDB::get_block_hash_from_height(const uint64_t& height)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -1088,7 +1094,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) std::vector<block> BlockchainLMDB::get_blocks_range(const uint64_t& h1, const uint64_t& h2)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
std::vector<block> v; std::vector<block> v;
@ -1102,7 +1108,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) std::vector<crypto::hash> BlockchainLMDB::get_hashes_range(const uint64_t& h1, const uint64_t& h2)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
std::vector<crypto::hash> v; std::vector<crypto::hash> v;
@ -1116,7 +1122,7 @@ std::vector<crypto::hash> BlockchainLMDB::get_hashes_range(const uint64_t& h1, c
crypto::hash BlockchainLMDB::top_block_hash() crypto::hash BlockchainLMDB::top_block_hash()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
if (m_height != 0) if (m_height != 0)
{ {
@ -1128,7 +1134,7 @@ crypto::hash BlockchainLMDB::top_block_hash()
block BlockchainLMDB::get_top_block() block BlockchainLMDB::get_top_block()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
if (m_height != 0) if (m_height != 0)
@ -1142,7 +1148,7 @@ block BlockchainLMDB::get_top_block()
uint64_t BlockchainLMDB::height() uint64_t BlockchainLMDB::height()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
return m_height; return m_height;
@ -1151,7 +1157,7 @@ uint64_t BlockchainLMDB::height()
bool BlockchainLMDB::tx_exists(const crypto::hash& h) bool BlockchainLMDB::tx_exists(const crypto::hash& h)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -1185,7 +1191,7 @@ bool BlockchainLMDB::tx_exists(const crypto::hash& h)
uint64_t BlockchainLMDB::get_tx_unlock_time(const crypto::hash& h) uint64_t BlockchainLMDB::get_tx_unlock_time(const crypto::hash& h)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -1218,7 +1224,7 @@ uint64_t BlockchainLMDB::get_tx_unlock_time(const crypto::hash& h)
transaction BlockchainLMDB::get_tx(const crypto::hash& h) transaction BlockchainLMDB::get_tx(const crypto::hash& h)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -1261,7 +1267,7 @@ transaction BlockchainLMDB::get_tx(const crypto::hash& h)
uint64_t BlockchainLMDB::get_tx_count() uint64_t BlockchainLMDB::get_tx_count()
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -1285,7 +1291,7 @@ uint64_t BlockchainLMDB::get_tx_count()
std::vector<transaction> BlockchainLMDB::get_tx_list(const std::vector<crypto::hash>& hlist) std::vector<transaction> BlockchainLMDB::get_tx_list(const std::vector<crypto::hash>& hlist)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
std::vector<transaction> v; std::vector<transaction> v;
@ -1299,7 +1305,7 @@ std::vector<transaction> BlockchainLMDB::get_tx_list(const std::vector<crypto::h
uint64_t BlockchainLMDB::get_tx_block_height(const crypto::hash& h) uint64_t BlockchainLMDB::get_tx_block_height(const crypto::hash& h)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -1333,7 +1339,7 @@ uint64_t BlockchainLMDB::get_tx_block_height(const crypto::hash& h)
//FIXME: make sure the random method used here is appropriate //FIXME: make sure the random method used here is appropriate
uint64_t BlockchainLMDB::get_random_output(const uint64_t& amount) uint64_t BlockchainLMDB::get_random_output(const uint64_t& amount)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
uint64_t num_outputs = get_num_outputs(amount); uint64_t num_outputs = get_num_outputs(amount);
@ -1348,7 +1354,7 @@ uint64_t BlockchainLMDB::get_random_output(const uint64_t& amount)
uint64_t BlockchainLMDB::get_num_outputs(const uint64_t& amount) uint64_t BlockchainLMDB::get_num_outputs(const uint64_t& amount)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -1387,7 +1393,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) crypto::public_key BlockchainLMDB::get_output_key(const uint64_t& amount, const uint64_t& index)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
uint64_t global = get_output_global_index(amount, index); uint64_t global = get_output_global_index(amount, index);
@ -1405,7 +1411,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) tx_out BlockchainLMDB::get_output(const crypto::hash& h, const uint64_t& index)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -1467,7 +1473,7 @@ tx_out BlockchainLMDB::get_output(const crypto::hash& h, const uint64_t& index)
tx_out BlockchainLMDB::get_output(const uint64_t& index) tx_out BlockchainLMDB::get_output(const uint64_t& index)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -1502,7 +1508,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) tx_out_index BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, const uint64_t& index)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -1595,7 +1601,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) std::vector<uint64_t> BlockchainLMDB::get_tx_output_indices(const crypto::hash& h)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
std::vector<uint64_t> index_vec; std::vector<uint64_t> index_vec;
@ -1647,7 +1653,7 @@ std::vector<uint64_t> BlockchainLMDB::get_tx_output_indices(const crypto::hash&
bool BlockchainLMDB::has_key_image(const crypto::key_image& img) bool BlockchainLMDB::has_key_image(const crypto::key_image& img)
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
@ -1680,7 +1686,7 @@ uint64_t BlockchainLMDB::add_block( const block& blk
, const std::vector<transaction>& txs , const std::vector<transaction>& txs
) )
{ {
LOG_PRINT_L2("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
txn_safe txn; txn_safe txn;
if (mdb_txn_begin(m_env, NULL, 0, txn)) if (mdb_txn_begin(m_env, NULL, 0, txn))

View File

@ -59,6 +59,7 @@
*/ */
using namespace cryptonote; using namespace cryptonote;
using epee::string_tools::pod_to_hex;
DISABLE_VS_WARNINGS(4267) DISABLE_VS_WARNINGS(4267)
@ -66,14 +67,14 @@ DISABLE_VS_WARNINGS(4267)
// TODO: initialize m_db with a concrete implementation of BlockchainDB // 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) 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__); LOG_PRINT_L3("Blockchain::" << __func__);
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
//TODO: is this still needed? I don't think so - tewinget //TODO: is this still needed? I don't think so - tewinget
template<class archive_t> template<class archive_t>
void Blockchain::serialize(archive_t & ar, const unsigned int version) void Blockchain::serialize(archive_t & ar, const unsigned int version)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
if(version < 11) if(version < 11)
return; return;
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
@ -116,7 +117,7 @@ void Blockchain::serialize(archive_t & ar, const unsigned int version)
} }
LOG_PRINT_L2("Blockchain storage:" << std::endl << LOG_PRINT_L3("Blockchain storage:" << std::endl <<
"m_blocks: " << m_db->height() << std::endl << "m_blocks: " << m_db->height() << std::endl <<
"m_blocks_index: " << m_blocks_index.size() << std::endl << "m_blocks_index: " << m_blocks_index.size() << std::endl <<
"m_transactions: " << m_transactions.size() << std::endl << "m_transactions: " << m_transactions.size() << std::endl <<
@ -129,14 +130,14 @@ void Blockchain::serialize(archive_t & ar, const unsigned int version)
//------------------------------------------------------------------ //------------------------------------------------------------------
bool Blockchain::have_tx(const crypto::hash &id) bool Blockchain::have_tx(const crypto::hash &id)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
return m_db->tx_exists(id); return m_db->tx_exists(id);
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
bool Blockchain::have_tx_keyimg_as_spent(const crypto::key_image &key_im) bool Blockchain::have_tx_keyimg_as_spent(const crypto::key_image &key_im)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
return m_db->has_key_image(key_im); return m_db->has_key_image(key_im);
} }
@ -147,7 +148,7 @@ bool Blockchain::have_tx_keyimg_as_spent(const crypto::key_image &key_im)
template<class visitor_t> 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) 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__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
// verify that the input has key offsets (that it exists properly, really) // verify that the input has key offsets (that it exists properly, really)
@ -180,8 +181,6 @@ bool Blockchain::scan_outputkeys_for_indexes(const txin_to_key& tx_in_to_key, vi
return false; return false;
} }
LOG_PRINT_L0(__func__ << ": amount == " << tx.vout[output_index.second].amount);
// call to the passed boost visitor to grab the public key for the output // call to the passed boost visitor to grab the public key for the output
if(!vis.handle_output(tx, tx.vout[output_index.second])) if(!vis.handle_output(tx, tx.vout[output_index.second]))
{ {
@ -219,7 +218,7 @@ LOG_PRINT_L0(__func__ << ": amount == " << tx.vout[output_index.second].amount);
//------------------------------------------------------------------ //------------------------------------------------------------------
uint64_t Blockchain::get_current_blockchain_height() uint64_t Blockchain::get_current_blockchain_height()
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
return m_db->height(); return m_db->height();
} }
@ -228,7 +227,7 @@ uint64_t Blockchain::get_current_blockchain_height()
// dereferencing a null BlockchainDB pointer // dereferencing a null BlockchainDB pointer
bool Blockchain::init(const std::string& config_folder, bool testnet) bool Blockchain::init(const std::string& config_folder, bool testnet)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
m_db = new BlockchainLMDB(); m_db = new BlockchainLMDB();
@ -307,7 +306,7 @@ bool Blockchain::init(const std::string& config_folder, bool testnet)
//------------------------------------------------------------------ //------------------------------------------------------------------
bool Blockchain::store_blockchain() bool Blockchain::store_blockchain()
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
// TODO: make sure if this throws that it is not simply ignored higher // TODO: make sure if this throws that it is not simply ignored higher
// up the call stack // up the call stack
try try
@ -330,7 +329,7 @@ bool Blockchain::store_blockchain()
//------------------------------------------------------------------ //------------------------------------------------------------------
bool Blockchain::deinit() bool Blockchain::deinit()
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
// as this should be called if handling a SIGSEGV, need to check // 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 // if m_db is a NULL pointer (and thus may have caused the illegal
// memory operation), otherwise we may cause a loop. // memory operation), otherwise we may cause a loop.
@ -361,7 +360,7 @@ bool Blockchain::deinit()
// from it to the tx_pool // from it to the tx_pool
block Blockchain::pop_block_from_blockchain() block Blockchain::pop_block_from_blockchain()
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
block popped_block; block popped_block;
@ -403,7 +402,7 @@ block Blockchain::pop_block_from_blockchain()
//------------------------------------------------------------------ //------------------------------------------------------------------
bool Blockchain::reset_and_set_genesis_block(const block& b) bool Blockchain::reset_and_set_genesis_block(const block& b)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
m_transactions.clear(); m_transactions.clear();
m_spent_keys.clear(); m_spent_keys.clear();
@ -421,7 +420,7 @@ bool Blockchain::reset_and_set_genesis_block(const block& b)
//TODO: move to BlockchainDB subclass //TODO: move to BlockchainDB subclass
bool Blockchain::purge_transaction_keyimages_from_blockchain(const transaction& tx, bool strict_check) bool Blockchain::purge_transaction_keyimages_from_blockchain(const transaction& tx, bool strict_check)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
struct purge_transaction_visitor: public boost::static_visitor<bool> struct purge_transaction_visitor: public boost::static_visitor<bool>
{ {
@ -467,7 +466,7 @@ bool Blockchain::purge_transaction_keyimages_from_blockchain(const transaction&
//------------------------------------------------------------------ //------------------------------------------------------------------
crypto::hash Blockchain::get_tail_id(uint64_t& height) crypto::hash Blockchain::get_tail_id(uint64_t& height)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
height = m_db->height(); height = m_db->height();
return get_tail_id(); return get_tail_id();
@ -475,7 +474,7 @@ crypto::hash Blockchain::get_tail_id(uint64_t& height)
//------------------------------------------------------------------ //------------------------------------------------------------------
crypto::hash Blockchain::get_tail_id() crypto::hash Blockchain::get_tail_id()
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
return m_db->top_block_hash(); return m_db->top_block_hash();
} }
@ -494,7 +493,7 @@ crypto::hash Blockchain::get_tail_id()
*/ */
bool Blockchain::get_short_chain_history(std::list<crypto::hash>& ids) bool Blockchain::get_short_chain_history(std::list<crypto::hash>& ids)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
uint64_t i = 0; uint64_t i = 0;
uint64_t current_multiplier = 1; uint64_t current_multiplier = 1;
@ -503,10 +502,16 @@ bool Blockchain::get_short_chain_history(std::list<crypto::hash>& ids)
if(!sz) if(!sz)
return true; return true;
uint64_t current_back_offset = 0; bool genesis_included = false;
uint64_t current_back_offset = 1;
while(current_back_offset < sz) while(current_back_offset < sz)
{ {
ids.push_back(m_db->get_block_hash_from_height(sz - current_back_offset - 1)); ids.push_back(m_db->get_block_hash_from_height(sz - current_back_offset));
if(sz-current_back_offset == 0)
{
genesis_included = true;
}
if(i < 10) if(i < 10)
{ {
++current_back_offset; ++current_back_offset;
@ -519,12 +524,17 @@ bool Blockchain::get_short_chain_history(std::list<crypto::hash>& ids)
++i; ++i;
} }
if (!genesis_included)
{
ids.push_back(m_db->get_block_hash_from_height(0));
}
return true; return true;
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
crypto::hash Blockchain::get_block_id_by_height(uint64_t height) crypto::hash Blockchain::get_block_id_by_height(uint64_t height)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
try try
{ {
@ -548,7 +558,7 @@ crypto::hash Blockchain::get_block_id_by_height(uint64_t height)
//------------------------------------------------------------------ //------------------------------------------------------------------
bool Blockchain::get_block_by_hash(const crypto::hash &h, block &blk) bool Blockchain::get_block_by_hash(const crypto::hash &h, block &blk)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
// try to find block in main chain // try to find block in main chain
@ -584,7 +594,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 // 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) 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__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
for (auto& a : m_db->get_hashes_range(0, m_db->height() - 1)) for (auto& a : m_db->get_hashes_range(0, m_db->height() - 1))
@ -605,7 +615,7 @@ void Blockchain::get_all_known_block_ids(std::list<crypto::hash> &main, std::lis
// less blocks than desired if there aren't enough. // less blocks than desired if there aren't enough.
difficulty_type Blockchain::get_difficulty_for_next_block() difficulty_type Blockchain::get_difficulty_for_next_block()
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
std::vector<uint64_t> timestamps; std::vector<uint64_t> timestamps;
std::vector<difficulty_type> cumulative_difficulties; std::vector<difficulty_type> cumulative_difficulties;
@ -632,7 +642,7 @@ difficulty_type Blockchain::get_difficulty_for_next_block()
// that had been removed. // that had been removed.
bool Blockchain::rollback_blockchain_switching(std::list<block>& original_chain, uint64_t rollback_height) bool Blockchain::rollback_blockchain_switching(std::list<block>& original_chain, uint64_t rollback_height)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
// remove blocks from blockchain until we get back to where we should be. // remove blocks from blockchain until we get back to where we should be.
@ -661,7 +671,7 @@ bool Blockchain::rollback_blockchain_switching(std::list<block>& original_chain,
// boolean based on success therein. // boolean based on success therein.
bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::iterator>& alt_chain, bool discard_disconnected_chain) bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::iterator>& alt_chain, bool discard_disconnected_chain)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
// if empty alt chain passed (not sure how that could happen), return false // if empty alt chain passed (not sure how that could happen), return false
@ -752,7 +762,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::
// an alternate chain. // 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) 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__); LOG_PRINT_L3("Blockchain::" << __func__);
std::vector<uint64_t> timestamps; std::vector<uint64_t> timestamps;
std::vector<difficulty_type> cumulative_difficulties; std::vector<difficulty_type> cumulative_difficulties;
@ -821,7 +831,7 @@ difficulty_type Blockchain::get_next_difficulty_for_alternative_chain(const std:
// a non-overflowing tx amount (dubious necessity on this check) // a non-overflowing tx amount (dubious necessity on this check)
bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height) bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("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.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"); 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) if(boost::get<txin_gen>(b.miner_tx.vin[0]).height != height)
@ -849,7 +859,7 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height)
// This function validates the miner transaction reward // 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) 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__); LOG_PRINT_L3("Blockchain::" << __func__);
//validate reward //validate reward
uint64_t money_in_use = 0; uint64_t money_in_use = 0;
BOOST_FOREACH(auto& o, b.miner_tx.vout) BOOST_FOREACH(auto& o, b.miner_tx.vout)
@ -879,7 +889,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
// and return by reference <sz>. // and return by reference <sz>.
void Blockchain::get_last_n_blocks_sizes(std::vector<size_t>& sz, size_t count) void Blockchain::get_last_n_blocks_sizes(std::vector<size_t>& sz, size_t count)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
auto h = m_db->height(); auto h = m_db->height();
@ -897,7 +907,7 @@ void Blockchain::get_last_n_blocks_sizes(std::vector<size_t>& sz, size_t count)
//------------------------------------------------------------------ //------------------------------------------------------------------
uint64_t Blockchain::get_current_cumulative_blocksize_limit() uint64_t Blockchain::get_current_cumulative_blocksize_limit()
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
return m_current_block_cumul_sz_limit; return m_current_block_cumul_sz_limit;
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
@ -914,7 +924,7 @@ uint64_t Blockchain::get_current_cumulative_blocksize_limit()
// necessary at all. // 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) 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__); LOG_PRINT_L3("Blockchain::" << __func__);
size_t median_size; size_t median_size;
uint64_t already_generated_coins; uint64_t already_generated_coins;
@ -1037,7 +1047,7 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
// the needed number of timestamps for the BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW. // 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) bool Blockchain::complete_timestamps_vector(uint64_t start_top_height, std::vector<uint64_t>& timestamps)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
if(timestamps.size() >= BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW) if(timestamps.size() >= BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW)
return true; return true;
@ -1062,7 +1072,7 @@ bool Blockchain::complete_timestamps_vector(uint64_t start_top_height, std::vect
// a long forked chain eventually. // a long forked chain eventually.
bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id, block_verification_context& bvc) bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id, block_verification_context& bvc)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
uint64_t block_height = get_block_height(b); uint64_t block_height = get_block_height(b);
@ -1242,7 +1252,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) bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks, std::list<transaction>& txs)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
if(start_offset > m_db->height()) if(start_offset > m_db->height())
return false; return false;
@ -1264,7 +1274,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) bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
if(start_offset > m_db->height()) if(start_offset > m_db->height())
return false; return false;
@ -1281,7 +1291,7 @@ bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list<block
// but it warrants some looking into later. // but it warrants some looking into later.
bool Blockchain::handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NOTIFY_RESPONSE_GET_OBJECTS::request& rsp) bool Blockchain::handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NOTIFY_RESPONSE_GET_OBJECTS::request& rsp)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
rsp.current_blockchain_height = get_current_blockchain_height(); rsp.current_blockchain_height = get_current_blockchain_height();
std::list<block> blocks; std::list<block> blocks;
@ -1315,7 +1325,7 @@ bool Blockchain::handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NO
//------------------------------------------------------------------ //------------------------------------------------------------------
bool Blockchain::get_alternative_blocks(std::list<block>& blocks) bool Blockchain::get_alternative_blocks(std::list<block>& blocks)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
BOOST_FOREACH(const auto& alt_bl, m_alternative_chains) BOOST_FOREACH(const auto& alt_bl, m_alternative_chains)
@ -1327,7 +1337,7 @@ bool Blockchain::get_alternative_blocks(std::list<block>& blocks)
//------------------------------------------------------------------ //------------------------------------------------------------------
size_t Blockchain::get_alternative_blocks_count() size_t Blockchain::get_alternative_blocks_count()
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
return m_alternative_chains.size(); return m_alternative_chains.size();
} }
@ -1336,7 +1346,7 @@ size_t Blockchain::get_alternative_blocks_count()
// unlocked and other such checks should be done by here. // 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) 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__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); 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()); 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());
@ -1350,7 +1360,7 @@ void Blockchain::add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_A
// in some cases // 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) 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__); LOG_PRINT_L3("Blockchain::" << __func__);
srand(static_cast<unsigned int>(time(NULL))); srand(static_cast<unsigned int>(time(NULL)));
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
@ -1423,7 +1433,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. // 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) bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, uint64_t& starter_offset)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
// make sure the request includes at least the genesis block, otherwise // make sure the request includes at least the genesis block, otherwise
@ -1489,7 +1499,7 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
//------------------------------------------------------------------ //------------------------------------------------------------------
uint64_t Blockchain::block_difficulty(uint64_t i) uint64_t Blockchain::block_difficulty(uint64_t i)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
try try
{ {
@ -1505,7 +1515,7 @@ uint64_t Blockchain::block_difficulty(uint64_t i)
template<class t_ids_container, class t_blocks_container, class t_missed_container> 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) bool Blockchain::get_blocks(const t_ids_container& block_ids, t_blocks_container& blocks, t_missed_container& missed_bs)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
for (const auto& block_hash : block_ids) for (const auto& block_hash : block_ids)
@ -1529,7 +1539,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> 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) bool Blockchain::get_transactions(const t_ids_container& txs_ids, t_tx_container& txs, t_missed_container& missed_txs)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
for (const auto& tx_hash : txs_ids) for (const auto& tx_hash : txs_ids)
@ -1553,7 +1563,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) void Blockchain::print_blockchain(uint64_t start_index, uint64_t end_index)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
std::stringstream ss; std::stringstream ss;
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
auto h = m_db->height(); auto h = m_db->height();
@ -1581,7 +1591,7 @@ void Blockchain::print_blockchain(uint64_t start_index, uint64_t end_index)
//------------------------------------------------------------------ //------------------------------------------------------------------
void Blockchain::print_blockchain_index() void Blockchain::print_blockchain_index()
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
std::stringstream ss; std::stringstream ss;
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
auto height = m_db->height(); auto height = m_db->height();
@ -1601,7 +1611,7 @@ void Blockchain::print_blockchain_index()
//TODO: remove this function and references to it //TODO: remove this function and references to it
void Blockchain::print_blockchain_outs(const std::string& file) void Blockchain::print_blockchain_outs(const std::string& file)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
return; return;
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
@ -1610,7 +1620,7 @@ void Blockchain::print_blockchain_outs(const std::string& file)
// BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT additional (more recent) hashes. // 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) bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
// if we can't find the split point, return false // if we can't find the split point, return false
@ -1634,7 +1644,7 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
// blocks by reference. // 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) 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__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
// if a specific start height has been requested // if a specific start height has been requested
@ -1670,7 +1680,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) bool Blockchain::add_block_as_invalid(const block& bl, const crypto::hash& h)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
block_extended_info bei = AUTO_VAL_INIT(bei); block_extended_info bei = AUTO_VAL_INIT(bei);
bei.bl = bl; bei.bl = bl;
return add_block_as_invalid(bei, h); return add_block_as_invalid(bei, h);
@ -1678,7 +1688,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) bool Blockchain::add_block_as_invalid(const block_extended_info& bei, const crypto::hash& h)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
auto i_res = m_invalid_blocks.insert(std::map<crypto::hash, block_extended_info>::value_type(h, bei)); 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"); CHECK_AND_ASSERT_MES(i_res.second, false, "at insertion invalid by tx returned status existed");
@ -1688,7 +1698,7 @@ bool Blockchain::add_block_as_invalid(const block_extended_info& bei, const cryp
//------------------------------------------------------------------ //------------------------------------------------------------------
bool Blockchain::have_block(const crypto::hash& id) bool Blockchain::have_block(const crypto::hash& id)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
if(m_db->block_exists(id)) if(m_db->block_exists(id))
@ -1705,14 +1715,14 @@ bool Blockchain::have_block(const crypto::hash& id)
//------------------------------------------------------------------ //------------------------------------------------------------------
bool Blockchain::handle_block_to_main_chain(const block& bl, block_verification_context& bvc) bool Blockchain::handle_block_to_main_chain(const block& bl, block_verification_context& bvc)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
crypto::hash id = get_block_hash(bl); crypto::hash id = get_block_hash(bl);
return handle_block_to_main_chain(bl, id, bvc); return handle_block_to_main_chain(bl, id, bvc);
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
size_t Blockchain::get_total_transactions() size_t Blockchain::get_total_transactions()
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
return m_db->get_tx_count(); return m_db->get_tx_count();
} }
@ -1725,7 +1735,7 @@ size_t Blockchain::get_total_transactions()
// remove them later if the block fails validation. // remove them later if the block fails validation.
bool Blockchain::check_for_double_spend(const transaction& tx, key_images_container& keys_this_block) bool Blockchain::check_for_double_spend(const transaction& tx, key_images_container& keys_this_block)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
struct add_transaction_input_visitor: public boost::static_visitor<bool> struct add_transaction_input_visitor: public boost::static_visitor<bool>
{ {
@ -1774,7 +1784,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) bool Blockchain::get_tx_outputs_gindexs(const crypto::hash& tx_id, std::vector<uint64_t>& indexs)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
if (!m_db->tx_exists(tx_id)) if (!m_db->tx_exists(tx_id))
{ {
@ -1791,7 +1801,7 @@ bool Blockchain::get_tx_outputs_gindexs(const crypto::hash& tx_id, std::vector<u
// as a return-by-reference. // 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) 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__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
bool res = check_tx_inputs(tx, &max_used_block_height); bool res = check_tx_inputs(tx, &max_used_block_height);
if(!res) return false; if(!res) return false;
@ -1802,7 +1812,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t& max_used_block
//------------------------------------------------------------------ //------------------------------------------------------------------
bool Blockchain::have_tx_keyimges_as_spent(const transaction &tx) bool Blockchain::have_tx_keyimges_as_spent(const transaction &tx)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
BOOST_FOREACH(const txin_v& in, tx.vin) BOOST_FOREACH(const txin_v& in, tx.vin)
{ {
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, in_to_key, true); CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, in_to_key, true);
@ -1817,7 +1827,7 @@ bool Blockchain::have_tx_keyimges_as_spent(const transaction &tx)
// own function. // own function.
bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t* pmax_used_block_height) bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t* pmax_used_block_height)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
size_t sig_index = 0; size_t sig_index = 0;
if(pmax_used_block_height) if(pmax_used_block_height)
*pmax_used_block_height = 0; *pmax_used_block_height = 0;
@ -1855,7 +1865,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t* pmax_used_bloc
// a block index or a unix time. // a block index or a unix time.
bool Blockchain::is_tx_spendtime_unlocked(uint64_t unlock_time) bool Blockchain::is_tx_spendtime_unlocked(uint64_t unlock_time)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
if(unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER) if(unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER)
{ {
//interpret as block index //interpret as block index
@ -1880,14 +1890,15 @@ bool Blockchain::is_tx_spendtime_unlocked(uint64_t unlock_time)
// signature for each input. // 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) 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__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
struct outputs_visitor struct outputs_visitor
{ {
std::vector<const crypto::public_key *>& m_results_collector; std::vector<const crypto::public_key *>& m_p_output_keys;
std::vector<crypto::public_key >& m_output_keys;
Blockchain& m_bch; Blockchain& m_bch;
outputs_visitor(std::vector<const crypto::public_key *>& results_collector, Blockchain& bch):m_results_collector(results_collector), m_bch(bch) outputs_visitor(std::vector<crypto::public_key >& output_keys, std::vector<const crypto::public_key *>& p_output_keys, Blockchain& bch) : m_output_keys(output_keys), m_p_output_keys(p_output_keys), m_bch(bch)
{} {}
bool handle_output(const transaction& tx, const tx_out& out) bool handle_output(const transaction& tx, const tx_out& out)
{ {
@ -1904,20 +1915,26 @@ bool Blockchain::check_tx_input(const txin_to_key& txin, const crypto::hash& tx_
return false; return false;
} }
m_results_collector.push_back(&boost::get<txout_to_key>(out.target).key); m_output_keys.push_back(boost::get<txout_to_key>(out.target).key);
return true; return true;
} }
}; };
//check ring signature //check ring signature
std::vector<const crypto::public_key *> output_keys; std::vector<crypto::public_key> output_keys;
outputs_visitor vi(output_keys, *this); std::vector<const crypto::public_key *> p_output_keys;
outputs_visitor vi(output_keys, p_output_keys, *this);
if(!scan_outputkeys_for_indexes(txin, vi, pmax_related_block_height)) if(!scan_outputkeys_for_indexes(txin, vi, pmax_related_block_height))
{ {
LOG_PRINT_L0("Failed to get output keys for tx with amount = " << print_money(txin.amount) << " and count indexes " << txin.key_offsets.size()); LOG_PRINT_L0("Failed to get output keys for tx with amount = " << print_money(txin.amount) << " and count indexes " << txin.key_offsets.size());
return false; return false;
} }
for (auto& k : output_keys)
{
p_output_keys.push_back(&k);
}
if(txin.key_offsets.size() != output_keys.size()) if(txin.key_offsets.size() != output_keys.size())
{ {
LOG_PRINT_L0("Output keys for tx with amount = " << txin.amount << " and count indexes " << txin.key_offsets.size() << " returned wrong keys count " << output_keys.size()); LOG_PRINT_L0("Output keys for tx with amount = " << txin.amount << " and count indexes " << txin.key_offsets.size() << " returned wrong keys count " << output_keys.size());
@ -1926,13 +1943,13 @@ bool Blockchain::check_tx_input(const txin_to_key& txin, const crypto::hash& tx_
CHECK_AND_ASSERT_MES(sig.size() == output_keys.size(), false, "internal error: tx signatures count=" << sig.size() << " mismatch with outputs keys count for inputs=" << output_keys.size()); CHECK_AND_ASSERT_MES(sig.size() == output_keys.size(), false, "internal error: tx signatures count=" << sig.size() << " mismatch with outputs keys count for inputs=" << output_keys.size());
if(m_is_in_checkpoint_zone) if(m_is_in_checkpoint_zone)
return true; return true;
return crypto::check_ring_signature(tx_prefix_hash, txin.k_image, output_keys, sig.data()); return crypto::check_ring_signature(tx_prefix_hash, txin.k_image, p_output_keys, sig.data());
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
//TODO: Is this intended to do something else? Need to look into the todo there. //TODO: Is this intended to do something else? Need to look into the todo there.
uint64_t Blockchain::get_adjusted_time() uint64_t Blockchain::get_adjusted_time()
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
//TODO: add collecting median time //TODO: add collecting median time
return time(NULL); return time(NULL);
} }
@ -1940,7 +1957,7 @@ uint64_t Blockchain::get_adjusted_time()
//TODO: revisit, has changed a bit on upstream //TODO: revisit, has changed a bit on upstream
bool Blockchain::check_block_timestamp(std::vector<uint64_t>& timestamps, const block& b) bool Blockchain::check_block_timestamp(std::vector<uint64_t>& timestamps, const block& b)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
uint64_t median_ts = epee::misc_utils::median(timestamps); uint64_t median_ts = epee::misc_utils::median(timestamps);
if(b.timestamp < median_ts) if(b.timestamp < median_ts)
@ -1961,7 +1978,7 @@ bool Blockchain::check_block_timestamp(std::vector<uint64_t>& timestamps, const
// false otherwise // false otherwise
bool Blockchain::check_block_timestamp(const block& b) bool Blockchain::check_block_timestamp(const block& b)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
if(b.timestamp > get_adjusted_time() + CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT) 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"); LOG_PRINT_L0("Timestamp of block with id: " << get_block_hash(b) << ", " << b.timestamp << ", bigger than adjusted time + 2 hours");
@ -1994,7 +2011,7 @@ bool Blockchain::check_block_timestamp(const block& b)
// m_db->add_block() // m_db->add_block()
bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash& id, block_verification_context& bvc) bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash& id, block_verification_context& bvc)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
// if we already have the block, return false // if we already have the block, return false
if (have_block(id)) if (have_block(id))
{ {
@ -2217,7 +2234,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
//------------------------------------------------------------------ //------------------------------------------------------------------
bool Blockchain::update_next_cumulative_size_limit() bool Blockchain::update_next_cumulative_size_limit()
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
std::vector<size_t> sz; std::vector<size_t> sz;
get_last_n_blocks_sizes(sz, CRYPTONOTE_REWARD_BLOCKS_WINDOW); get_last_n_blocks_sizes(sz, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
@ -2231,7 +2248,7 @@ bool Blockchain::update_next_cumulative_size_limit()
//------------------------------------------------------------------ //------------------------------------------------------------------
bool Blockchain::add_new_block(const block& bl_, block_verification_context& bvc) bool Blockchain::add_new_block(const block& bl_, block_verification_context& bvc)
{ {
LOG_PRINT_L2("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
//copy block here to let modify block.target //copy block here to let modify block.target
block bl = bl_; block bl = bl_;
crypto::hash id = get_block_hash(bl); crypto::hash id = get_block_hash(bl);

View File

@ -45,10 +45,6 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti
{ {
crypto::hash tx_hash = get_transaction_hash(tx); crypto::hash tx_hash = get_transaction_hash(tx);
LOG_PRINT_L0("Adding tx with hash " << pod_to_hex(tx_hash) << " to BlockchainDB instance");
LOG_PRINT_L0("Included in block with hash " << pod_to_hex(blk_hash));
LOG_PRINT_L0("Unlock time == " << tx.unlock_time);
add_transaction_data(blk_hash, tx); add_transaction_data(blk_hash, tx);
// iterate tx.vout using indices instead of C++11 foreach syntax because // iterate tx.vout using indices instead of C++11 foreach syntax because
@ -66,10 +62,6 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti
{ {
add_spent_key(boost::get<txin_to_key>(tx_input).k_image); add_spent_key(boost::get<txin_to_key>(tx_input).k_image);
} }
else
{
LOG_PRINT_L0("Is miner tx");
}
} }
} }
} }
@ -82,7 +74,6 @@ uint64_t BlockchainDB::add_block( const block& blk
) )
{ {
crypto::hash blk_hash = get_block_hash(blk); crypto::hash blk_hash = get_block_hash(blk);
LOG_PRINT_L0("Adding block with hash " << pod_to_hex(blk_hash) << " to BlockchainDB instance.");
// call out to subclass implementation to add the block & metadata // call out to subclass implementation to add the block & metadata
add_block(blk, block_size, cumulative_difficulty, coins_generated); add_block(blk, block_size, cumulative_difficulty, coins_generated);