diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 2ce807b29674..37ac64f21108 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -12,6 +12,7 @@ #include "sync.h" #include "spork.h" #include "addrman.h" +#include "utilmoneystr.h" #include #include @@ -313,16 +314,21 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe CAmount blockValue = GetBlockValue(pindexPrev->nHeight); CAmount masternodePayment = GetMasternodePayment(pindexPrev->nHeight, blockValue); - txNew.vout[0].nValue = blockValue; - 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 txNew.vout[i - 1].nValue -= masternodePayment; } else @@ -330,14 +336,14 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe txNew.vout.resize(2); txNew.vout[1].scriptPubKey = payee; txNew.vout[1].nValue = masternodePayment; - txNew.vout[0].nValue -= masternodePayment; + txNew.vout[0].nValue = blockValue - masternodePayment; } CTxDestination address1; ExtractDestination(payee, address1); CBitcoinAddress address2(address1); - LogPrintf("Masternode payment to %s\n", address2.ToString().c_str()); + LogPrintf("Masternode payment of %s to %s\n", FormatMoney(masternodePayment).c_str(), address2.ToString().c_str()); } } @@ -519,14 +525,10 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) int nMaxSignatures = 0; std::string strPayeesPossible = ""; - uint64_t nReward; - uint64_t masternodePayment; - - nReward = GetBlockValue(nBlockHeight); - masternodePayment = GetMasternodePayment(nBlockHeight, nReward); + CAmount nReward = GetBlockValue(nBlockHeight); + CAmount requiredMasternodePayment = GetMasternodePayment(nBlockHeight, nReward); //require at least 6 signatures - BOOST_FOREACH(CMasternodePayee& payee, vecPayments) if(payee.nVotes >= nMaxSignatures && payee.nVotes >= MNPAYMENTS_SIGNATURES_REQUIRED) nMaxSignatures = payee.nVotes; @@ -537,8 +539,9 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) BOOST_FOREACH(CMasternodePayee& payee, vecPayments) { bool found = false; - BOOST_FOREACH(CTxOut out, txNew.vout){ - if(payee.scriptPubKey == out.scriptPubKey && masternodePayment == out.nValue){ + BOOST_FOREACH(CTxOut out, txNew.vout) + { + if(payee.scriptPubKey == out.scriptPubKey && out.nValue >= requiredMasternodePayment){ found = true; } } @@ -559,7 +562,7 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) } - LogPrintf("CMasternodePayments::IsTransactionValid - Missing required payment - %s\n", strPayeesPossible.c_str()); + LogPrintf("CMasternodePayments::IsTransactionValid - Missing required payment of %s to %s\n", FormatMoney(requiredMasternodePayment).c_str(),strPayeesPossible.c_str()); return false; } diff --git a/src/miner.cpp b/src/miner.cpp index cbdf21d60048..0dd86d3be049 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -494,7 +494,7 @@ void BitcoinMiner(CWallet *pwallet, bool fProofOfStake) continue; } - while (chainActive.Tip()->nTime < 1471482000 /*|| vNodes.empty()*/ || pwallet->IsLocked() || !fMintableCoins || nReserveBalance >= pwallet->GetBalance() /*|| !masternodeSync.IsSynced()*/) + while (chainActive.Tip()->nTime < 1471482000 || vNodes.empty() || pwallet->IsLocked() || !fMintableCoins || nReserveBalance >= pwallet->GetBalance() || !masternodeSync.IsSynced()) { nLastCoinStakeSearchInterval = 0; MilliSleep(5000);