From e09cb7e7798fa431521d0360cb37454b0fcafdbe Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Fri, 26 Jun 2020 22:45:17 +0200 Subject: [PATCH 01/49] POSIX Fixed path to --- src/compat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compat.h b/src/compat.h index 751a2bf..47be5e8 100644 --- a/src/compat.h +++ b/src/compat.h @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include #include From 1bd1c0bc309386bce6bc4047b49fe1279f4d4c9d Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Fri, 26 Jun 2020 22:57:48 +0200 Subject: [PATCH 02/49] Added .gitignore --- .gitignore | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c0c37de --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +.dirstamp +*.o +*.a +*.Po +*.Plo +*.Tpo +src/masterwin-cli +src/masterwin-tx +src/masterwind +src/test/buildenv.py +src/test/data/*.h +autom4te.cache/* +Makefile +Makefile.in +aclocal.m4 +build_cmd +config.log +config.status +configure +contrib/devtools/split-debug.sh +libtool +qa/pull-tester/run-bitcoind-for-test.sh +qa/pull-tester/tests-config.sh +share/qt/Info.plist +share/setup.nsi +src/Makefile +src/Makefile.in +src/config/masterwin-config.h +src/config/stamp-h1 From b711eb539d7a1ab7b6733a0f6bafd5561a592ca1 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Fri, 26 Jun 2020 23:32:16 +0200 Subject: [PATCH 03/49] Removed obsolete DarkSend-Announcements --- src/activemasternode.cpp | 70 ---------- src/masternode.cpp | 6 - src/masternodeman.cpp | 280 --------------------------------------- 3 files changed, 356 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 553903e..5cd39aa 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -194,38 +194,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 (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() + boost::lexical_cast(masterNodeSignatureTime) + boost::lexical_cast(false); - - if (!obfuScationSigner.SignMessage(strMessage, retErrorMessage, vchMasterNodeSignature, keyMasternode)) { - errorMessage = "dseep sign message failed: " + retErrorMessage; - return false; - } - - if (!obfuScationSigner.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); - BOOST_FOREACH (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 @@ -296,44 +264,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 (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() + boost::lexical_cast(masterNodeSignatureTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(PROTOCOL_VERSION) + donationAddress + boost::lexical_cast(donationPercantage); - - if (!obfuScationSigner.SignMessage(strMessage, retErrorMessage, vchMasterNodeSignature, keyCollateralAddress)) { - errorMessage = "dsee sign message failed: " + retErrorMessage; - LogPrintf("CActiveMasternode::Register() - Error: %s\n", errorMessage.c_str()); - return false; - } - - if (!obfuScationSigner.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); - BOOST_FOREACH (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.cpp b/src/masternode.cpp index 3e5b0cc..bf34ede 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -79,8 +79,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) @@ -104,8 +102,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 } CMasternode::CMasternode(const CMasternodeBroadcast& mnb) @@ -129,8 +125,6 @@ CMasternode::CMasternode(const CMasternodeBroadcast& mnb) 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 } // diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index cf5955d..48cd22a 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 (IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return; - - CTxIn vin; - CService addr; - CPubKey pubkey; - CPubKey pubkey2; - 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 errorMessage = ""; - if (!obfuScationSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)) { - LogPrintf("CMasternodeMan::ProcessMessage() : dsee - Got bad Masternode address signature\n"); - Misbehaving(pfrom->GetId(), 100); - return; - } - - if (Params().NetworkID() == CBaseChainParams::MAIN) { - if (addr.GetPort() != 33555) return; - } else if (addr.GetPort() == 33555) - 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->sig = 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(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 (!obfuScationSigner.IsVinAssociatedWithPubkey(vin, pubkey)) { - 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(3999.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 15000 MW tx got MASTERNODE_MIN_CONFIRMATIONS - uint256 hashBlock = 0; - 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 15000 MW 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.sig = 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 (IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return; - - CTxIn vin; - 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 errorMessage = ""; - if (!obfuScationSigner.VerifyMessage(pmn->pubKeyMasternode, vchSig, strMessage, errorMessage)) { - LogPrint("masternode","dseep - Got bad Masternode address signature %s \n", vin.prevout.hash.ToString()); - //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) From 2bbb7f73b8b48b787c984a08e2abe812193c2165 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Fri, 26 Jun 2020 23:39:57 +0200 Subject: [PATCH 04/49] Added Masternode-Collaterals to chainparams --- src/chainparams.cpp | 5 +++++ src/chainparams.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index e9e1814..f484546 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -217,6 +217,11 @@ class CMainParams : public CChainParams blacklistedAddresses = std::set{ "MUqGH9fvKxjSSJhLQuKMM1yD8EsuZnc6P3", }; + + vMasternodeCollateral.push_back (1000 * COIN); + vMasternodeCollateral.push_back (4000 * COIN); + vMasternodeCollateral.push_back (10000 * COIN); + vMasternodeCollateral.push_back (100000 * COIN); } const Checkpoints::CCheckpointData& Checkpoints() const diff --git a/src/chainparams.h b/src/chainparams.h index 91dab21..9d07fca 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -191,6 +191,8 @@ class CChainParams int nBlockLastGoodCheckpoint; int nBlockEnforceInvalidUTXO; int nBlockZerocoinV2; + + std::vector vMasternodeCollateral; }; /** From d3f217f06767d27b25a44cadf6be78a83075c989 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Fri, 26 Jun 2020 23:43:31 +0200 Subject: [PATCH 05/49] Removed DarkSend-Stuff from src/masternode.h (was missing in b711eb539d7a1ab7b6733a0f6bafd5561a592ca1) --- src/masternode.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/masternode.h b/src/masternode.h index 49619d2..514d823 100644 --- a/src/masternode.h +++ b/src/masternode.h @@ -145,9 +145,6 @@ class CMasternode 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); CMasternode(const CMasternodeBroadcast& mnb); From fc48fe1de196309e81476cf217f0213ef4e02aa6 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Fri, 26 Jun 2020 23:59:35 +0200 Subject: [PATCH 06/49] Check Collateral-Value against chainparams --- src/activemasternode.cpp | 2 +- src/chainparams.h | 12 ++++++++++++ src/masternode.cpp | 35 +++++++++++++++-------------------- src/obfuscation.cpp | 5 +++-- src/wallet.cpp | 23 +++++++++++++++-------- 5 files changed, 46 insertions(+), 31 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 5cd39aa..8518686 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -387,7 +387,7 @@ vector CActiveMasternode::SelectCoinsMasternode() // Filter BOOST_FOREACH (const COutput& out, vCoins) { - if (out.tx->vout[out.i].nValue == 4000 * COIN) { //exactly + if (Params ().isMasternodeCollateral (out.tx->vout [out.i].nValue)) { filteredCoins.push_back(out); } } diff --git a/src/chainparams.h b/src/chainparams.h index 9d07fca..bb40ae2 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -17,6 +17,7 @@ #include "libzerocoin/Params.h" #include +#include typedef unsigned char MessageStartChars[MESSAGE_START_SIZE]; @@ -127,6 +128,17 @@ class CChainParams int Block_Enforce_Invalid() const { return nBlockEnforceInvalidUTXO; } int Zerocoin_Block_V2_Start() const { return nBlockZerocoinV2; } CAmount InvalidAmountFiltered() const { return nInvalidAmountFiltered; }; + + bool isMasternodeCollateral (CAmount nValue) const { + // Check if the given value is on collateral-list + BOOST_FOREACH (const CAmount& tierCollateral, vMasternodeCollateral) { + if (nValue == tierCollateral) + return true; + } + + // Cannot be a valid collateral-value if we get here + return false; + } protected: CChainParams() {} diff --git a/src/masternode.cpp b/src/masternode.cpp index bf34ede..28d0052 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -209,20 +209,17 @@ void CMasternode::Check(bool forceCheck) } if (!unitTest) { - CValidationState state; - CMutableTransaction tx = CMutableTransaction(); - CTxOut vout = CTxOut(3999.99 * COIN, obfuScationPool.collateralPubKey); - tx.vin.push_back(vin); - tx.vout.push_back(vout); - - { - TRY_LOCK(cs_main, lockMain); - if (!lockMain) return; - - if (!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)) { - activeState = MASTERNODE_VIN_SPENT; - return; - } + TRY_LOCK (cs_main, lockMain); + if (!lockMain) + return; + + CCoinsViewCache cache (pcoinsTip); + const CCoins* coins = cache.AccessCoins (vin.prevout.hash); + + if (!coins || !coins->IsAvailable (vin.prevout.n) || !Params ().isMasternodeCollateral (coins->vout [vin.prevout.n].nValue)) { + activeState = MASTERNODE_VIN_SPENT; + + return; } } @@ -580,11 +577,6 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS) } CValidationState state; - CMutableTransaction tx = CMutableTransaction(); - CTxOut vout = CTxOut(3999.99 * COIN, obfuScationPool.collateralPubKey); - tx.vin.push_back(vin); - tx.vout.push_back(vout); - { TRY_LOCK(cs_main, lockMain); if (!lockMain) { @@ -594,7 +586,10 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS) return false; } - if (!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)) { + CCoinsViewCache cache (pcoinsTip); + const CCoins* coins = cache.AccessCoins (vin.prevout.hash); + + if (!coins || !coins->IsAvailable (vin.prevout.n) || !Params ().isMasternodeCollateral (coins->vout [vin.prevout.n].nValue)) { //set nDos state.IsInvalid(nDoS); return false; diff --git a/src/obfuscation.cpp b/src/obfuscation.cpp index 4ee051b..181e445 100644 --- a/src/obfuscation.cpp +++ b/src/obfuscation.cpp @@ -2110,8 +2110,9 @@ bool CObfuScationSigner::IsVinAssociatedWithPubkey(CTxIn& vin, CPubKey& pubkey) uint256 hash; if (GetTransaction(vin.prevout.hash, txVin, hash, true)) { BOOST_FOREACH (CTxOut out, txVin.vout) { - if (out.nValue == 4000 * COIN) { - if (out.scriptPubKey == payee2) return true; + if (Params ().isMasternodeCollateral (out.nValue)) { + if (out.scriptPubKey == payee2) + return true; } } } diff --git a/src/wallet.cpp b/src/wallet.cpp index 7e51f33..339e049 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1106,7 +1106,9 @@ CAmount CWalletTx::GetAnonymizableCredit(bool fUseCache) const const CTxIn vin = CTxIn(hashTx, i); if (pwallet->IsSpent(hashTx, i) || pwallet->IsLockedCoin(hashTx, i)) continue; - if (fMasterNode && vout[i].nValue == 4000 * COIN) continue; // do not count MN-like outputs + + if (fMasterNode && Params ().isMasternodeCollateral (vout [i].nValue)) + continue; const int rounds = pwallet->GetInputObfuscationRounds(vin); if (rounds >= -2 && rounds < nZeromintPercentage) { @@ -1170,7 +1172,9 @@ CAmount CWalletTx::GetUnlockedCredit() const const CTxOut& txout = vout[i]; if (pwallet->IsSpent(hashTx, i) || pwallet->IsLockedCoin(hashTx, i)) continue; - if (fMasterNode && vout[i].nValue == 4000 * COIN) continue; // do not count MN-like outputs + + if (fMasterNode && Params ().isMasternodeCollateral (vout [i].nValue)) + continue; nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE); if (!MoneyRange(nCredit)) @@ -1204,7 +1208,7 @@ CAmount CWalletTx::GetLockedCredit() const } // Add masternode collaterals which are handled likc locked coins - else if (fMasterNode && vout[i].nValue == 4000 * COIN) { + else if (fMasterNode && Params ().isMasternodeCollateral (vout [i].nValue)) { nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE); } @@ -1323,7 +1327,7 @@ CAmount CWalletTx::GetLockedWatchOnlyCredit() const } // Add masternode collaterals which are handled likc locked coins - else if (fMasterNode && vout[i].nValue == 4000 * COIN) { + else if (fMasterNode && Params ().isMasternodeCollateral (vout [i].nValue)) { nCredit += pwallet->GetCredit(txout, ISMINE_WATCH_ONLY); } @@ -1956,13 +1960,14 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if (nCoinType == ONLY_DENOMINATED) { found = IsDenominatedAmount(pcoin->vout[i].nValue); } else if (nCoinType == ONLY_NOT15000IFMN) { - found = !(fMasterNode && pcoin->vout[i].nValue == 4000 * COIN); + found = !(fMasterNode && Params ().isMasternodeCollateral (pcoin->vout [i].nValue)); } else if (nCoinType == ONLY_NONDENOMINATED_NOT10000IFMN) { if (IsCollateralAmount(pcoin->vout[i].nValue)) continue; // do not use collateral amounts found = !IsDenominatedAmount(pcoin->vout[i].nValue); - if (found && fMasterNode) found = pcoin->vout[i].nValue != 4000 * COIN; // do not use Hot MN funds + if (found && fMasterNode) + found = !Params ().isMasternodeCollateral (pcoin->vout [i].nValue); } else if (nCoinType == ONLY_15000) { - found = pcoin->vout[i].nValue == 4000 * COIN; + found = Params ().isMasternodeCollateral (pcoin->vout [i].nValue); } else { found = true; } @@ -2458,7 +2463,9 @@ bool CWallet::SelectCoinsDark(CAmount nValueMin, CAmount nValueMax, std::vector< if (out.tx->vout[out.i].nValue < CENT) continue; //do not allow collaterals to be selected if (IsCollateralAmount(out.tx->vout[out.i].nValue)) continue; - if (fMasterNode && out.tx->vout[out.i].nValue == 4000 * COIN) continue; //masternode input + + if (fMasterNode && Params ().isMasternodeCollateral (out.tx->vout [out.i].nValue)) + continue; if (nValueRet + out.tx->vout[out.i].nValue <= nValueMax) { CTxIn vin = CTxIn(out.tx->GetHash(), out.i); From f9b39c4aaaf60bdf6f2447383f7121c5f9c4d9ba Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Thu, 2 Jul 2020 18:35:33 +0200 Subject: [PATCH 07/49] Allow to calculate rewards for Masternode-Levels --- src/chainparams.h | 4 ++++ src/main.cpp | 12 ++++++++++++ src/main.h | 1 + 3 files changed, 17 insertions(+) diff --git a/src/chainparams.h b/src/chainparams.h index bb40ae2..34b1b0f 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -139,6 +139,10 @@ class CChainParams // Cannot be a valid collateral-value if we get here return false; } + + unsigned int getMasterNodeLevels () const { + return vMasternodeCollateral.size (); + } protected: CChainParams() {} diff --git a/src/main.cpp b/src/main.cpp index e216704..f50173a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2000,6 +2000,18 @@ int64_t GetMasternodePayment(int nHeight, int64_t blockValue, int nMasternodeCou return ret; } +int64_t GetMasternodePayment (int nHeight, unsigned int mnLevel, int64_t blockValue, int nMasternodeCount, bool isZMWStake) { + int64_t masternodeTotalPayment = GetMasternodePayment (nHeight, blockValue, nMasternodeCount, isZMWStake); + unsigned int masternodeLevels = Params ().getMasterNodeLevels (); + unsigned int masternodeLevelSum = 0; + + for (unsigned int masternodeLevel = 1; masternodeLevel < masternodeLevels; masternodeLevel++) + masternodeLevelSum += masternodeLevel; + + return masternodeTotalPayment * mnLevel / masternodeLevelSum; +} + + bool IsInitialBlockDownload() { LOCK(cs_main); diff --git a/src/main.h b/src/main.h index 40d2903..1744382 100644 --- a/src/main.h +++ b/src/main.h @@ -231,6 +231,7 @@ bool GetTransaction(const uint256& hash, CTransaction& tx, uint256& hashBlock, b // ***TODO*** double ConvertBitsToDouble(unsigned int nBits); int64_t GetMasternodePayment(int nHeight, int64_t blockValue, int nMasternodeCount, bool isZMWStake); +int64_t GetMasternodePayment (int nHeight, unsigned int mnLevel, int64_t blockValue, int nMasternodeCount, bool isZMWStake); unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader* pblock, bool fProofOfStake); bool ActivateBestChain(CValidationState& state, CBlock* pblock = NULL, bool fAlreadyChecked = false); From 597304766c0202ef443505f486b52dbf7dfa8c48 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Thu, 2 Jul 2020 19:22:48 +0200 Subject: [PATCH 08/49] Renamed constants to better describe what they are doing --- src/obfuscation.cpp | 10 +++++----- src/wallet.cpp | 20 ++++++++++---------- src/wallet.h | 6 +++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/obfuscation.cpp b/src/obfuscation.cpp index 181e445..a920a88 100644 --- a/src/obfuscation.cpp +++ b/src/obfuscation.cpp @@ -1727,16 +1727,16 @@ bool CObfuscationPool::MakeCollateralAmounts() // try to use non-denominated and not mn-like funds bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekeyChange, - nFeeRet, strFail, &coinControl, ONLY_NONDENOMINATED_NOT10000IFMN); + nFeeRet, strFail, &coinControl, EXCEPT_DENOMINATED_OR_MASTERNODE_COLLATERAL); if (!success) { // if we failed (most likeky not enough funds), try to use all coins instead - // MN-like funds should not be touched in any case and we can't mix denominated without collaterals anyway CCoinControl* coinControlNull = NULL; - LogPrintf("MakeCollateralAmounts: ONLY_NONDENOMINATED_NOT10000IFMN Error - %s\n", strFail); + LogPrintf("MakeCollateralAmounts: EXCEPT_DENOMINATED_OR_MASTERNODE_COLLATERAL Error - %s\n", strFail); success = pwalletMain->CreateTransaction(vecSend, wtx, reservekeyChange, - nFeeRet, strFail, coinControlNull, ONLY_NOT15000IFMN); + nFeeRet, strFail, coinControlNull, EXCEPT_MASTERNODE_COLLATERAL); if (!success) { - LogPrintf("MakeCollateralAmounts: ONLY_NOT15000IFMN Error - %s\n", strFail); + LogPrintf("MakeCollateralAmounts: EXCEPT_MASTERNODE_COLLATERAL Error - %s\n", strFail); reservekeyCollateral.ReturnKey(); return false; } @@ -1814,7 +1814,7 @@ bool CObfuscationPool::CreateDenominated(CAmount nTotalValue) CCoinControl* coinControl = NULL; bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekeyChange, - nFeeRet, strFail, coinControl, ONLY_NONDENOMINATED_NOT10000IFMN); + nFeeRet, strFail, coinControl, EXCEPT_DENOMINATED_OR_MASTERNODE_COLLATERAL); if (!success) { LogPrintf("CreateDenominated: Error - %s\n", strFail); // TODO: return reservekeyDenom here diff --git a/src/wallet.cpp b/src/wallet.cpp index 339e049..4206224 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -473,7 +473,7 @@ bool CWallet::GetMasternodeVinAndKeys(CTxIn& txinRet, CPubKey& pubKeyRet, CKey& // Find possible candidates std::vector vPossibleCoins; - AvailableCoins(vPossibleCoins, true, NULL, false, ONLY_15000); + AvailableCoins(vPossibleCoins, true, NULL, false, ONLY_MASTERNODE_COLLATERAL); if (vPossibleCoins.empty()) { LogPrintf("CWallet::GetMasternodeVinAndKeys -- Could not locate any valid masternode vin\n"); return false; @@ -1959,14 +1959,14 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const bool found = false; if (nCoinType == ONLY_DENOMINATED) { found = IsDenominatedAmount(pcoin->vout[i].nValue); - } else if (nCoinType == ONLY_NOT15000IFMN) { + } else if (nCoinType == EXCEPT_MASTERNODE_COLLATERAL) { found = !(fMasterNode && Params ().isMasternodeCollateral (pcoin->vout [i].nValue)); - } else if (nCoinType == ONLY_NONDENOMINATED_NOT10000IFMN) { + } else if (nCoinType == EXCEPT_DENOMINATED_OR_MASTERNODE_COLLATERAL) { if (IsCollateralAmount(pcoin->vout[i].nValue)) continue; // do not use collateral amounts found = !IsDenominatedAmount(pcoin->vout[i].nValue); if (found && fMasterNode) found = !Params ().isMasternodeCollateral (pcoin->vout [i].nValue); - } else if (nCoinType == ONLY_15000) { + } else if (nCoinType == ONLY_MASTERNODE_COLLATERAL) { found = Params ().isMasternodeCollateral (pcoin->vout [i].nValue); } else { found = true; @@ -1990,7 +1990,7 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if (mine == ISMINE_WATCH_ONLY && nWatchonlyConfig == 1) continue; - if (IsLockedCoin((*it).first, i) && nCoinType != ONLY_15000) + if (IsLockedCoin((*it).first, i) && nCoinType != ONLY_MASTERNODE_COLLATERAL) continue; if (pcoin->vout[i].nValue <= 0 && !fIncludeZeroValue) continue; @@ -2451,7 +2451,7 @@ bool CWallet::SelectCoinsDark(CAmount nValueMin, CAmount nValueMax, std::vector< nValueRet = 0; vector vCoins; - AvailableCoins(vCoins, true, coinControl, false, nObfuscationRoundsMin < 0 ? ONLY_NONDENOMINATED_NOT10000IFMN : ONLY_DENOMINATED); + AvailableCoins(vCoins, true, coinControl, false, nObfuscationRoundsMin < 0 ? EXCEPT_DENOMINATED_OR_MASTERNODE_COLLATERAL : ONLY_DENOMINATED); set > setCoinsRet2; @@ -2750,10 +2750,10 @@ bool CWallet::CreateTransaction(const vector >& vecSend, if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl, coin_type, useIX)) { if (coin_type == ALL_COINS) { strFailReason = _("Insufficient funds."); - } else if (coin_type == ONLY_NOT15000IFMN) { - strFailReason = _("Unable to locate enough funds for this transaction that are not equal 3000 MW."); - } else if (coin_type == ONLY_NONDENOMINATED_NOT10000IFMN) { - strFailReason = _("Unable to locate enough Obfuscation non-denominated funds for this transaction that are not equal 3000 MW."); + } else if (coin_type == EXCEPT_MASTERNODE_COLLATERAL) { + strFailReason = _("Unable to locate enough funds for this transaction that are not equal to a masternode-collateral."); + } else if (coin_type == EXCEPT_DENOMINATED_OR_MASTERNODE_COLLATERAL) { + strFailReason = _("Unable to locate enough Obfuscation non-denominated funds for this transaction that are not equal to a masternode-collateral."); } else { strFailReason = _("Unable to locate enough Obfuscation denominated funds for this transaction."); strFailReason += " " + _("Obfuscation uses exact denominated amounts to send funds, you might simply need to anonymize some more coins."); diff --git a/src/wallet.h b/src/wallet.h index c6db965..6c9e24e 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -84,9 +84,9 @@ enum WalletFeature { enum AvailableCoinsType { ALL_COINS = 1, ONLY_DENOMINATED = 2, - ONLY_NOT15000IFMN = 3, - ONLY_NONDENOMINATED_NOT10000IFMN = 4, // ONLY_NONDENOMINATED and not 15000 MW at the same time - ONLY_15000 = 5, // find masternode outputs including locked ones (use with caution) + EXCEPT_MASTERNODE_COLLATERAL = 3, + EXCEPT_DENOMINATED_OR_MASTERNODE_COLLATERAL = 4, // ONLY_NONDENOMINATED and not 15000 MW at the same time + ONLY_MASTERNODE_COLLATERAL = 5, // find masternode outputs including locked ones (use with caution) STAKABLE_COINS = 6 // UTXO's that are valid for staking }; From 69fe5f197d63bf4d3d3c2dc35b68a1cff3ef1537 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Tue, 21 Jul 2020 11:15:36 +0200 Subject: [PATCH 09/49] BUGFIX Correctly compute sum of masternode-levels --- src/chainparams.h | 2 +- src/main.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/chainparams.h b/src/chainparams.h index 34b1b0f..714a00b 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -140,7 +140,7 @@ class CChainParams return false; } - unsigned int getMasterNodeLevels () const { + unsigned int getMasternodeLevels () const { return vMasternodeCollateral.size (); } diff --git a/src/main.cpp b/src/main.cpp index f50173a..0754582 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2002,13 +2002,12 @@ int64_t GetMasternodePayment(int nHeight, int64_t blockValue, int nMasternodeCou int64_t GetMasternodePayment (int nHeight, unsigned int mnLevel, int64_t blockValue, int nMasternodeCount, bool isZMWStake) { int64_t masternodeTotalPayment = GetMasternodePayment (nHeight, blockValue, nMasternodeCount, isZMWStake); - unsigned int masternodeLevels = Params ().getMasterNodeLevels (); - unsigned int masternodeLevelSum = 0; + unsigned int masternodeLevels = Params ().getMasternodeLevels (); - for (unsigned int masternodeLevel = 1; masternodeLevel < masternodeLevels; masternodeLevel++) - masternodeLevelSum += masternodeLevel; + if (masternodeLevels == 0) + return 0; - return masternodeTotalPayment * mnLevel / masternodeLevelSum; + return masternodeTotalPayment * mnLevel / ((1 << masternodeLevels) - 1); } From 4019a0bd486a4324e4ce4baf0220f266155ca2a3 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Tue, 21 Jul 2020 11:59:01 +0200 Subject: [PATCH 10/49] Added collateral-checks to activemasternodes --- src/activemasternode.cpp | 45 +++++++++++++++++++++++++++++++--------- src/chainparams.h | 14 +++++++++++++ 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 8518686..8dbb097 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -285,6 +285,8 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr COutput* selectedOutput; // Find the vin + bool found = false; + if (!strTxHash.empty()) { // Let's find it uint256 txHash(strTxHash); @@ -296,26 +298,49 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr return false; } - bool found = false; BOOST_FOREACH (COutput& out, possibleCoins) { - if (out.tx->GetHash() == txHash && out.i == outputIndex) { + if ((out.tx->GetHash () == txHash) && + (out.i == outputIndex) && + (Params ().isMasternodeCollateral (out.tx->vout [out.i].nValue))) { selectedOutput = &out; found = true; break; } } - if (!found) { - LogPrintf("CActiveMasternode::GetMasterNodeVin - Could not locate valid vin\n"); - return false; - } } else { - // No output specified, Select the first one - if (possibleCoins.size() > 0) { - selectedOutput = &possibleCoins[0]; - } else { + // No output specified, Select the first usable one + if (!possibleCoins.size ()) { LogPrintf("CActiveMasternode::GetMasterNodeVin - Could not locate specified vin from possible list\n"); return false; } + + selectedOutput = &possibleCoins [0]; + + unsigned int selectedLevel = Params ().getMasternodeLevel (selectedOutput->tx->vout [selectedOutput->i].nValue); + unsigned int maxLevel = Params ().getMasternodeLevels (); + + BOOST_FOREACH (COutput& out, possibleCoins) { + if (selectedLevel == maxLevel) + break; + + unsigned int nextLevel = Params ().getMasternodeLevel (out.tx->vout [out.i].nValue); + + if (nextLevel <= selectedLevel) + continue; + + selectedLevel = nextLevel; + selectedOutput = &out; + found = true; + } + + if (maxLevel < 1) + found = false; + } + + if (!found) { + LogPrintf("CActiveMasternode::GetMasterNodeVin - Could not locate valid vin\n"); + + return false; } // At this point we have a selected output, retrieve the associated info diff --git a/src/chainparams.h b/src/chainparams.h index 714a00b..6099b83 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -143,6 +143,20 @@ class CChainParams unsigned int getMasternodeLevels () const { return vMasternodeCollateral.size (); } + + unsigned int getMasternodeLevel (CAmount collateralValue) const { + unsigned int currentLevel = 0; + + // Check if the given value is on collateral-list + BOOST_FOREACH (const CAmount& tierCollateral, vMasternodeCollateral) { + currentLevel++; + + if (collateralValue == tierCollateral) + return currentLevel; + } + + return 0; + } protected: CChainParams() {} From c783e7268469bf140b7abb3ec357fb7ba968895c Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Tue, 21 Jul 2020 12:00:13 +0200 Subject: [PATCH 11/49] Removed GetRequiredPaymentsString() --- src/masternode-budget.cpp | 29 -------------------------- src/masternode-budget.h | 1 - src/masternode-payments.cpp | 41 ------------------------------------- src/masternode-payments.h | 3 --- 4 files changed, 74 deletions(-) diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index b38751f..cfd7ade 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -882,35 +882,6 @@ std::vector CBudgetManager::GetFinalizedBudgets() return vFinalizedBudgetsRet; } -std::string CBudgetManager::GetRequiredPaymentsString(int nBlockHeight) -{ - LOCK(cs); - - std::string ret = "unknown-budget"; - - std::map::iterator it = mapFinalizedBudgets.begin(); - while (it != mapFinalizedBudgets.end()) { - CFinalizedBudget* pfinalizedBudget = &((*it).second); - if (nBlockHeight >= pfinalizedBudget->GetBlockStart() && nBlockHeight <= pfinalizedBudget->GetBlockEnd()) { - CTxBudgetPayment payment; - if (pfinalizedBudget->GetBudgetPaymentByBlock(nBlockHeight, payment)) { - if (ret == "unknown-budget") { - ret = payment.nProposalHash.ToString(); - } else { - ret += ","; - ret += payment.nProposalHash.ToString(); - } - } else { - LogPrint("mnbudget","CBudgetManager::GetRequiredPaymentsString - Couldn't find budget payment for block %d\n", nBlockHeight); - } - } - - ++it; - } - - return ret; -} - CAmount CBudgetManager::GetTotalBudget(int nHeight) { if (chainActive.Tip() == NULL) return 0; diff --git a/src/masternode-budget.h b/src/masternode-budget.h index bc4f537..9e168d0 100644 --- a/src/masternode-budget.h +++ b/src/masternode-budget.h @@ -244,7 +244,6 @@ class CBudgetManager bool UpdateFinalizedBudget(CFinalizedBudgetVote& vote, CNode* pfrom, std::string& strError); bool PropExists(uint256 nHash); TrxValidationStatus IsTransactionValid(const CTransaction& txNew, int nBlockHeight); - std::string GetRequiredPaymentsString(int nBlockHeight); void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees, bool fProofOfStake); void CheckOrphanVotes(); diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 7e03220..2df48a9 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -282,15 +282,6 @@ void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees, bool fProofOfStak } } -std::string GetRequiredPaymentsString(int nBlockHeight) -{ - if (IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) && budget.IsBudgetPaymentBlock(nBlockHeight)) { - return budget.GetRequiredPaymentsString(nBlockHeight); - } else { - return masternodePayments.GetRequiredPaymentsString(nBlockHeight); - } -} - void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool fProofOfStake, bool fZMWStake) { CBlockIndex* pindexPrev = chainActive.Tip(); @@ -585,38 +576,6 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) return false; } -std::string CMasternodeBlockPayees::GetRequiredPaymentsString() -{ - LOCK(cs_vecPayments); - - std::string ret = "Unknown"; - - for (CMasternodePayee& payee : vecPayments) { - CTxDestination address1; - ExtractDestination(payee.scriptPubKey, address1); - CBitcoinAddress address2(address1); - - if (ret != "Unknown") { - ret += ", " + address2.ToString() + ":" + std::to_string(payee.nVotes); - } else { - ret = address2.ToString() + ":" + std::to_string(payee.nVotes); - } - } - - return ret; -} - -std::string CMasternodePayments::GetRequiredPaymentsString(int nBlockHeight) -{ - LOCK(cs_mapMasternodeBlocks); - - if (mapMasternodeBlocks.count(nBlockHeight)) { - return mapMasternodeBlocks[nBlockHeight].GetRequiredPaymentsString(); - } - - return "Unknown"; -} - bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlockHeight) { LOCK(cs_mapMasternodeBlocks); diff --git a/src/masternode-payments.h b/src/masternode-payments.h index 50c0928..c0470c5 100644 --- a/src/masternode-payments.h +++ b/src/masternode-payments.h @@ -29,7 +29,6 @@ extern CMasternodePayments masternodePayments; void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); bool IsBlockPayeeValid(const CBlock& block, int nBlockHeight); -std::string GetRequiredPaymentsString(int nBlockHeight); bool IsBlockValueValid(const CBlock& block, CAmount nExpectedValue, CAmount nMinted); void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees, bool fProofOfStake, bool fZMWStake); @@ -147,7 +146,6 @@ class CMasternodeBlockPayees } bool IsTransactionValid(const CTransaction& txNew); - std::string GetRequiredPaymentsString(); ADD_SERIALIZE_METHODS; @@ -283,7 +281,6 @@ class CMasternodePayments int GetMinMasternodePaymentsProto(); void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); - std::string GetRequiredPaymentsString(int nBlockHeight); void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool fProofOfStake, bool fZMWStake); std::string ToString() const; int GetOldestBlock(); From b5d65a06333ff6e51615ccde6c8043d5755191ea Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Tue, 21 Jul 2020 15:24:49 +0200 Subject: [PATCH 12/49] Added GetLevel() to CMasternode --- src/masternode.cpp | 13 +++++++++++++ src/masternode.h | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/masternode.cpp b/src/masternode.cpp index 28d0052..b00a6c9 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -127,6 +127,19 @@ CMasternode::CMasternode(const CMasternodeBroadcast& mnb) lastTimeChecked = 0; } +unsigned int CMasternode::GetLevel () { + CTransaction prevTx; + uint256 hashBlock = 0; + + if (!GetTransaction (vin.prevout.hash, prevTx, hashBlock, true)) + return 0; + + if (vin.prevout.n >= prevout_tx.vout.size ()) + return 0; + + return Params ().getMasternodeLevel (prevTx.vout [vin.prevout.n].nValue); +} + // // When a new masternode broadcast is sent, update our information // diff --git a/src/masternode.h b/src/masternode.h index 514d823..f7c4def 100644 --- a/src/masternode.h +++ b/src/masternode.h @@ -72,7 +72,7 @@ class CMasternodePing ss << sigTime; return ss.GetHash(); } - + void swap(CMasternodePing& first, CMasternodePing& second) // nothrow { // enable ADL (not necessary in our case, but good practice) @@ -149,6 +149,7 @@ class CMasternode CMasternode(const CMasternode& other); CMasternode(const CMasternodeBroadcast& mnb); + unsigned int GetLevel (); void swap(CMasternode& first, CMasternode& second) // nothrow { From 2f980d27e2465ba058b447324119708c5d25098f Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Wed, 5 Aug 2020 16:30:49 +0200 Subject: [PATCH 13/49] WORKAROUND Bug introduced in c783e7268469bf140b7abb3ec357fb7ba968895c --- src/rpc/masternode.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index a3f5c9c..b92e32e 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -776,6 +776,7 @@ UniValue getmasternodewinners (const UniValue& params, bool fHelp) UniValue ret(UniValue::VARR); + /* for (int i = nHeight - nLast; i < nHeight + 20; i++) { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("nHeight", i)); @@ -814,6 +815,7 @@ UniValue getmasternodewinners (const UniValue& params, bool fHelp) ret.push_back(obj); } + */ return ret; } From fea6f8afd6f84e1477abc1efb9584f9810f9c0b5 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Wed, 5 Aug 2020 16:31:18 +0200 Subject: [PATCH 14/49] BUGFIX Renamed invalid variable --- src/masternode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/masternode.cpp b/src/masternode.cpp index b00a6c9..9b25bdb 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -134,7 +134,7 @@ unsigned int CMasternode::GetLevel () { if (!GetTransaction (vin.prevout.hash, prevTx, hashBlock, true)) return 0; - if (vin.prevout.n >= prevout_tx.vout.size ()) + if (vin.prevout.n >= prevTx.vout.size ()) return 0; return Params ().getMasternodeLevel (prevTx.vout [vin.prevout.n].nValue); From 3ac785913869a337f475d855a66d94e3c15701c3 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Wed, 5 Aug 2020 17:38:07 +0200 Subject: [PATCH 15/49] WiP Vote for next masternode on tiered level --- src/masternode-payments.cpp | 71 +++++++++++++++++++++++++++++++------ src/masternode-payments.h | 69 ++++++++++++++++++++++++++++++++++- src/masternode.cpp | 2 +- src/masternodeman.cpp | 28 ++++++++++----- src/masternodeman.h | 1 + 5 files changed, 149 insertions(+), 22 deletions(-) diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 2df48a9..abdca16 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -291,7 +291,8 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe CScript payee; //spork - if (!masternodePayments.GetBlockPayee(pindexPrev->nHeight + 1, payee)) { + // TODO: Insert masternode-levels + if (!masternodePayments.GetBlockPayee (pindexPrev->nHeight + 1, payee)) { //no masternode detected CMasternode* winningNode = mnodeman.GetCurrentMasterNode(1); if (winningNode) { @@ -380,6 +381,11 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st if (!locked || chainActive.Tip() == NULL) return; nHeight = chainActive.Tip()->nHeight; } + + CTxDestination masternodeAddress; + CMasternode *masternodeWinner; + ExtractDestination (winner.payee, masternodeAddress); + CBitcoinAddress payee_addr (masternodeAddress); if (masternodePayments.mapMasternodePayeeVotes.count(winner.GetHash())) { LogPrint("mnpayments", "mnw - Already seen - %s bestHeight %d\n", winner.GetHash().ToString().c_str(), nHeight); @@ -387,7 +393,8 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st return; } - int nFirstBlock = nHeight - (mnodeman.CountEnabled() * 1.25); + int nFirstBlock = nHeight - int (mnodeman.CountEnabledOnLevel (winner.masternodeLevel) * 1.25); + if (winner.nBlockHeight < nFirstBlock || winner.nBlockHeight > nHeight + 20) { LogPrint("mnpayments", "mnw - winner out of range - FirstBlock %d Height %d bestHeight %d\n", nFirstBlock, winner.nBlockHeight, nHeight); return; @@ -399,7 +406,7 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st return; } - if (!masternodePayments.CanVote(winner.vinMasternode.prevout, winner.nBlockHeight)) { + if (!masternodePayments.CanVote (winner.vinMasternode.prevout, winner.masternodeLevel, winner.nBlockHeight)) { // LogPrint("masternode","mnw - masternode already voted - %s\n", winner.vinMasternode.prevout.ToStringShort()); return; } @@ -414,12 +421,6 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st return; } - CTxDestination address1; - ExtractDestination(winner.payee, address1); - CBitcoinAddress address2(address1); - - // LogPrint("mnpayments", "mnw - winning vote - Addr %s Height %d bestHeight %d - %s\n", address2.ToString().c_str(), winner.nBlockHeight, nHeight, winner.vinMasternode.prevout.ToStringShort()); - if (masternodePayments.AddWinningMasternode(winner)) { winner.Relay(); masternodeSync.AddedMasternodeWinner(winner.GetHash()); @@ -456,6 +457,13 @@ bool CMasternodePayments::GetBlockPayee(int nBlockHeight, CScript& payee) return false; } +bool CMasternodePayments::GetBlockPayee (int nBlockHeight, unsigned mnLevel, CScript& payee) { + if (mapMasternodeBlocks.count (nBlockHeight)) + return mapMasternodeBlocks [nBlockHeight].GetPayee (payee, mnLevel); + + return false; +} + // Is this masternode scheduled to get paid soon? // -- Only look ahead up to 8 blocks to allow for propagation of the latest 2 winners bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight) @@ -487,6 +495,44 @@ bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight) return false; } +bool CMasternodePayments::IsScheduled (CMasternode& mn, int mnLevelCount, int nNotBlockHeight) { + LOCK (cs_mapMasternodeBlocks); + + int nHeight; + + { + TRY_LOCK (cs_main, locked); + + if (!locked || (chainActive.Tip () == NULL)) + return false; + + nHeight = chainActive.Tip ()->nHeight; + } + + CScript mnPayee; + CScript payee; + unsigned int masternodeLevel = mn.GetLevel (); + + mnPayee = GetScriptForDestination (mn.pubKeyCollateralAddress.GetID()); + + for (int h_upper_bound = nHeight + 10, h = h_upper_bound - std::min (10, mnLevelCount - 1); h < h_upper_bound; ++h) { + if (h == nNotBlockHeight) + continue; + + if (!mapMasternodeBlocks.count(h)) + continue; + + if (!mapMasternodeBlocks [h].GetPayee (payee, masternodeLevel)) + continue; + + if (mnPayee == payee) + return true; + + } + + return false; +} + bool CMasternodePayments::AddWinningMasternode(CMasternodePaymentWinner& winnerIn) { uint256 blockHash = 0; @@ -509,7 +555,7 @@ bool CMasternodePayments::AddWinningMasternode(CMasternodePaymentWinner& winnerI } } - mapMasternodeBlocks[winnerIn.nBlockHeight].AddPayee(winnerIn.payee, 1); + mapMasternodeBlocks [winnerIn.nBlockHeight].AddPayee (winnerIn.payee, winnerIn.masternodeLevel, 1); return true; } @@ -540,6 +586,7 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) //require at least 6 signatures for (CMasternodePayee& payee : vecPayments) + // TODO: Honor masternode-level if (payee.nVotes >= nMaxSignatures && payee.nVotes >= MNPAYMENTS_SIGNATURES_REQUIRED) nMaxSignatures = payee.nVotes; @@ -547,6 +594,7 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) if (nMaxSignatures < MNPAYMENTS_SIGNATURES_REQUIRED) return true; for (CMasternodePayee& payee : vecPayments) { + // TODO: Honor masternode-level bool found = false; for (CTxOut out : txNew.vout) { if (payee.scriptPubKey == out.scriptPubKey) { @@ -686,7 +734,8 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight) newWinner.nBlockHeight = nBlockHeight; CScript payee = GetScriptForDestination(pmn->pubKeyCollateralAddress.GetID()); - newWinner.AddPayee(payee); + // TODO: Fix masternode-Level + newWinner.AddPayee (payee, 1); CTxDestination address1; ExtractDestination(payee, address1); diff --git a/src/masternode-payments.h b/src/masternode-payments.h index c0470c5..6c05c25 100644 --- a/src/masternode-payments.h +++ b/src/masternode-payments.h @@ -62,17 +62,26 @@ class CMasternodePayee { public: CScript scriptPubKey; + unsigned int masternodeLevel; int nVotes; CMasternodePayee() { scriptPubKey = CScript(); + masternodeLevel = 0; nVotes = 0; } CMasternodePayee(CScript payee, int nVotesIn) { scriptPubKey = payee; + masternodeLevel = 0; + nVotes = nVotesIn; + } + + CMasternodePayee(CScript payee, unsigned int nLevel, int nVotesIn) { + scriptPubKey = payee; + masternodeLevel = nLevel; nVotes = nVotesIn; } @@ -82,6 +91,7 @@ class CMasternodePayee inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { READWRITE(scriptPubKey); + READWRITE (masternodeLevel); READWRITE(nVotes); } }; @@ -118,6 +128,22 @@ class CMasternodeBlockPayees CMasternodePayee c(payeeIn, nIncrement); vecPayments.push_back(c); } + + void AddPayee (CScript payeeIn, unsigned int masternodeLevel, int nIncrement) { + LOCK (cs_vecPayments); + + BOOST_FOREACH (CMasternodePayee& payee, vecPayments) { + if ((payee.scriptPubKey == payeeIn) && + (payee.masternodeLevel == masternodeLevel)) { + payee.nVotes += nIncrement; + + return; + } + } + + CMasternodePayee c (payeeIn, masternodeLevel, nIncrement); + vecPayments.push_back (c); + } bool GetPayee(CScript& payee) { @@ -133,6 +159,22 @@ class CMasternodeBlockPayees return (nVotes > -1); } + + bool GetPayee (CScript& payee, unsigned int masternodeLevel) { + LOCK (cs_vecPayments); + + int nVotes = -1; + + BOOST_FOREACH (CMasternodePayee& p, vecPayments) { + if ((p.masternodeLevel == masternodeLevel) && + (p.nVotes > nVotes)) { + payee = p.scriptPubKey; + nVotes = p.nVotes; + } + } + + return (nVotes > -1); + } bool HasPayeeWithVotes(CScript payee, int nVotesReq) { @@ -165,6 +207,7 @@ class CMasternodePaymentWinner int nBlockHeight; CScript payee; + unsigned int masternodeLevel; std::vector vchSig; CMasternodePaymentWinner() @@ -172,6 +215,7 @@ class CMasternodePaymentWinner nBlockHeight = 0; vinMasternode = CTxIn(); payee = CScript(); + masternodeLevel = 0; } CMasternodePaymentWinner(CTxIn vinIn) @@ -179,6 +223,7 @@ class CMasternodePaymentWinner nBlockHeight = 0; vinMasternode = vinIn; payee = CScript(); + masternodeLevel = 0; } uint256 GetHash() @@ -200,6 +245,11 @@ class CMasternodePaymentWinner { payee = payeeIn; } + + void AddPayee (CScript payeeIn, unsigned int mnLevel) { + payee = payeeIn; + masternodeLevel = mnLevel; + } ADD_SERIALIZE_METHODS; @@ -218,7 +268,7 @@ class CMasternodePaymentWinner std::string ret = ""; ret += vinMasternode.ToString(); ret += ", " + boost::lexical_cast(nBlockHeight); - ret += ", " + payee.ToString(); + ret += ", " + payee.ToString() + "@" + boost::lexical_cast(masternodeLevel); ret += ", " + boost::lexical_cast((int)vchSig.size()); return ret; } @@ -261,8 +311,10 @@ class CMasternodePayments int LastPayment(CMasternode& mn); bool GetBlockPayee(int nBlockHeight, CScript& payee); + bool GetBlockPayee (int nBlockHeight, unsigned mnlevel, CScript& payee); bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight); bool IsScheduled(CMasternode& mn, int nNotBlockHeight); + bool IsScheduled (CMasternode& mn, int mnLevelCount, int nNotBlockHeight); bool CanVote(COutPoint outMasternode, int nBlockHeight) { @@ -278,6 +330,21 @@ class CMasternodePayments mapMasternodesLastVote[outMasternode.hash + outMasternode.n] = nBlockHeight; return true; } + + bool CanVote (const COutPoint& outMasternode, unsigned int mnLevel, int nBlockHeight) { + LOCK (cs_mapMasternodePayeeVotes); + + uint256 key = ((outMasternode.hash + outMasternode.n) << 4) + mnLevel; + + if (mapMasternodesLastVote.count (key)) { + if (mapMasternodesLastVote [key] == nBlockHeight) + return false; + } + + mapMasternodesLastVote [key] = nBlockHeight; + + return true; + } int GetMinMasternodePaymentsProto(); void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); diff --git a/src/masternode.cpp b/src/masternode.cpp index 9b25bdb..1d8c44f 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -277,7 +277,7 @@ int64_t CMasternode::GetLastPaid() const CBlockIndex* BlockReading = chainActive.Tip(); - int nMnCount = mnodeman.CountEnabled() * 1.25; + int nMnCount = mnodeman.CountEnabledOnLevel (GetLevel ()) * 1.25; int n = 0; for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) { if (n >= nMnCount) { diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 48cd22a..1484bda 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -375,18 +375,27 @@ int CMasternodeMan::stable_size () return nStable_size; } -int CMasternodeMan::CountEnabled(int protocolVersion) -{ - int i = 0; - protocolVersion = protocolVersion == -1 ? masternodePayments.GetMinMasternodePaymentsProto() : protocolVersion; +int CMasternodeMan::CountEnabled (int protocolVersion) { + return CountEnabledOnLevel (0, protocolVersion); +} +int CMasternodeMan::CountEnabledOnLevel (unsigned int mnLevel, int protocolVersion) { + int masternodeCount = 0; + + protocolVersion = (protocolVersion == -1 ? masternodePayments.GetMinMasternodePaymentsProto () : protocolVersion); + for (CMasternode& mn : vMasternodes) { - mn.Check(); - if (mn.protocolVersion < protocolVersion || !mn.IsEnabled()) continue; - i++; + mn.Check (); + + if (mn.protocolVersion < protocolVersion || + !mn.IsEnabled () || + ((mnLevel > 0) && (mnLevel != mn.GetLevel ()))) + continue; + + masternodeCount++; } - return i; + return masternodeCount; } void CMasternodeMan::CountNetworks(int protocolVersion, int& ipv4, int& ipv6, int& onion) @@ -494,7 +503,8 @@ CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight if (mn.protocolVersion < masternodePayments.GetMinMasternodePaymentsProto()) continue; //it's in the list (up to 8 entries ahead of current block to allow propagation) -- so let's skip it - if (masternodePayments.IsScheduled(mn, nBlockHeight)) continue; + // TODO: Insert masternode-level + if (masternodePayments.IsScheduled (mn, nBlockHeight)) continue; //it's too new, wait for a cycle if (fFilterSigTime && mn.sigTime + (nMnCount * 2.6 * 60) > GetAdjustedTime()) continue; diff --git a/src/masternodeman.h b/src/masternodeman.h index 2df4b58..cd557f0 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -111,6 +111,7 @@ class CMasternodeMan void Clear(); int CountEnabled(int protocolVersion = -1); + int CountEnabledOnLevel (unsigned int mnLevel, int protocolVersion = -1); void CountNetworks(int protocolVersion, int& ipv4, int& ipv6, int& onion); From 8310786287cf1bba5302cd95bbfb8b8adb3d9e75 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Wed, 12 Aug 2020 14:20:09 +0200 Subject: [PATCH 16/49] WiP Added tiers to FillBlockPayee --- src/masternode-payments.cpp | 77 ++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index abdca16..3e5e347 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -289,50 +289,42 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe bool hasPayment = true; CScript payee; - - //spork - // TODO: Insert masternode-levels - if (!masternodePayments.GetBlockPayee (pindexPrev->nHeight + 1, payee)) { - //no masternode detected - CMasternode* winningNode = mnodeman.GetCurrentMasterNode(1); - if (winningNode) { - payee = GetScriptForDestination(winningNode->pubKeyCollateralAddress.GetID()); - } else { - LogPrint("masternode","CreateNewBlock: Failed to detect masternode to pay\n"); - hasPayment = false; - } - } - - CAmount blockValue = GetBlockValue(pindexPrev->nHeight); - CAmount masternodePayment = GetMasternodePayment(pindexPrev->nHeight, blockValue, 0, fZMWStake); - - if (hasPayment) { - if (fProofOfStake) { - /**For Proof Of Stake vout[0] must be null - * Stake reward can be split into many different outputs, so we must - * use vout.size() to align with several different cases. - * An additional output is appended as the masternode payment - */ - unsigned int i = txNew.vout.size(); - txNew.vout.resize(i + 1); - txNew.vout[i].scriptPubKey = payee; - txNew.vout[i].nValue = masternodePayment; - - //subtract mn payment from the stake reward - if (!txNew.vout[1].IsZerocoinMint()) - txNew.vout[i - 1].nValue -= masternodePayment; - } else { - txNew.vout.resize(2); - txNew.vout[1].scriptPubKey = payee; - txNew.vout[1].nValue = masternodePayment; - txNew.vout[0].nValue = blockValue - masternodePayment; + + for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + hasPayment = true; + + if (!masternodePayments.GetBlockPayee (pindexPrev->nHeight + 1, masternodeLevel, payee)) { + // No masternode was detected + // TODO: This is missing the level + CMasternode* winningNode = mnodeman.GetCurrentMasterNode (1); + + if (!winningNode) { + LogPrint ("masternode", "CreateNewBlock: Failed to detect masternode to pay\n"); + hasPayment = false; + } else + payee = GetScriptForDestination (winningNode->pubKeyCollateralAddress.GetID ()); } - CTxDestination address1; - ExtractDestination(payee, address1); - CBitcoinAddress address2(address1); - - LogPrint("masternode","Masternode payment of %s to %s\n", FormatMoney(masternodePayment).c_str(), address2.ToString().c_str()); + CAmount blockValue = GetBlockValue (pindexPrev->nHeight); + CAmount masternodePayment = GetMasternodePayment (pindexPrev->nHeight, masternodeLevel, blockValue, 0, fZMWStake); + + if (hasPayment) { + unsigned int i = txNew.vout.size (); + txNew.vout.resize (i + 1); + + txNew.vout [i].scriptPubKey = payee; + txNew.vout [i].nValue = masternodePayment; + + if (!txNew.vout [fProofOfStake ? 1 : 0].IsZerocoinMint ()) + txNew.vout [fProofOfStake ? 1 : 0].nValue -= masternodePayment; + + CTxDestination address1; + ExtractDestination (payee, address1); + CBitcoinAddress address2 (address1); + + LogPrint ("masternode", "Masternode payment of %s to %s\n", FormatMoney(masternodePayment).c_str (), address2.ToString ().c_str ()); + } else if (!fProofOfStake) + txNew.vout [0].nValue = blockValue - masternodePayment; } } @@ -383,7 +375,6 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st } CTxDestination masternodeAddress; - CMasternode *masternodeWinner; ExtractDestination (winner.payee, masternodeAddress); CBitcoinAddress payee_addr (masternodeAddress); From 20add9dbda8165e93ac41a7328a454267c9d0437 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Fri, 14 Aug 2020 14:43:22 +0200 Subject: [PATCH 17/49] Added tiered payments --- src/masternode-payments.cpp | 131 +++++++++++++++++++++--------------- src/masternodeman.cpp | 33 ++++++--- src/masternodeman.h | 2 + 3 files changed, 102 insertions(+), 64 deletions(-) diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 3e5e347..e5e60d2 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -295,8 +295,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe if (!masternodePayments.GetBlockPayee (pindexPrev->nHeight + 1, masternodeLevel, payee)) { // No masternode was detected - // TODO: This is missing the level - CMasternode* winningNode = mnodeman.GetCurrentMasterNode (1); + CMasternode* winningNode = mnodeman.GetCurrentMasternodeOnLevel (masternodeLevel, 1); if (!winningNode) { LogPrint ("masternode", "CreateNewBlock: Failed to detect masternode to pay\n"); @@ -555,7 +554,6 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) { LOCK(cs_vecPayments); - int nMaxSignatures = 0; int nMasternode_Drift_Count = 0; std::string strPayeesPossible = ""; @@ -572,47 +570,68 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) //for mnPayment >= required, so it only makes sense to check the max node count allowed. nMasternode_Drift_Count = mnodeman.size() + Params().MasternodeCountDrift(); } + + bool transactionCorrect = false; + CAmount requiredMasternodePayment = 0; - CAmount requiredMasternodePayment = GetMasternodePayment(nBlockHeight, nReward, nMasternode_Drift_Count, txNew.IsZerocoinSpend()); - - //require at least 6 signatures - for (CMasternodePayee& payee : vecPayments) - // TODO: Honor masternode-level - if (payee.nVotes >= nMaxSignatures && payee.nVotes >= MNPAYMENTS_SIGNATURES_REQUIRED) - nMaxSignatures = payee.nVotes; - - // if we don't have at least 6 signatures on a payee, approve whichever is the longest chain - if (nMaxSignatures < MNPAYMENTS_SIGNATURES_REQUIRED) return true; - - for (CMasternodePayee& payee : vecPayments) { - // TODO: Honor masternode-level - bool found = false; - for (CTxOut out : txNew.vout) { - if (payee.scriptPubKey == out.scriptPubKey) { - if(out.nValue >= requiredMasternodePayment) - found = true; - else - LogPrint("masternode","Masternode payment is out of drift range. Paid=%s Min=%s\n", FormatMoney(out.nValue).c_str(), FormatMoney(requiredMasternodePayment).c_str()); - } + for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + // Require at least 6 signatures + int nMaxSignatures = 0; + + for (CMasternodePayee& payee : vecPayments) + if ((payee.nVotes >= nMaxSignatures) && + (payee.nVotes >= MNPAYMENTS_SIGNATURES_REQUIRED) && + (payee.masternodeLevel == masternodeLevel)) + nMaxSignatures = payee.nVotes; + + // if we don't have at least 6 signatures on a payee, approve whichever is the longest chain + if (nMaxSignatures < MNPAYMENTS_SIGNATURES_REQUIRED) { + transactionCorrect = true; + + continue; } + + requiredMasternodePayment = GetMasternodePayment (nBlockHeight, masternodeLevel, nReward, nMasternode_Drift_Count); + + for (CMasternodePayee& payee : vecPayments) { + bool found = false; + + if (payee.masternodeLevel != masternodeLevel) + continue; + + for (CTxOut out : txNew.vout) + if (payee.scriptPubKey == out.scriptPubKey) { + if(out.nValue >= requiredMasternodePayment) { + found = true; + + break; + } else + LogPrint ("masternode", "Masternode payment is out of drift range. Paid=%s Min=%s\n", FormatMoney (out.nValue).c_str (), FormatMoney (requiredMasternodePayment).c_str ()); + } + + if (payee.nVotes >= MNPAYMENTS_SIGNATURES_REQUIRED) { + if (found) { + transactionCorrect = true; + + continue; + } + + CTxDestination address1; + ExtractDestination (payee.scriptPubKey, address1); + CBitcoinAddress address2 (address1); - if (payee.nVotes >= MNPAYMENTS_SIGNATURES_REQUIRED) { - if (found) return true; - - CTxDestination address1; - ExtractDestination(payee.scriptPubKey, address1); - CBitcoinAddress address2(address1); - - if (strPayeesPossible == "") { - strPayeesPossible += address2.ToString(); - } else { - strPayeesPossible += "," + address2.ToString(); + if (strPayeesPossible == "") + strPayeesPossible += address2.ToString (); + else + strPayeesPossible += "," + address2.ToString (); } } } - LogPrint("masternode","CMasternodePayments::IsTransactionValid - Missing required payment of %s to %s\n", FormatMoney(requiredMasternodePayment).c_str(), strPayeesPossible.c_str()); - return false; + if (!transactionCorrect) + LogPrint ("masternode", "CMasternodePayments::IsTransactionValid - Missing required payment of %s to %s\n", FormatMoney (requiredMasternodePayment).c_str (), strPayeesPossible.c_str ()); + + return transactionCorrect; } bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlockHeight) @@ -710,31 +729,31 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight) CMasternodePaymentWinner newWinner(activeMasternode.vin); - if (budget.IsBudgetPaymentBlock(nBlockHeight)) { - //is budget payment block -- handled by the budgeting software - } else { - LogPrint("masternode","CMasternodePayments::ProcessBlock() Start nHeight %d - vin %s. \n", nBlockHeight, activeMasternode.vin.prevout.hash.ToString()); - - // pay to the oldest MN that still had no payment but its input is old enough and it was active long enough - int nCount = 0; - CMasternode* pmn = mnodeman.GetNextMasternodeInQueueForPayment(nBlockHeight, true, nCount); - - if (pmn != NULL) { - LogPrint("masternode","CMasternodePayments::ProcessBlock() Found by FindOldestNotInVec \n"); + if (!budget.IsBudgetPaymentBlock (nBlockHeight)) { + LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Start nHeight %d - vin %s. \n", nBlockHeight, activeMasternode.vin.prevout.hash.ToString ()); + + for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + // pay to the oldest MN that still had no payment but its input is old enough and it was active long enough + int nCount = 0; + CMasternode* pmn = mnodeman.GetNextMasternodeInQueueForPayment (nBlockHeight, masternodeLevel, true, nCount); + + if (pmn == NULL) { + LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Failed to find masternode to pay\n"); + continue; + } + + LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Found by FindOldestNotInVec\n"); newWinner.nBlockHeight = nBlockHeight; - CScript payee = GetScriptForDestination(pmn->pubKeyCollateralAddress.GetID()); - // TODO: Fix masternode-Level - newWinner.AddPayee (payee, 1); + CScript payee = GetScriptForDestination (pmn->pubKeyCollateralAddress.GetID()); + newWinner.AddPayee (payee, masternodeLevel); CTxDestination address1; - ExtractDestination(payee, address1); - CBitcoinAddress address2(address1); + ExtractDestination (payee, address1); + CBitcoinAddress address2 (address1); - LogPrint("masternode","CMasternodePayments::ProcessBlock() Winner payee %s nHeight %d. \n", address2.ToString().c_str(), newWinner.nBlockHeight); - } else { - LogPrint("masternode","CMasternodePayments::ProcessBlock() Failed to find masternode to pay\n"); + LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Winner payee %s nHeight %d. \n", address2.ToString ().c_str (), newWinner.nBlockHeight); } } diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 1484bda..aed2f26 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -485,26 +485,33 @@ CMasternode* CMasternodeMan::Find(const CPubKey& pubKeyMasternode) // CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCount) { + return GetNextMasternodeInQueueForPayment (nBlockHeight, 0, fFilterSigTime, nCount); +} + +CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment (int nBlockHeight, unsigned int masternodeLevel, bool fFilterSigTime, int& nCount) { LOCK(cs); CMasternode* pBestMasternode = NULL; std::vector > vecMasternodeLastPaid; - /* - Make a vector with all of the last paid times - */ - - int nMnCount = CountEnabled(); + // Make a vector with all of the last paid times + int nMnCount = CountEnabledOnLevel (masternodeLevel); + for (CMasternode& mn : vMasternodes) { mn.Check(); + + // Check the level of tiered masternode + if ((masternodeLevel > 0) && + (mn.GetLevel () != masternodeLevel)) + continue; + if (!mn.IsEnabled()) continue; // //check protocol version if (mn.protocolVersion < masternodePayments.GetMinMasternodePaymentsProto()) continue; //it's in the list (up to 8 entries ahead of current block to allow propagation) -- so let's skip it - // TODO: Insert masternode-level - if (masternodePayments.IsScheduled (mn, nBlockHeight)) continue; + if (masternodePayments.IsScheduled (mn, nMnCount, nBlockHeight)) continue; //it's too new, wait for a cycle if (fFilterSigTime && mn.sigTime + (nMnCount * 2.6 * 60) > GetAdjustedTime()) continue; @@ -518,7 +525,8 @@ CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight nCount = (int)vecMasternodeLastPaid.size(); //when the network is in the process of upgrading, don't penalize nodes that recently restarted - if (fFilterSigTime && nCount < nMnCount / 3) return GetNextMasternodeInQueueForPayment(nBlockHeight, false, nCount); + if (fFilterSigTime && nCount < nMnCount / 3) + return GetNextMasternodeInQueueForPayment (nBlockHeight, masternodeLevel, false, nCount); // Sort them high to low sort(vecMasternodeLastPaid.rbegin(), vecMasternodeLastPaid.rend(), CompareLastPaid()); @@ -579,12 +587,21 @@ CMasternode* CMasternodeMan::FindRandomNotInVec(std::vector& vecToExclude CMasternode* CMasternodeMan::GetCurrentMasterNode(int mod, int64_t nBlockHeight, int minProtocol) { + return GetCurrentMasternodeOnLevel (0, mod, nBlockHeight, minProtocol); +} + +CMasternode* CMasternodeMan::GetCurrentMasternodeOnLevel (unsigned int masternodeLevel, int mod, int64_t nBlockHeight, int minProtocol) { int64_t score = 0; CMasternode* winner = NULL; // scan for winner for (CMasternode& mn : vMasternodes) { mn.Check(); + + if ((masternodeLevel > 0) && + (mn.GetLevel () != masternodeLevel)) + continue; + if (mn.protocolVersion < minProtocol || !mn.IsEnabled()) continue; // calculate the score for each Masternode diff --git a/src/masternodeman.h b/src/masternodeman.h index cd557f0..9e864de 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -124,12 +124,14 @@ class CMasternodeMan /// Find an entry in the masternode list that is next to be paid CMasternode* GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCount); + CMasternode* GetNextMasternodeInQueueForPayment (int nBlockHeight, unsigned int masternodeLevel, bool fFilterSigTime, int& nCount); /// Find a random entry CMasternode* FindRandomNotInVec(std::vector& vecToExclude, int protocolVersion = -1); /// Get the current winner for this block CMasternode* GetCurrentMasterNode(int mod = 1, int64_t nBlockHeight = 0, int minProtocol = 0); + CMasternode* GetCurrentMasternodeOnLevel (unsigned int masternodeLevel, int mod = 1, int64_t nBlockHeight = 0, int minProtocol = 0); std::vector GetFullMasternodeVector() { From 6f1fb9feb4c84e44d7d507022d0a72a6a8281154 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Sun, 6 Sep 2020 17:46:23 +0200 Subject: [PATCH 18/49] Removed static references to default port --- src/init.cpp | 4 ++-- src/masternode.cpp | 4 ++-- src/masternodeconfig.cpp | 12 +++++------- src/rpc/masternode.cpp | 2 +- src/rpc/net.cpp | 4 ++-- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 1c91743..792700e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -411,7 +411,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-onlynet=", _("Only connect to nodes in network (ipv4, ipv6 or onion)")); strUsage += HelpMessageOpt("-permitbaremultisig", strprintf(_("Relay non-P2SH multisig (default: %u)"), 1)); strUsage += HelpMessageOpt("-peerbloomfilters", strprintf(_("Support filtering of blocks and transaction with bloom filters (default: %u)"), DEFAULT_PEERBLOOMFILTERS)); - strUsage += HelpMessageOpt("-port=", strprintf(_("Listen for connections on (default: %u or testnet: %u)"), 33555, 29991)); + strUsage += HelpMessageOpt("-port=", strprintf(_("Listen for connections on (default: %u or testnet: %u)"), Params ().GetDefaultPort (), 29991)); strUsage += HelpMessageOpt("-proxy=", _("Connect through SOCKS5 proxy")); strUsage += HelpMessageOpt("-proxyrandomize", strprintf(_("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)"), 1)); strUsage += HelpMessageOpt("-seednode=", _("Connect to a node to retrieve peer addresses, and disconnect")); @@ -531,7 +531,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-mnconf=", strprintf(_("Specify masternode configuration file (default: %s)"), "masternode.conf")); strUsage += HelpMessageOpt("-mnconflock=", strprintf(_("Lock masternodes from masternode configuration file (default: %u)"), 1)); strUsage += HelpMessageOpt("-masternodeprivkey=", _("Set the masternode private key")); - strUsage += HelpMessageOpt("-masternodeaddr=", strprintf(_("Set external address:port to get to this masternode (example: %s)"), "128.127.106.235:33555")); + strUsage += HelpMessageOpt("-masternodeaddr=", strprintf(_("Set external address:port to get to this masternode (example: %s)"), "128.127.106.235:" + Params ().GetDefaultPort ())); strUsage += HelpMessageOpt("-budgetvotemode=", _("Change automatic finalized budget voting behavior. mode=auto: Vote for only exact finalized budget match to my generated budget. (string, default: auto)")); diff --git a/src/masternode.cpp b/src/masternode.cpp index 1d8c44f..694bb42 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -532,8 +532,8 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) } if (Params().NetworkID() == CBaseChainParams::MAIN) { - if (addr.GetPort() != 33555) return false; - } else if (addr.GetPort() == 33555) + if (addr.GetPort() != Params ().GetDefaultPort ()) return false; + } else if (addr.GetPort() == Params ().GetDefaultPort ()) return false; //search existing Masternode list, this is where we update existing Masternodes with new mnb broadcasts diff --git a/src/masternodeconfig.cpp b/src/masternodeconfig.cpp index 8451b17..b3622ae 100644 --- a/src/masternodeconfig.cpp +++ b/src/masternodeconfig.cpp @@ -29,7 +29,7 @@ bool CMasternodeConfig::read(std::string& strErr) if (configFile != NULL) { std::string strHeader = "# Masternode config file\n" "# Format: alias IP:port masternodeprivkey collateral_output_txid collateral_output_index\n" - "# Example: mn1 127.0.0.2:33555 93HaYBVUCYjEMeeH1Y4sBGLALQZE1Yc1K64xiqgX37tGBDQL8Xg 2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c 0\n"; + "# Example: mn1 127.0.0.2:" + std::to_string (Params ().GetDefaultPort ()) + " 93HaYBVUCYjEMeeH1Y4sBGLALQZE1Yc1K64xiqgX37tGBDQL8Xg 2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c 0\n"; fwrite(strHeader.c_str(), std::strlen(strHeader.c_str()), 1, configFile); fclose(configFile); } @@ -70,17 +70,15 @@ bool CMasternodeConfig::read(std::string& strErr) } if (Params().NetworkID() == CBaseChainParams::MAIN) { - if (port != 33555) { + if (port !=Params ().GetDefaultPort ()) { strErr = _("Invalid port detected in masternode.conf") + "\n" + - strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"" + "\n" + - _("(must be 33555 for mainnet)"); + strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\""; streamConfig.close(); return false; } - } else if (port == 33555) { + } else if (port == Params ().GetDefaultPort ()) { strErr = _("Invalid port detected in masternode.conf") + "\n" + - strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"" + "\n" + - _("(33555 could be used only on mainnet)"); + strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\""; streamConfig.close(); return false; } diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index b92e32e..5456cdf 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -279,7 +279,7 @@ UniValue masternodeconnect(const UniValue& params, bool fHelp) "1. \"address\" (string, required) IP or net address to connect to\n" "\nExamples:\n" + - HelpExampleCli("masternodeconnect", "\"192.168.0.6:33555\"") + HelpExampleRpc("masternodeconnect", "\"192.168.0.6:33555\"")); + HelpExampleCli("masternodeconnect", "\"192.168.0.6:" + std::to_string (Params ().GetDefaultPort ()) + "\"") + HelpExampleRpc("masternodeconnect", "\"192.168.0.6:" + std::to_string (Params ().GetDefaultPort ()) + "\"")); std::string strAddress = params[0].get_str(); diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index f3a1e5f..0ce3a96 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -184,7 +184,7 @@ UniValue addnode(const UniValue& params, bool fHelp) "2. \"command\" (string, required) 'add' to add a node to the list, 'remove' to remove a node from the list, 'onetry' to try a connection to the node once\n" "\nExamples:\n" + - HelpExampleCli("addnode", "\"192.168.0.6:33555\" \"onetry\"") + HelpExampleRpc("addnode", "\"192.168.0.6:33555\", \"onetry\"")); + HelpExampleCli("addnode", "\"192.168.0.6:" + std::to_string (Params ().GetDefaultPort ()) + "\" \"onetry\"") + HelpExampleRpc("addnode", "\"192.168.0.6:" + std::to_string (Params ().GetDefaultPort ()) + "\", \"onetry\"")); string strNode = params[0].get_str(); @@ -258,7 +258,7 @@ UniValue getaddednodeinfo(const UniValue& params, bool fHelp) " \"connected\" : true|false, (boolean) If connected\n" " \"addresses\" : [\n" " {\n" - " \"address\" : \"192.168.0.201:33555\", (string) The masterwin server host and port\n" + " \"address\" : \"192.168.0.201:" + std::to_string (Params ().GetDefaultPort ()) + "\", (string) The masterwin server host and port\n" " \"connected\" : \"outbound\" (string) connection, inbound or outbound\n" " }\n" " ,...\n" From ba9bda4b129d92245c3b70478501f5e891e1beb1 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Sun, 6 Sep 2020 17:50:10 +0200 Subject: [PATCH 19/49] Output masternode-level on masternode-list (rpc) --- src/rpc/masternode.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 5456cdf..b836adc 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -210,6 +210,7 @@ UniValue listmasternodes(const UniValue& params, bool fHelp) " \"status\": s, (string) Status (ENABLED/EXPIRED/REMOVE/etc)\n" " \"addr\": \"addr\", (string) Masternode MasterWin address\n" " \"version\": v, (numeric) Masternode protocol version\n" + " \"level\": l, (numeric) Masternode-Tier Level\n" " \"lastseen\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last seen\n" " \"activetime\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) masternode has been active\n" " \"lastpaid\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) masternode was last paid\n" @@ -257,6 +258,7 @@ UniValue listmasternodes(const UniValue& params, bool fHelp) obj.push_back(Pair("ip", mn->addr.ToStringIP())); obj.push_back(Pair("addr", CBitcoinAddress(mn->pubKeyCollateralAddress.GetID()).ToString())); obj.push_back(Pair("version", mn->protocolVersion)); + obj.push_back (Pair ("level", (uint64_t)mn->GetLevel ())); obj.push_back(Pair("lastseen", (int64_t)mn->lastPing.sigTime)); obj.push_back(Pair("activetime", (int64_t)(mn->lastPing.sigTime - mn->sigTime))); obj.push_back(Pair("lastpaid", (int64_t)mn->GetLastPaid())); From 0462ace70a1d0777b07fbcd3f375870c41317064 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Sun, 6 Sep 2020 18:40:31 +0200 Subject: [PATCH 20/49] Send out mnw for each masternode-level --- src/masternode-payments.cpp | 91 +++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index e5e60d2..364a93b 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -727,57 +727,60 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight) if (nBlockHeight <= nLastBlockHeight) return false; - CMasternodePaymentWinner newWinner(activeMasternode.vin); - - if (!budget.IsBudgetPaymentBlock (nBlockHeight)) { - LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Start nHeight %d - vin %s. \n", nBlockHeight, activeMasternode.vin.prevout.hash.ToString ()); - - for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { - // pay to the oldest MN that still had no payment but its input is old enough and it was active long enough - int nCount = 0; - CMasternode* pmn = mnodeman.GetNextMasternodeInQueueForPayment (nBlockHeight, masternodeLevel, true, nCount); - - if (pmn == NULL) { - LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Failed to find masternode to pay\n"); - continue; - } - - LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Found by FindOldestNotInVec\n"); - - newWinner.nBlockHeight = nBlockHeight; - - CScript payee = GetScriptForDestination (pmn->pubKeyCollateralAddress.GetID()); - newWinner.AddPayee (payee, masternodeLevel); - - CTxDestination address1; - ExtractDestination (payee, address1); - CBitcoinAddress address2 (address1); - - LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Winner payee %s nHeight %d. \n", address2.ToString ().c_str (), newWinner.nBlockHeight); - } - } - + if (budget.IsBudgetPaymentBlock (nBlockHeight)) + return true; + + LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Start nHeight %d - vin %s. \n", nBlockHeight, activeMasternode.vin.prevout.hash.ToString ()); + + // Prepare for signing messages std::string errorMessage; CPubKey pubKeyMasternode; CKey keyMasternode; - - if (!obfuScationSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)) { - LogPrint("masternode","CMasternodePayments::ProcessBlock() - Error upon calling SetKey: %s\n", errorMessage.c_str()); + + if (!obfuScationSigner.SetKey (strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)) { + LogPrint ("masternode", "CMasternodePayments::ProcessBlock() - Error upon calling SetKey: %s\n", errorMessage.c_str ()); + return false; } - - LogPrint("masternode","CMasternodePayments::ProcessBlock() - Signing Winner\n"); - if (newWinner.Sign(keyMasternode, pubKeyMasternode)) { - LogPrint("masternode","CMasternodePayments::ProcessBlock() - AddWinningMasternode\n"); - - if (AddWinningMasternode(newWinner)) { - newWinner.Relay(); - nLastBlockHeight = nBlockHeight; - return true; + + for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + // Create a new winner for this level + CMasternodePaymentWinner newWinner (activeMasternode.vin); + + // pay to the oldest MN that still had no payment but its input is old enough and it was active long enough + int nCount = 0; + CMasternode* pmn = mnodeman.GetNextMasternodeInQueueForPayment (nBlockHeight, masternodeLevel, true, nCount); + + if (pmn == NULL) { + LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Failed to find masternode to pay\n"); + + continue; } + + LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Found by FindOldestNotInVec\n"); + + newWinner.nBlockHeight = nBlockHeight; + + CScript payee = GetScriptForDestination (pmn->pubKeyCollateralAddress.GetID()); + newWinner.AddPayee (payee, masternodeLevel); + + CTxDestination address1; + ExtractDestination (payee, address1); + CBitcoinAddress address2 (address1); + + LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Winner payee %s nHeight %d level %d. \n", address2.ToString ().c_str (), newWinner.nBlockHeight, masternodeLevel); + + if (newWinner.Sign (keyMasternode, pubKeyMasternode)) { + if (AddWinningMasternode (newWinner)) { + newWinner.Relay (); + nLastBlockHeight = nBlockHeight; + } else + LogPrint ("masternode", "CMasternodePayments::ProcessBlock() FAILED to add winning masternode\n"); + } else + LogPrint ("masternode", "CMasternodePayments::ProcessBlock() FAILED to sign winner\n"); } - - return false; + + return (nLastBlockHeight == nBlockHeight); } void CMasternodePaymentWinner::Relay() From eaffbdc905b03edf958b4fca433b48d7a6992322 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Sun, 6 Sep 2020 18:53:12 +0200 Subject: [PATCH 21/49] Include masternode-level on winners --- src/masternode-payments.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/masternode-payments.h b/src/masternode-payments.h index 6c05c25..e5df0f0 100644 --- a/src/masternode-payments.h +++ b/src/masternode-payments.h @@ -232,6 +232,7 @@ class CMasternodePaymentWinner ss << payee; ss << nBlockHeight; ss << vinMasternode.prevout; + ss << masternodeLevel; return ss.GetHash(); } @@ -260,6 +261,7 @@ class CMasternodePaymentWinner READWRITE(vinMasternode); READWRITE(nBlockHeight); READWRITE(payee); + READWRITE(masternodeLevel); READWRITE(vchSig); } From 2ee005dd1db8062481db56c26b68cd46bac46298 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Sun, 6 Sep 2020 19:24:28 +0200 Subject: [PATCH 22/49] Show masternode-level for getmasternodeoutputs (rpc) --- src/rpc/masternode.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index b836adc..5446ba4 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -596,7 +596,8 @@ UniValue getmasternodeoutputs (const UniValue& params, bool fHelp) "[\n" " {\n" " \"txhash\": \"xxxx\", (string) output transaction hash\n" - " \"outputidx\": n (numeric) output index number\n" + " \"outputidx\": n, (numeric) output index number\n" + " \"level\": l, (numeric) level of output\n" " }\n" " ,...\n" "]\n" @@ -612,6 +613,7 @@ UniValue getmasternodeoutputs (const UniValue& params, bool fHelp) UniValue obj(UniValue::VOBJ); obj.push_back(Pair("txhash", out.tx->GetHash().ToString())); obj.push_back(Pair("outputidx", out.i)); + obj.push_back (Pair ("level", (uint64_t)Params ().getMasternodeLevel (out.tx->vout [out.i].nValue))); ret.push_back(obj); } From 7259c59fdb140c4f1a8b936827ead12bc253f46f Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Sun, 6 Sep 2020 22:28:35 +0200 Subject: [PATCH 23/49] Fixed Masternode-Rewards --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 0754582..a58bb88 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2007,7 +2007,7 @@ int64_t GetMasternodePayment (int nHeight, unsigned int mnLevel, int64_t blockVa if (masternodeLevels == 0) return 0; - return masternodeTotalPayment * mnLevel / ((1 << masternodeLevels) - 1); + return masternodeTotalPayment * (1 << (mnLevel - 1)) / ((1 << masternodeLevels) - 1); } From 2905ce5ea0275429a072b47548e0939c7fa39828 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Mon, 7 Sep 2020 10:02:49 +0200 Subject: [PATCH 24/49] Improved transaction-valid check --- src/masternode-payments.cpp | 59 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 364a93b..d4a9b3a 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -555,9 +555,6 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) LOCK(cs_vecPayments); int nMasternode_Drift_Count = 0; - - std::string strPayeesPossible = ""; - CAmount nReward = GetBlockValue(nBlockHeight); if (IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) { @@ -571,7 +568,7 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) nMasternode_Drift_Count = mnodeman.size() + Params().MasternodeCountDrift(); } - bool transactionCorrect = false; + bool transactionCorrect = true; CAmount requiredMasternodePayment = 0; for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { @@ -585,51 +582,53 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) nMaxSignatures = payee.nVotes; // if we don't have at least 6 signatures on a payee, approve whichever is the longest chain - if (nMaxSignatures < MNPAYMENTS_SIGNATURES_REQUIRED) { - transactionCorrect = true; - + if (nMaxSignatures < MNPAYMENTS_SIGNATURES_REQUIRED) continue; - } requiredMasternodePayment = GetMasternodePayment (nBlockHeight, masternodeLevel, nReward, nMasternode_Drift_Count); + bool hasLevelPayment = false; + std::string strPayeesPossible = ""; for (CMasternodePayee& payee : vecPayments) { - bool found = false; - + // Skip payees on other levels if (payee.masternodeLevel != masternodeLevel) continue; + // Skip payees with little votes + if (payee.nVotes < MNPAYMENTS_SIGNATURES_REQUIRED) + continue; + + // Check if this payee was paid for (CTxOut out : txNew.vout) if (payee.scriptPubKey == out.scriptPubKey) { if(out.nValue >= requiredMasternodePayment) { - found = true; + hasLevelPayment = true; break; } else LogPrint ("masternode", "Masternode payment is out of drift range. Paid=%s Min=%s\n", FormatMoney (out.nValue).c_str (), FormatMoney (requiredMasternodePayment).c_str ()); } - if (payee.nVotes >= MNPAYMENTS_SIGNATURES_REQUIRED) { - if (found) { - transactionCorrect = true; - - continue; - } - - CTxDestination address1; - ExtractDestination (payee.scriptPubKey, address1); - CBitcoinAddress address2 (address1); - - if (strPayeesPossible == "") - strPayeesPossible += address2.ToString (); - else - strPayeesPossible += "," + address2.ToString (); - } + if (hasLevelPayment) + break; + + // Push payee to possible payees + CTxDestination address1; + ExtractDestination (payee.scriptPubKey, address1); + CBitcoinAddress address2 (address1); + + if (strPayeesPossible == "") + strPayeesPossible += address2.ToString (); + else + strPayeesPossible += "," + address2.ToString (); + } + + if (!hasLevelPayment) { + LogPrint ("masternode", "CMasternodePayments::IsTransactionValid - Missing required payment of %s to %s on level %d\n", FormatMoney (requiredMasternodePayment).c_str (), strPayeesPossible.c_str (), masternodeLevel); + + transactionCorrect = false; } } - - if (!transactionCorrect) - LogPrint ("masternode", "CMasternodePayments::IsTransactionValid - Missing required payment of %s to %s\n", FormatMoney (requiredMasternodePayment).c_str (), strPayeesPossible.c_str ()); return transactionCorrect; } From 037e01e9056ee153ef8fef0fb68457b726bc50fc Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Mon, 7 Sep 2020 18:14:27 +0200 Subject: [PATCH 25/49] Added tiers to getpoolinfo (rpc) --- src/rpc/masternode.cpp | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 5446ba4..2f88f2c 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -29,10 +29,20 @@ UniValue getpoolinfo(const UniValue& params, bool fHelp) "\nResult:\n" "{\n" - " \"current\": \"addr\", (string) MasterWin address of current masternode\n" - " \"state\": xxxx, (string) unknown\n" - " \"entries\": xxxx, (numeric) Number of entries\n" - " \"accepted\": xxxx, (numeric) Number of entries accepted\n" + " \"current\": \"addr\", (string) MasterWin address of current masternode\n" + " \"state\": xxxx, (string) unknown\n" + " \"entries\": xxxx, (numeric) Number of entries\n" + " \"accepted\": xxxx, (numeric) Number of entries accepted\n" + " \"tiers\": [\n" + " {\n" + " \"level\": l, (numeric) Level of tier\n" + " \"current\": \"addr\", (string) MasterWin address of current masternode\n" + " \"state\": xxxx, (string) unknown\n" + " \"entries\": xxxx, (numeric) Number of entries\n" + " \"accepted\": xxxx, (numeric) Number of entries accepted\n" + " },\n" + " ...\n" + " ]\n" "}\n" "\nExamples:\n" + @@ -43,6 +53,25 @@ UniValue getpoolinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("state", obfuScationPool.GetState())); obj.push_back(Pair("entries", obfuScationPool.GetEntriesCount())); obj.push_back(Pair("entries_accepted", obfuScationPool.GetCountEntriesAccepted())); + + UniValue tiers (UniValue::VARR); + + for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + UniValue tier (UniValue::VOBJ); + + tier.push_back (Pair ("level", (uint64_t)masternodeLevel)); + tier.push_back (Pair ("current", mnodeman.GetCurrentMasternodeOnLevel (masternodeLevel)->addr.ToString())); + + // TODO: This is senseless :) + tier.push_back (Pair ("state", obfuScationPool.GetState ())); + tier.push_back (Pair ("entries", obfuScationPool.GetEntriesCount ())); + tier.push_back (Pair ("entries_accepted", obfuScationPool.GetCountEntriesAccepted ())); + + tiers.push_back (tier); + } + + obj.push_back (Pair ("tiers", tiers)); + return obj; } From 7fa673f94136dab544e3512b97db49c3a2af027d Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Mon, 7 Sep 2020 18:16:38 +0200 Subject: [PATCH 26/49] Added tiers to masternode list (rpc) --- src/rpc/masternode.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 2f88f2c..6b66b0d 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -233,6 +233,7 @@ UniValue listmasternodes(const UniValue& params, bool fHelp) "\nResult:\n" "[\n" " {\n" + " \"level\": l, (numeric) Tier/Level of masternode\n" " \"rank\": n, (numeric) Masternode Rank (or 0 if not enabled)\n" " \"txhash\": \"hash\", (string) Collateral transaction hash\n" " \"outidx\": n, (numeric) Collateral transaction output index\n" @@ -279,6 +280,7 @@ UniValue listmasternodes(const UniValue& params, bool fHelp) CNetAddr node = CNetAddr(strHost, false); std::string strNetwork = GetNetworkName(node.GetNetwork()); + obj.push_back (Pair ("level", (uint64_t)mn->GetLevel ())); obj.push_back(Pair("rank", (strStatus == "ENABLED" ? s.first : 0))); obj.push_back(Pair("network", strNetwork)); obj.push_back(Pair("txhash", strTxHash)); From d9a29e6f3b086e9a1ca62e84c2130ae69a83240d Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Sat, 12 Sep 2020 23:22:55 +0200 Subject: [PATCH 27/49] Added tiers to masternode count (rpc) --- src/masternodeman.cpp | 20 ++++++++++++---- src/masternodeman.h | 17 ++++++++++++- src/rpc/masternode.cpp | 54 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 81 insertions(+), 10 deletions(-) diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index aed2f26..c2bd247 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -348,14 +348,20 @@ void CMasternodeMan::Clear() nDsqCount = 0; } -int CMasternodeMan::stable_size () -{ +int CMasternodeMan::stable_size () { + return stable_size (0); +} + +int CMasternodeMan::stable_size (unsigned int masternodeLevel) { int nStable_size = 0; int nMinProtocol = ActiveProtocol(); int64_t nMasternode_Min_Age = MN_WINNER_MINIMUM_AGE; int64_t nMasternode_Age = 0; for (CMasternode& mn : vMasternodes) { + if ((masternodeLevel > 0) && (mn.GetLevel () != masternodeLevel)) + continue; + if (mn.protocolVersion < nMinProtocol) { continue; // Skip obsolete versions } @@ -398,11 +404,17 @@ int CMasternodeMan::CountEnabledOnLevel (unsigned int mnLevel, int protocolVersi return masternodeCount; } -void CMasternodeMan::CountNetworks(int protocolVersion, int& ipv4, int& ipv6, int& onion) -{ +void CMasternodeMan::CountNetworks (int protocolVersion, int& ipv4, int& ipv6, int& onion) { + return CountNetworks (0, protocolVersion, ipv4, ipv6, onion); +} + +void CMasternodeMan::CountNetworks (unsigned int masternodeLevel, int protocolVersion, int& ipv4, int& ipv6, int& onion) { protocolVersion = protocolVersion == -1 ? masternodePayments.GetMinMasternodePaymentsProto() : protocolVersion; for (CMasternode& mn : vMasternodes) { + if ((masternodeLevel > 0) && (mn.GetLevel () != masternodeLevel)) + continue; + mn.Check(); std::string strHost; int port; diff --git a/src/masternodeman.h b/src/masternodeman.h index 9e864de..e6dd061 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -114,6 +114,7 @@ class CMasternodeMan int CountEnabledOnLevel (unsigned int mnLevel, int protocolVersion = -1); void CountNetworks(int protocolVersion, int& ipv4, int& ipv6, int& onion); + void CountNetworks (unsigned int masternodeLevel, int protocolVersion, int& ipv4, int& ipv6, int& onion); void DsegUpdate(CNode* pnode); @@ -148,10 +149,24 @@ class CMasternodeMan void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); /// Return the number of (unique) Masternodes - int size() { return vMasternodes.size(); } + int size () { + return vMasternodes.size(); + } + + int size (unsigned int masternodeLevel) { + int masternodeCount = 0; + + BOOST_FOREACH (CMasternode masternode, vMasternodes) { + if (masternode.GetLevel () == masternodeLevel) + masternodeCount++; + } + + return masternodeCount; + } /// Return the number of Masternodes older than (default) 8000 seconds int stable_size (); + int stable_size (unsigned int masternodeLevel); std::string ToString() const; diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 6b66b0d..22ef52c 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -336,11 +336,28 @@ UniValue getmasternodecount (const UniValue& params, bool fHelp) "\nResult:\n" "{\n" - " \"total\": n, (numeric) Total masternodes\n" - " \"stable\": n, (numeric) Stable count\n" - " \"obfcompat\": n, (numeric) Obfuscation Compatible\n" - " \"enabled\": n, (numeric) Enabled masternodes\n" - " \"inqueue\": n (numeric) Masternodes in queue\n" + " \"total\": n, (numeric) Total masternodes\n" + " \"stable\": n, (numeric) Stable count\n" + " \"obfcompat\": n, (numeric) Obfuscation Compatible\n" + " \"enabled\": n, (numeric) Enabled masternodes\n" + " \"inqueue\": n, (numeric) Masternodes in queue\n" + " \"ipv4\": n, (numeric) Masternodes with IPv4 address\n" + " \"ipv6\": n, (numeric) Masternodes with IPv6 address\n" + " \"onion\": n, (numeric) Masternodes with Onion address\n" + " \"tiers\": [\n" + " {\n" + " \"level\": l, (numeric) Tier-Level\n" + " \"total\": n, (numeric) Total masternodes\n" + " \"stable\": n, (numeric) Stable count\n" + " \"obfcompat\": n, (numeric) Obfuscation Compatible\n" + " \"enabled\": n, (numeric) Enabled masternodes\n" + " \"inqueue\": n, (numeric) Masternodes in queue\n" + " \"ipv4\": n, (numeric) Masternodes with IPv4 address\n" + " \"ipv6\": n, (numeric) Masternodes with IPv6 address\n" + " \"onion\": n, (numeric) Masternodes with Onion address\n" + " },\n" + " ...\n" + " ]\n" "}\n" "\nExamples:\n" + @@ -363,6 +380,33 @@ UniValue getmasternodecount (const UniValue& params, bool fHelp) obj.push_back(Pair("ipv4", ipv4)); obj.push_back(Pair("ipv6", ipv6)); obj.push_back(Pair("onion", onion)); + + UniValue tiers (UniValue::VARR); + + for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + UniValue tier (UniValue::VOBJ); + + nCount = ipv4 = ipv6 = onion = 0; + + if (chainActive.Tip ()) + mnodeman.GetNextMasternodeInQueueForPayment (chainActive.Tip ()->nHeight, masternodeLevel, true, nCount); + + mnodeman.CountNetworks (masternodeLevel, ActiveProtocol (), ipv4, ipv6, onion); + + tier.push_back (Pair ("level", (uint64_t)masternodeLevel)); + tier.push_back (Pair ("total", mnodeman.size (masternodeLevel))); + tier.push_back (Pair ("stable", mnodeman.stable_size (masternodeLevel))); + tier.push_back (Pair ("obfcompat", mnodeman.CountEnabledOnLevel (masternodeLevel, ActiveProtocol ()))); + tier.push_back (Pair ("enabled", mnodeman.CountEnabledOnLevel (masternodeLevel))); + tier.push_back (Pair ("inqueue", nCount)); + tier.push_back (Pair ("ipv4", ipv4)); + tier.push_back (Pair ("ipv6", ipv6)); + tier.push_back (Pair ("onion", onion)); + + tiers.push_back (tier); + } + + obj.push_back (Pair ("tiers", tiers)); return obj; } From 06a6d388b30c9599882d7752516b2f4fe0a29af3 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Sat, 12 Sep 2020 23:31:28 +0200 Subject: [PATCH 28/49] Added tiers to masternode current (rpc) --- src/rpc/masternode.cpp | 60 ++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 22ef52c..5b55d10 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -420,29 +420,61 @@ UniValue masternodecurrent (const UniValue& params, bool fHelp) "\nResult:\n" "{\n" - " \"protocol\": xxxx, (numeric) Protocol version\n" - " \"txhash\": \"xxxx\", (string) Collateral transaction hash\n" - " \"pubkey\": \"xxxx\", (string) MN Public key\n" - " \"lastseen\": xxx, (numeric) Time since epoch of last seen\n" - " \"activeseconds\": xxx, (numeric) Seconds MN has been active\n" + " \"protocol\": xxxx, (numeric) Protocol version\n" + " \"txhash\": \"xxxx\", (string) Collateral transaction hash\n" + " \"pubkey\": \"xxxx\", (string) MN Public key\n" + " \"lastseen\": xxx, (numeric) Time since epoch of last seen\n" + " \"activeseconds\": xxx, (numeric) Seconds MN has been active\n" + " \"tiers\": [\n" + " {\n" + " \"level\": level, (numeric) Tier-Level\n" + " \"protocol\": xxxx, (numeric) Protocol version\n" + " \"txhash\": \"xxxx\", (string) Collateral transaction hash\n" + " \"pubkey\": \"xxxx\", (string) MN Public key\n" + " \"lastseen\": xxx, (numeric) Time since epoch of last seen\n" + " \"activeseconds\": xxx, (numeric) Seconds MN has been active\n" + " },\n" + " ...\n" + " ]\n" "}\n" "\nExamples:\n" + HelpExampleCli("masternodecurrent", "") + HelpExampleRpc("masternodecurrent", "")); CMasternode* winner = mnodeman.GetCurrentMasterNode(1); - if (winner) { - UniValue obj(UniValue::VOBJ); + + if (!winner) + throw runtime_error ("unknown"); + + UniValue obj (UniValue::VOBJ); + + obj.push_back (Pair ("protocol", (int64_t)winner->protocolVersion)); + obj.push_back (Pair ("txhash", winner->vin.prevout.hash.ToString ())); + obj.push_back (Pair ("pubkey", CBitcoinAddress (winner->pubKeyCollateralAddress.GetID ()).ToString ())); + obj.push_back (Pair ("lastseen", (winner->lastPing == CMasternodePing ()) ? winner->sigTime : (int64_t)winner->lastPing.sigTime)); + obj.push_back (Pair ("activeseconds", (winner->lastPing == CMasternodePing ()) ? 0 : (int64_t)(winner->lastPing.sigTime - winner->sigTime))); + + UniValue tiers (UniValue::VARR); + + for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + if (!(winner = mnodeman.GetCurrentMasternodeOnLevel (masternodeLevel, 1))) + continue; + + UniValue tier (UniValue::VOBJ); + + tier.push_back (Pair ("level", (uint64_t)masternodeLevel)); + tier.push_back (Pair ("protocol", (int64_t)winner->protocolVersion)); + tier.push_back (Pair ("txhash", winner->vin.prevout.hash.ToString ())); + tier.push_back (Pair ("pubkey", CBitcoinAddress (winner->pubKeyCollateralAddress.GetID ()).ToString ())); + tier.push_back (Pair ("lastseen", (winner->lastPing == CMasternodePing ()) ? winner->sigTime : (int64_t)winner->lastPing.sigTime)); + tier.push_back (Pair ("activeseconds", (winner->lastPing == CMasternodePing ()) ? 0 : (int64_t)(winner->lastPing.sigTime - winner->sigTime))); - obj.push_back(Pair("protocol", (int64_t)winner->protocolVersion)); - obj.push_back(Pair("txhash", winner->vin.prevout.hash.ToString())); - obj.push_back(Pair("pubkey", CBitcoinAddress(winner->pubKeyCollateralAddress.GetID()).ToString())); - obj.push_back(Pair("lastseen", (winner->lastPing == CMasternodePing()) ? winner->sigTime : (int64_t)winner->lastPing.sigTime)); - obj.push_back(Pair("activeseconds", (winner->lastPing == CMasternodePing()) ? 0 : (int64_t)(winner->lastPing.sigTime - winner->sigTime))); - return obj; + tiers.push_back (tier); } - throw runtime_error("unknown"); + obj.push_back (Pair ("tiers", tiers)); + + return obj; } UniValue masternodedebug (const UniValue& params, bool fHelp) From 1a56975fb756fc48b1d5aaa6a42d424bdd1e2a82 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Sat, 12 Sep 2020 23:38:26 +0200 Subject: [PATCH 29/49] Added tiers to masternode list-conf (rpc) --- src/rpc/masternode.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 5b55d10..88cab7c 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -749,7 +749,8 @@ UniValue listmasternodeconf (const UniValue& params, bool fHelp) " \"privateKey\": \"xxxx\", (string) masternode private key\n" " \"txHash\": \"xxxx\", (string) transaction hash\n" " \"outputIndex\": n, (numeric) transaction output index\n" - " \"status\": \"xxxx\" (string) masternode status\n" + " \"status\": \"xxxx\", (string) masternode status\n" + " \"level\": level, (numeric) Level of tiered masternode\n" " }\n" " ,...\n" "]\n" @@ -768,6 +769,8 @@ UniValue listmasternodeconf (const UniValue& params, bool fHelp) continue; CTxIn vin = CTxIn(uint256(mne.getTxHash()), uint32_t(nIndex)); CMasternode* pmn = mnodeman.Find(vin); + CTransaction prevTx; + uint256 hashBlock = 0; std::string strStatus = pmn ? pmn->Status() : "MISSING"; @@ -783,6 +786,11 @@ UniValue listmasternodeconf (const UniValue& params, bool fHelp) mnObj.push_back(Pair("txHash", mne.getTxHash())); mnObj.push_back(Pair("outputIndex", mne.getOutputIndex())); mnObj.push_back(Pair("status", strStatus)); + + if (GetTransaction (vin.prevout.hash, prevTx, hashBlock, true) && + (prevTx.vout.size () > vin.prevout.n)) + mnObj.push_back (Pair ("level", (uint64_t)Params ().getMasternodeLevel (prevTx.vout [vin.prevout.n].nValue))); + ret.push_back(mnObj); } From 4150dd74c44bf3edc16c2c1b16b0e567230a0f7f Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Sat, 12 Sep 2020 23:41:39 +0200 Subject: [PATCH 30/49] Added tiers to masternode status (rpc) --- src/rpc/masternode.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 88cab7c..2c2e619 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -811,7 +811,8 @@ UniValue getmasternodestatus (const UniValue& params, bool fHelp) " \"netaddr\": \"xxxx\", (string) Masternode network address\n" " \"addr\": \"xxxx\", (string) MasterWin address for masternode payments\n" " \"status\": \"xxxx\", (string) Masternode status\n" - " \"message\": \"xxxx\" (string) Masternode status message\n" + " \"message\": \"xxxx\", (string) Masternode status message\n" + " \"level\": level, (numeric) Tier-Level of masternode\n" "}\n" "\nExamples:\n" + @@ -829,6 +830,8 @@ UniValue getmasternodestatus (const UniValue& params, bool fHelp) mnObj.push_back(Pair("addr", CBitcoinAddress(pmn->pubKeyCollateralAddress.GetID()).ToString())); mnObj.push_back(Pair("status", activeMasternode.status)); mnObj.push_back(Pair("message", activeMasternode.GetStatus())); + mnObj.push_back (Pair ("level", (uint64_t)pmn->GetLevel ())); + return mnObj; } throw runtime_error("Masternode not found in the list of available masternodes. Current status: " From 82ae13d673c2c01c7d5f8509102c1e2a38ead1a5 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Sun, 13 Sep 2020 00:47:42 +0200 Subject: [PATCH 31/49] Restored and improved masternode winners (rpc) --- src/masternode-budget.cpp | 28 ++++++++++++ src/masternode-budget.h | 2 + src/masternode-payments.cpp | 38 +++++++++++++++++ src/masternode-payments.h | 10 +++++ src/rpc/masternode.cpp | 85 +++++++++++++------------------------ 5 files changed, 108 insertions(+), 55 deletions(-) diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index cfd7ade..2a7c054 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -882,6 +882,34 @@ std::vector CBudgetManager::GetFinalizedBudgets() return vFinalizedBudgetsRet; } +std::vector CBudgetManager::GetRequiredPayments (int nBlockHeight) { + LOCK (cs); + + std::vector vPaymentWinners; + std::map::iterator it = mapFinalizedBudgets.begin (); + + while (it != mapFinalizedBudgets.end ()) { + CFinalizedBudget* pfinalizedBudget = &((*it).second); + + if ((nBlockHeight >= pfinalizedBudget->GetBlockStart ()) && (nBlockHeight <= pfinalizedBudget->GetBlockEnd ())) { + CTxBudgetPayment payment; + + if (pfinalizedBudget->GetBudgetPaymentByBlock (nBlockHeight, payment)) { + CPaymentWinner paymentWinner; + + paymentWinner.strAddress = payment.nProposalHash.ToString (); + + vPaymentWinners.push_back (paymentWinner); + } else + LogPrint ("mnbudget","CBudgetManager::GetRequiredPaymentsString - Couldn't find budget payment for block %d\n", nBlockHeight); + } + + ++it; + } + + return vPaymentWinners; +} + CAmount CBudgetManager::GetTotalBudget(int nHeight) { if (chainActive.Tip() == NULL) return 0; diff --git a/src/masternode-budget.h b/src/masternode-budget.h index 9e168d0..be5faba 100644 --- a/src/masternode-budget.h +++ b/src/masternode-budget.h @@ -16,6 +16,7 @@ #include "sync.h" #include "util.h" #include +#include "masternode-payments.h" using namespace std; @@ -244,6 +245,7 @@ class CBudgetManager bool UpdateFinalizedBudget(CFinalizedBudgetVote& vote, CNode* pfrom, std::string& strError); bool PropExists(uint256 nHash); TrxValidationStatus IsTransactionValid(const CTransaction& txNew, int nBlockHeight); + std::vector GetRequiredPayments (int nBlockHeight); void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees, bool fProofOfStake); void CheckOrphanVotes(); diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index d4a9b3a..f4a6c6b 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -282,6 +282,13 @@ void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees, bool fProofOfStak } } +std::vector GetRequiredPayments (int nBlockHeight) { + if (IsSporkActive (SPORK_13_ENABLE_SUPERBLOCKS) && budget.IsBudgetPaymentBlock (nBlockHeight)) + return budget.GetRequiredPayments (nBlockHeight); + + return masternodePayments.GetRequiredPayments (nBlockHeight); +} + void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool fProofOfStake, bool fZMWStake) { CBlockIndex* pindexPrev = chainActive.Tip(); @@ -633,6 +640,37 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) return transactionCorrect; } +std::vector CMasternodeBlockPayees::GetRequiredPayments () { + LOCK (cs_vecPayments); + std::vector vPaymentWinners; + + for (CMasternodePayee& payee : vecPayments) { + CTxDestination address1; + ExtractDestination (payee.scriptPubKey, address1); + CBitcoinAddress address2 (address1); + CPaymentWinner paymentWinner; + + paymentWinner.strAddress = address2.ToString (); + paymentWinner.nVotes = payee.nVotes; + paymentWinner.masternodeLevel = payee.masternodeLevel; + + vPaymentWinners.push_back (paymentWinner); + } + + return vPaymentWinners; +} + +std::vector CMasternodePayments::GetRequiredPayments (int nBlockHeight) { + LOCK (cs_mapMasternodeBlocks); + + if (mapMasternodeBlocks.count (nBlockHeight)) + return mapMasternodeBlocks [nBlockHeight].GetRequiredPayments (); + + std::vector vPaymentWinners; + + return vPaymentWinners; +} + bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlockHeight) { LOCK(cs_mapMasternodeBlocks); diff --git a/src/masternode-payments.h b/src/masternode-payments.h index e5df0f0..30191f2 100644 --- a/src/masternode-payments.h +++ b/src/masternode-payments.h @@ -27,8 +27,16 @@ extern CMasternodePayments masternodePayments; #define MNPAYMENTS_SIGNATURES_REQUIRED 6 #define MNPAYMENTS_SIGNATURES_TOTAL 10 +class CPaymentWinner { + public: + std::string strAddress; + uint64_t nVotes; + unsigned int masternodeLevel; +}; + void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); bool IsBlockPayeeValid(const CBlock& block, int nBlockHeight); +std::vector GetRequiredPayments (int nBlockHeight); bool IsBlockValueValid(const CBlock& block, CAmount nExpectedValue, CAmount nMinted); void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees, bool fProofOfStake, bool fZMWStake); @@ -188,6 +196,7 @@ class CMasternodeBlockPayees } bool IsTransactionValid(const CTransaction& txNew); + std::vector GetRequiredPayments (); ADD_SERIALIZE_METHODS; @@ -350,6 +359,7 @@ class CMasternodePayments int GetMinMasternodePaymentsProto(); void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); + std::vector GetRequiredPayments (int nBlockHeight); void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool fProofOfStake, bool fZMWStake); std::string ToString() const; int GetOldestBlock(); diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 2c2e619..9f857aa 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -842,33 +842,21 @@ UniValue getmasternodewinners (const UniValue& params, bool fHelp) { if (fHelp || params.size() > 3) throw runtime_error( - "getmasternodewinners ( blocks \"filter\" )\n" + "getmasternodewinners ( blocks )\n" "\nPrint the masternode winners for the last n blocks\n" "\nArguments:\n" "1. blocks (numeric, optional) Number of previous blocks to show (default: 10)\n" - "2. filter (string, optional) Search filter matching MN address\n" - "\nResult (single winner):\n" - "[\n" - " {\n" - " \"nHeight\": n, (numeric) block height\n" - " \"winner\": {\n" - " \"address\": \"xxxx\", (string) MasterWin MN Address\n" - " \"nVotes\": n, (numeric) Number of votes for winner\n" - " }\n" - " }\n" - " ,...\n" - "]\n" - - "\nResult (multiple winners):\n" + "\nResult:\n" "[\n" " {\n" " \"nHeight\": n, (numeric) block height\n" " \"winner\": [\n" " {\n" - " \"address\": \"xxxx\", (string) MasterWin MN Address\n" - " \"nVotes\": n, (numeric) Number of votes for winner\n" + " \"address\": \"xxxx\", (string) MasterWin MN/Budget Address\n" + " \"nVotes\": n, (numeric) Number of votes for winner if payee is a masternode\n" + " \"level\": level, (numeric) Tier-Level if payee is a masternode\n" " }\n" " ,...\n" " ]\n" @@ -888,56 +876,43 @@ UniValue getmasternodewinners (const UniValue& params, bool fHelp) } int nLast = 10; - std::string strFilter = ""; if (params.size() >= 1) nLast = atoi(params[0].get_str()); - if (params.size() == 2) - strFilter = params[1].get_str(); - UniValue ret(UniValue::VARR); - /* for (int i = nHeight - nLast; i < nHeight + 20; i++) { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("nHeight", i)); - std::string strPayment = GetRequiredPaymentsString(i); - if (strFilter != "" && strPayment.find(strFilter) == std::string::npos) continue; - - if (strPayment.find(',') != std::string::npos) { - UniValue winner(UniValue::VARR); - boost::char_separator sep(","); - boost::tokenizer< boost::char_separator > tokens(strPayment, sep); - BOOST_FOREACH (const string& t, tokens) { - UniValue addr(UniValue::VOBJ); - std::size_t pos = t.find(":"); - std::string strAddress = t.substr(0,pos); - uint64_t nVotes = atoi(t.substr(pos+1)); - addr.push_back(Pair("address", strAddress)); - addr.push_back(Pair("nVotes", nVotes)); - winner.push_back(addr); - } - obj.push_back(Pair("winner", winner)); - } else if (strPayment.find("Unknown") == std::string::npos) { - UniValue winner(UniValue::VOBJ); - std::size_t pos = strPayment.find(":"); - std::string strAddress = strPayment.substr(0,pos); - uint64_t nVotes = atoi(strPayment.substr(pos+1)); - winner.push_back(Pair("address", strAddress)); - winner.push_back(Pair("nVotes", nVotes)); - obj.push_back(Pair("winner", winner)); - } else { - UniValue winner(UniValue::VOBJ); - winner.push_back(Pair("address", strPayment)); - winner.push_back(Pair("nVotes", 0)); - obj.push_back(Pair("winner", winner)); + std::vector vPaymentWinners = GetRequiredPayments (i); + + UniValue winners (UniValue::VARR); + + BOOST_FOREACH (CPaymentWinner &paymentWinner, vPaymentWinners) { + UniValue winner (UniValue::VOBJ); + + winner.push_back (Pair ("address", paymentWinner.strAddress)); + winner.push_back (Pair ("nVotes", paymentWinner.nVotes)); + winner.push_back (Pair ("level", (uint64_t)paymentWinner.masternodeLevel)); + + winners.push_back (winner); } - - ret.push_back(obj); + + if (!vPaymentWinners.size ()) { + UniValue winner (UniValue::VOBJ); + + winner.push_back (Pair ("address", "Unknown")); + winner.push_back (Pair ("nVotes", 0)); + winner.push_back (Pair ("level", 0)); + + winners.push_back (winner); + } + + obj.push_back (Pair ("winner", winners)); + ret.push_back (obj); } - */ return ret; } From 6f6214dde926a5469b5fd1c86f8036e2559aa40d Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Sun, 13 Sep 2020 01:01:04 +0200 Subject: [PATCH 32/49] Added tiers to masternode calcscore (rpc) --- src/rpc/masternode.cpp | 47 ++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 9f857aa..6156c94 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -929,8 +929,14 @@ UniValue getmasternodescores (const UniValue& params, bool fHelp) "\nResult:\n" "{\n" - " xxxx: \"xxxx\" (numeric : string) Block height : Masternode hash\n" - " ,...\n" + " xxxx: [\n (numeric) Block height\n" + " {\n" + " \"level\": level,\n" + " \"hash\": \"hash\"\n" + " },\n" + " ...\n" + " ],\n" + " ...\n" "}\n" "\nExamples:\n" + @@ -949,17 +955,36 @@ UniValue getmasternodescores (const UniValue& params, bool fHelp) std::vector vMasternodes = mnodeman.GetFullMasternodeVector(); for (int nHeight = chainActive.Tip()->nHeight - nLast; nHeight < chainActive.Tip()->nHeight + 20; nHeight++) { - uint256 nHigh = 0; - CMasternode* pBestMasternode = NULL; - BOOST_FOREACH (CMasternode& mn, vMasternodes) { - uint256 n = mn.CalculateScore(1, nHeight - 100); - if (n > nHigh) { - nHigh = n; - pBestMasternode = &mn; + UniValue block (UniValue::VARR); + + for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + uint256 nHigh = 0; + CMasternode* pBestMasternode = NULL; + + BOOST_FOREACH (CMasternode& mn, vMasternodes) { + if (mn.GetLevel () != masternodeLevel) + continue; + + uint256 n = mn.CalculateScore (1, nHeight - 100); + + if (n > nHigh) { + nHigh = n; + pBestMasternode = &mn; + } + } + + if (pBestMasternode) { + UniValue tier (UniValue::VOBJ); + + tier.push_back (Pair ("level", (uint64_t)masternodeLevel)); + tier.push_back (Pair ("hash", pBestMasternode->vin.prevout.hash.ToString ().c_str ())); + + block.push_back (tier); } } - if (pBestMasternode) - obj.push_back(Pair(strprintf("%d", nHeight), pBestMasternode->vin.prevout.hash.ToString().c_str())); + + if (block.size ()) + obj.push_back (Pair (strprintf("%d", nHeight), block)); } return obj; From 98c1e4c3e73fb153b9333aedd3e26800fdbb32c6 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Sun, 13 Sep 2020 01:15:36 +0200 Subject: [PATCH 33/49] Fixed QT-Event-Issue with coingecko --- src/qt/overviewpage.cpp | 13 +++++-------- src/qt/overviewpage.h | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 85a8422..dcee3fc 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -194,11 +194,9 @@ void OverviewPage::setBalance(const CAmount& balance, const CAmount& unconfirmed ui->labelTotalz->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, sumTotalBalance, false, BitcoinUnits::separatorAlways)); QNetworkAccessManager *manager = new QNetworkAccessManager(this); + QNetworkReply *reply = manager->get (QNetworkRequest (QUrl ("https://api.coingecko.com/api/v3/coins/masterwin?localization=false"))); - connect(manager, SIGNAL(finished(QNetworkReply*)), - this, SLOT(syncRequestFinished(QNetworkReply*))); - - manager->get(QNetworkRequest(QUrl("https://api.coingecko.com/api/v3/coins/masterwin?localization=false"))); + connect (reply, SIGNAL (finished ()), this, SLOT (syncRequestFinished ())); // Adjust bubble-help according to AutoMint settings QString automintHelp = tr("Current percentage of zmw.\nIf AutoMint is enabled this percentage will settle around the configured AutoMint percentage (default = 10%).\n"); @@ -342,8 +340,9 @@ void OverviewPage::showOutOfSyncWarning(bool fShow) ui->labelTransactionsStatus->setVisible(fShow); } //GET Price from Gecko -void OverviewPage::syncRequestFinished(QNetworkReply *reply) -{ +void OverviewPage::syncRequestFinished () { + QNetworkReply *reply = qobject_cast(sender ()); + //market_data / current_price / usd if (reply->error() == QNetworkReply::NoError) @@ -356,7 +355,6 @@ void OverviewPage::syncRequestFinished(QNetworkReply *reply) ui->labelPricez->setText("NON"); return; } - QJsonObject jsonObject = jsonResponse.object(); QJsonObject sett3 = jsonObject["market_data"].toObject(); @@ -375,7 +373,6 @@ void OverviewPage::syncRequestFinished(QNetworkReply *reply) ui->labelPricez->setText(totalPrice); ui->labelUSDPricez->setText(unitPrice); - } else{ ui->labelPricez->setText("NULL"); diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index 240e036..bdf2b19 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -70,7 +70,7 @@ private slots: void handleTransactionClicked(const QModelIndex& index); void updateAlerts(const QString& warnings); void updateWatchOnlyLabels(bool showWatchOnly); - void syncRequestFinished(QNetworkReply *reply); + void syncRequestFinished (); }; #endif // BITCOIN_QT_OVERVIEWPAGE_H From 7102c938a8437a051be8d5607b8c2e0be9ef4d1a Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Mon, 14 Sep 2020 13:49:15 +0200 Subject: [PATCH 34/49] Added tier-level to masternode-list (qt) --- src/qt/forms/masternodelist.ui | 5 +++++ src/qt/masternodelist.cpp | 18 +++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/qt/forms/masternodelist.ui b/src/qt/forms/masternodelist.ui index b3c7cac..f39e88b 100644 --- a/src/qt/forms/masternodelist.ui +++ b/src/qt/forms/masternodelist.ui @@ -255,6 +255,11 @@ Protocol + + + Level + + Status diff --git a/src/qt/masternodelist.cpp b/src/qt/masternodelist.cpp index d5d83aa..6508b5e 100644 --- a/src/qt/masternodelist.cpp +++ b/src/qt/masternodelist.cpp @@ -35,6 +35,7 @@ MasternodeList::MasternodeList(QWidget* parent) : QWidget(parent), int columnAliasWidth = 100; int columnAddressWidth = 200; int columnProtocolWidth = 60; + int columnLevelWidth = 40; int columnStatusWidth = 80; int columnActiveWidth = 130; int columnLastSeenWidth = 130; @@ -43,9 +44,10 @@ MasternodeList::MasternodeList(QWidget* parent) : QWidget(parent), ui->tableWidgetMyMasternodes->setColumnWidth(0, columnAliasWidth); ui->tableWidgetMyMasternodes->setColumnWidth(1, columnAddressWidth); ui->tableWidgetMyMasternodes->setColumnWidth(2, columnProtocolWidth); - ui->tableWidgetMyMasternodes->setColumnWidth(3, columnStatusWidth); - ui->tableWidgetMyMasternodes->setColumnWidth(4, columnActiveWidth); - ui->tableWidgetMyMasternodes->setColumnWidth(5, columnLastSeenWidth); + ui->tableWidgetMyMasternodes->setColumnWidth (3, columnLevelWidth); + ui->tableWidgetMyMasternodes->setColumnWidth (4, columnStatusWidth); + ui->tableWidgetMyMasternodes->setColumnWidth (5, columnActiveWidth); + ui->tableWidgetMyMasternodes->setColumnWidth (6, columnLastSeenWidth); ui->tableWidgetMyMasternodes->setContextMenuPolicy(Qt::CustomContextMenu); @@ -183,6 +185,7 @@ void MasternodeList::updateMyMasternodeInfo(QString strAlias, QString strAddr, C QTableWidgetItem* aliasItem = new QTableWidgetItem(strAlias); QTableWidgetItem* addrItem = new QTableWidgetItem(pmn ? QString::fromStdString(pmn->addr.ToString()) : strAddr); QTableWidgetItem* protocolItem = new QTableWidgetItem(QString::number(pmn ? pmn->protocolVersion : -1)); + QTableWidgetItem* levelItem = new QTableWidgetItem (QString::number (pmn ? pmn->GetLevel () : - 1)); QTableWidgetItem* statusItem = new QTableWidgetItem(QString::fromStdString(pmn ? pmn->GetStatus() : "MISSING")); GUIUtil::DHMSTableWidgetItem* activeSecondsItem = new GUIUtil::DHMSTableWidgetItem(pmn ? (pmn->lastPing.sigTime - pmn->sigTime) : 0); QTableWidgetItem* lastSeenItem = new QTableWidgetItem(QString::fromStdString(DateTimeStrFormat("%Y-%m-%d %H:%M", pmn ? pmn->lastPing.sigTime : 0))); @@ -191,10 +194,11 @@ void MasternodeList::updateMyMasternodeInfo(QString strAlias, QString strAddr, C ui->tableWidgetMyMasternodes->setItem(nNewRow, 0, aliasItem); ui->tableWidgetMyMasternodes->setItem(nNewRow, 1, addrItem); ui->tableWidgetMyMasternodes->setItem(nNewRow, 2, protocolItem); - ui->tableWidgetMyMasternodes->setItem(nNewRow, 3, statusItem); - ui->tableWidgetMyMasternodes->setItem(nNewRow, 4, activeSecondsItem); - ui->tableWidgetMyMasternodes->setItem(nNewRow, 5, lastSeenItem); - ui->tableWidgetMyMasternodes->setItem(nNewRow, 6, pubkeyItem); + ui->tableWidgetMyMasternodes->setItem (nNewRow, 3, levelItem); + ui->tableWidgetMyMasternodes->setItem (nNewRow, 4, statusItem); + ui->tableWidgetMyMasternodes->setItem (nNewRow, 5, activeSecondsItem); + ui->tableWidgetMyMasternodes->setItem (nNewRow, 6, lastSeenItem); + ui->tableWidgetMyMasternodes->setItem (nNewRow, 7, pubkeyItem); } void MasternodeList::updateMyNodeList(bool fForce) From 9ac4764947b204e73d61041e5d1147a626891f5d Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Tue, 15 Sep 2020 10:15:12 +0200 Subject: [PATCH 35/49] Fixed transaction-classification --- src/qt/transactionrecord.cpp | 119 +++++++---------------------------- 1 file changed, 23 insertions(+), 96 deletions(-) diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index d32ba63..8a19d01 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -41,113 +41,40 @@ QList TransactionRecord::decomposeTransaction(const CWallet* CAmount nNet = nCredit - nDebit; uint256 hash = wtx.GetHash(); std::map mapValue = wtx.mapValue; - bool fZSpendFromMe = false; - - if (wtx.IsZerocoinSpend()) { - // a zerocoin spend that was created by this wallet - libzerocoin::CoinSpend zcspend = TxInToZerocoinSpend(wtx.vin[0]); - fZSpendFromMe = wallet->IsMyZerocoinSpend(zcspend.getCoinSerialNumber()); - } if (wtx.IsCoinStake()) { TransactionRecord sub(hash, nTime); CTxDestination address; - if (!wtx.IsZerocoinSpend() && !ExtractDestination(wtx.vout[1].scriptPubKey, address)) + + if (!ExtractDestination (wtx.vout [1].scriptPubKey, address)) return parts; - if (wtx.IsZerocoinSpend() && (fZSpendFromMe || wallet->zmwTracker->HasMintTx(hash))) { - //zmw stake reward - sub.involvesWatchAddress = false; - sub.type = TransactionRecord::StakeZMW; - sub.address = mapValue["zerocoinmint"]; - sub.credit = 0; - for (const CTxOut& out : wtx.vout) { - if (out.IsZerocoinMint()) - sub.credit += out.nValue; - } - sub.debit -= wtx.vin[0].nSequence * COIN; - } else if (isminetype mine = wallet->IsMine(wtx.vout[1])) { - // MW stake reward + // Check if Stake-Output is ours + if (isminetype mine = wallet->IsMine (wtx.vout [1])) { sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY; sub.type = TransactionRecord::StakeMint; - sub.address = CBitcoinAddress(address).ToString(); - sub.credit = nNet; - } else { - //Masternode reward - CTxDestination destMN; - int nIndexMN = wtx.vout.size() - 1; - if (ExtractDestination(wtx.vout[nIndexMN].scriptPubKey, destMN) && IsMine(*wallet, destMN)) { - isminetype mine = wallet->IsMine(wtx.vout[nIndexMN]); - sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY; - sub.type = TransactionRecord::MNReward; - sub.address = CBitcoinAddress(destMN).ToString(); - sub.credit = wtx.vout[nIndexMN].nValue; - } + sub.address = CBitcoinAddress (address).ToString (); + sub.credit = wtx.vout [1].nValue - nDebit; + + parts.append (sub); } - - parts.append(sub); - } else if (wtx.IsZerocoinSpend()) { - //zerocoin spend outputs - bool fFeeAssigned = false; - for (const CTxOut& txout : wtx.vout) { - // change that was reminted as zerocoins - if (txout.IsZerocoinMint()) { - // do not display record if this isn't from our wallet - if (!fZSpendFromMe) - continue; - - isminetype mine = wallet->IsMine(txout); - TransactionRecord sub(hash, nTime); - sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY; - sub.type = TransactionRecord::ZerocoinSpend_Change_zMW; - sub.address = mapValue["zerocoinmint"]; - if (!fFeeAssigned) { - sub.debit -= (wtx.GetZerocoinSpent() - wtx.GetValueOut()); - fFeeAssigned = true; - } - sub.idx = parts.size(); - parts.append(sub); - continue; - } - - string strAddress = ""; - CTxDestination address; - if (ExtractDestination(txout.scriptPubKey, address)) - strAddress = CBitcoinAddress(address).ToString(); - - // a zerocoinspend that was sent to an address held by this wallet - isminetype mine = wallet->IsMine(txout); - if (mine) { - TransactionRecord sub(hash, nTime); - sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY; - if (fZSpendFromMe) { - sub.type = TransactionRecord::ZerocoinSpend_FromMe; - } else { - sub.type = TransactionRecord::RecvFromZerocoinSpend; - sub.credit = txout.nValue; - } - sub.address = mapValue["recvzerocoinspend"]; - if (strAddress != "") - sub.address = strAddress; - sub.idx = parts.size(); - parts.append(sub); - continue; - } - - // spend is not from us, so do not display the spend side of the record - if (!fZSpendFromMe) + + // Check if one of the masternode-rewards is our (prefered) + CTxDestination destMN; + + for (int nIndexMN = 2; nIndexMN < wtx.vout.size (); nIndexMN++) { + if (!ExtractDestination (wtx.vout [nIndexMN].scriptPubKey, destMN) || + !IsMine (*wallet, destMN)) continue; - - // zerocoin spend that was sent to someone else - TransactionRecord sub(hash, nTime); + + isminetype mine = wallet->IsMine (wtx.vout [nIndexMN]); + sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY; - sub.debit = -txout.nValue; - sub.type = TransactionRecord::ZerocoinSpend; - sub.address = mapValue["zerocoinspend"]; - if (strAddress != "") - sub.address = strAddress; - sub.idx = parts.size(); - parts.append(sub); + sub.type = TransactionRecord::MNReward; + sub.address = CBitcoinAddress (destMN).ToString (); + sub.credit = wtx.vout [nIndexMN].nValue; + + parts.append (sub); } } else if (nNet > 0 || wtx.IsCoinBase()) { // From 5921d2d87278ca95eddf5304f439cd44f6ab5316 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Thu, 17 Sep 2020 09:44:20 +0200 Subject: [PATCH 36/49] Prepared lock out of old clients --- src/main.cpp | 12 ++++++------ src/version.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a58bb88..b256bfc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6577,13 +6577,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, // it was the one which was commented out int ActiveProtocol() { - // SPORK_14 is used for 70913 (v3.1.0+) - if (IsSporkActive(SPORK_14_NEW_PROTOCOL_ENFORCEMENT)) - return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT; + // SPORK_14 was used for 70918 (v2.0.0+) + // if (IsSporkActive(SPORK_14_NEW_PROTOCOL_ENFORCEMENT)) + // return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT; - // SPORK_15 was used for 70912 (v3.0.5+), commented out now. - //if (IsSporkActive(SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2)) - // return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT; + // SPORK_15 is used for 70919 (v3.0.0+) + if (IsSporkActive (SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2)) + return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT; return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT; } diff --git a/src/version.h b/src/version.h index a79ea1e..6cd0ea4 100644 --- a/src/version.h +++ b/src/version.h @@ -12,7 +12,7 @@ * network protocol versioning */ -static const int PROTOCOL_VERSION = 70918; +static const int PROTOCOL_VERSION = 70919; //! initial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209; @@ -21,8 +21,8 @@ static const int INIT_PROTO_VERSION = 209; static const int GETHEADERS_VERSION = 70077; //! disconnect from peers older than this proto version -static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 70917; -static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 70918; +static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 70918; +static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 70919; //! masternodes older than this proto version use old strMessage format for mnannounce static const int MIN_PEER_MNANNOUNCE = 70915; From e7dad026bea6306cae1630697f53741e837179c0 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Thu, 17 Sep 2020 09:51:04 +0200 Subject: [PATCH 37/49] Increased client-version --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index dda8ff6..1acd21b 100644 --- a/configure.ac +++ b/configure.ac @@ -1,11 +1,11 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N) AC_PREREQ([2.60]) -define(_CLIENT_VERSION_MAJOR, 2) +define(_CLIENT_VERSION_MAJOR, 3) define(_CLIENT_VERSION_MINOR, 0) define(_CLIENT_VERSION_REVISION, 0) define(_CLIENT_VERSION_BUILD, 0) define(_CLIENT_VERSION_IS_RELEASE, true) -define(_COPYRIGHT_YEAR, 2019) +define(_COPYRIGHT_YEAR, 2020) AC_INIT([MasterWin],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[www.mw.one],[masterwin]) AC_CONFIG_SRCDIR([src/main.cpp]) AC_CONFIG_HEADERS([src/config/masterwin-config.h]) From 6f4e9727ca46f8a5003eed85b52ee2ffa6f0de6e Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Mon, 21 Sep 2020 15:08:32 +0200 Subject: [PATCH 38/49] Added custom weight to tier-levels --- src/chainparams.cpp | 8 ++++---- src/chainparams.h | 40 ++++++++++++++++++++++++++++++++++------ src/main.cpp | 8 +------- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index f484546..fb88217 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -218,10 +218,10 @@ class CMainParams : public CChainParams "MUqGH9fvKxjSSJhLQuKMM1yD8EsuZnc6P3", }; - vMasternodeCollateral.push_back (1000 * COIN); - vMasternodeCollateral.push_back (4000 * COIN); - vMasternodeCollateral.push_back (10000 * COIN); - vMasternodeCollateral.push_back (100000 * COIN); + vMasternodeTiers.push_back ({ 1000 * COIN, 1 }); + vMasternodeTiers.push_back ({ 4000 * COIN, 2 }); + vMasternodeTiers.push_back ({ 10000 * COIN, 4 }); + vMasternodeTiers.push_back ({ 100000 * COIN, 8 }); } const Checkpoints::CCheckpointData& Checkpoints() const diff --git a/src/chainparams.h b/src/chainparams.h index 6099b83..0e5fc23 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -26,6 +26,11 @@ struct CDNSSeedData { CDNSSeedData(const std::string& strName, const std::string& strHost) : name(strName), host(strHost) {} }; +struct MasternodeTier { + CAmount Collateral; + uint16_t Weight; +}; + /** * CChainParams defines various tweakable parameters of a given instance of the * MasterWin system. There are three: the main network on which people trade goods @@ -131,8 +136,8 @@ class CChainParams bool isMasternodeCollateral (CAmount nValue) const { // Check if the given value is on collateral-list - BOOST_FOREACH (const CAmount& tierCollateral, vMasternodeCollateral) { - if (nValue == tierCollateral) + BOOST_FOREACH (const MasternodeTier& masternodeTier, vMasternodeTiers) { + if (nValue == masternodeTier.Collateral) return true; } @@ -141,22 +146,45 @@ class CChainParams } unsigned int getMasternodeLevels () const { - return vMasternodeCollateral.size (); + return vMasternodeTiers.size (); } unsigned int getMasternodeLevel (CAmount collateralValue) const { unsigned int currentLevel = 0; // Check if the given value is on collateral-list - BOOST_FOREACH (const CAmount& tierCollateral, vMasternodeCollateral) { + BOOST_FOREACH (const MasternodeTier& masternodeTier, vMasternodeTiers) { currentLevel++; - if (collateralValue == tierCollateral) + if (collateralValue == masternodeTier.Collateral) return currentLevel; } return 0; } + + unsigned int getMasternodeTierWeight (unsigned int masternodeTier = 0) const { + // Make sure the tier is valid + if (masternodeTier > vMasternodeTiers.size ()) + return 0; + + // Return weight of a given tier + if (masternodeTier > 0) + return vMasternodeTiers [masternodeTier - 1].Weight; + + // Collect sum of all tiers + unsigned int tierWeightSum = 0; + + BOOST_FOREACH (const MasternodeTier& masternodeTier, vMasternodeTiers) { + tierWeightSum += masternodeTier.Weight; + } + + // Never return something less than one, to prevent divisions by zero + if (tierWeightSum < 1) + tierWeightSum = 1; + + return tierWeightSum; + } protected: CChainParams() {} @@ -222,7 +250,7 @@ class CChainParams int nBlockEnforceInvalidUTXO; int nBlockZerocoinV2; - std::vector vMasternodeCollateral; + std::vector vMasternodeTiers; }; /** diff --git a/src/main.cpp b/src/main.cpp index b256bfc..5b7c6d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2001,13 +2001,7 @@ int64_t GetMasternodePayment(int nHeight, int64_t blockValue, int nMasternodeCou } int64_t GetMasternodePayment (int nHeight, unsigned int mnLevel, int64_t blockValue, int nMasternodeCount, bool isZMWStake) { - int64_t masternodeTotalPayment = GetMasternodePayment (nHeight, blockValue, nMasternodeCount, isZMWStake); - unsigned int masternodeLevels = Params ().getMasternodeLevels (); - - if (masternodeLevels == 0) - return 0; - - return masternodeTotalPayment * (1 << (mnLevel - 1)) / ((1 << masternodeLevels) - 1); + return GetMasternodePayment (nHeight, blockValue, nMasternodeCount, isZMWStake) * Params ().getMasternodeTierWeight (mnLevel) / Params ().getMasternodeTierWeight (); } From 505d3b1992b6176b692abc8098c567720bcce529 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Mon, 21 Sep 2020 15:58:43 +0200 Subject: [PATCH 39/49] BUGFIX Detect stakesplits more propper --- src/qt/transactionrecord.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 8a19d01..c225c6e 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -50,19 +50,29 @@ QList TransactionRecord::decomposeTransaction(const CWallet* return parts; // Check if Stake-Output is ours + unsigned int nIndexMN = 2; + if (isminetype mine = wallet->IsMine (wtx.vout [1])) { sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY; sub.type = TransactionRecord::StakeMint; sub.address = CBitcoinAddress (address).ToString (); sub.credit = wtx.vout [1].nValue - nDebit; + while ((sub.credit < 0) && (wtx.vout.size () > nIndexMN)) { + if (wtx.vout [1].scriptPubKey != wtx.vout [nIndexMN].scriptPubKey) + break; + + sub.credit += wtx.vout [nIndexMN].nValue; + nIndexMN++; + } + parts.append (sub); } // Check if one of the masternode-rewards is our (prefered) CTxDestination destMN; - for (int nIndexMN = 2; nIndexMN < wtx.vout.size (); nIndexMN++) { + for (; nIndexMN < wtx.vout.size (); nIndexMN++) { if (!ExtractDestination (wtx.vout [nIndexMN].scriptPubKey, destMN) || !IsMine (*wallet, destMN)) continue; From a639bf30455bc024092115a62741f713118efcbe Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Tue, 22 Sep 2020 01:07:07 +0200 Subject: [PATCH 40/49] Allow different tiers at different block-heights --- src/activemasternode.cpp | 14 ++-- src/chainparams.cpp | 15 +++-- src/chainparams.h | 125 +++++++++++++++++++++++++++--------- src/main.cpp | 2 +- src/main.h | 3 - src/masternode-payments.cpp | 26 ++++---- src/masternode.cpp | 2 +- src/rpc/masternode.cpp | 66 +++++++++---------- 8 files changed, 160 insertions(+), 93 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 8dbb097..fc35416 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -316,24 +316,24 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr selectedOutput = &possibleCoins [0]; - unsigned int selectedLevel = Params ().getMasternodeLevel (selectedOutput->tx->vout [selectedOutput->i].nValue); - unsigned int maxLevel = Params ().getMasternodeLevels (); + unsigned int selectedTier = Params ().getMasternodeTier (selectedOutput->tx->vout [selectedOutput->i].nValue); + unsigned int maxTier = Params ().getMasternodeTiers (); BOOST_FOREACH (COutput& out, possibleCoins) { - if (selectedLevel == maxLevel) + if (selectedTier == maxTier) break; - unsigned int nextLevel = Params ().getMasternodeLevel (out.tx->vout [out.i].nValue); + unsigned int nextTier = Params ().getMasternodeTier (out.tx->vout [out.i].nValue); - if (nextLevel <= selectedLevel) + if (nextTier <= selectedTier) continue; - selectedLevel = nextLevel; + selectedTier = nextTier; selectedOutput = &out; found = true; } - if (maxLevel < 1) + if (maxTier < 1) found = false; } diff --git a/src/chainparams.cpp b/src/chainparams.cpp index fb88217..8d23bae 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -218,11 +218,16 @@ class CMainParams : public CChainParams "MUqGH9fvKxjSSJhLQuKMM1yD8EsuZnc6P3", }; - vMasternodeTiers.push_back ({ 1000 * COIN, 1 }); - vMasternodeTiers.push_back ({ 4000 * COIN, 2 }); - vMasternodeTiers.push_back ({ 10000 * COIN, 4 }); - vMasternodeTiers.push_back ({ 100000 * COIN, 8 }); - } + vMasternodeTiers.push_back ({ + nLastPOWBlock, + { + { 1000 * COIN, 1 }, + { 4000 * COIN, 2 }, + { 10000 * COIN, 4 }, + { 100000 * COIN, 8 } + } + }); + } const Checkpoints::CCheckpointData& Checkpoints() const { diff --git a/src/chainparams.h b/src/chainparams.h index 0e5fc23..c52c893 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -14,6 +14,7 @@ #include "primitives/block.h" #include "protocol.h" #include "uint256.h" +#include "chain.h" #include "libzerocoin/Params.h" #include @@ -27,10 +28,18 @@ struct CDNSSeedData { }; struct MasternodeTier { - CAmount Collateral; - uint16_t Weight; + CAmount Collateral; + uint16_t Weight; }; +struct MasternodeTiers { + unsigned int blockHeight; + std::vector masternodeTiers; +}; + +/** The currently-connected chain of blocks. */ +extern CChain chainActive; + /** * CChainParams defines various tweakable parameters of a given instance of the * MasterWin system. There are three: the main network on which people trade goods @@ -133,49 +142,104 @@ class CChainParams int Block_Enforce_Invalid() const { return nBlockEnforceInvalidUTXO; } int Zerocoin_Block_V2_Start() const { return nBlockZerocoinV2; } CAmount InvalidAmountFiltered() const { return nInvalidAmountFiltered; }; + + bool isMasternodeCollateral (CAmount nValue, unsigned int atBlockHeight = 0) const { + if (atBlockHeight == 0) { + CBlockIndex* chainTip = chainActive.Tip (); + + if (chainTip != NULL) + atBlockHeight = chainTip->nHeight; + } - bool isMasternodeCollateral (CAmount nValue) const { - // Check if the given value is on collateral-list - BOOST_FOREACH (const MasternodeTier& masternodeTier, vMasternodeTiers) { - if (nValue == masternodeTier.Collateral) - return true; - } - - // Cannot be a valid collateral-value if we get here - return false; + BOOST_FOREACH (const MasternodeTiers& masternodeTiers, vMasternodeTiers) { + // Check if this tiers aren't active yet + if (masternodeTiers.blockHeight > atBlockHeight) + continue; + + // Check if the given value is on collateral-list + BOOST_FOREACH (const MasternodeTier& masternodeTier, masternodeTiers.masternodeTiers) { + if (nValue == masternodeTier.Collateral) + return true; + } + + break; + } + + // Cannot be a valid collateral-value if we get here + return false; + } + + unsigned int getMasternodeTiers (unsigned int atBlockHeight = 0) const { + if (atBlockHeight == 0) { + CBlockIndex* chainTip = chainActive.Tip (); + + if (chainTip != NULL) + atBlockHeight = chainTip->nHeight; } - unsigned int getMasternodeLevels () const { - return vMasternodeTiers.size (); + BOOST_FOREACH (const MasternodeTiers& masternodeTiers, vMasternodeTiers) { + // Find first active tiers + if (masternodeTiers.blockHeight <= atBlockHeight) + return masternodeTiers.masternodeTiers.size (); } - unsigned int getMasternodeLevel (CAmount collateralValue) const { - unsigned int currentLevel = 0; - - // Check if the given value is on collateral-list - BOOST_FOREACH (const MasternodeTier& masternodeTier, vMasternodeTiers) { - currentLevel++; - - if (collateralValue == masternodeTier.Collateral) - return currentLevel; - } + return 0; + } + + unsigned int getMasternodeTier (CAmount collateralValue, unsigned int atBlockHeight = 0) const { + if (atBlockHeight == 0) { + CBlockIndex* chainTip = chainActive.Tip (); + + if (chainTip != NULL) + atBlockHeight = chainTip->nHeight; + } + + BOOST_FOREACH (const MasternodeTiers& masternodeTiers, vMasternodeTiers) { + // Check if this tiers aren't active yet + if (masternodeTiers.blockHeight > atBlockHeight) + continue; + + unsigned int currentLevel = 0; + + // Check if the given value is on collateral-list + BOOST_FOREACH (const MasternodeTier& masternodeTier, masternodeTiers.masternodeTiers) { + currentLevel++; - return 0; + if (collateralValue == masternodeTier.Collateral) + return currentLevel; + } + + break; + } + + return 0; + } + + unsigned int getMasternodeTierWeight (unsigned int masternodeTier = 0, unsigned int atBlockHeight = 0) const { + if (atBlockHeight == 0) { + CBlockIndex* chainTip = chainActive.Tip (); + + if (chainTip != NULL) + atBlockHeight = chainTip->nHeight; } - unsigned int getMasternodeTierWeight (unsigned int masternodeTier = 0) const { + BOOST_FOREACH (const MasternodeTiers& masternodeTiers, vMasternodeTiers) { + // Check if this tiers aren't active yet + if (masternodeTiers.blockHeight > atBlockHeight) + continue; + // Make sure the tier is valid - if (masternodeTier > vMasternodeTiers.size ()) + if (masternodeTier > masternodeTiers.masternodeTiers.size ()) return 0; // Return weight of a given tier if (masternodeTier > 0) - return vMasternodeTiers [masternodeTier - 1].Weight; + return masternodeTiers.masternodeTiers [masternodeTier - 1].Weight; // Collect sum of all tiers unsigned int tierWeightSum = 0; - BOOST_FOREACH (const MasternodeTier& masternodeTier, vMasternodeTiers) { + BOOST_FOREACH (const MasternodeTier& masternodeTier, masternodeTiers.masternodeTiers) { tierWeightSum += masternodeTier.Weight; } @@ -185,6 +249,9 @@ class CChainParams return tierWeightSum; } + + return (masternodeTier == 0 ? 1 : 0); + } protected: CChainParams() {} @@ -250,7 +317,7 @@ class CChainParams int nBlockEnforceInvalidUTXO; int nBlockZerocoinV2; - std::vector vMasternodeTiers; + std::vector vMasternodeTiers; }; /** diff --git a/src/main.cpp b/src/main.cpp index 5b7c6d0..35bb7a0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2001,7 +2001,7 @@ int64_t GetMasternodePayment(int nHeight, int64_t blockValue, int nMasternodeCou } int64_t GetMasternodePayment (int nHeight, unsigned int mnLevel, int64_t blockValue, int nMasternodeCount, bool isZMWStake) { - return GetMasternodePayment (nHeight, blockValue, nMasternodeCount, isZMWStake) * Params ().getMasternodeTierWeight (mnLevel) / Params ().getMasternodeTierWeight (); + return GetMasternodePayment (nHeight, blockValue, nMasternodeCount, isZMWStake) * Params ().getMasternodeTierWeight (mnLevel, nHeight) / Params ().getMasternodeTierWeight (0, nHeight); } diff --git a/src/main.h b/src/main.h index 1744382..40faedd 100644 --- a/src/main.h +++ b/src/main.h @@ -616,9 +616,6 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex* pindex); /** Remove invalidity status from a block and its descendants. */ bool ReconsiderBlock(CValidationState& state, CBlockIndex* pindex); -/** The currently-connected chain of blocks. */ -extern CChain chainActive; - /** Global variable that points to the active CCoinsView (protected by cs_main) */ extern CCoinsViewCache* pcoinsTip; diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index f4a6c6b..b5f955e 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -297,12 +297,12 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe bool hasPayment = true; CScript payee; - for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (pindexPrev->nHeight + 1); masternodeTier++) { hasPayment = true; - if (!masternodePayments.GetBlockPayee (pindexPrev->nHeight + 1, masternodeLevel, payee)) { + if (!masternodePayments.GetBlockPayee (pindexPrev->nHeight + 1, masternodeTier, payee)) { // No masternode was detected - CMasternode* winningNode = mnodeman.GetCurrentMasternodeOnLevel (masternodeLevel, 1); + CMasternode* winningNode = mnodeman.GetCurrentMasternodeOnLevel (masternodeTier, 1); if (!winningNode) { LogPrint ("masternode", "CreateNewBlock: Failed to detect masternode to pay\n"); @@ -312,7 +312,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe } CAmount blockValue = GetBlockValue (pindexPrev->nHeight); - CAmount masternodePayment = GetMasternodePayment (pindexPrev->nHeight, masternodeLevel, blockValue, 0, fZMWStake); + CAmount masternodePayment = GetMasternodePayment (pindexPrev->nHeight, masternodeTier, blockValue, 0, fZMWStake); if (hasPayment) { unsigned int i = txNew.vout.size (); @@ -578,27 +578,27 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) bool transactionCorrect = true; CAmount requiredMasternodePayment = 0; - for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (nBlockHeight); masternodeTier++) { // Require at least 6 signatures int nMaxSignatures = 0; for (CMasternodePayee& payee : vecPayments) if ((payee.nVotes >= nMaxSignatures) && (payee.nVotes >= MNPAYMENTS_SIGNATURES_REQUIRED) && - (payee.masternodeLevel == masternodeLevel)) + (payee.masternodeLevel == masternodeTier)) nMaxSignatures = payee.nVotes; // if we don't have at least 6 signatures on a payee, approve whichever is the longest chain if (nMaxSignatures < MNPAYMENTS_SIGNATURES_REQUIRED) continue; - requiredMasternodePayment = GetMasternodePayment (nBlockHeight, masternodeLevel, nReward, nMasternode_Drift_Count); + requiredMasternodePayment = GetMasternodePayment (nBlockHeight, masternodeTier, nReward, nMasternode_Drift_Count); bool hasLevelPayment = false; std::string strPayeesPossible = ""; for (CMasternodePayee& payee : vecPayments) { // Skip payees on other levels - if (payee.masternodeLevel != masternodeLevel) + if (payee.masternodeLevel != masternodeTier) continue; // Skip payees with little votes @@ -631,7 +631,7 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) } if (!hasLevelPayment) { - LogPrint ("masternode", "CMasternodePayments::IsTransactionValid - Missing required payment of %s to %s on level %d\n", FormatMoney (requiredMasternodePayment).c_str (), strPayeesPossible.c_str (), masternodeLevel); + LogPrint ("masternode", "CMasternodePayments::IsTransactionValid - Missing required payment of %s to %s on level %d\n", FormatMoney (requiredMasternodePayment).c_str (), strPayeesPossible.c_str (), masternodeTier); transactionCorrect = false; } @@ -780,13 +780,13 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight) return false; } - for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (nBlockHeight); masternodeTier++) { // Create a new winner for this level CMasternodePaymentWinner newWinner (activeMasternode.vin); // pay to the oldest MN that still had no payment but its input is old enough and it was active long enough int nCount = 0; - CMasternode* pmn = mnodeman.GetNextMasternodeInQueueForPayment (nBlockHeight, masternodeLevel, true, nCount); + CMasternode* pmn = mnodeman.GetNextMasternodeInQueueForPayment (nBlockHeight, masternodeTier, true, nCount); if (pmn == NULL) { LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Failed to find masternode to pay\n"); @@ -799,13 +799,13 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight) newWinner.nBlockHeight = nBlockHeight; CScript payee = GetScriptForDestination (pmn->pubKeyCollateralAddress.GetID()); - newWinner.AddPayee (payee, masternodeLevel); + newWinner.AddPayee (payee, masternodeTier); CTxDestination address1; ExtractDestination (payee, address1); CBitcoinAddress address2 (address1); - LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Winner payee %s nHeight %d level %d. \n", address2.ToString ().c_str (), newWinner.nBlockHeight, masternodeLevel); + LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Winner payee %s nHeight %d level %d. \n", address2.ToString ().c_str (), newWinner.nBlockHeight, masternodeTier); if (newWinner.Sign (keyMasternode, pubKeyMasternode)) { if (AddWinningMasternode (newWinner)) { diff --git a/src/masternode.cpp b/src/masternode.cpp index 694bb42..8249073 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -137,7 +137,7 @@ unsigned int CMasternode::GetLevel () { if (vin.prevout.n >= prevTx.vout.size ()) return 0; - return Params ().getMasternodeLevel (prevTx.vout [vin.prevout.n].nValue); + return Params ().getMasternodeTier (prevTx.vout [vin.prevout.n].nValue); } // diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 6156c94..76787df 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -35,7 +35,7 @@ UniValue getpoolinfo(const UniValue& params, bool fHelp) " \"accepted\": xxxx, (numeric) Number of entries accepted\n" " \"tiers\": [\n" " {\n" - " \"level\": l, (numeric) Level of tier\n" + " \"tier\": t, (numeric) Level of tier\n" " \"current\": \"addr\", (string) MasterWin address of current masternode\n" " \"state\": xxxx, (string) unknown\n" " \"entries\": xxxx, (numeric) Number of entries\n" @@ -56,11 +56,11 @@ UniValue getpoolinfo(const UniValue& params, bool fHelp) UniValue tiers (UniValue::VARR); - for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (); masternodeTier++) { UniValue tier (UniValue::VOBJ); - tier.push_back (Pair ("level", (uint64_t)masternodeLevel)); - tier.push_back (Pair ("current", mnodeman.GetCurrentMasternodeOnLevel (masternodeLevel)->addr.ToString())); + tier.push_back (Pair ("tier", (uint64_t)masternodeTier)); + tier.push_back (Pair ("current", mnodeman.GetCurrentMasternodeOnLevel (masternodeTier)->addr.ToString())); // TODO: This is senseless :) tier.push_back (Pair ("state", obfuScationPool.GetState ())); @@ -233,14 +233,13 @@ UniValue listmasternodes(const UniValue& params, bool fHelp) "\nResult:\n" "[\n" " {\n" - " \"level\": l, (numeric) Tier/Level of masternode\n" + " \"tier\": t, (numeric) Tier-Level of masternode\n" " \"rank\": n, (numeric) Masternode Rank (or 0 if not enabled)\n" " \"txhash\": \"hash\", (string) Collateral transaction hash\n" " \"outidx\": n, (numeric) Collateral transaction output index\n" " \"status\": s, (string) Status (ENABLED/EXPIRED/REMOVE/etc)\n" " \"addr\": \"addr\", (string) Masternode MasterWin address\n" " \"version\": v, (numeric) Masternode protocol version\n" - " \"level\": l, (numeric) Masternode-Tier Level\n" " \"lastseen\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last seen\n" " \"activetime\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) masternode has been active\n" " \"lastpaid\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) masternode was last paid\n" @@ -280,7 +279,7 @@ UniValue listmasternodes(const UniValue& params, bool fHelp) CNetAddr node = CNetAddr(strHost, false); std::string strNetwork = GetNetworkName(node.GetNetwork()); - obj.push_back (Pair ("level", (uint64_t)mn->GetLevel ())); + obj.push_back (Pair ("tier", (uint64_t)mn->GetLevel ())); obj.push_back(Pair("rank", (strStatus == "ENABLED" ? s.first : 0))); obj.push_back(Pair("network", strNetwork)); obj.push_back(Pair("txhash", strTxHash)); @@ -289,7 +288,6 @@ UniValue listmasternodes(const UniValue& params, bool fHelp) obj.push_back(Pair("ip", mn->addr.ToStringIP())); obj.push_back(Pair("addr", CBitcoinAddress(mn->pubKeyCollateralAddress.GetID()).ToString())); obj.push_back(Pair("version", mn->protocolVersion)); - obj.push_back (Pair ("level", (uint64_t)mn->GetLevel ())); obj.push_back(Pair("lastseen", (int64_t)mn->lastPing.sigTime)); obj.push_back(Pair("activetime", (int64_t)(mn->lastPing.sigTime - mn->sigTime))); obj.push_back(Pair("lastpaid", (int64_t)mn->GetLastPaid())); @@ -346,7 +344,7 @@ UniValue getmasternodecount (const UniValue& params, bool fHelp) " \"onion\": n, (numeric) Masternodes with Onion address\n" " \"tiers\": [\n" " {\n" - " \"level\": l, (numeric) Tier-Level\n" + " \"tier\": t, (numeric) Tier-Level\n" " \"total\": n, (numeric) Total masternodes\n" " \"stable\": n, (numeric) Stable count\n" " \"obfcompat\": n, (numeric) Obfuscation Compatible\n" @@ -383,21 +381,21 @@ UniValue getmasternodecount (const UniValue& params, bool fHelp) UniValue tiers (UniValue::VARR); - for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (); masternodeTier++) { UniValue tier (UniValue::VOBJ); nCount = ipv4 = ipv6 = onion = 0; if (chainActive.Tip ()) - mnodeman.GetNextMasternodeInQueueForPayment (chainActive.Tip ()->nHeight, masternodeLevel, true, nCount); + mnodeman.GetNextMasternodeInQueueForPayment (chainActive.Tip ()->nHeight, masternodeTier, true, nCount); - mnodeman.CountNetworks (masternodeLevel, ActiveProtocol (), ipv4, ipv6, onion); + mnodeman.CountNetworks (masternodeTier, ActiveProtocol (), ipv4, ipv6, onion); - tier.push_back (Pair ("level", (uint64_t)masternodeLevel)); - tier.push_back (Pair ("total", mnodeman.size (masternodeLevel))); - tier.push_back (Pair ("stable", mnodeman.stable_size (masternodeLevel))); - tier.push_back (Pair ("obfcompat", mnodeman.CountEnabledOnLevel (masternodeLevel, ActiveProtocol ()))); - tier.push_back (Pair ("enabled", mnodeman.CountEnabledOnLevel (masternodeLevel))); + tier.push_back (Pair ("tier", (uint64_t)masternodeTier)); + tier.push_back (Pair ("total", mnodeman.size (masternodeTier))); + tier.push_back (Pair ("stable", mnodeman.stable_size (masternodeTier))); + tier.push_back (Pair ("obfcompat", mnodeman.CountEnabledOnLevel (masternodeTier, ActiveProtocol ()))); + tier.push_back (Pair ("enabled", mnodeman.CountEnabledOnLevel (masternodeTier))); tier.push_back (Pair ("inqueue", nCount)); tier.push_back (Pair ("ipv4", ipv4)); tier.push_back (Pair ("ipv6", ipv6)); @@ -427,7 +425,7 @@ UniValue masternodecurrent (const UniValue& params, bool fHelp) " \"activeseconds\": xxx, (numeric) Seconds MN has been active\n" " \"tiers\": [\n" " {\n" - " \"level\": level, (numeric) Tier-Level\n" + " \"tier\": tier, (numeric) Tier-Level\n" " \"protocol\": xxxx, (numeric) Protocol version\n" " \"txhash\": \"xxxx\", (string) Collateral transaction hash\n" " \"pubkey\": \"xxxx\", (string) MN Public key\n" @@ -456,13 +454,13 @@ UniValue masternodecurrent (const UniValue& params, bool fHelp) UniValue tiers (UniValue::VARR); - for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { - if (!(winner = mnodeman.GetCurrentMasternodeOnLevel (masternodeLevel, 1))) + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (); masternodeTier++) { + if (!(winner = mnodeman.GetCurrentMasternodeOnLevel (masternodeTier, 1))) continue; UniValue tier (UniValue::VOBJ); - tier.push_back (Pair ("level", (uint64_t)masternodeLevel)); + tier.push_back (Pair ("tier", (uint64_t)masternodeTier)); tier.push_back (Pair ("protocol", (int64_t)winner->protocolVersion)); tier.push_back (Pair ("txhash", winner->vin.prevout.hash.ToString ())); tier.push_back (Pair ("pubkey", CBitcoinAddress (winner->pubKeyCollateralAddress.GetID ()).ToString ())); @@ -704,7 +702,7 @@ UniValue getmasternodeoutputs (const UniValue& params, bool fHelp) " {\n" " \"txhash\": \"xxxx\", (string) output transaction hash\n" " \"outputidx\": n, (numeric) output index number\n" - " \"level\": l, (numeric) level of output\n" + " \"tier\": t, (numeric) tier-level of output\n" " }\n" " ,...\n" "]\n" @@ -720,7 +718,7 @@ UniValue getmasternodeoutputs (const UniValue& params, bool fHelp) UniValue obj(UniValue::VOBJ); obj.push_back(Pair("txhash", out.tx->GetHash().ToString())); obj.push_back(Pair("outputidx", out.i)); - obj.push_back (Pair ("level", (uint64_t)Params ().getMasternodeLevel (out.tx->vout [out.i].nValue))); + obj.push_back (Pair ("tier", (uint64_t)Params ().getMasternodeTier (out.tx->vout [out.i].nValue))); ret.push_back(obj); } @@ -750,7 +748,7 @@ UniValue listmasternodeconf (const UniValue& params, bool fHelp) " \"txHash\": \"xxxx\", (string) transaction hash\n" " \"outputIndex\": n, (numeric) transaction output index\n" " \"status\": \"xxxx\", (string) masternode status\n" - " \"level\": level, (numeric) Level of tiered masternode\n" + " \"tier\": tier, (numeric) Tier-Level of masternode\n" " }\n" " ,...\n" "]\n" @@ -789,7 +787,7 @@ UniValue listmasternodeconf (const UniValue& params, bool fHelp) if (GetTransaction (vin.prevout.hash, prevTx, hashBlock, true) && (prevTx.vout.size () > vin.prevout.n)) - mnObj.push_back (Pair ("level", (uint64_t)Params ().getMasternodeLevel (prevTx.vout [vin.prevout.n].nValue))); + mnObj.push_back (Pair ("tier", (uint64_t)Params ().getMasternodeTier (prevTx.vout [vin.prevout.n].nValue))); ret.push_back(mnObj); } @@ -812,7 +810,7 @@ UniValue getmasternodestatus (const UniValue& params, bool fHelp) " \"addr\": \"xxxx\", (string) MasterWin address for masternode payments\n" " \"status\": \"xxxx\", (string) Masternode status\n" " \"message\": \"xxxx\", (string) Masternode status message\n" - " \"level\": level, (numeric) Tier-Level of masternode\n" + " \"tier\": tier, (numeric) Tier-Level of masternode\n" "}\n" "\nExamples:\n" + @@ -830,7 +828,7 @@ UniValue getmasternodestatus (const UniValue& params, bool fHelp) mnObj.push_back(Pair("addr", CBitcoinAddress(pmn->pubKeyCollateralAddress.GetID()).ToString())); mnObj.push_back(Pair("status", activeMasternode.status)); mnObj.push_back(Pair("message", activeMasternode.GetStatus())); - mnObj.push_back (Pair ("level", (uint64_t)pmn->GetLevel ())); + mnObj.push_back (Pair ("tier", (uint64_t)pmn->GetLevel ())); return mnObj; } @@ -856,7 +854,7 @@ UniValue getmasternodewinners (const UniValue& params, bool fHelp) " {\n" " \"address\": \"xxxx\", (string) MasterWin MN/Budget Address\n" " \"nVotes\": n, (numeric) Number of votes for winner if payee is a masternode\n" - " \"level\": level, (numeric) Tier-Level if payee is a masternode\n" + " \"tier\": tier, (numeric) Tier-Level if payee is a masternode\n" " }\n" " ,...\n" " ]\n" @@ -895,7 +893,7 @@ UniValue getmasternodewinners (const UniValue& params, bool fHelp) winner.push_back (Pair ("address", paymentWinner.strAddress)); winner.push_back (Pair ("nVotes", paymentWinner.nVotes)); - winner.push_back (Pair ("level", (uint64_t)paymentWinner.masternodeLevel)); + winner.push_back (Pair ("tier", (uint64_t)paymentWinner.masternodeLevel)); winners.push_back (winner); } @@ -905,7 +903,7 @@ UniValue getmasternodewinners (const UniValue& params, bool fHelp) winner.push_back (Pair ("address", "Unknown")); winner.push_back (Pair ("nVotes", 0)); - winner.push_back (Pair ("level", 0)); + winner.push_back (Pair ("tier", 0)); winners.push_back (winner); } @@ -931,7 +929,7 @@ UniValue getmasternodescores (const UniValue& params, bool fHelp) "{\n" " xxxx: [\n (numeric) Block height\n" " {\n" - " \"level\": level,\n" + " \"tier\": tier,\n" " \"hash\": \"hash\"\n" " },\n" " ...\n" @@ -957,12 +955,12 @@ UniValue getmasternodescores (const UniValue& params, bool fHelp) for (int nHeight = chainActive.Tip()->nHeight - nLast; nHeight < chainActive.Tip()->nHeight + 20; nHeight++) { UniValue block (UniValue::VARR); - for (unsigned int masternodeLevel = 1; masternodeLevel <= Params ().getMasternodeLevels (); masternodeLevel++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (); masternodeTier++) { uint256 nHigh = 0; CMasternode* pBestMasternode = NULL; BOOST_FOREACH (CMasternode& mn, vMasternodes) { - if (mn.GetLevel () != masternodeLevel) + if (mn.GetLevel () != masternodeTier) continue; uint256 n = mn.CalculateScore (1, nHeight - 100); @@ -976,7 +974,7 @@ UniValue getmasternodescores (const UniValue& params, bool fHelp) if (pBestMasternode) { UniValue tier (UniValue::VOBJ); - tier.push_back (Pair ("level", (uint64_t)masternodeLevel)); + tier.push_back (Pair ("tier", (uint64_t)masternodeTier)); tier.push_back (Pair ("hash", pBestMasternode->vin.prevout.hash.ToString ().c_str ())); block.push_back (tier); From 2009f9268b473284de932752bd29ad9a2a916756 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Tue, 22 Sep 2020 10:19:34 +0200 Subject: [PATCH 41/49] WiP Prepare test-fork for block 22222 --- src/chainparams.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 8d23bae..6122b72 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -227,6 +227,16 @@ class CMainParams : public CChainParams { 100000 * COIN, 8 } } }); + + vMasternodeTiers.push_back ({ + 22222, + { + { 1000 * COIN, 5 }, + { 4000 * COIN, 10 }, + { 10000 * COIN, 25 }, + { 100000 * COIN, 60 } + } + }); } const Checkpoints::CCheckpointData& Checkpoints() const From 3abaa12407a9a900d72c35673049eb1f1c712d72 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Tue, 22 Sep 2020 14:26:34 +0200 Subject: [PATCH 42/49] BUGFIX Correctly detect which version of tier-definition to use --- src/activemasternode.cpp | 2 +- src/chainparams.h | 134 ++++++++++++++++-------------------- src/masternode-payments.cpp | 6 +- src/rpc/masternode.cpp | 8 +-- 4 files changed, 66 insertions(+), 84 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index fc35416..fcd4554 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -317,7 +317,7 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr selectedOutput = &possibleCoins [0]; unsigned int selectedTier = Params ().getMasternodeTier (selectedOutput->tx->vout [selectedOutput->i].nValue); - unsigned int maxTier = Params ().getMasternodeTiers (); + unsigned int maxTier = Params ().getMasternodeTierCount (); BOOST_FOREACH (COutput& out, possibleCoins) { if (selectedTier == maxTier) diff --git a/src/chainparams.h b/src/chainparams.h index c52c893..913fbb7 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -144,32 +144,22 @@ class CChainParams CAmount InvalidAmountFiltered() const { return nInvalidAmountFiltered; }; bool isMasternodeCollateral (CAmount nValue, unsigned int atBlockHeight = 0) const { - if (atBlockHeight == 0) { - CBlockIndex* chainTip = chainActive.Tip (); + MasternodeTiers *currentTiers = getMasternodeTiers (atBlockHeight); - if (chainTip != NULL) - atBlockHeight = chainTip->nHeight; - } + if (currentTiers == NULL) + return false; - BOOST_FOREACH (const MasternodeTiers& masternodeTiers, vMasternodeTiers) { - // Check if this tiers aren't active yet - if (masternodeTiers.blockHeight > atBlockHeight) - continue; - - // Check if the given value is on collateral-list - BOOST_FOREACH (const MasternodeTier& masternodeTier, masternodeTiers.masternodeTiers) { - if (nValue == masternodeTier.Collateral) - return true; - } - - break; + // Check if the given value is on collateral-list + BOOST_FOREACH (const MasternodeTier& masternodeTier, currentTiers->masternodeTiers) { + if (nValue == masternodeTier.Collateral) + return true; } // Cannot be a valid collateral-value if we get here return false; } - unsigned int getMasternodeTiers (unsigned int atBlockHeight = 0) const { + MasternodeTiers *getMasternodeTiers (unsigned int atBlockHeight = 0) const { if (atBlockHeight == 0) { CBlockIndex* chainTip = chainActive.Tip (); @@ -177,82 +167,74 @@ class CChainParams atBlockHeight = chainTip->nHeight; } + MasternodeTiers *currentTiers = NULL; + BOOST_FOREACH (const MasternodeTiers& masternodeTiers, vMasternodeTiers) { - // Find first active tiers if (masternodeTiers.blockHeight <= atBlockHeight) - return masternodeTiers.masternodeTiers.size (); + currentTiers = (MasternodeTiers *)&masternodeTiers; + else + break; } - return 0; + return currentTiers; + } + + unsigned int getMasternodeTierCount (unsigned int atBlockHeight = 0) const { + MasternodeTiers *currentTiers = getMasternodeTiers (atBlockHeight); + + if (currentTiers == NULL) + return 0; + + return currentTiers->masternodeTiers.size (); } unsigned int getMasternodeTier (CAmount collateralValue, unsigned int atBlockHeight = 0) const { - if (atBlockHeight == 0) { - CBlockIndex* chainTip = chainActive.Tip (); - - if (chainTip != NULL) - atBlockHeight = chainTip->nHeight; - } + MasternodeTiers *currentTiers = getMasternodeTiers (atBlockHeight); - BOOST_FOREACH (const MasternodeTiers& masternodeTiers, vMasternodeTiers) { - // Check if this tiers aren't active yet - if (masternodeTiers.blockHeight > atBlockHeight) - continue; - - unsigned int currentLevel = 0; - - // Check if the given value is on collateral-list - BOOST_FOREACH (const MasternodeTier& masternodeTier, masternodeTiers.masternodeTiers) { - currentLevel++; - - if (collateralValue == masternodeTier.Collateral) - return currentLevel; - } + if (currentTiers == NULL) + return 0; + + unsigned int currentLevel = 0; + + // Check if the given value is on collateral-list + BOOST_FOREACH (const MasternodeTier& masternodeTier, currentTiers->masternodeTiers) { + currentLevel++; - break; + if (collateralValue == masternodeTier.Collateral) + return currentLevel; } - + return 0; } unsigned int getMasternodeTierWeight (unsigned int masternodeTier = 0, unsigned int atBlockHeight = 0) const { - if (atBlockHeight == 0) { - CBlockIndex* chainTip = chainActive.Tip (); - - if (chainTip != NULL) - atBlockHeight = chainTip->nHeight; - } + MasternodeTiers *currentTiers = getMasternodeTiers (atBlockHeight); - BOOST_FOREACH (const MasternodeTiers& masternodeTiers, vMasternodeTiers) { - // Check if this tiers aren't active yet - if (masternodeTiers.blockHeight > atBlockHeight) - continue; - - // Make sure the tier is valid - if (masternodeTier > masternodeTiers.masternodeTiers.size ()) - return 0; - - // Return weight of a given tier - if (masternodeTier > 0) - return masternodeTiers.masternodeTiers [masternodeTier - 1].Weight; - - // Collect sum of all tiers - unsigned int tierWeightSum = 0; - - BOOST_FOREACH (const MasternodeTier& masternodeTier, masternodeTiers.masternodeTiers) { - tierWeightSum += masternodeTier.Weight; - } - - // Never return something less than one, to prevent divisions by zero - if (tierWeightSum < 1) - tierWeightSum = 1; - - return tierWeightSum; + if (currentTiers == NULL) + return (masternodeTier == 0 ? 1 : 0); + + // Make sure the tier is valid + if (masternodeTier > currentTiers->masternodeTiers.size ()) + return 0; + + // Return weight of a given tier + if (masternodeTier > 0) + return currentTiers->masternodeTiers [masternodeTier - 1].Weight; + + // Collect sum of all tiers + unsigned int tierWeightSum = 0; + + BOOST_FOREACH (const MasternodeTier& masternodeTier, currentTiers->masternodeTiers) { + tierWeightSum += masternodeTier.Weight; } - return (masternodeTier == 0 ? 1 : 0); + // Never return something less than one, to prevent divisions by zero + if (tierWeightSum < 1) + tierWeightSum = 1; + + return tierWeightSum; } - + protected: CChainParams() {} diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index b5f955e..bd86a2b 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -297,7 +297,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe bool hasPayment = true; CScript payee; - for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (pindexPrev->nHeight + 1); masternodeTier++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTierCount (pindexPrev->nHeight + 1); masternodeTier++) { hasPayment = true; if (!masternodePayments.GetBlockPayee (pindexPrev->nHeight + 1, masternodeTier, payee)) { @@ -578,7 +578,7 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) bool transactionCorrect = true; CAmount requiredMasternodePayment = 0; - for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (nBlockHeight); masternodeTier++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTierCount (nBlockHeight); masternodeTier++) { // Require at least 6 signatures int nMaxSignatures = 0; @@ -780,7 +780,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight) return false; } - for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (nBlockHeight); masternodeTier++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTierCount (nBlockHeight); masternodeTier++) { // Create a new winner for this level CMasternodePaymentWinner newWinner (activeMasternode.vin); diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 76787df..330ef7b 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -56,7 +56,7 @@ UniValue getpoolinfo(const UniValue& params, bool fHelp) UniValue tiers (UniValue::VARR); - for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (); masternodeTier++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTierCount (); masternodeTier++) { UniValue tier (UniValue::VOBJ); tier.push_back (Pair ("tier", (uint64_t)masternodeTier)); @@ -381,7 +381,7 @@ UniValue getmasternodecount (const UniValue& params, bool fHelp) UniValue tiers (UniValue::VARR); - for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (); masternodeTier++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTierCount (); masternodeTier++) { UniValue tier (UniValue::VOBJ); nCount = ipv4 = ipv6 = onion = 0; @@ -454,7 +454,7 @@ UniValue masternodecurrent (const UniValue& params, bool fHelp) UniValue tiers (UniValue::VARR); - for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (); masternodeTier++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTierCount (); masternodeTier++) { if (!(winner = mnodeman.GetCurrentMasternodeOnLevel (masternodeTier, 1))) continue; @@ -955,7 +955,7 @@ UniValue getmasternodescores (const UniValue& params, bool fHelp) for (int nHeight = chainActive.Tip()->nHeight - nLast; nHeight < chainActive.Tip()->nHeight + 20; nHeight++) { UniValue block (UniValue::VARR); - for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTiers (); masternodeTier++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTierCount (); masternodeTier++) { uint256 nHigh = 0; CMasternode* pBestMasternode = NULL; From e4dde4d3aa693ac9f593df17d8bbd0e547e9ce08 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Tue, 22 Sep 2020 21:16:31 +0200 Subject: [PATCH 43/49] WiP Added next forking-points for testing --- src/chainparams.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 6122b72..34b7a4b 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -229,7 +229,7 @@ class CMainParams : public CChainParams }); vMasternodeTiers.push_back ({ - 22222, + 20301, { { 1000 * COIN, 5 }, { 4000 * COIN, 10 }, @@ -237,6 +237,25 @@ class CMainParams : public CChainParams { 100000 * COIN, 60 } } }); + + vMasternodeTiers.push_back ({ + 20600, + { + { 1000 * COIN, 1 }, + { 4000 * COIN, 5 }, + { 10000 * COIN, 12 }, + { 100000 * COIN, 82 } + } + }); + + vMasternodeTiers.push_back ({ + 20700, + { + { 1000 * COIN, 2 }, + { 10000 * COIN, 14 }, + { 100000 * COIN, 84 } + } + }); } const Checkpoints::CCheckpointData& Checkpoints() const From f3a5611c1ffefa667eef4715ac3ea4ac8b310064 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Tue, 22 Sep 2020 21:20:30 +0200 Subject: [PATCH 44/49] BUGFIX Correctly set masternode-payments on forking-points --- src/masternode-payments.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index bd86a2b..4a18e85 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -312,7 +312,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe } CAmount blockValue = GetBlockValue (pindexPrev->nHeight); - CAmount masternodePayment = GetMasternodePayment (pindexPrev->nHeight, masternodeTier, blockValue, 0, fZMWStake); + CAmount masternodePayment = GetMasternodePayment (pindexPrev->nHeight + 1, masternodeTier, blockValue, 0, fZMWStake); if (hasPayment) { unsigned int i = txNew.vout.size (); @@ -328,7 +328,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe ExtractDestination (payee, address1); CBitcoinAddress address2 (address1); - LogPrint ("masternode", "Masternode payment of %s to %s\n", FormatMoney(masternodePayment).c_str (), address2.ToString ().c_str ()); + LogPrint ("masternode", "Masternode payment of %s to %s\n", FormatMoney (masternodePayment).c_str (), address2.ToString ().c_str ()); } else if (!fProofOfStake) txNew.vout [0].nValue = blockValue - masternodePayment; } @@ -592,7 +592,7 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) if (nMaxSignatures < MNPAYMENTS_SIGNATURES_REQUIRED) continue; - requiredMasternodePayment = GetMasternodePayment (nBlockHeight, masternodeTier, nReward, nMasternode_Drift_Count); + requiredMasternodePayment = GetMasternodePayment (nBlockHeight, masternodeTier, nReward, nMasternode_Drift_Count, false); bool hasLevelPayment = false; std::string strPayeesPossible = ""; From 0fe5078b7a3bf39df9adc160e4364a0ca85a94d7 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Wed, 23 Sep 2020 10:29:33 +0200 Subject: [PATCH 45/49] Only vote for masternodes that will be masternodes on the next block --- src/masternode-payments.cpp | 6 +++--- src/masternode.cpp | 6 +++--- src/masternode.h | 2 +- src/masternodeman.cpp | 10 +++++----- src/masternodeman.h | 2 +- src/rpc/masternode.cpp | 6 +++--- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 4a18e85..1dee64c 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -508,7 +508,7 @@ bool CMasternodePayments::IsScheduled (CMasternode& mn, int mnLevelCount, int nN CScript mnPayee; CScript payee; - unsigned int masternodeLevel = mn.GetLevel (); + unsigned int masternodeLevel = mn.GetTier (); mnPayee = GetScriptForDestination (mn.pubKeyCollateralAddress.GetID()); @@ -780,13 +780,13 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight) return false; } - for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTierCount (nBlockHeight); masternodeTier++) { + for (unsigned int masternodeTier = 1; masternodeTier <= Params ().getMasternodeTierCount (nBlockHeight + 1); masternodeTier++) { // Create a new winner for this level CMasternodePaymentWinner newWinner (activeMasternode.vin); // pay to the oldest MN that still had no payment but its input is old enough and it was active long enough int nCount = 0; - CMasternode* pmn = mnodeman.GetNextMasternodeInQueueForPayment (nBlockHeight, masternodeTier, true, nCount); + CMasternode* pmn = mnodeman.GetNextMasternodeInQueueForPayment (nBlockHeight + 1, masternodeTier, true, nCount); if (pmn == NULL) { LogPrint ("masternode", "CMasternodePayments::ProcessBlock() Failed to find masternode to pay\n"); diff --git a/src/masternode.cpp b/src/masternode.cpp index 8249073..6658f89 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -127,7 +127,7 @@ CMasternode::CMasternode(const CMasternodeBroadcast& mnb) lastTimeChecked = 0; } -unsigned int CMasternode::GetLevel () { +unsigned int CMasternode::GetTier (unsigned int atBlockHeight) { CTransaction prevTx; uint256 hashBlock = 0; @@ -137,7 +137,7 @@ unsigned int CMasternode::GetLevel () { if (vin.prevout.n >= prevTx.vout.size ()) return 0; - return Params ().getMasternodeTier (prevTx.vout [vin.prevout.n].nValue); + return Params ().getMasternodeTier (prevTx.vout [vin.prevout.n].nValue, atBlockHeight); } // @@ -277,7 +277,7 @@ int64_t CMasternode::GetLastPaid() const CBlockIndex* BlockReading = chainActive.Tip(); - int nMnCount = mnodeman.CountEnabledOnLevel (GetLevel ()) * 1.25; + int nMnCount = mnodeman.CountEnabledOnLevel (GetTier ()) * 1.25; int n = 0; for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) { if (n >= nMnCount) { diff --git a/src/masternode.h b/src/masternode.h index f7c4def..107d242 100644 --- a/src/masternode.h +++ b/src/masternode.h @@ -149,7 +149,7 @@ class CMasternode CMasternode(const CMasternode& other); CMasternode(const CMasternodeBroadcast& mnb); - unsigned int GetLevel (); + unsigned int GetTier (unsigned int atBlockHeight = 0); void swap(CMasternode& first, CMasternode& second) // nothrow { diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index c2bd247..2a65d89 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -359,7 +359,7 @@ int CMasternodeMan::stable_size (unsigned int masternodeLevel) { int64_t nMasternode_Age = 0; for (CMasternode& mn : vMasternodes) { - if ((masternodeLevel > 0) && (mn.GetLevel () != masternodeLevel)) + if ((masternodeLevel > 0) && (mn.GetTier () != masternodeLevel)) continue; if (mn.protocolVersion < nMinProtocol) { @@ -395,7 +395,7 @@ int CMasternodeMan::CountEnabledOnLevel (unsigned int mnLevel, int protocolVersi if (mn.protocolVersion < protocolVersion || !mn.IsEnabled () || - ((mnLevel > 0) && (mnLevel != mn.GetLevel ()))) + ((mnLevel > 0) && (mnLevel != mn.GetTier ()))) continue; masternodeCount++; @@ -412,7 +412,7 @@ void CMasternodeMan::CountNetworks (unsigned int masternodeLevel, int protocolVe protocolVersion = protocolVersion == -1 ? masternodePayments.GetMinMasternodePaymentsProto() : protocolVersion; for (CMasternode& mn : vMasternodes) { - if ((masternodeLevel > 0) && (mn.GetLevel () != masternodeLevel)) + if ((masternodeLevel > 0) && (mn.GetTier () != masternodeLevel)) continue; mn.Check(); @@ -514,7 +514,7 @@ CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment (int nBlockHeigh // Check the level of tiered masternode if ((masternodeLevel > 0) && - (mn.GetLevel () != masternodeLevel)) + (mn.GetTier (nBlockHeight) != masternodeLevel)) continue; if (!mn.IsEnabled()) continue; @@ -611,7 +611,7 @@ CMasternode* CMasternodeMan::GetCurrentMasternodeOnLevel (unsigned int masternod mn.Check(); if ((masternodeLevel > 0) && - (mn.GetLevel () != masternodeLevel)) + (mn.GetTier () != masternodeLevel)) continue; if (mn.protocolVersion < minProtocol || !mn.IsEnabled()) continue; diff --git a/src/masternodeman.h b/src/masternodeman.h index e6dd061..29196cc 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -157,7 +157,7 @@ class CMasternodeMan int masternodeCount = 0; BOOST_FOREACH (CMasternode masternode, vMasternodes) { - if (masternode.GetLevel () == masternodeLevel) + if (masternode.GetTier () == masternodeLevel) masternodeCount++; } diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 330ef7b..bfaf4bf 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -279,7 +279,7 @@ UniValue listmasternodes(const UniValue& params, bool fHelp) CNetAddr node = CNetAddr(strHost, false); std::string strNetwork = GetNetworkName(node.GetNetwork()); - obj.push_back (Pair ("tier", (uint64_t)mn->GetLevel ())); + obj.push_back (Pair ("tier", (uint64_t)mn->GetTier ())); obj.push_back(Pair("rank", (strStatus == "ENABLED" ? s.first : 0))); obj.push_back(Pair("network", strNetwork)); obj.push_back(Pair("txhash", strTxHash)); @@ -828,7 +828,7 @@ UniValue getmasternodestatus (const UniValue& params, bool fHelp) mnObj.push_back(Pair("addr", CBitcoinAddress(pmn->pubKeyCollateralAddress.GetID()).ToString())); mnObj.push_back(Pair("status", activeMasternode.status)); mnObj.push_back(Pair("message", activeMasternode.GetStatus())); - mnObj.push_back (Pair ("tier", (uint64_t)pmn->GetLevel ())); + mnObj.push_back (Pair ("tier", (uint64_t)pmn->GetTier ())); return mnObj; } @@ -960,7 +960,7 @@ UniValue getmasternodescores (const UniValue& params, bool fHelp) CMasternode* pBestMasternode = NULL; BOOST_FOREACH (CMasternode& mn, vMasternodes) { - if (mn.GetLevel () != masternodeTier) + if (mn.GetTier () != masternodeTier) continue; uint256 n = mn.CalculateScore (1, nHeight - 100); From 5e361b57cb9363a2e05ac6cda281060b8543cf1b Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Fri, 2 Oct 2020 18:52:36 +0200 Subject: [PATCH 46/49] Restored current Masterwin-Masternode-Tiers --- src/chainparams.cpp | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 34b7a4b..2a284be 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -221,39 +221,7 @@ class CMainParams : public CChainParams vMasternodeTiers.push_back ({ nLastPOWBlock, { - { 1000 * COIN, 1 }, - { 4000 * COIN, 2 }, - { 10000 * COIN, 4 }, - { 100000 * COIN, 8 } - } - }); - - vMasternodeTiers.push_back ({ - 20301, - { - { 1000 * COIN, 5 }, - { 4000 * COIN, 10 }, - { 10000 * COIN, 25 }, - { 100000 * COIN, 60 } - } - }); - - vMasternodeTiers.push_back ({ - 20600, - { - { 1000 * COIN, 1 }, - { 4000 * COIN, 5 }, - { 10000 * COIN, 12 }, - { 100000 * COIN, 82 } - } - }); - - vMasternodeTiers.push_back ({ - 20700, - { - { 1000 * COIN, 2 }, - { 10000 * COIN, 14 }, - { 100000 * COIN, 84 } + { 4000 * COIN, 1 } } }); } From 822d21765edeb5fae92f49fee6edb5c8d6ec28a1 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Fri, 2 Oct 2020 18:58:53 +0200 Subject: [PATCH 47/49] Removed masternodeTier from MNW again --- src/masternode-payments.cpp | 33 +++++++++++++++++++++++++++------ src/masternode-payments.h | 18 ++++-------------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 1dee64c..58b67ab 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -372,6 +372,17 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st vRecv >> winner; if (pfrom->nVersion < ActiveProtocol()) return; + + if (winner.GetTier () == 0) { + LogPrintf ("CMasternodePayments::ProcessMessageMasternodePayments() : mnw - Could not find tier of masternode \n"); + + if (masternodeSync.IsSynced ()) + Misbehaving (pfrom->GetId (), 20); + + mnodeman.AskForMN (pfrom, winner.vinMasternode); + + return; + } int nHeight; { @@ -390,7 +401,7 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st return; } - int nFirstBlock = nHeight - int (mnodeman.CountEnabledOnLevel (winner.masternodeLevel) * 1.25); + int nFirstBlock = nHeight - int (mnodeman.CountEnabledOnLevel (winner.GetTier ()) * 1.25); if (winner.nBlockHeight < nFirstBlock || winner.nBlockHeight > nHeight + 20) { LogPrint("mnpayments", "mnw - winner out of range - FirstBlock %d Height %d bestHeight %d\n", nFirstBlock, winner.nBlockHeight, nHeight); @@ -403,7 +414,7 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st return; } - if (!masternodePayments.CanVote (winner.vinMasternode.prevout, winner.masternodeLevel, winner.nBlockHeight)) { + if (!masternodePayments.CanVote (winner.vinMasternode.prevout, winner.GetTier (), winner.nBlockHeight)) { // LogPrint("masternode","mnw - masternode already voted - %s\n", winner.vinMasternode.prevout.ToStringShort()); return; } @@ -417,7 +428,7 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st mnodeman.AskForMN(pfrom, winner.vinMasternode); return; } - + if (masternodePayments.AddWinningMasternode(winner)) { winner.Relay(); masternodeSync.AddedMasternodeWinner(winner.GetHash()); @@ -425,6 +436,15 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st } } +unsigned int CMasternodePaymentWinner::GetTier () { + CMasternode* pmn = mnodeman.Find (vinMasternode); + + if (pmn) + return pmn->GetTier (); + + return 0; +} + bool CMasternodePaymentWinner::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) { std::string errorMessage; @@ -552,7 +572,7 @@ bool CMasternodePayments::AddWinningMasternode(CMasternodePaymentWinner& winnerI } } - mapMasternodeBlocks [winnerIn.nBlockHeight].AddPayee (winnerIn.payee, winnerIn.masternodeLevel, 1); + mapMasternodeBlocks [winnerIn.nBlockHeight].AddPayee (winnerIn.payee, winnerIn.GetTier (), 1); return true; } @@ -584,7 +604,6 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) for (CMasternodePayee& payee : vecPayments) if ((payee.nVotes >= nMaxSignatures) && - (payee.nVotes >= MNPAYMENTS_SIGNATURES_REQUIRED) && (payee.masternodeLevel == masternodeTier)) nMaxSignatures = payee.nVotes; @@ -593,6 +612,7 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) continue; requiredMasternodePayment = GetMasternodePayment (nBlockHeight, masternodeTier, nReward, nMasternode_Drift_Count, false); + bool hasLevelPayment = false; std::string strPayeesPossible = ""; @@ -610,6 +630,7 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) if (payee.scriptPubKey == out.scriptPubKey) { if(out.nValue >= requiredMasternodePayment) { hasLevelPayment = true; + LogPrintf ("Found payment of %s on tier %d at %d\n", FormatMoney (out.nValue).c_str (), masternodeTier, nBlockHeight); break; } else @@ -799,7 +820,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight) newWinner.nBlockHeight = nBlockHeight; CScript payee = GetScriptForDestination (pmn->pubKeyCollateralAddress.GetID()); - newWinner.AddPayee (payee, masternodeTier); + newWinner.AddPayee (payee); CTxDestination address1; ExtractDestination (payee, address1); diff --git a/src/masternode-payments.h b/src/masternode-payments.h index 30191f2..013def2 100644 --- a/src/masternode-payments.h +++ b/src/masternode-payments.h @@ -216,7 +216,6 @@ class CMasternodePaymentWinner int nBlockHeight; CScript payee; - unsigned int masternodeLevel; std::vector vchSig; CMasternodePaymentWinner() @@ -224,7 +223,6 @@ class CMasternodePaymentWinner nBlockHeight = 0; vinMasternode = CTxIn(); payee = CScript(); - masternodeLevel = 0; } CMasternodePaymentWinner(CTxIn vinIn) @@ -232,7 +230,6 @@ class CMasternodePaymentWinner nBlockHeight = 0; vinMasternode = vinIn; payee = CScript(); - masternodeLevel = 0; } uint256 GetHash() @@ -241,24 +238,18 @@ class CMasternodePaymentWinner ss << payee; ss << nBlockHeight; ss << vinMasternode.prevout; - ss << masternodeLevel; return ss.GetHash(); } - + + unsigned int GetTier (); bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode); bool IsValid(CNode* pnode, std::string& strError); bool SignatureValid(); void Relay(); - void AddPayee(CScript payeeIn) - { - payee = payeeIn; - } - - void AddPayee (CScript payeeIn, unsigned int mnLevel) { + void AddPayee (CScript payeeIn) { payee = payeeIn; - masternodeLevel = mnLevel; } @@ -270,7 +261,6 @@ class CMasternodePaymentWinner READWRITE(vinMasternode); READWRITE(nBlockHeight); READWRITE(payee); - READWRITE(masternodeLevel); READWRITE(vchSig); } @@ -279,7 +269,7 @@ class CMasternodePaymentWinner std::string ret = ""; ret += vinMasternode.ToString(); ret += ", " + boost::lexical_cast(nBlockHeight); - ret += ", " + payee.ToString() + "@" + boost::lexical_cast(masternodeLevel); + ret += ", " + payee.ToString() + "@" + boost::lexical_cast(GetTier ()); ret += ", " + boost::lexical_cast((int)vchSig.size()); return ret; } From 3dcef70ee70fa1b63bc1af0d8918f258d6744125 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Fri, 2 Oct 2020 18:59:15 +0200 Subject: [PATCH 48/49] BUGFIX Removed stale call to GetLevel() --- src/qt/masternodelist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/masternodelist.cpp b/src/qt/masternodelist.cpp index 6508b5e..f67bb97 100644 --- a/src/qt/masternodelist.cpp +++ b/src/qt/masternodelist.cpp @@ -185,7 +185,7 @@ void MasternodeList::updateMyMasternodeInfo(QString strAlias, QString strAddr, C QTableWidgetItem* aliasItem = new QTableWidgetItem(strAlias); QTableWidgetItem* addrItem = new QTableWidgetItem(pmn ? QString::fromStdString(pmn->addr.ToString()) : strAddr); QTableWidgetItem* protocolItem = new QTableWidgetItem(QString::number(pmn ? pmn->protocolVersion : -1)); - QTableWidgetItem* levelItem = new QTableWidgetItem (QString::number (pmn ? pmn->GetLevel () : - 1)); + QTableWidgetItem* levelItem = new QTableWidgetItem (QString::number (pmn ? pmn->GetTier () : - 1)); QTableWidgetItem* statusItem = new QTableWidgetItem(QString::fromStdString(pmn ? pmn->GetStatus() : "MISSING")); GUIUtil::DHMSTableWidgetItem* activeSecondsItem = new GUIUtil::DHMSTableWidgetItem(pmn ? (pmn->lastPing.sigTime - pmn->sigTime) : 0); QTableWidgetItem* lastSeenItem = new QTableWidgetItem(QString::fromStdString(DateTimeStrFormat("%Y-%m-%d %H:%M", pmn ? pmn->lastPing.sigTime : 0))); From bb53c376e80090a40bccc789e939ad0c3580e585 Mon Sep 17 00:00:00 2001 From: kerryoncrypto Date: Fri, 2 Oct 2020 19:01:19 +0200 Subject: [PATCH 49/49] Updated splashscreen --- src/qt/splashscreen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp index ad2892a..a9f64df 100644 --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -39,7 +39,7 @@ SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle* networkStyle) QString copyrightTextBtc = QChar(0xA9) + QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Core developers")); QString copyrightTextDash = QChar(0xA9) + QString(" 2014-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Dash Core developers")); QString copyrightTextPIVX = QChar(0xA9) + QString(" 2015-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The PIVX Core developers")); - QString copyrightTextMasterWin = QChar(0xA9) + QString(" %1 ").arg(COPYRIGHT_YEAR) + QString(tr("The MasterWin developers")); + QString copyrightTextMasterWin = QChar (0xA9) + QString (" 2019-%1 ").arg (COPYRIGHT_YEAR) + QString (tr ("The MasterWin developers")); QString titleAddText = networkStyle->getTitleAddText(); QString font = QApplication::font().toString();