mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-30 06:43:28 +01:00
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:
parent
5086ca1db5
commit
14555eefd5
@ -1072,13 +1072,14 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
|
|||||||
uint64_t block_height = get_block_height(b);
|
uint64_t block_height = get_block_height(b);
|
||||||
if(0 == block_height)
|
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;
|
bvc.m_verifivation_failed = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// TODO: this basically says if the blockchain is smaller than the first
|
// this basically says if the blockchain is smaller than the first
|
||||||
// checkpoint then alternate blocks are allowed...this seems backwards, but
|
// checkpoint then alternate blocks are allowed. Alternatively, if the
|
||||||
// I'm not sure. Needs further investigating.
|
// 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))
|
if (!m_checkpoints.is_alternative_block_allowed(get_current_blockchain_height(), block_height))
|
||||||
{
|
{
|
||||||
LOG_PRINT_RED_L0("Block with id: " << id
|
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:
|
// FIXME:
|
||||||
// this brings up an interesting point: consider allowing to get block
|
// this brings up an interesting point: consider allowing to get block
|
||||||
// difficulty both by height OR by hash, not just height.
|
// 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;
|
bei.cumulative_difficulty += current_diff;
|
||||||
|
|
||||||
// add block to alternate blocks storage,
|
// add block to alternate blocks storage,
|
||||||
@ -1210,7 +1212,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
|
|||||||
|
|
||||||
return r;
|
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!
|
//do reorganize!
|
||||||
LOG_PRINT_GREEN("###### REORGANIZE on height: "
|
LOG_PRINT_GREEN("###### REORGANIZE on height: "
|
||||||
|
@ -84,6 +84,10 @@ namespace cryptonote
|
|||||||
return check_block(height, h, ignored);
|
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
|
bool checkpoints::is_alternative_block_allowed(uint64_t blockchain_height, uint64_t block_height) const
|
||||||
{
|
{
|
||||||
if (0 == block_height)
|
if (0 == block_height)
|
||||||
|
Loading…
Reference in New Issue
Block a user