mirror of
https://github.com/monero-project/monero.git
synced 2024-12-14 04:16:32 +02:00
Blockchain: reflect log and assert updates from blockchain_storage
See commit cf5a8b1d6c
This commit is contained in:
parent
70342ecada
commit
7f9b070165
@ -650,7 +650,7 @@ bool Blockchain::rollback_blockchain_switching(std::list<block>& original_chain,
|
||||
{
|
||||
block_verification_context bvc = boost::value_initialized<block_verification_context>();
|
||||
bool r = handle_block_to_main_chain(bl, bvc);
|
||||
CHECK_AND_ASSERT_MES(r && bvc.m_added_to_main_chain, false, "PANIC!!! failed to add (again) block while chain switching during the rollback!");
|
||||
CHECK_AND_ASSERT_MES(r && bvc.m_added_to_main_chain, false, "PANIC! failed to add (again) block while chain switching during the rollback!");
|
||||
}
|
||||
|
||||
LOG_PRINT_L1("Rollback to height " << rollback_height << " was successful.");
|
||||
@ -702,7 +702,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::
|
||||
// return false
|
||||
if(!r || !bvc.m_added_to_main_chain)
|
||||
{
|
||||
LOG_PRINT_L0("Failed to switch to alternative blockchain");
|
||||
LOG_PRINT_L1("Failed to switch to alternative blockchain");
|
||||
|
||||
// rollback_blockchain_switching should be moved to two different
|
||||
// functions: rollback and apply_chain, but for now we pretend it is
|
||||
@ -713,7 +713,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::
|
||||
// about them again so we can immediately dismiss them, but needs some
|
||||
// looking into.
|
||||
add_block_as_invalid(ch_ent->second, get_block_hash(ch_ent->second.bl));
|
||||
LOG_PRINT_L0("The block was inserted as invalid while connecting new alternative chain, block_id: " << get_block_hash(ch_ent->second.bl));
|
||||
LOG_PRINT_L1("The block was inserted as invalid while connecting new alternative chain, block_id: " << get_block_hash(ch_ent->second.bl));
|
||||
m_alternative_chains.erase(ch_ent);
|
||||
|
||||
for(auto alt_ch_to_orph_iter = ++alt_ch_iter; alt_ch_to_orph_iter != alt_chain.end(); alt_ch_to_orph_iter++)
|
||||
@ -835,7 +835,8 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height)
|
||||
}
|
||||
CHECK_AND_ASSERT_MES(b.miner_tx.unlock_time == height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW,
|
||||
false,
|
||||
"coinbase transaction transaction have wrong unlock time=" << b.miner_tx.unlock_time << ", expected " << height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW);
|
||||
"coinbase transaction transaction has the wrong unlock time=" << b.miner_tx.unlock_time << ", expected " << height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW);
|
||||
|
||||
|
||||
//check outs overflow
|
||||
//NOTE: not entirely sure this is necessary, given that this function is
|
||||
@ -843,7 +844,7 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height)
|
||||
// does not overflow a uint64_t, and this transaction *is* a uint64_t...
|
||||
if(!check_outs_overflow(b.miner_tx))
|
||||
{
|
||||
LOG_PRINT_RED_L1("miner transaction have money overflow in block " << get_block_hash(b));
|
||||
LOG_PRINT_RED_L1("miner transaction has money overflow in block " << get_block_hash(b));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -862,7 +863,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
|
||||
std::vector<size_t> last_blocks_sizes;
|
||||
get_last_n_blocks_sizes(last_blocks_sizes, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
|
||||
if (!get_block_reward(epee::misc_utils::median(last_blocks_sizes), cumulative_block_size, already_generated_coins, base_reward)) {
|
||||
LOG_PRINT_L0("block size " << cumulative_block_size << " is bigger than allowed for this blockchain");
|
||||
LOG_PRINT_L1("block size " << cumulative_block_size << " is bigger than allowed for this blockchain");
|
||||
return false;
|
||||
}
|
||||
if(base_reward + fee < money_in_use)
|
||||
@ -1019,7 +1020,7 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
|
||||
b.miner_tx.extra.resize(b.miner_tx.extra.size() - 1);
|
||||
if (cumulative_size != txs_size + get_object_blobsize(b.miner_tx)) {
|
||||
//fuck, not lucky, -1 makes varint-counter size smaller, in that case we continue to grow with cumulative_size
|
||||
LOG_PRINT_RED("Miner tx creation have no luck with delta_extra size = " << delta << " and " << delta - 1 , LOG_LEVEL_2);
|
||||
LOG_PRINT_RED("Miner tx creation has no luck with delta_extra size = " << delta << " and " << delta - 1 , LOG_LEVEL_2);
|
||||
cumulative_size += delta - 1;
|
||||
continue;
|
||||
}
|
||||
@ -1125,7 +1126,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
|
||||
|
||||
// make sure block connects correctly to the main chain
|
||||
auto h = m_db->get_block_hash_from_height(alt_chain.front()->second.height - 1);
|
||||
CHECK_AND_ASSERT_MES(h == alt_chain.front()->second.bl.prev_id, false, "alternative chain have wrong connection to main chain");
|
||||
CHECK_AND_ASSERT_MES(h == alt_chain.front()->second.bl.prev_id, false, "alternative chain has wrong connection to main chain");
|
||||
complete_timestamps_vector(m_db->get_block_height(alt_chain.front()->second.bl.prev_id), timestamps);
|
||||
}
|
||||
// if block not associated with known alternate chain
|
||||
@ -1143,7 +1144,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
|
||||
if(!check_block_timestamp(timestamps, b))
|
||||
{
|
||||
LOG_PRINT_RED_L1("Block with id: " << id
|
||||
<< std::endl << " for alternative chain, have invalid timestamp: " << b.timestamp);
|
||||
<< std::endl << " for alternative chain, has invalid timestamp: " << b.timestamp);
|
||||
bvc.m_verifivation_failed = true;
|
||||
return false;
|
||||
}
|
||||
@ -1170,7 +1171,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
|
||||
if(!check_hash(proof_of_work, current_diff))
|
||||
{
|
||||
LOG_PRINT_RED_L1("Block with id: " << id
|
||||
<< std::endl << " for alternative chain, have not enough proof of work: " << proof_of_work
|
||||
<< std::endl << " for alternative chain, does not have enough proof of work: " << proof_of_work
|
||||
<< std::endl << " expected difficulty: " << current_diff);
|
||||
bvc.m_verifivation_failed = true;
|
||||
return false;
|
||||
@ -1179,7 +1180,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
|
||||
if(!prevalidate_miner_transaction(b, bei.height))
|
||||
{
|
||||
LOG_PRINT_RED_L1("Block with id: " << epee::string_tools::pod_to_hex(id)
|
||||
<< " (as alternative) have wrong miner transaction.");
|
||||
<< " (as alternative) has incorrect miner transaction.");
|
||||
bvc.m_verifivation_failed = true;
|
||||
return false;
|
||||
|
||||
@ -1270,7 +1271,7 @@ bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list<block
|
||||
{
|
||||
std::list<crypto::hash> missed_ids;
|
||||
get_transactions(blk.tx_hashes, txs, missed_ids);
|
||||
CHECK_AND_ASSERT_MES(!missed_ids.size(), false, "have missed transactions in own block in main blockchain");
|
||||
CHECK_AND_ASSERT_MES(!missed_ids.size(), false, "has missed transactions in own block in main blockchain");
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -1306,7 +1307,7 @@ bool Blockchain::handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NO
|
||||
std::list<crypto::hash> missed_tx_id;
|
||||
std::list<transaction> txs;
|
||||
get_transactions(bl.tx_hashes, txs, rsp.missed_ids);
|
||||
CHECK_AND_ASSERT_MES(!missed_tx_id.size(), false, "Internal error: have missed missed_tx_id.size()=" << missed_tx_id.size()
|
||||
CHECK_AND_ASSERT_MES(!missed_tx_id.size(), false, "Internal error: has missed missed_tx_id.size()=" << missed_tx_id.size()
|
||||
<< std::endl << "for block id = " << get_block_hash(bl));
|
||||
rsp.blocks.push_back(block_complete_entry());
|
||||
block_complete_entry& e = rsp.blocks.back();
|
||||
@ -1574,7 +1575,7 @@ void Blockchain::print_blockchain(uint64_t start_index, uint64_t end_index)
|
||||
auto h = m_db->height();
|
||||
if(start_index > h)
|
||||
{
|
||||
LOG_PRINT_L0("Wrong starter index set: " << start_index << ", expected max index " << h);
|
||||
LOG_PRINT_L1("Wrong starter index set: " << start_index << ", expected max index " << h);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1697,7 +1698,7 @@ bool Blockchain::add_block_as_invalid(const block_extended_info& bei, const cryp
|
||||
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");
|
||||
LOG_PRINT_L0("BLOCK ADDED AS INVALID: " << h << std::endl << ", prev_id=" << bei.bl.prev_id << ", m_invalid_blocks count=" << m_invalid_blocks.size());
|
||||
LOG_PRINT_L1("BLOCK ADDED AS INVALID: " << h << std::endl << ", prev_id=" << bei.bl.prev_id << ", m_invalid_blocks count=" << m_invalid_blocks.size());
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
@ -1868,10 +1869,10 @@ bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t* pmax_used_bloc
|
||||
// signature spending it.
|
||||
if(!check_tx_input(in_to_key, tx_prefix_hash, tx.signatures[sig_index], pmax_used_block_height))
|
||||
{
|
||||
LOG_PRINT_L0("Failed to check ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
|
||||
LOG_PRINT_L1("Failed to check ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
|
||||
if (pmax_used_block_height) // a default value of NULL is used when called from Blockchain::handle_block_to_main_chain()
|
||||
{
|
||||
LOG_PRINT_L0(" *pmax_used_block_height: " << *pmax_used_block_height);
|
||||
LOG_PRINT_L1(" *pmax_used_block_height: " << *pmax_used_block_height);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -1926,13 +1927,13 @@ bool Blockchain::check_tx_input(const txin_to_key& txin, const crypto::hash& tx_
|
||||
//check tx unlock time
|
||||
if(!m_bch.is_tx_spendtime_unlocked(tx.unlock_time))
|
||||
{
|
||||
LOG_PRINT_L0("One of outputs for one of inputs have wrong tx.unlock_time = " << tx.unlock_time);
|
||||
LOG_PRINT_L1("One of outputs for one of inputs has wrong tx.unlock_time = " << tx.unlock_time);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(out.target.type() != typeid(txout_to_key))
|
||||
{
|
||||
LOG_PRINT_L0("Output have wrong type id, which=" << out.target.which());
|
||||
LOG_PRINT_L1("Output has wrong type id, which=" << out.target.which());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1947,7 +1948,7 @@ bool Blockchain::check_tx_input(const txin_to_key& txin, const crypto::hash& tx_
|
||||
outputs_visitor vi(output_keys, p_output_keys, *this);
|
||||
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_L1("Failed to get output keys for tx with amount = " << print_money(txin.amount) << " and count indexes " << txin.key_offsets.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1958,7 +1959,7 @@ bool Blockchain::check_tx_input(const txin_to_key& txin, const crypto::hash& tx_
|
||||
|
||||
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_L1("Output keys for tx with amount = " << txin.amount << " and count indexes " << txin.key_offsets.size() << " returned wrong keys count " << output_keys.size());
|
||||
return false;
|
||||
}
|
||||
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());
|
||||
@ -1983,7 +1984,7 @@ bool Blockchain::check_block_timestamp(std::vector<uint64_t>& timestamps, const
|
||||
|
||||
if(b.timestamp < median_ts)
|
||||
{
|
||||
LOG_PRINT_L0("Timestamp of block with id: " << get_block_hash(b) << ", " << b.timestamp << ", less than median of last " << BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW << " blocks, " << median_ts);
|
||||
LOG_PRINT_L1("Timestamp of block with id: " << get_block_hash(b) << ", " << b.timestamp << ", less than median of last " << BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW << " blocks, " << median_ts);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2002,7 +2003,7 @@ bool Blockchain::check_block_timestamp(const block& b) const
|
||||
LOG_PRINT_L3("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");
|
||||
LOG_PRINT_L1("Timestamp of block with id: " << get_block_hash(b) << ", " << b.timestamp << ", bigger than adjusted time + 2 hours");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2038,8 +2039,8 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
if(bl.prev_id != get_tail_id())
|
||||
{
|
||||
LOG_PRINT_L0("Block with id: " << id << std::endl
|
||||
<< "have wrong prev_id: " << bl.prev_id << std::endl
|
||||
LOG_PRINT_L1("Block with id: " << id << std::endl
|
||||
<< "has wrong prev_id: " << bl.prev_id << std::endl
|
||||
<< "expected: " << get_tail_id());
|
||||
return false;
|
||||
}
|
||||
@ -2048,8 +2049,8 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
||||
// of a set number of the most recent blocks.
|
||||
if(!check_block_timestamp(bl))
|
||||
{
|
||||
LOG_PRINT_L0("Block with id: " << id << std::endl
|
||||
<< "have invalid timestamp: " << bl.timestamp);
|
||||
LOG_PRINT_L1("Block with id: " << id << std::endl
|
||||
<< "has invalid timestamp: " << bl.timestamp);
|
||||
bvc.m_verifivation_failed = true;
|
||||
return false;
|
||||
}
|
||||
@ -2084,9 +2085,9 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
||||
// validate proof_of_work versus difficulty target
|
||||
if(!check_hash(proof_of_work, current_diffic))
|
||||
{
|
||||
LOG_PRINT_L0("Block with id: " << id << std::endl
|
||||
<< "have not enough proof of work: " << proof_of_work << std::endl
|
||||
<< "nexpected difficulty: " << current_diffic );
|
||||
LOG_PRINT_L1("Block with id: " << id << std::endl
|
||||
<< "does not have enough proof of work: " << proof_of_work << std::endl
|
||||
<< "unexpected difficulty: " << current_diffic );
|
||||
bvc.m_verifivation_failed = true;
|
||||
return false;
|
||||
}
|
||||
@ -2108,7 +2109,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
||||
// sanity check basic miner tx properties
|
||||
if(!prevalidate_miner_transaction(bl, m_db->height()))
|
||||
{
|
||||
LOG_PRINT_L0("Block with id: " << id
|
||||
LOG_PRINT_L1("Block with id: " << id
|
||||
<< " failed to pass prevalidation");
|
||||
bvc.m_verifivation_failed = true;
|
||||
return false;
|
||||
@ -2133,7 +2134,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
||||
|
||||
if (m_db->tx_exists(tx_id))
|
||||
{
|
||||
LOG_PRINT_L0("Block with id: " << id << " attempting to add transaction already in blockchain with id: " << tx_id);
|
||||
LOG_PRINT_L1("Block with id: " << id << " attempting to add transaction already in blockchain with id: " << tx_id);
|
||||
bvc.m_verifivation_failed = true;
|
||||
break;
|
||||
}
|
||||
@ -2141,7 +2142,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
||||
// get transaction with hash <tx_id> from tx_pool
|
||||
if(!m_tx_pool.take_tx(tx_id, tx, blob_size, fee))
|
||||
{
|
||||
LOG_PRINT_L0("Block with id: " << id << "have at least one unknown transaction with id: " << tx_id);
|
||||
LOG_PRINT_L1("Block with id: " << id << " has at least one unknown transaction with id: " << tx_id);
|
||||
bvc.m_verifivation_failed = true;
|
||||
break;
|
||||
}
|
||||
@ -2154,11 +2155,11 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
||||
// validate that transaction inputs and the keys spending them are correct.
|
||||
if(!check_tx_inputs(tx))
|
||||
{
|
||||
LOG_PRINT_L0("Block with id: " << id << "have at least one transaction (id: " << tx_id << ") with wrong inputs.");
|
||||
LOG_PRINT_L1("Block with id: " << id << " has at least one transaction (id: " << tx_id << ") with wrong inputs.");
|
||||
|
||||
//TODO: why is this done? make sure that keeping invalid blocks makes sense.
|
||||
add_block_as_invalid(bl, id);
|
||||
LOG_PRINT_L0("Block with id " << id << " added as invalid becouse of wrong inputs in transactions");
|
||||
LOG_PRINT_L1("Block with id " << id << " added as invalid becouse of wrong inputs in transactions");
|
||||
bvc.m_verifivation_failed = true;
|
||||
break;
|
||||
}
|
||||
@ -2178,8 +2179,8 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
||||
uint64_t already_generated_coins = m_db->height() ? m_db->get_block_already_generated_coins(m_db->height() - 1) : 0;
|
||||
if(!validate_miner_transaction(bl, cumulative_block_size, fee_summary, base_reward, already_generated_coins))
|
||||
{
|
||||
LOG_PRINT_L0("Block with id: " << id
|
||||
<< " have wrong miner transaction");
|
||||
LOG_PRINT_L1("Block with id: " << id
|
||||
<< " has incorrect miner transaction");
|
||||
bvc.m_verifivation_failed = true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user