mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 11:23:26 +01:00
Fix comparison between main and alternate chain's cumulative
difficulty. This fixes the continual reorganization between a main and alternate chain, using the same two latest blocks from each. The check that cumulative difficulty of the alternate chain is bigger than main's was not using main's last block, but incorrectly using the passed-in block's previous block. main_chain_cumulative_difficulty was being used in two different ways. This has been split up to keep use of main_chain_cumulative_difficulty consistent.
This commit is contained in:
parent
909ea81067
commit
63051bea1c
@ -1188,8 +1188,16 @@ 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.
|
||||
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;
|
||||
difficulty_type main_chain_cumulative_difficulty = m_db->get_block_cumulative_difficulty(m_db->height() - 1);
|
||||
if (alt_chain.size())
|
||||
{
|
||||
bei.cumulative_difficulty = it_prev->second.cumulative_difficulty;
|
||||
}
|
||||
else
|
||||
{
|
||||
// passed-in block's previous block's cumulative difficulty, found on the main chain
|
||||
bei.cumulative_difficulty = m_db->get_block_cumulative_difficulty(m_db->get_block_height(b.prev_id));
|
||||
}
|
||||
bei.cumulative_difficulty += current_diff;
|
||||
|
||||
// add block to alternate blocks storage,
|
||||
|
Loading…
Reference in New Issue
Block a user