Skip to content

Commit a570d85

Browse files
committed
Pay to reward script of masternodes.
Instead of using the collateral pubkey, pay to the declared reward script of masternodes (and use that to check payments).
1 parent 33bf875 commit a570d85

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

divi/src/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4977,6 +4977,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
49774977
// it was the one which was commented out
49784978
int ActiveProtocol()
49794979
{
4980+
if (Params().NetworkID() == CBaseChainParams::REGTEST)
4981+
return MN_REWARD_SCRIPT_VERSION;
4982+
49804983
return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;
49814984
}
49824985

divi/src/masternode-payments.cpp

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, const CBloc
339339
// No masternode detected, fall back to our own queue.
340340
const CMasternode* winningNode = mnodeman.GetNextMasternodeInQueueForPayment(pindexPrev, 1, true);
341341
if (winningNode) {
342-
payee = GetScriptForDestination(winningNode->pubKeyCollateralAddress.GetID());
342+
payee = winningNode->rewardScript;
343343
} else {
344344
LogPrint("masternode","CreateNewBlock: Failed to detect masternode to pay\n");
345345
hasPayment = false;
@@ -496,15 +496,13 @@ bool CMasternodePayments::IsScheduled(const CMasternode& mn, int nNotBlockHeight
496496
if (tip == nullptr)
497497
return false;
498498

499-
const CScript mnpayee = GetScriptForDestination(mn.pubKeyCollateralAddress.GetID());
500-
501499
for (int64_t h = 0; h <= 8; ++h) {
502500
if (tip->nHeight + h == nNotBlockHeight) continue;
503501
uint256 seedHash;
504502
if (!GetBlockHashForScoring(seedHash, tip, h)) continue;
505503
auto* payees = GetPayeesForScoreHash(seedHash);
506504
CScript payee;
507-
if (payees != nullptr && payees->GetPayee(payee) && payee == mnpayee)
505+
if (payees != nullptr && payees->GetPayee(payee) && payee == mn.rewardScript)
508506
return true;
509507
}
510508

@@ -591,21 +589,31 @@ std::string CMasternodeBlockPayees::GetRequiredPaymentsString() const
591589
{
592590
LOCK(cs_vecPayments);
593591

594-
std::string ret = "Unknown";
592+
std::ostringstream ret;
593+
bool found = false;
595594

596595
for (const auto& payee : vecPayments) {
597-
CTxDestination address1;
598-
ExtractDestination(payee.scriptPubKey, address1);
599-
CBitcoinAddress address2(address1);
596+
std::string thisPayee;
600597

601-
if (ret != "Unknown") {
602-
ret += ", " + address2.ToString() + ":" + boost::lexical_cast<std::string>(payee.nVotes);
598+
CTxDestination address1;
599+
if (ExtractDestination(payee.scriptPubKey, address1)) {
600+
const CBitcoinAddress address2(address1);
601+
thisPayee = address2.ToString();
603602
} else {
604-
ret = address2.ToString() + ":" + boost::lexical_cast<std::string>(payee.nVotes);
603+
thisPayee = HexStr(payee.scriptPubKey);
605604
}
605+
606+
if (found)
607+
ret << ", ";
608+
609+
found = true;
610+
ret << thisPayee << ":" << payee.nVotes;
606611
}
607612

608-
return ret;
613+
if (!found)
614+
return "Unknown";
615+
616+
return ret.str();
609617
}
610618

611619
std::string CMasternodePayments::GetRequiredPaymentsString(const uint256& seedHash) const
@@ -705,9 +713,7 @@ bool CMasternodePaymentWinner::IsValid(CNode* pnode, std::string& strError) cons
705713
/* Make sure that the payee is in our own payment queue near the top. */
706714
const std::vector<CMasternode*> mnQueue = mnodeman.GetMasternodePaymentQueue(seedHash, nBlockHeight, true);
707715
for (int i = 0; i < std::min<int>(2 * MNPAYMENTS_SIGNATURES_TOTAL, mnQueue.size()); ++i) {
708-
const auto& mn = *mnQueue[i];
709-
const CScript mnPayee = GetScriptForDestination(mn.pubKeyCollateralAddress.GetID());
710-
if (mnPayee == payee)
716+
if (payee == mnQueue[i]->rewardScript)
711717
return true;
712718
}
713719
return false;
@@ -750,11 +756,13 @@ bool CMasternodePayments::ProcessBlock(const CBlockIndex* pindex, const int offs
750756
if (pmn != NULL) {
751757
LogPrint("masternode","CMasternodePayments::ProcessBlock() Found by FindOldestNotInVec \n");
752758

753-
const CTxDestination dest(pmn->pubKeyCollateralAddress.GetID());
754-
newWinner.AddPayee(GetScriptForDestination(dest));
759+
newWinner.AddPayee(pmn->rewardScript);
760+
761+
CTxDestination address1;
762+
ExtractDestination(pmn->rewardScript, address1);
763+
CBitcoinAddress address2(address1);
755764

756-
const CBitcoinAddress address(dest);
757-
LogPrint("masternode","CMasternodePayments::ProcessBlock() Winner payee %s nHeight %d. \n", address.ToString().c_str(), newWinner.GetHeight());
765+
LogPrint("masternode","CMasternodePayments::ProcessBlock() Winner payee %s nHeight %d. \n", address2.ToString().c_str(), newWinner.GetHeight());
758766
} else {
759767
LogPrint("masternode","CMasternodePayments::ProcessBlock() Failed to find masternode to pay\n");
760768
}

0 commit comments

Comments
 (0)