@@ -131,6 +131,7 @@ bool CBudgetDB::Write(const CBudgetManager& budgetToSave)
131
131
132
132
CBudgetDB::ReadResult CBudgetDB::Read (CBudgetManager& budgetToLoad)
133
133
{
134
+
134
135
int64_t nStart = GetTimeMillis ();
135
136
// open input file, and associate with CAutoFile
136
137
FILE *file = fopen (pathDB.string ().c_str (), " rb" );
@@ -245,16 +246,10 @@ void DumpBudgets()
245
246
246
247
void CBudgetManager::AddFinalizedBudget (CFinalizedBudget& prop)
247
248
{
248
- printf (" ! 1\n " );
249
-
250
249
LOCK (cs);
251
250
if (mapFinalizedBudgets.count (prop.GetHash ())) return ;
252
251
253
- printf (" ! 2\n " );
254
-
255
252
mapFinalizedBudgets.insert (make_pair (prop.GetHash (), prop));
256
-
257
- printf (" ! 3\n " );
258
253
}
259
254
260
255
void CBudgetManager::AddProposal (CBudgetProposal& prop)
@@ -267,6 +262,9 @@ void CBudgetManager::AddProposal(CBudgetProposal& prop)
267
262
268
263
void CBudgetManager::CheckAndRemove ()
269
264
{
265
+ return ;
266
+
267
+ // segfault happening in the following code sometimes
270
268
std::map<uint256, CFinalizedBudget>::iterator it = mapFinalizedBudgets.begin ();
271
269
while (it != mapFinalizedBudgets.end ())
272
270
{
@@ -456,7 +454,11 @@ std::vector<CBudgetProposal*> CBudgetManager::GetBudget()
456
454
std::vector<CBudgetProposal*> ret;
457
455
458
456
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);
460
462
461
463
462
464
std::map<uint256, CBudgetProposal>::iterator it2 = mapProposals.begin ();
@@ -528,12 +530,21 @@ std::string CBudgetManager::GetRequiredPaymentsString(int64_t nBlockHeight)
528
530
return ret;
529
531
}
530
532
531
- int64_t CBudgetManager::GetTotalBudget ()
533
+ int64_t CBudgetManager::GetTotalBudget (int nHeight )
532
534
{
533
535
if (chainActive.Tip () == NULL ) return 0 ;
534
536
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 ;
537
548
}
538
549
539
550
void CBudgetManager::NewBlock ()
@@ -781,14 +792,19 @@ CBudgetProposal::CBudgetProposal(const CBudgetProposal& other)
781
792
bool CBudgetProposal::IsValid ()
782
793
{
783
794
CBlockIndex* pindexPrev = chainActive.Tip ();
784
- if (pindexPrev == NULL ) return false ;
795
+ if (pindexPrev == NULL ) return true ;
785
796
786
797
// TODO: if < 20 votes and 2+ weeks old, invalid
787
798
788
799
if (pindexPrev->nHeight < nBlockStart || pindexPrev->nHeight > nBlockEnd) return false ;
789
800
790
801
if (nBlockEnd - nBlockStart <= GetBudgetPaymentCycleBlocks ()) return false ;
791
802
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
+
792
808
return true ;
793
809
}
794
810
@@ -1131,6 +1147,17 @@ void CFinalizedBudget::AutoCheck()
1131
1147
}
1132
1148
}
1133
1149
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
+
1134
1161
std::string CFinalizedBudget::GetProposals () {
1135
1162
std::string ret = " aeu" ;
1136
1163
@@ -1190,6 +1217,9 @@ bool CFinalizedBudget::IsValid()
1190
1217
if (GetBlockEnd () - nBlockStart > 100 ) return false ;
1191
1218
if (vecProposals.size () > 100 ) return false ;
1192
1219
1220
+ // can only pay out 10% of the possible coins (min value of coins)
1221
+ if (GetTotalPayout () > budget.GetTotalBudget (nBlockStart)) return false ;
1222
+
1193
1223
// TODO: if N cycles old, invalid, invalid
1194
1224
1195
1225
return true ;
0 commit comments