mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-08-19 21:18:46 -06:00
SideChain: faster check for low-diff spam blocks
This commit is contained in:
parent
113e39817d
commit
806e1ca0a3
@ -370,7 +370,7 @@ bool SideChain::add_external_block(PoolBlock& block, std::vector<hash>& missing_
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
difficulty_type min_accepted_diff;
|
bool too_low_diff = (block.m_difficulty < m_curDifficulty);
|
||||||
{
|
{
|
||||||
MutexLock lock(m_sidechainLock);
|
MutexLock lock(m_sidechainLock);
|
||||||
if (m_blocksById.find(block.m_sidechainId) != m_blocksById.end()) {
|
if (m_blocksById.find(block.m_sidechainId) != m_blocksById.end()) {
|
||||||
@ -378,23 +378,25 @@ bool SideChain::add_external_block(PoolBlock& block, std::vector<hash>& missing_
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the minimum difficulty in the current PPLNS window
|
// This is mainly an anti-spam measure, not an actual verification step
|
||||||
min_accepted_diff = m_curDifficulty;
|
if (too_low_diff) {
|
||||||
for (PoolBlock* tmp = m_chainTip; tmp && (tmp->m_sidechainHeight + m_chainWindowSize > m_chainTip->m_sidechainHeight); tmp = get_parent(tmp)) {
|
// Reduce required diff by 50% (by doubling this block's diff) to account for alternative chains
|
||||||
if (tmp->m_difficulty < min_accepted_diff) {
|
difficulty_type diff2 = block.m_difficulty;
|
||||||
min_accepted_diff = tmp->m_difficulty;
|
diff2 += block.m_difficulty;
|
||||||
|
|
||||||
|
for (PoolBlock* tmp = m_chainTip; tmp && (tmp->m_sidechainHeight + m_chainWindowSize > m_chainTip->m_sidechainHeight); tmp = get_parent(tmp)) {
|
||||||
|
if (diff2 >= tmp->m_difficulty) {
|
||||||
|
too_low_diff = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGINFO(4, "add_external_block: height = " << block.m_sidechainHeight << ", id = " << block.m_sidechainId << ", mainchain height = " << block.m_txinGenHeight);
|
LOGINFO(4, "add_external_block: height = " << block.m_sidechainHeight << ", id = " << block.m_sidechainId << ", mainchain height = " << block.m_txinGenHeight);
|
||||||
|
|
||||||
// Reduce it by 50% to account for alternative chains. This is mainly an anti-spam measure, not an actual verification step
|
if (too_low_diff) {
|
||||||
min_accepted_diff.lo = (min_accepted_diff.lo >> 1) | (min_accepted_diff.hi << 63);
|
LOGWARN(4, "add_external_block: block has too low difficulty " << block.m_difficulty << ", expected >= ~" << m_curDifficulty << ". Ignoring it.");
|
||||||
min_accepted_diff.hi >>= 1;
|
|
||||||
|
|
||||||
if (block.m_difficulty < min_accepted_diff) {
|
|
||||||
LOGWARN(4, "add_external_block: block has too low difficulty " << block.m_difficulty << ", expected >= " << min_accepted_diff << ". Ignoring it.");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user