aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorwarptangent <warptangent@inbox.com>2015-01-11 18:46:08 -0800
committerwarptangent <warptangent@inbox.com>2015-01-11 21:23:02 -0800
commit63051bea1c5f37b922a50af444e039d5ea33c09d (patch)
tree7dbf6c645d117041c571e80f3d713fedd12ff680 /src
parentRemove a have_block() check so alternate block can be processed (diff)
downloadmonero-63051bea1c5f37b922a50af444e039d5ea33c09d.tar.xz
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.
Diffstat (limited to 'src')
-rw-r--r--src/cryptonote_core/blockchain.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 7015383fa..c052e3944 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -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,