Skip to content

Commit 9605099

Browse files
committed
Prepare to drop legacy fields from version message
Early in its life, Gridcoin added some fields to CNode for the legacy research reward system. The design of the code that used these fields had security and privacy issues so later changes set the fields to an empty string. This commit prepares nodes for the removal of fields in legacy "version" messages in the release that will follow the pending mandatory version.
1 parent a470c81 commit 9605099

File tree

2 files changed

+50
-28
lines changed

2 files changed

+50
-28
lines changed

src/main.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,17 +4427,22 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
44274427
CAddress addrMe;
44284428
CAddress addrFrom;
44294429
uint64_t nNonce = 1;
4430-
std::string legacy_dummy;
4431-
4432-
vRecv >> pfrom->nVersion
4433-
>> legacy_dummy // pfrom->boinchashnonce
4434-
>> legacy_dummy // pfrom->boinchashpw
4435-
>> legacy_dummy // pfrom->cpid
4436-
>> legacy_dummy // pfrom->enccpid
4437-
>> legacy_dummy // acid
4438-
>> pfrom->nServices
4439-
>> nTime
4440-
>> addrMe;
4430+
4431+
vRecv >> pfrom->nVersion;
4432+
4433+
// In the version following 180324 (mandatory v5.0.0 - Fern), we can finally
4434+
// drop the garbage legacy fields added to the version message:
4435+
//
4436+
if (pfrom->nVersion <= 180324) {
4437+
std::string legacy_dummy;
4438+
vRecv >> legacy_dummy // pfrom->boinchashnonce
4439+
>> legacy_dummy // pfrom->boinchashpw
4440+
>> legacy_dummy // pfrom->cpid
4441+
>> legacy_dummy // pfrom->enccpid
4442+
>> legacy_dummy; // acid
4443+
}
4444+
4445+
vRecv >> pfrom->nServices >> nTime >> addrMe;
44414446

44424447
LogPrint(BCLog::LogFlags::NOISY, "received aries version %i ...", pfrom->nVersion);
44434448

@@ -4463,15 +4468,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
44634468
vRecv >> addrFrom >> nNonce;
44644469
if (!vRecv.empty())
44654470
vRecv >> pfrom->strSubVer;
4466-
44674471
if (!vRecv.empty())
44684472
vRecv >> pfrom->nStartingHeight;
4473+
44694474
// 12-5-2015 - Append Trust fields
44704475
pfrom->nTrust = 0;
44714476

4472-
if (!vRecv.empty()) vRecv >> legacy_dummy; // pfrom->sGRCAddress;
4473-
4474-
44754477
// Allow newbies to connect easily with 0 blocks
44764478
if (GetArgument("autoban","true") == "true")
44774479
{

src/net.cpp

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -722,19 +722,39 @@ void CNode::PushVersion()
722722
LogPrint(BCLog::LogFlags::NOISY, "send version message: version %d, blocks=%d, us=%s, them=%s, peer=%s",
723723
PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), addrYou.ToString(), addr.ToString());
724724

725-
std::string sboinchashargs;
726-
std::string nonce;
727-
std::string pw1;
728-
std::string mycpid;
729-
std::string acid;
730-
731-
//TODO: change `PushMessage()` to use ServiceFlags so we don't need to cast nLocalServices
732-
PushMessage("aries", PROTOCOL_VERSION, nonce, pw1,
733-
mycpid, mycpid, acid, (uint64_t) nLocalServices, nTime, addrYou, addrMe,
734-
nLocalHostNonce, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>()),
735-
nBestHeight);
736-
737-
725+
// In the version following 180324 (mandatory v5.0.0 - Fern), we can finally
726+
// drop the garbage legacy fields added to the version message:
727+
//
728+
if (PROTOCOL_VERSION > 180324) {
729+
//TODO: change `PushMessage()` to use ServiceFlags so we don't need to cast nLocalServices
730+
PushMessage(
731+
"aries",
732+
PROTOCOL_VERSION,
733+
(uint64_t)nLocalServices,
734+
nTime,
735+
addrYou,
736+
addrMe,
737+
nLocalHostNonce,
738+
FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>()),
739+
nBestHeight);
740+
} else {
741+
const std::string legacy_dummy;
742+
PushMessage(
743+
"aries",
744+
PROTOCOL_VERSION,
745+
legacy_dummy, // nonce
746+
legacy_dummy, // pw1
747+
legacy_dummy, // mycpid
748+
legacy_dummy, // enccpid
749+
legacy_dummy, // acid
750+
(uint64_t)nLocalServices,
751+
nTime,
752+
addrYou,
753+
addrMe,
754+
nLocalHostNonce,
755+
FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>()),
756+
nBestHeight);
757+
}
738758
}
739759

740760
bool CNode::Misbehaving(int howmuch)

0 commit comments

Comments
 (0)