Skip to content

Commit 928f6ed

Browse files
author
Evan Duffield
committed
Adjusted max payment per finalized budget to 10% of the monthly block reward
1 parent a4b6b7d commit 928f6ed

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@ bool AppInit2(boost::thread_group& threadGroup)
14201420

14211421
CBudgetDB budgetdb;
14221422
CBudgetDB::ReadResult readResult2 = budgetdb.Read(budget);
1423+
14231424
if (readResult2 == CBudgetDB::FileError)
14241425
LogPrintf("Missing budget cache - budget.dat, will try to recreate\n");
14251426
else if (readResult2 != CBudgetDB::Ok)

src/masternode-budget.cpp

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ bool CBudgetDB::Write(const CBudgetManager& budgetToSave)
131131

132132
CBudgetDB::ReadResult CBudgetDB::Read(CBudgetManager& budgetToLoad)
133133
{
134+
134135
int64_t nStart = GetTimeMillis();
135136
// open input file, and associate with CAutoFile
136137
FILE *file = fopen(pathDB.string().c_str(), "rb");
@@ -245,16 +246,10 @@ void DumpBudgets()
245246

246247
void CBudgetManager::AddFinalizedBudget(CFinalizedBudget& prop)
247248
{
248-
printf("! 1\n");
249-
250249
LOCK(cs);
251250
if(mapFinalizedBudgets.count(prop.GetHash())) return;
252251

253-
printf("! 2\n");
254-
255252
mapFinalizedBudgets.insert(make_pair(prop.GetHash(), prop));
256-
257-
printf("! 3\n");
258253
}
259254

260255
void CBudgetManager::AddProposal(CBudgetProposal& prop)
@@ -267,6 +262,9 @@ void CBudgetManager::AddProposal(CBudgetProposal& prop)
267262

268263
void CBudgetManager::CheckAndRemove()
269264
{
265+
return;
266+
267+
//segfault happening in the following code sometimes
270268
std::map<uint256, CFinalizedBudget>::iterator it = mapFinalizedBudgets.begin();
271269
while(it != mapFinalizedBudgets.end())
272270
{
@@ -456,7 +454,11 @@ std::vector<CBudgetProposal*> CBudgetManager::GetBudget()
456454
std::vector<CBudgetProposal*> ret;
457455

458456
int64_t nBudgetAllocated = 0;
459-
int64_t nTotalBudget = GetTotalBudget();
457+
CBlockIndex* pindexPrev = chainActive.Tip();
458+
if(pindexPrev == NULL) return ret;
459+
460+
int nBlockStart = pindexPrev->nHeight-(pindexPrev->nHeight % GetBudgetPaymentCycleBlocks())+GetBudgetPaymentCycleBlocks();
461+
int64_t nTotalBudget = GetTotalBudget(nBlockStart);
460462

461463

462464
std::map<uint256, CBudgetProposal>::iterator it2 = mapProposals.begin();
@@ -528,12 +530,21 @@ std::string CBudgetManager::GetRequiredPaymentsString(int64_t nBlockHeight)
528530
return ret;
529531
}
530532

531-
int64_t CBudgetManager::GetTotalBudget()
533+
int64_t CBudgetManager::GetTotalBudget(int nHeight)
532534
{
533535
if(chainActive.Tip() == NULL) return 0;
534536

535-
const CBlockIndex* pindex = chainActive.Tip();
536-
return (GetBlockValue(pindex->pprev->nBits, pindex->pprev->nHeight, 0)/100)*15;
537+
//get min block value and calculate from that
538+
int64_t nSubsidy = 5 * COIN;
539+
540+
if(Params().NetworkID() == CBaseChainParams::TESTNET){
541+
for(int i = 46200; i <= nHeight; i += 210240) nSubsidy -= nSubsidy/14;
542+
} else {
543+
// yearly decline of production by 7.1% per year, projected 21.3M coins max by year 2050.
544+
for(int i = 210240; i <= nHeight; i += 210240) nSubsidy -= nSubsidy/14;
545+
}
546+
547+
return ((nSubsidy/100)*10)*576*30;
537548
}
538549

539550
void CBudgetManager::NewBlock()
@@ -781,14 +792,19 @@ CBudgetProposal::CBudgetProposal(const CBudgetProposal& other)
781792
bool CBudgetProposal::IsValid()
782793
{
783794
CBlockIndex* pindexPrev = chainActive.Tip();
784-
if(pindexPrev == NULL) return false;
795+
if(pindexPrev == NULL) return true;
785796

786797
//TODO: if < 20 votes and 2+ weeks old, invalid
787798

788799
if(pindexPrev->nHeight < nBlockStart || pindexPrev->nHeight > nBlockEnd) return false;
789800

790801
if(nBlockEnd - nBlockStart <= GetBudgetPaymentCycleBlocks()) return false;
791802

803+
//can only pay out 10% of the possible coins (min value of coins)
804+
if(nAmount > budget.GetTotalBudget(nBlockStart)) {
805+
return false;
806+
}
807+
792808
return true;
793809
}
794810

@@ -1131,6 +1147,17 @@ void CFinalizedBudget::AutoCheck()
11311147
}
11321148
}
11331149

1150+
int64_t CFinalizedBudget::GetTotalPayout()
1151+
{
1152+
int64_t ret = 0;
1153+
1154+
for(unsigned int i = 0; i < vecProposals.size(); i++){
1155+
ret += vecProposals[i].nAmount;
1156+
}
1157+
1158+
return ret;
1159+
}
1160+
11341161
std::string CFinalizedBudget::GetProposals() {
11351162
std::string ret = "aeu";
11361163

@@ -1190,6 +1217,9 @@ bool CFinalizedBudget::IsValid()
11901217
if(GetBlockEnd() - nBlockStart > 100) return false;
11911218
if(vecProposals.size() > 100) return false;
11921219

1220+
//can only pay out 10% of the possible coins (min value of coins)
1221+
if(GetTotalPayout() > budget.GetTotalBudget(nBlockStart)) return false;
1222+
11931223
//TODO: if N cycles old, invalid, invalid
11941224

11951225
return true;

src/masternode-budget.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class CBudgetManager
9999

100100
void CleanUp();
101101

102-
int64_t GetTotalBudget();
102+
int64_t GetTotalBudget(int nHeight);
103103
std::vector<CBudgetProposal*> GetBudget();
104104
std::vector<CFinalizedBudget*> GetFinalizedBudgets();
105105
bool IsBudgetPaymentBlock(int nBlockHeight);
@@ -218,6 +218,8 @@ class CFinalizedBudget
218218

219219
//check to see if we should vote on this
220220
void AutoCheck();
221+
//total dash paid out by this budget
222+
int64_t GetTotalPayout();
221223
//vote on this finalized budget as a masternode
222224
void SubmitVote();
223225

0 commit comments

Comments
 (0)