added non-enforcement masternode payments

This commit is contained in:
Evan Duffield 2014-06-25 08:43:16 -07:00
parent a950f31002
commit df7734b684
2 changed files with 52 additions and 36 deletions

View File

@ -9,7 +9,7 @@
#define CLIENT_VERSION_MAJOR 0 #define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 9 #define CLIENT_VERSION_MINOR 9
#define CLIENT_VERSION_REVISION 11 #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 // Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE true #define CLIENT_VERSION_IS_RELEASE true

View File

@ -1813,7 +1813,7 @@ uint256 CBlockHeader::GetSpecialHash() const
{ {
// calculate additional masternode vote info to include in hash // calculate additional masternode vote info to include in hash
uint256 hash = 0; uint256 hash = 0;
uint256 vmnAdditional; uint256 vmnAdditional = 0;
//printf("------------------------------------------------\n"); //printf("------------------------------------------------\n");
if( (fTestNet && nTime > START_MASTERNODE_PAYMENTS_TESTNET) || (!fTestNet && nTime > START_MASTERNODE_PAYMENTS)) { if( (fTestNet && nTime > START_MASTERNODE_PAYMENTS_TESTNET) || (!fTestNet && nTime > START_MASTERNODE_PAYMENTS)) {
@ -5175,46 +5175,62 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
CBlockIndex* pindexPrev = pindexBest; CBlockIndex* pindexPrev = pindexBest;
if(bMasterNodePayment) { if(bMasterNodePayment) {
CBlock blockLast; if(!pblock->MasterNodePaymentsEnforcing()){
if(blockLast.ReadFromDisk(pindexPrev)){ int winningNode = darkSendPool.GetCurrentMasterNode(1);
BOOST_FOREACH(CMasterNodeVote& mv1, blockLast.vmn){ if(winningNode >= 0){
// vote if you agree with it, if you're the last vote you must vote yes to avoid the greedy voter exploit pblock->payee.SetDestination(darkSendMasterNodes[winningNode].pubkey.GetID());
// 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){ payments++;
mv1.Vote(); txNew.vout.resize(payments);
} else {
BOOST_FOREACH(CMasterNodeVote& mv2, darkSendMasterNodeVotes) { //txNew.vout[0].scriptPubKey = scriptPubKeyIn;
if((mv1.blockHeight == mv2.blockHeight && mv1.GetPubKey() == mv2.GetPubKey())) { txNew.vout[payments-1].scriptPubKey.SetDestination(darkSendMasterNodes[winningNode].pubkey.GetID());
mv1.Vote(); txNew.vout[payments-1].nValue = 0;
break;
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) { if (((pindexPrev->nHeight+1) - mv1.GetHeight()) >= MASTERNODE_PAYMENTS_EXPIRATION) {
// do nothing // do nothing
} else if(mv1.GetVotes() >= MASTERNODE_PAYMENTS_MIN_VOTES && payments <= MASTERNODE_PAYMENTS_MAX) { } else if( (mv1.GetVotes() >= MASTERNODE_PAYMENTS_MIN_VOTES && pblock->MasterNodePaymentsEnforcing()) && payments <= MASTERNODE_PAYMENTS_MAX) {
pblock->payee = mv1.GetPubKey(); pblock->payee = mv1.GetPubKey();
payments++; payments++;
txNew.vout.resize(payments); txNew.vout.resize(payments);
//txNew.vout[0].scriptPubKey = scriptPubKeyIn; //txNew.vout[0].scriptPubKey = scriptPubKeyIn;
txNew.vout[payments-1].scriptPubKey = mv1.GetPubKey(); txNew.vout[payments-1].scriptPubKey = mv1.GetPubKey();
txNew.vout[payments-1].nValue = 0; txNew.vout[payments-1].nValue = 0;
printf("Masternode payment to %s\n", txNew.vout[payments-1].scriptPubKey.ToString().c_str()); printf("Masternode payment to %s\n", txNew.vout[payments-1].scriptPubKey.ToString().c_str());
} else if (((pindexPrev->nHeight+1) - mv1.GetHeight()) < MASTERNODE_PAYMENTS_EXPIRATION) { } else if (((pindexPrev->nHeight+1) - mv1.GetHeight()) < MASTERNODE_PAYMENTS_EXPIRATION) {
pblock->vmn.push_back(mv1); pblock->vmn.push_back(mv1);
} }
} }
} }
int winningNode = darkSendPool.GetCurrentMasterNode(1); int winningNode = darkSendPool.GetCurrentMasterNode(1);
if(winningNode >= 0){ if(winningNode >= 0){
CMasterNodeVote mv; CMasterNodeVote mv;
mv.Set(darkSendMasterNodes[winningNode].pubkey, pindexPrev->nHeight + 1); mv.Set(darkSendMasterNodes[winningNode].pubkey, pindexPrev->nHeight + 1);
pblock->vmn.push_back(mv); pblock->vmn.push_back(mv);
}
} }
} }