Skip to content

Commit

Permalink
Consensus: enforce that proposal BlockStart must be a superblock
Browse files Browse the repository at this point in the history
Github-Pull: #2101
Rebased-From: 2b53142
  • Loading branch information
random-zebra authored and Fuzzbawls committed Dec 27, 2020
1 parent 5fb488a commit 723a41b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/budget/budgetproposal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "masternodeman.h"

CBudgetProposal::CBudgetProposal():
nAlloted(0),
fValid(true),
strInvalid(""),
strProposalName("unknown"),
Expand All @@ -27,6 +28,7 @@ CBudgetProposal::CBudgetProposal(const std::string& name,
const CAmount& amount,
int blockstart,
const uint256& nfeetxhash):
nAlloted(0),
fValid(true),
strInvalid(""),
strProposalName(name),
Expand All @@ -38,14 +40,10 @@ CBudgetProposal::CBudgetProposal(const std::string& name,
nTime(0)
{
const int nBlocksPerCycle = Params().GetConsensus().nBudgetCycleBlocks;
// !todo: remove this when v5 rules are enforced (nBlockStart is always = to nCycleStart)
int nCycleStart = nBlockStart - nBlockStart % nBlocksPerCycle;

// Right now single payment proposals have nBlockEnd have a cycle too early!
// switch back if it break something else
// calculate the end of the cycle for this vote, add half a cycle (vote will be deleted after that block)
// nBlockEnd = nCycleStart + GetBudgetPaymentCycleBlocks() * nPaymentCount + GetBudgetPaymentCycleBlocks() / 2;

// Calculate the end of the cycle for this vote, vote will be deleted after next cycle
// calculate the expiration block
nBlockEnd = nCycleStart + (nBlocksPerCycle + 1) * paycount;
}

Expand Down Expand Up @@ -90,8 +88,13 @@ bool CBudgetProposal::IsHeavilyDownvoted(bool fNewRules)

bool CBudgetProposal::CheckStartEnd()
{
if (nBlockStart < 0) {
strInvalid = "Invalid Proposal";
// !TODO: remove (and always use new rules) when all proposals submitted before v5 enforcement are expired.
bool fNewRules = Params().GetConsensus().NetworkUpgradeActive(nBlockStart, Consensus::UPGRADE_V5_0);

if (nBlockStart < 0 ||
// block start must be a superblock
(fNewRules && (nBlockStart % Params().GetConsensus().nBudgetCycleBlocks) != 0)) {
strInvalid = "Invalid nBlockStart";
return false;
}

Expand All @@ -100,8 +103,6 @@ bool CBudgetProposal::CheckStartEnd()
return false;
}

// !TODO: remove (and alwyas use new rules) when all proposals submitted before v5 enforcement are expired.
bool fNewRules = Params().GetConsensus().NetworkUpgradeActive(nBlockStart, Consensus::UPGRADE_V5_0);
if (fNewRules && GetTotalPaymentCount() > Params().GetConsensus().nMaxProposalPayments) {
strInvalid = "Invalid payment count";
return false;
Expand Down

0 comments on commit 723a41b

Please sign in to comment.