net: Check against the next epoch's version when evicting peers
This commit is contained in:
12
src/net.cpp
12
src/net.cpp
@@ -820,15 +820,18 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Consensus::Params& params = Params().GetConsensus();
|
const Consensus::Params& params = Params().GetConsensus();
|
||||||
int nActivationHeight = params.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight;
|
auto nextEpoch = NextEpoch(height, params);
|
||||||
|
if (nextEpoch) {
|
||||||
|
auto idx = nextEpoch.get();
|
||||||
|
int nActivationHeight = params.vUpgrades[idx].nActivationHeight;
|
||||||
|
|
||||||
if (nActivationHeight > 0 &&
|
if (nActivationHeight > 0 &&
|
||||||
height < nActivationHeight &&
|
height < nActivationHeight &&
|
||||||
height >= nActivationHeight - NETWORK_UPGRADE_PEER_PREFERENCE_BLOCK_PERIOD)
|
height >= nActivationHeight - NETWORK_UPGRADE_PEER_PREFERENCE_BLOCK_PERIOD)
|
||||||
{
|
{
|
||||||
// Find any nodes which don't support Overwinter protocol version
|
// Find any nodes which don't support the protocol version for the next upgrade
|
||||||
BOOST_FOREACH(const CNodeRef &node, vEvictionCandidates) {
|
for (const CNodeRef &node : vEvictionCandidates) {
|
||||||
if (node->nVersion < params.vUpgrades[Consensus::UPGRADE_SAPLING].nProtocolVersion) {
|
if (node->nVersion < params.vUpgrades[idx].nProtocolVersion) {
|
||||||
vTmpEvictionCandidates.push_back(node);
|
vTmpEvictionCandidates.push_back(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -838,6 +841,7 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
|
|||||||
vEvictionCandidates = vTmpEvictionCandidates;
|
vEvictionCandidates = vTmpEvictionCandidates;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Deterministically select 4 peers to protect by netgroup.
|
// Deterministically select 4 peers to protect by netgroup.
|
||||||
// An attacker cannot predict which netgroups will be protected.
|
// An attacker cannot predict which netgroups will be protected.
|
||||||
|
|||||||
Reference in New Issue
Block a user