Fixed cppcheck errors

This commit is contained in:
SChernykh 2023-03-06 14:52:47 +01:00
parent 4741880044
commit 1b5860eec8
2 changed files with 8 additions and 5 deletions

View file

@ -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);
}
}

View file

@ -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();