Fixes segfault in Blockchain::handle_alternative_block

This commit should fix the segfault in
Blockchain::handle_alternative_block, and also updates a few comments
that were either incorrect or incomplete.
This commit is contained in:
Thomas Winget 2015-01-09 05:56:51 -05:00
parent 5086ca1db5
commit 14555eefd5
No known key found for this signature in database
GPG Key ID: 58131A160789E630
2 changed files with 12 additions and 6 deletions

View File

@ -1072,13 +1072,14 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
uint64_t block_height = get_block_height(b);
if(0 == block_height)
{
LOG_ERROR("Block with id: " << epee::string_tools::pod_to_hex(id) << " (as alternative) have wrong miner transaction");
LOG_ERROR("Block with id: " << epee::string_tools::pod_to_hex(id) << " (as alternative), but miner tx says height is 0.");
bvc.m_verifivation_failed = true;
return false;
}
// TODO: this basically says if the blockchain is smaller than the first
// checkpoint then alternate blocks are allowed...this seems backwards, but
// I'm not sure. Needs further investigating.
// this basically says if the blockchain is smaller than the first
// checkpoint then alternate blocks are allowed. Alternatively, if the
// last checkpoint *before* the end of the current chain is also before
// the block to be added, then this is fine.
if (!m_checkpoints.is_alternative_block_allowed(get_current_blockchain_height(), block_height))
{
LOG_PRINT_RED_L0("Block with id: " << id
@ -1187,7 +1188,8 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
// FIXME:
// this brings up an interesting point: consider allowing to get block
// difficulty both by height OR by hash, not just height.
bei.cumulative_difficulty = alt_chain.size() ? it_prev->second.cumulative_difficulty : m_db->get_block_cumulative_difficulty(m_db->get_block_height(b.prev_id));
auto main_chain_cumulative_difficulty = m_db->get_block_cumulative_difficulty(m_db->get_block_height(b.prev_id));
bei.cumulative_difficulty = alt_chain.size() ? it_prev->second.cumulative_difficulty : main_chain_cumulative_difficulty;
bei.cumulative_difficulty += current_diff;
// add block to alternate blocks storage,
@ -1210,7 +1212,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
return r;
}
else if(m_blocks.back().cumulative_difficulty < bei.cumulative_difficulty) //check if difficulty bigger then in main chain
else if(main_chain_cumulative_difficulty < bei.cumulative_difficulty) //check if difficulty bigger then in main chain
{
//do reorganize!
LOG_PRINT_GREEN("###### REORGANIZE on height: "

View File

@ -84,6 +84,10 @@ namespace cryptonote
return check_block(height, h, ignored);
}
//---------------------------------------------------------------------------
// this basically says if the blockchain is smaller than the first
// checkpoint then alternate blocks are allowed. Alternatively, if the
// last checkpoint *before* the end of the current chain is also before
// the block to be added, then this is fine.
bool checkpoints::is_alternative_block_allowed(uint64_t blockchain_height, uint64_t block_height) const
{
if (0 == block_height)