From df7734b68446723b56a3f61165d40503127217e0 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Wed, 25 Jun 2014 08:43:16 -0700 Subject: [PATCH] added non-enforcement masternode payments --- src/clientversion.h | 2 +- src/main.cpp | 86 +++++++++++++++++++++++++++------------------ 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/src/clientversion.h b/src/clientversion.h index f3809d6bf7..2b67fd2917 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -9,7 +9,7 @@ #define CLIENT_VERSION_MAJOR 0 #define CLIENT_VERSION_MINOR 9 #define CLIENT_VERSION_REVISION 11 -#define CLIENT_VERSION_BUILD 2 +#define CLIENT_VERSION_BUILD 3 // Set to true for release, false for prerelease or test build #define CLIENT_VERSION_IS_RELEASE true diff --git a/src/main.cpp b/src/main.cpp index 1d729cbba4..e3ea423b88 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1813,7 +1813,7 @@ uint256 CBlockHeader::GetSpecialHash() const { // calculate additional masternode vote info to include in hash uint256 hash = 0; - uint256 vmnAdditional; + uint256 vmnAdditional = 0; //printf("------------------------------------------------\n"); if( (fTestNet && nTime > START_MASTERNODE_PAYMENTS_TESTNET) || (!fTestNet && nTime > START_MASTERNODE_PAYMENTS)) { @@ -5175,46 +5175,62 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) CBlockIndex* pindexPrev = pindexBest; if(bMasterNodePayment) { - CBlock blockLast; - if(blockLast.ReadFromDisk(pindexPrev)){ - BOOST_FOREACH(CMasterNodeVote& mv1, blockLast.vmn){ - // vote if you agree with it, if you're the last vote you must vote yes to avoid the greedy voter exploit - // i.e: You only vote yes when you're not the one that is going to pay - if(mv1.GetVotes() >= MASTERNODE_PAYMENTS_MIN_VOTES-1){ - mv1.Vote(); - } else { - BOOST_FOREACH(CMasterNodeVote& mv2, darkSendMasterNodeVotes) { - if((mv1.blockHeight == mv2.blockHeight && mv1.GetPubKey() == mv2.GetPubKey())) { - mv1.Vote(); - break; + if(!pblock->MasterNodePaymentsEnforcing()){ + int winningNode = darkSendPool.GetCurrentMasterNode(1); + if(winningNode >= 0){ + pblock->payee.SetDestination(darkSendMasterNodes[winningNode].pubkey.GetID()); + + payments++; + txNew.vout.resize(payments); + + //txNew.vout[0].scriptPubKey = scriptPubKeyIn; + txNew.vout[payments-1].scriptPubKey.SetDestination(darkSendMasterNodes[winningNode].pubkey.GetID()); + txNew.vout[payments-1].nValue = 0; + + printf("Masternode payment to %s\n", txNew.vout[payments-1].scriptPubKey.ToString().c_str()); + } + } else { + CBlock blockLast; + if(blockLast.ReadFromDisk(pindexPrev)){ + BOOST_FOREACH(CMasterNodeVote& mv1, blockLast.vmn){ + // vote if you agree with it, if you're the last vote you must vote yes to avoid the greedy voter exploit + // i.e: You only vote yes when you're not the one that is going to pay + if(mv1.GetVotes() >= MASTERNODE_PAYMENTS_MIN_VOTES-1){ + mv1.Vote(); + } else { + BOOST_FOREACH(CMasterNodeVote& mv2, darkSendMasterNodeVotes) { + if((mv1.blockHeight == mv2.blockHeight && mv1.GetPubKey() == mv2.GetPubKey())) { + mv1.Vote(); + break; + } } } - } - if (((pindexPrev->nHeight+1) - mv1.GetHeight()) >= MASTERNODE_PAYMENTS_EXPIRATION) { - // do nothing - } else if(mv1.GetVotes() >= MASTERNODE_PAYMENTS_MIN_VOTES && payments <= MASTERNODE_PAYMENTS_MAX) { - pblock->payee = mv1.GetPubKey(); - - payments++; - txNew.vout.resize(payments); + if (((pindexPrev->nHeight+1) - mv1.GetHeight()) >= MASTERNODE_PAYMENTS_EXPIRATION) { + // do nothing + } else if( (mv1.GetVotes() >= MASTERNODE_PAYMENTS_MIN_VOTES && pblock->MasterNodePaymentsEnforcing()) && payments <= MASTERNODE_PAYMENTS_MAX) { + pblock->payee = mv1.GetPubKey(); + + payments++; + txNew.vout.resize(payments); - //txNew.vout[0].scriptPubKey = scriptPubKeyIn; - txNew.vout[payments-1].scriptPubKey = mv1.GetPubKey(); - txNew.vout[payments-1].nValue = 0; + //txNew.vout[0].scriptPubKey = scriptPubKeyIn; + txNew.vout[payments-1].scriptPubKey = mv1.GetPubKey(); + txNew.vout[payments-1].nValue = 0; - printf("Masternode payment to %s\n", txNew.vout[payments-1].scriptPubKey.ToString().c_str()); - } else if (((pindexPrev->nHeight+1) - mv1.GetHeight()) < MASTERNODE_PAYMENTS_EXPIRATION) { - pblock->vmn.push_back(mv1); - } - } - } + printf("Masternode payment to %s\n", txNew.vout[payments-1].scriptPubKey.ToString().c_str()); + } else if (((pindexPrev->nHeight+1) - mv1.GetHeight()) < MASTERNODE_PAYMENTS_EXPIRATION) { + pblock->vmn.push_back(mv1); + } + } + } - int winningNode = darkSendPool.GetCurrentMasterNode(1); - if(winningNode >= 0){ - CMasterNodeVote mv; - mv.Set(darkSendMasterNodes[winningNode].pubkey, pindexPrev->nHeight + 1); - pblock->vmn.push_back(mv); + int winningNode = darkSendPool.GetCurrentMasterNode(1); + if(winningNode >= 0){ + CMasterNodeVote mv; + mv.Set(darkSendMasterNodes[winningNode].pubkey, pindexPrev->nHeight + 1); + pblock->vmn.push_back(mv); + } } }