From a07dee477ee0d139d0b3167a473132305b84d451 Mon Sep 17 00:00:00 2001 From: Fuzzbawls Date: Sat, 28 Mar 2020 02:31:02 -0700 Subject: [PATCH] [Cleanup] Remove redundant and unused code `SPORK_10_MASTERNODE_PAY_UPDATED_NODES` has remained active for the past 3+ years through multiple protocol updates and was largely already deprecated at the time we code-forked from DASH. Since the masternode broadcast message was introduced, the only remaining practical use of SPORK_10 was a redundant if/else that this PR removes. Additionally, since the masternode broadcast message was introduced, we no longer need to continue supporting the already deprecated `dsee` and `dseep` network messages, which were themselves only ever used when SPORK_10 was inactive. --- src/activemasternode.cpp | 70 --------- src/masternode-payments.cpp | 5 +- src/masternode.cpp | 4 - src/masternode.h | 3 - src/masternodeman.cpp | 280 ------------------------------------ src/spork.cpp | 1 - src/sporkid.h | 1 - 7 files changed, 1 insertion(+), 363 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 6b29adc71447..6499a040de13 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -199,38 +199,6 @@ bool CActiveMasternode::SendMasternodePing(std::string& errorMessage) mnp.Relay(); - /* - * IT'S SAFE TO REMOVE THIS IN FURTHER VERSIONS - * AFTER MIGRATION TO V12 IS DONE - */ - - if (sporkManager.IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return true; - // for migration purposes ping our node on old masternodes network too - std::string retErrorMessage; - std::vector vchMasterNodeSignature; - int64_t masterNodeSignatureTime = GetAdjustedTime(); - - std::string strMessage = service.ToString() + std::to_string(masterNodeSignatureTime) + std::to_string(false); - - if (!CMessageSigner::SignMessage(strMessage, vchMasterNodeSignature, keyMasternode)) { - errorMessage = "dseep sign message failed."; - return false; - } - - if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchMasterNodeSignature, strMessage, retErrorMessage)) { - errorMessage = "dseep verify message failed: " + retErrorMessage; - return false; - } - - LogPrint("masternode", "dseep - relaying from active mn, %s \n", vin.ToString().c_str()); - LOCK(cs_vNodes); - for (CNode* pnode : vNodes) - pnode->PushMessage("dseep", vin, vchMasterNodeSignature, masterNodeSignatureTime, false); - - /* - * END OF "REMOVE" - */ - return true; } else { // Seems like we are trying to send a ping while the Masternode is not registered in the network @@ -307,44 +275,6 @@ bool CActiveMasternode::CreateBroadcast(CTxIn vin, CService service, CKey keyCol return false; } - /* - * IT'S SAFE TO REMOVE THIS IN FURTHER VERSIONS - * AFTER MIGRATION TO V12 IS DONE - */ - - if (sporkManager.IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return true; - // for migration purposes inject our node in old masternodes' list too - std::string retErrorMessage; - std::vector vchMasterNodeSignature; - int64_t masterNodeSignatureTime = GetAdjustedTime(); - std::string donationAddress = ""; - int donationPercantage = 0; - - std::string vchPubKey(pubKeyCollateralAddress.begin(), pubKeyCollateralAddress.end()); - std::string vchPubKey2(pubKeyMasternode.begin(), pubKeyMasternode.end()); - - std::string strMessage = service.ToString() + std::to_string(masterNodeSignatureTime) + vchPubKey + vchPubKey2 + std::to_string(PROTOCOL_VERSION) + donationAddress + std::to_string(donationPercantage); - - if (!CMessageSigner::SignMessage(strMessage, vchMasterNodeSignature, keyCollateralAddress)) { - errorMessage = "dsee sign message failed."; - LogPrintf("CActiveMasternode::Register() - Error: %s\n", errorMessage.c_str()); - return false; - } - - if (!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchMasterNodeSignature, strMessage, retErrorMessage)) { - errorMessage = "dsee verify message failed: " + retErrorMessage; - LogPrintf("CActiveMasternode::Register() - Error: %s\n", errorMessage.c_str()); - return false; - } - - LOCK(cs_vNodes); - for (CNode* pnode : vNodes) - pnode->PushMessage("dsee", vin, service, vchMasterNodeSignature, masterNodeSignatureTime, pubKeyCollateralAddress, pubKeyMasternode, -1, -1, masterNodeSignatureTime, PROTOCOL_VERSION, donationAddress, donationPercantage); - - /* - * END OF "REMOVE" - */ - return true; } diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 1394526b41ce..dd4f26fcbde7 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -411,10 +411,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe int CMasternodePayments::GetMinMasternodePaymentsProto() { - if (sporkManager.IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) - return ActiveProtocol(); // Allow only updated peers - else - return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT; // Also allow old peers as long as they are allowed to run + return ActiveProtocol(); } void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) diff --git a/src/masternode.cpp b/src/masternode.cpp index 776e8a29d4a0..551dbe8b0862 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -77,8 +77,6 @@ CMasternode::CMasternode() : nScanningErrorCount = 0; nLastScanningErrorBlockHeight = 0; lastTimeChecked = 0; - nLastDsee = 0; // temporary, do not save. Remove after migration to v12 - nLastDseep = 0; // temporary, do not save. Remove after migration to v12 } CMasternode::CMasternode(const CMasternode& other) : @@ -102,8 +100,6 @@ CMasternode::CMasternode(const CMasternode& other) : nScanningErrorCount = other.nScanningErrorCount; nLastScanningErrorBlockHeight = other.nLastScanningErrorBlockHeight; lastTimeChecked = 0; - nLastDsee = other.nLastDsee; // temporary, do not save. Remove after migration to v12 - nLastDseep = other.nLastDseep; // temporary, do not save. Remove after migration to v12 } uint256 CMasternode::GetSignatureHash() const diff --git a/src/masternode.h b/src/masternode.h index 13d405e28ede..adb2e4922c45 100644 --- a/src/masternode.h +++ b/src/masternode.h @@ -146,9 +146,6 @@ class CMasternode : public CSignedMessage int nLastScanningErrorBlockHeight; CMasternodePing lastPing; - int64_t nLastDsee; // temporary, do not save. Remove after migration to v12 - int64_t nLastDseep; // temporary, do not save. Remove after migration to v12 - CMasternode(); CMasternode(const CMasternode& other); diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 418baf556d26..48cf6bad2589 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -849,286 +849,6 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData LogPrint("masternode", "dseg - Sent %d Masternode entries to peer %i\n", nInvCount, pfrom->GetId()); } } - /* - * IT'S SAFE TO REMOVE THIS IN FURTHER VERSIONS - * AFTER MIGRATION TO V12 IS DONE - */ - - // Light version for OLD MASSTERNODES - fake pings, no self-activation - else if (strCommand == "dsee") { //ObfuScation Election Entry - - if (sporkManager.IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return; - - CTxIn vin; - CService addr; - CPubKey pubkey; - CPubKey pubkey2; - std::vector vchSig; - int64_t sigTime; - int count; - int current; - int64_t lastUpdated; - int protocolVersion; - CScript donationAddress; - int donationPercentage; - std::string strMessage; - - vRecv >> vin >> addr >> vchSig >> sigTime >> pubkey >> pubkey2 >> count >> current >> lastUpdated >> protocolVersion >> donationAddress >> donationPercentage; - - // make sure signature isn't in the future (past is OK) - if (sigTime > GetAdjustedTime() + 60 * 60) { - LogPrintf("CMasternodeMan::ProcessMessage() : dsee - Signature rejected, too far into the future %s\n", vin.prevout.hash.ToString()); - Misbehaving(pfrom->GetId(), 1); - return; - } - - std::string vchPubKey(pubkey.begin(), pubkey.end()); - std::string vchPubKey2(pubkey2.begin(), pubkey2.end()); - - strMessage = addr.ToString() + std::to_string(sigTime) + vchPubKey + vchPubKey2 + std::to_string(protocolVersion) + donationAddress.ToString() + std::to_string(donationPercentage); - - if (protocolVersion < masternodePayments.GetMinMasternodePaymentsProto()) { - LogPrintf("CMasternodeMan::ProcessMessage() : dsee - ignoring outdated Masternode %s protocol version %d < %d\n", vin.prevout.hash.ToString(), protocolVersion, masternodePayments.GetMinMasternodePaymentsProto()); - Misbehaving(pfrom->GetId(), 1); - return; - } - - CScript pubkeyScript; - pubkeyScript = GetScriptForDestination(pubkey.GetID()); - - if (pubkeyScript.size() != 25) { - LogPrintf("CMasternodeMan::ProcessMessage() : dsee - pubkey the wrong size\n"); - Misbehaving(pfrom->GetId(), 100); - return; - } - - CScript pubkeyScript2; - pubkeyScript2 = GetScriptForDestination(pubkey2.GetID()); - - if (pubkeyScript2.size() != 25) { - LogPrintf("CMasternodeMan::ProcessMessage() : dsee - pubkey2 the wrong size\n"); - Misbehaving(pfrom->GetId(), 100); - return; - } - - if (!vin.scriptSig.empty()) { - LogPrintf("CMasternodeMan::ProcessMessage() : dsee - Ignore Not Empty ScriptSig %s\n", vin.prevout.hash.ToString()); - Misbehaving(pfrom->GetId(), 100); - return; - } - - std::string strError = ""; - if (!CMessageSigner::VerifyMessage(pubkey, vchSig, strMessage, strError)) { - LogPrintf("CMasternodeMan::ProcessMessage() : dsee - Got bad Masternode address signature: %s\n", strError); - Misbehaving(pfrom->GetId(), 100); - return; - } - - if (Params().NetworkID() == CBaseChainParams::MAIN) { - if (addr.GetPort() != 51472) return; - } else if (addr.GetPort() == 51472) - return; - - //search existing Masternode list, this is where we update existing Masternodes with new dsee broadcasts - CMasternode* pmn = this->Find(vin); - if (pmn != NULL) { - // count == -1 when it's a new entry - // e.g. We don't want the entry relayed/time updated when we're syncing the list - // mn.pubkey = pubkey, IsVinAssociatedWithPubkey is validated once below, - // after that they just need to match - if (count == -1 && pmn->pubKeyCollateralAddress == pubkey && (GetAdjustedTime() - pmn->nLastDsee > MASTERNODE_MIN_MNB_SECONDS)) { - if (pmn->protocolVersion > GETHEADERS_VERSION && sigTime - pmn->lastPing.sigTime < MASTERNODE_MIN_MNB_SECONDS) return; - if (pmn->nLastDsee < sigTime) { //take the newest entry - LogPrint("masternode", "dsee - Got updated entry for %s\n", vin.prevout.hash.ToString()); - if (pmn->protocolVersion < GETHEADERS_VERSION) { - pmn->pubKeyMasternode = pubkey2; - pmn->sigTime = sigTime; - pmn->SetVchSig(vchSig); - pmn->protocolVersion = protocolVersion; - pmn->addr = addr; - //fake ping - pmn->lastPing = CMasternodePing(vin); - } - pmn->nLastDsee = sigTime; - pmn->Check(); - if (pmn->IsEnabled()) { - TRY_LOCK(cs_vNodes, lockNodes); - if (!lockNodes) return; - for (CNode* pnode : vNodes) - if (pnode->nVersion >= masternodePayments.GetMinMasternodePaymentsProto()) - pnode->PushMessage("dsee", vin, addr, vchSig, sigTime, pubkey, pubkey2, count, current, lastUpdated, protocolVersion, donationAddress, donationPercentage); - } - } - } - - return; - } - - static std::map mapSeenDsee; - if (mapSeenDsee.count(vin.prevout) && mapSeenDsee[vin.prevout] == pubkey) { - LogPrint("masternode", "dsee - already seen this vin %s\n", vin.prevout.ToString()); - return; - } - mapSeenDsee.insert(std::make_pair(vin.prevout, pubkey)); - // make sure the vout that was signed is related to the transaction that spawned the Masternode - // - this is expensive, so it's only done once per Masternode - if (!pmn->IsInputAssociatedWithPubkey()) { - LogPrintf("CMasternodeMan::ProcessMessage() : dsee - Got mismatched pubkey and vin\n"); - Misbehaving(pfrom->GetId(), 100); - return; - } - - - LogPrint("masternode", "dsee - Got NEW OLD Masternode entry %s\n", vin.prevout.hash.ToString()); - - // make sure it's still unspent - // - this is checked later by .check() in many places and by ThreadCheckObfuScationPool() - - CValidationState state; - CMutableTransaction tx = CMutableTransaction(); - CTxOut vout = CTxOut(9999.99 * COIN, obfuScationPool.collateralPubKey); - tx.vin.push_back(vin); - tx.vout.push_back(vout); - - bool fAcceptable = false; - { - TRY_LOCK(cs_main, lockMain); - if (!lockMain) return; - fAcceptable = AcceptableInputs(mempool, state, CTransaction(tx), false, NULL); - } - - if (fAcceptable) { - if (GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS) { - LogPrintf("CMasternodeMan::ProcessMessage() : dsee - Input must have least %d confirmations\n", MASTERNODE_MIN_CONFIRMATIONS); - Misbehaving(pfrom->GetId(), 20); - return; - } - - // verify that sig time is legit in past - // should be at least not earlier than block when 1000 PIVX tx got MASTERNODE_MIN_CONFIRMATIONS - uint256 hashBlock = UINT256_ZERO; - CTransaction tx2; - GetTransaction(vin.prevout.hash, tx2, hashBlock, true); - BlockMap::iterator mi = mapBlockIndex.find(hashBlock); - if (mi != mapBlockIndex.end() && (*mi).second) { - CBlockIndex* pMNIndex = (*mi).second; // block for 10000 PIV tx -> 1 confirmation - CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + MASTERNODE_MIN_CONFIRMATIONS - 1]; // block where tx got MASTERNODE_MIN_CONFIRMATIONS - if (pConfIndex->GetBlockTime() > sigTime) { - LogPrint("masternode","mnb - Bad sigTime %d for Masternode %s (%i conf block is at %d)\n", - sigTime, vin.prevout.hash.ToString(), MASTERNODE_MIN_CONFIRMATIONS, pConfIndex->GetBlockTime()); - return; - } - } - - // use this as a peer - addrman.Add(CAddress(addr), pfrom->addr, 2 * 60 * 60); - - // add Masternode - CMasternode mn = CMasternode(); - mn.addr = addr; - mn.vin = vin; - mn.pubKeyCollateralAddress = pubkey; - mn.SetVchSig(vchSig); - mn.sigTime = sigTime; - mn.pubKeyMasternode = pubkey2; - mn.protocolVersion = protocolVersion; - // fake ping - mn.lastPing = CMasternodePing(vin); - mn.Check(true); - // add v11 masternodes, v12 should be added by mnb only - if (protocolVersion < GETHEADERS_VERSION) { - LogPrint("masternode", "dsee - Accepted OLD Masternode entry %i %i\n", count, current); - Add(mn); - } - if (mn.IsEnabled()) { - TRY_LOCK(cs_vNodes, lockNodes); - if (!lockNodes) return; - for (CNode* pnode : vNodes) - if (pnode->nVersion >= masternodePayments.GetMinMasternodePaymentsProto()) - pnode->PushMessage("dsee", vin, addr, vchSig, sigTime, pubkey, pubkey2, count, current, lastUpdated, protocolVersion, donationAddress, donationPercentage); - } - } else { - LogPrint("masternode","dsee - Rejected Masternode entry %s\n", vin.prevout.hash.ToString()); - - int nDoS = 0; - if (state.IsInvalid(nDoS)) { - LogPrint("masternode","dsee - %s from %i %s was not accepted into the memory pool\n", tx.GetHash().ToString().c_str(), - pfrom->GetId(), pfrom->cleanSubVer.c_str()); - if (nDoS > 0) - Misbehaving(pfrom->GetId(), nDoS); - } - } - } - - else if (strCommand == "dseep") { //ObfuScation Election Entry Ping - - if (sporkManager.IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return; - - CTxIn vin; - std::vector vchSig; - int64_t sigTime; - bool stop; - vRecv >> vin >> vchSig >> sigTime >> stop; - - //LogPrint("masternode","dseep - Received: vin: %s sigTime: %lld stop: %s\n", vin.ToString().c_str(), sigTime, stop ? "true" : "false"); - - if (sigTime > GetAdjustedTime() + 60 * 60) { - LogPrintf("CMasternodeMan::ProcessMessage() : dseep - Signature rejected, too far into the future %s\n", vin.prevout.hash.ToString()); - Misbehaving(pfrom->GetId(), 1); - return; - } - - if (sigTime <= GetAdjustedTime() - 60 * 60) { - LogPrintf("CMasternodeMan::ProcessMessage() : dseep - Signature rejected, too far into the past %s - %d %d \n", vin.prevout.hash.ToString(), sigTime, GetAdjustedTime()); - Misbehaving(pfrom->GetId(), 1); - return; - } - - std::map::iterator i = mWeAskedForMasternodeListEntry.find(vin.prevout); - if (i != mWeAskedForMasternodeListEntry.end()) { - int64_t t = (*i).second; - if (GetTime() < t) return; // we've asked recently - } - - // see if we have this Masternode - CMasternode* pmn = this->Find(vin); - if (pmn != NULL && pmn->protocolVersion >= masternodePayments.GetMinMasternodePaymentsProto()) { - // LogPrint("masternode","dseep - Found corresponding mn for vin: %s\n", vin.ToString().c_str()); - // take this only if it's newer - if (sigTime - pmn->nLastDseep > MASTERNODE_MIN_MNP_SECONDS) { - std::string strMessage = pmn->addr.ToString() + std::to_string(sigTime) + std::to_string(stop); - - std::string strError = ""; - if (!CMessageSigner::VerifyMessage(pmn->pubKeyMasternode, vchSig, strMessage, strError)) { - LogPrint("masternode","dseep - Got bad Masternode address signature %s, error: %s\n", vin.prevout.hash.ToString(), strError); - //Misbehaving(pfrom->GetId(), 100); - return; - } - - // fake ping for v11 masternodes, ignore for v12 - if (pmn->protocolVersion < GETHEADERS_VERSION) pmn->lastPing = CMasternodePing(vin); - pmn->nLastDseep = sigTime; - pmn->Check(); - if (pmn->IsEnabled()) { - TRY_LOCK(cs_vNodes, lockNodes); - if (!lockNodes) return; - LogPrint("masternode", "dseep - relaying %s \n", vin.prevout.hash.ToString()); - for (CNode* pnode : vNodes) - if (pnode->nVersion >= masternodePayments.GetMinMasternodePaymentsProto()) - pnode->PushMessage("dseep", vin, vchSig, sigTime, stop); - } - } - return; - } - - LogPrint("masternode", "dseep - Couldn't find Masternode entry %s peer=%i\n", vin.prevout.hash.ToString(), pfrom->GetId()); - - AskForMN(pfrom, vin); - } - - /* - * END OF "REMOVE" - */ } void CMasternodeMan::Remove(CTxIn vin) diff --git a/src/spork.cpp b/src/spork.cpp index 6c0ec12b7b83..df79e4e7be16 100644 --- a/src/spork.cpp +++ b/src/spork.cpp @@ -19,7 +19,6 @@ std::vector sporkDefs = { MAKE_SPORK_DEF(SPORK_5_MAX_VALUE, 1000), // 1000 PIV MAKE_SPORK_DEF(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT, 4070908800ULL), // OFF MAKE_SPORK_DEF(SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT, 4070908800ULL), // OFF - MAKE_SPORK_DEF(SPORK_10_MASTERNODE_PAY_UPDATED_NODES, 0), // OFF MAKE_SPORK_DEF(SPORK_13_ENABLE_SUPERBLOCKS, 4070908800ULL), // OFF MAKE_SPORK_DEF(SPORK_14_NEW_PROTOCOL_ENFORCEMENT, 4070908800ULL), // OFF MAKE_SPORK_DEF(SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2, 4070908800ULL), // OFF diff --git a/src/sporkid.h b/src/sporkid.h index bd986f14ab4f..de504817afdc 100644 --- a/src/sporkid.h +++ b/src/sporkid.h @@ -17,7 +17,6 @@ enum SporkId : int32_t { SPORK_5_MAX_VALUE = 10004, SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT = 10007, SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT = 10008, - SPORK_10_MASTERNODE_PAY_UPDATED_NODES = 10009, SPORK_13_ENABLE_SUPERBLOCKS = 10012, SPORK_14_NEW_PROTOCOL_ENFORCEMENT = 10013, SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2 = 10014,