Commit 63ead324 authored by Tom Bradshaw's avatar Tom Bradshaw
Browse files

Make MasternodePing serialization compatible with old and new protocols.

parent 7cdb6b49
Pipeline #942 failed with stage
in 1 minute and 13 seconds
Showing with 36 additions and 20 deletions
+36 -20
......@@ -2172,7 +2172,7 @@ bool CheckBlockProofPointer(const CBlockIndex* pindex, const CBlock& block, CPub
return error("%s: Stake pointer from height %d is too recent", __func__, pindexFrom->nHeight);
//No stakepointers from budgetblocks
if (budget.IsBudgetPaymentBlock(pindexFrom->nHeight))
if (GetAdjustedTime() - block.GetBlockTime() < 24*60*60 && budget.IsBudgetPaymentBlock(pindexFrom->nHeight))
return error("%s: Stake pointers cannot be from budget blocks", __func__);
//Ensure that this stake pointer is not already used by another block in the chain
......@@ -4609,30 +4609,36 @@ void static ProcessGetData(CNode* pfrom)
if (!pushed && inv.type == MSG_MASTERNODE_ANNOUNCE) {
if(mnodeman.mapSeenMasternodeBroadcast.count(inv.hash)) {
int nVersionSend = PROTOCOL_VERSION;
auto mnb = mnodeman.mapSeenMasternodeBroadcast[inv.hash];
std::string strCommand = "mnb_new";
if (pfrom->nVersion < MIN_MNW_PING_VERSION) {
//Make sure this serializes to a format that is readable by the peer we are sending to
nVersionSend = MIN_MNW_PING_VERSION - 1;
mnb.lastPing.nVersion = 1;
}
CDataStream ss(SER_NETWORK, nVersionSend);
if (mnb.lastPing.nVersion == 1)
strCommand = "mnb";
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << mnodeman.mapSeenMasternodeBroadcast[inv.hash];
pfrom->PushMessage("mnb", ss);
ss << mnb;
pfrom->PushMessage(strCommand.c_str(), ss);
pushed = true;
}
}
if (!pushed && inv.type == MSG_MASTERNODE_PING) {
if(mnodeman.mapSeenMasternodePing.count(inv.hash)){
int nVersionSend = PROTOCOL_VERSION;
auto mnp = mnodeman.mapSeenMasternodePing[inv.hash];
std::string strCommand = "mnp_new";
if (pfrom->nVersion < MIN_MNW_PING_VERSION) {
//Make sure this serializes to a format that is readable by the peer we are sending to
nVersionSend = MIN_MNW_PING_VERSION - 1;
mnp.nVersion = 1;
}
CDataStream ss(SER_NETWORK, nVersionSend);
if (mnp.nVersion == 1)
strCommand = "mnp";
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << mnodeman.mapSeenMasternodePing[inv.hash];
pfrom->PushMessage("mnp", ss);
ss << mnp;
pfrom->PushMessage(strCommand.c_str(), ss);
pushed = true;
}
}
......@@ -4718,8 +4724,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
CAddress addrFrom;
uint64_t nNonce = 1;
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
vRecv.nVersion = pfrom->nVersion;
if (pfrom->nVersion != PROTOCOL_VERSION)
if (pfrom->nVersion < MinPeerProtoVersion())
{
// disconnect from peers older than this proto version
LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion);
......
......@@ -1237,6 +1237,7 @@ bool CBudgetManager::SubmitProposalVote(const CBudgetVote& vote, std::string& st
mapSeenMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), vote));
return true;
}
return false;
}
bool CBudgetManager::CanSubmitVotes(int blockStart, int blockEnd)
......
......@@ -911,7 +911,7 @@ bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled, bool fChec
if (this->nVersion > 1) {
for (const uint256& hashBlock : vPrevBlockHash) {
LogPrintf("%s:*************8********** adding witness for block %s\n", __func__, hashBlock.GetHex());
LogPrint("masternode", "%s: Adding witness for block %s from mn %s\n", __func__, hashBlock.GetHex(), vin.ToString());
g_proofTracker->AddWitness(BlockWitness(pmn->vin, hashBlock));
}
}
......
......@@ -64,8 +64,8 @@ public:
READWRITE(sigTime);
READWRITE(vchSig);
//New versioning signalled comes through protocol version passed to datastream
if (nVersion >= MIN_MNW_PING_VERSION) {
//New versioning is set externally before serialization
if (this->nVersion >= 2) {
READWRITE(this->nVersion);
READWRITE(vPrevBlockHash);
READWRITE(vchSigPrevBlocks);
......
......@@ -537,8 +537,14 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
LOCK(cs_process_message);
if (strCommand == "mnb") { //Masternode Broadcast
if (strCommand == "mnb" || strCommand == "mnb_new") { //Masternode Broadcast
CMasternodeBroadcast mnb;
if (strCommand == "mnb") {
//Set to old version for old serialization
mnb.lastPing.nVersion = 1;
} else {
mnb.lastPing.nVersion = 2;
}
vRecv >> mnb;
int nDoS = 0;
......@@ -550,8 +556,12 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
}
}
else if (strCommand == "mnp") { //Masternode Ping
else if (strCommand == "mnp" || strCommand == "mnp_new") { //Masternode Ping
CMasternodePing mnp;
if (strCommand == "mnp") {
//Set to old version for old serialization
mnp.nVersion = 1;
}
vRecv >> mnp;
LogPrint("masternode", "mnp - Masternode ping, vin: %s\n", mnp.vin.ToString());
......
......@@ -9,7 +9,7 @@
/**
* network protocol versioning
*/
static const int PROTOCOL_VERSION = 71058;
static const int PROTOCOL_VERSION = 71059;
static const int PROTOCOL_POS_START = 71057;
//! initial proto version, to be increased after version/verack negotiation
......@@ -29,7 +29,7 @@ static const int MIN_BUDGET_PEER_PROTO_VERSION = PROTOCOL_POS_START;
static const int MIN_MNW_PEER_PROTO_VERSION = PROTOCOL_POS_START;
//! minimum version to get version 2 masternode ping messages
static const int MIN_MNW_PING_VERSION = 71058;
static const int MIN_MNW_PING_VERSION = 71059;
//! minimum peer version that can receive masternode payments
// V1 - Last protocol version before update
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment