From 16455e0796f358b007777a37fd01a736642b890a Mon Sep 17 00:00:00 2001 From: random-zebra Date: Sun, 20 Dec 2020 02:50:40 +0100 Subject: [PATCH] [BUG] Miner not paying valid finalized budget if <20 active masternodes Verifier: (`CheckBlock` --> `IsBlockPayeeValid` --> `IsBudgetPaymentBlock`) expects a payment to a budget even with the case of N<20 active masternodes on the network, provided that all N voted on the finalized budget (the threshold is N-1). Also remove the extra call to `IsBudgetPaymentBlock` directly from `FillBlockPayee` (it is already called by `CBudgetManager::FillBlockPayee` --> `GetPayeeAndAmount`). --- src/budget/budgetmanager.cpp | 13 ++++--------- src/masternode-payments.cpp | 7 +++---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/budget/budgetmanager.cpp b/src/budget/budgetmanager.cpp index d04bb2e29ed7..87228855a354 100644 --- a/src/budget/budgetmanager.cpp +++ b/src/budget/budgetmanager.cpp @@ -401,17 +401,12 @@ int CBudgetManager::GetHighestVoteCount(int chainHeight) const bool CBudgetManager::GetPayeeAndAmount(int chainHeight, CScript& payeeRet, CAmount& nAmountRet) const { - const CFinalizedBudget* pfb = GetBudgetWithHighestVoteCount(chainHeight); - if (!pfb) return false; - - // Check that there are enough votes - int mnCount = mnodeman.CountEnabled(ActiveProtocol()); - int nFivePercent = mnCount / 20; - if ((nFivePercent == 0 && !(Params().IsRegTestNet() && mnCount > 0) ) || - pfb->GetVoteCount() < nFivePercent) + int nCountThreshold; + if (!IsBudgetPaymentBlock(chainHeight, nCountThreshold)) return false; - return pfb->GetPayeeAndAmount(chainHeight, payeeRet, nAmountRet); + const CFinalizedBudget* pfb = GetBudgetWithHighestVoteCount(chainHeight); + return pfb && pfb->GetPayeeAndAmount(chainHeight, payeeRet, nAmountRet) && pfb->GetVoteCount() > nCountThreshold; } bool CBudgetManager::FillBlockPayee(CMutableTransaction& txNew, const int nHeight, bool fProofOfStake) const diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 5c283ece3c80..f084a967615c 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -295,10 +295,9 @@ void FillBlockPayee(CMutableTransaction& txNew, const int nHeight, bool fProofOf { if (nHeight == 0) return; - if (!sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) || // if superblocks are not enabled - !g_budgetman.IsBudgetPaymentBlock(nHeight) || // or this is not a superblock - !g_budgetman.FillBlockPayee(txNew, nHeight, fProofOfStake) ) { // or there's no budget with enough votes - // pay a masternode + if (!sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) || // if superblocks are not enabled + !g_budgetman.FillBlockPayee(txNew, nHeight, fProofOfStake) ) { // or this is not a superblock, + // ... or there's no budget with enough votes, then pay a masternode masternodePayments.FillBlockPayee(txNew, nHeight, fProofOfStake); } }