diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index 502967c4807b0..f632beec9d1f7 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -793,23 +793,19 @@ std::vector CBudgetManager::GetBudget() int nBlockStart = pindexPrev->nHeight - pindexPrev->nHeight % Params().GetBudgetCycleBlocks() + Params().GetBudgetCycleBlocks(); int nBlockEnd = nBlockStart + Params().GetBudgetCycleBlocks() - 1; + int mnCount = mnodeman.CountEnabled(ActiveProtocol()); CAmount nTotalBudget = GetTotalBudget(nBlockStart); - std::vector >::iterator it2 = vBudgetPorposalsSort.begin(); while (it2 != vBudgetPorposalsSort.end()) { CBudgetProposal* pbudgetProposal = (*it2).first; LogPrint("mnbudget","CBudgetManager::GetBudget() - Processing Budget %s\n", pbudgetProposal->strProposalName.c_str()); //prop start/end should be inside this period - if (pbudgetProposal->fValid && pbudgetProposal->nBlockStart <= nBlockStart && - pbudgetProposal->nBlockEnd >= nBlockEnd && - pbudgetProposal->GetYeas() - pbudgetProposal->GetNays() > mnodeman.CountEnabled(ActiveProtocol()) / 10 && - pbudgetProposal->IsEstablished()) { - + if (pbudgetProposal->IsPassing(pindexPrev, nBlockStart, nBlockEnd, mnCount)) { LogPrint("mnbudget","CBudgetManager::GetBudget() - Check 1 passed: valid=%d | %ld <= %ld | %ld >= %ld | Yeas=%d Nays=%d Count=%d | established=%d\n", pbudgetProposal->fValid, pbudgetProposal->nBlockStart, nBlockStart, pbudgetProposal->nBlockEnd, - nBlockEnd, pbudgetProposal->GetYeas(), pbudgetProposal->GetNays(), mnodeman.CountEnabled(ActiveProtocol()) / 10, + nBlockEnd, pbudgetProposal->GetYeas(), pbudgetProposal->GetNays(), mnCount / 10, pbudgetProposal->IsEstablished()); if (pbudgetProposal->GetAmount() + nBudgetAllocated <= nTotalBudget) { @@ -1558,6 +1554,29 @@ bool CBudgetProposal::IsEstablished() return nTime < GetAdjustedTime() - Params().GetProposalEstablishmentTime(); } +bool CBudgetProposal::IsPassing(const CBlockIndex* pindexPrev, int nBlockStartBudget, int nBlockEndBudget, int mnCount) +{ + if (!fValid) + return false; + + if (!pindexPrev) + return false; + + if (this->nBlockStart > nBlockStartBudget) + return false; + + if (this->nBlockEnd < nBlockEndBudget) + return false; + + if (GetYeas() - GetNays() <= mnCount / 10) + return false; + + if (!IsEstablished()) + return false; + + return true; +} + bool CBudgetProposal::AddOrUpdateVote(CBudgetVote& vote, std::string& strError) { std::string strAction = "New vote inserted:"; diff --git a/src/masternode-budget.h b/src/masternode-budget.h index a762c809b55ef..0a8b592e73636 100644 --- a/src/masternode-budget.h +++ b/src/masternode-budget.h @@ -493,6 +493,7 @@ class CBudgetProposal bool IsValid(std::string& strError, bool fCheckCollateral = true); bool IsEstablished(); + bool IsPassing(const CBlockIndex* pindexPrev, int nBlockStartBudget, int nBlockEndBudget, int mnCount); std::string GetName() { return strProposalName; } std::string GetURL() { return strURL; }