Skip to content

Commit

Permalink
[Consensus] New DMN payment logic
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed May 22, 2021
1 parent 1e40e2b commit 4c731a9
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,23 @@ std::string GetRequiredPaymentsString(int nBlockHeight)
bool CMasternodePayments::GetMasternodeTxOuts(const CBlockIndex* pindexPrev, std::vector<CTxOut>& voutMasternodePaymentsRet) const
{
if (deterministicMNManager->LegacyMNObsolete(pindexPrev->nHeight + 1)) {
// New payment logic (!TODO)
return false;
CAmount masternodeReward = GetMasternodePayment();
auto dmnPayee = deterministicMNManager->GetListForBlock(pindexPrev).GetMNPayee();
if (!dmnPayee) {
return error("%s: Failed to get payees for block at height %d", __func__, pindexPrev->nHeight + 1);
}
CAmount operatorReward = 0;
if (dmnPayee->nOperatorReward != 0 && !dmnPayee->pdmnState->scriptOperatorPayout.empty()) {
operatorReward = (masternodeReward * dmnPayee->nOperatorReward) / 10000;
masternodeReward -= operatorReward;
}
if (masternodeReward > 0) {
voutMasternodePaymentsRet.emplace_back(masternodeReward, dmnPayee->pdmnState->scriptPayout);
}
if (operatorReward > 0) {
voutMasternodePaymentsRet.emplace_back(operatorReward, dmnPayee->pdmnState->scriptOperatorPayout);
}
return true;
}

// Legacy payment logic. !TODO: remove when transition to DMN is complete
Expand All @@ -318,7 +333,6 @@ bool CMasternodePayments::GetMasternodeTxOuts(const CBlockIndex* pindexPrev, std

bool CMasternodePayments::GetLegacyMasternodeTxOut(int nHeight, std::vector<CTxOut>& voutMasternodePaymentsRet) const
{
if (nHeight == 0) return false;
voutMasternodePaymentsRet.clear();

CScript payee;
Expand Down Expand Up @@ -622,8 +636,24 @@ bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, const CB
{
const int nBlockHeight = pindexPrev->nHeight + 1;
if (deterministicMNManager->LegacyMNObsolete(nBlockHeight)) {
// !TODO
return false;
std::vector<CTxOut> vecMnOuts;
if (!GetMasternodeTxOuts(pindexPrev, vecMnOuts)) {
// No masternode scheduled to be paid.
return true;
}

for (const CTxOut& o : vecMnOuts) {
if (std::find(txNew.vout.begin(), txNew.vout.end(), o) == txNew.vout.end()) {
CTxDestination mnDest;
const std::string& payee = ExtractDestination(o.scriptPubKey, mnDest) ? EncodeDestination(mnDest)
: HexStr(o.scriptPubKey);
LogPrint(BCLog::MASTERNODE, "%s: Failed to find expected payee %s in block at height %d (tx %s)",
__func__, payee, pindexPrev->nHeight + 1, txNew.GetHash().ToString());
return false;
}
}
// all the expected payees have been found in txNew outputs
return true;
}

// Legacy payment logic. !TODO: remove when transition to DMN is complete
Expand Down

0 comments on commit 4c731a9

Please sign in to comment.