Disconnect peers with version < 70212 after DIP3 activation via BIP9 (#2497)

* Disconnect peers with version < 70212 after DIP3 activation via BIP9

* Send REJECT and log when diconnecting peers after DIP3 activation
This commit is contained in:
Alexander Block 2018-11-26 16:23:17 +01:00 committed by GitHub
parent c248c48e4d
commit a18ca49a22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -1340,6 +1340,19 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
return true; return true;
} }
// BEGIN TEMPORARY CODE
bool fDIP0003Active;
{
LOCK(cs_main);
fDIP0003Active = VersionBitsState(chainActive.Tip(), chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) == THRESHOLD_ACTIVE;
}
// TODO delete this in next release after v13
int nMinPeerProtoVersion = MIN_PEER_PROTO_VERSION;
if (fDIP0003Active) {
nMinPeerProtoVersion = MIN_PEER_PROTO_VERSION_DIP3;
}
// END TEMPORARY CODE
if (!(pfrom->GetLocalServices() & NODE_BLOOM) && if (!(pfrom->GetLocalServices() & NODE_BLOOM) &&
(strCommand == NetMsgType::FILTERLOAD || (strCommand == NetMsgType::FILTERLOAD ||
strCommand == NetMsgType::FILTERADD)) strCommand == NetMsgType::FILTERADD))
@ -1418,12 +1431,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
return false; return false;
} }
if (nVersion < MIN_PEER_PROTO_VERSION) if (nVersion < nMinPeerProtoVersion)
{ {
// disconnect from peers older than this proto version // disconnect from peers older than this proto version
LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, nVersion); LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, nVersion);
connman.PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, strCommand, REJECT_OBSOLETE, connman.PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, strCommand, REJECT_OBSOLETE,
strprintf("Version must be %d or greater", MIN_PEER_PROTO_VERSION))); strprintf("Version must be %d or greater", nMinPeerProtoVersion)));
pfrom->fDisconnect = true; pfrom->fDisconnect = true;
return false; return false;
} }
@ -1564,6 +1577,17 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
// At this point, the outgoing message serialization version can't change. // At this point, the outgoing message serialization version can't change.
const CNetMsgMaker msgMaker(pfrom->GetSendVersion()); const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
// BEGIN TEMPORARY CODE
if (pfrom->nVersion < nMinPeerProtoVersion) {
// disconnect from peers with version < 70212 after DIP3 has activated through the BIP9 deployment
LogPrintf("peer=%d using obsolete version %i after DIP3 activation; disconnecting\n", pfrom->id, pfrom->GetSendVersion());
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::REJECT, strCommand, REJECT_OBSOLETE,
strprintf("Version must be %d or greater", nMinPeerProtoVersion)));
pfrom->fDisconnect = true;
return false;
}
// END TEMPORARY CODE
if (strCommand == NetMsgType::VERACK) if (strCommand == NetMsgType::VERACK)
{ {
pfrom->SetRecvVersion(std::min(pfrom->nVersion.load(), PROTOCOL_VERSION)); pfrom->SetRecvVersion(std::min(pfrom->nVersion.load(), PROTOCOL_VERSION));

View File

@ -22,6 +22,9 @@ static const int GETHEADERS_VERSION = 70077;
//! disconnect from peers older than this proto version //! disconnect from peers older than this proto version
static const int MIN_PEER_PROTO_VERSION = 70210; static const int MIN_PEER_PROTO_VERSION = 70210;
//! disconnect from peers older than this proto version when DIP3 is activated via the BIP9 deployment
static const int MIN_PEER_PROTO_VERSION_DIP3 = 70212;
//! nTime field added to CAddress, starting with this version; //! nTime field added to CAddress, starting with this version;
//! if possible, avoid requesting addresses nodes older than this //! if possible, avoid requesting addresses nodes older than this
static const int CADDR_TIME_VERSION = 31402; static const int CADDR_TIME_VERSION = 31402;