diff --git a/src/side_chain.cpp b/src/side_chain.cpp index f037ccd..6ec6f6e 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -1724,7 +1724,7 @@ PoolBlock* SideChain::get_parent(const PoolBlock* block) const return nullptr; } -bool SideChain::is_longer_chain(const PoolBlock* block, const PoolBlock* candidate, bool& is_alternative) +bool SideChain::is_longer_chain(const PoolBlock* block, const PoolBlock* candidate, bool& is_alternative) const { is_alternative = false; @@ -1834,7 +1834,11 @@ bool SideChain::is_longer_chain(const PoolBlock* block, const PoolBlock* candida void SideChain::update_depths(PoolBlock* block) { for (size_t i = 1; i <= UNCLE_BLOCK_DEPTH; ++i) { - for (PoolBlock* child : m_blocksByHeight[block->m_sidechainHeight + i]) { + auto it = m_blocksByHeight.find(block->m_sidechainHeight + i); + if (it == m_blocksByHeight.end()) { + continue; + } + for (PoolBlock* child : it->second) { if (child->m_parent == block->m_sidechainId) { if (i != 1) { LOGERR(1, "m_blocksByHeight is inconsistent with child->m_parent. Fix the code!"); @@ -1844,8 +1848,7 @@ void SideChain::update_depths(PoolBlock* block) } } - auto it = std::find(child->m_uncles.begin(), child->m_uncles.end(), block->m_sidechainId); - if (it != child->m_uncles.end()) { + if (std::find(child->m_uncles.begin(), child->m_uncles.end(), block->m_sidechainId) != child->m_uncles.end()) { block->m_depth = std::max(block->m_depth, child->m_depth + i); } } diff --git a/src/side_chain.h b/src/side_chain.h index 395839c..4cda4f2 100644 --- a/src/side_chain.h +++ b/src/side_chain.h @@ -99,7 +99,7 @@ private: PoolBlock* get_parent(const PoolBlock* block) const; // Checks if "candidate" has longer (higher difficulty) chain than "block" - bool is_longer_chain(const PoolBlock* block, const PoolBlock* candidate, bool& is_alternative); + bool is_longer_chain(const PoolBlock* block, const PoolBlock* candidate, bool& is_alternative) const; void update_depths(PoolBlock* block); void prune_old_blocks();