-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented rollover treasury #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -547,8 +547,48 @@ CAmount CSuperblock::GetPaymentsLimit(int nBlockHeight) | |
// min subsidy for high diff networks and vice versa | ||
int nBits = consensusParams.fPowAllowMinDifficultyBlocks ? UintToArith256(consensusParams.powLimit).GetCompact() : 1; | ||
// some part of all blocks issued during the cycle goes to superblock, see GetBlockSubsidy | ||
CAmount nSuperblockPartOfSubsidy = GetBlockSubsidy(nBits, nBlockHeight - 1, consensusParams, true); | ||
CAmount nPaymentsLimit = nSuperblockPartOfSubsidy * consensusParams.nSuperblockCycle; | ||
LOCK(cs_main); | ||
|
||
CCoinsView *view = (CCoinsView*)pcoinsdbview; | ||
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor()); | ||
|
||
|
||
uint256 prevkey; | ||
std::map<uint32_t, Coin> outputs; | ||
while (pcursor->Valid()) { | ||
boost::this_thread::interruption_point(); | ||
COutPoint key; | ||
Coin coin; | ||
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) { | ||
if (!outputs.empty() && key.hash != prevkey) { | ||
outputs.clear(); | ||
} | ||
prevkey = key.hash; | ||
outputs[key.n] = std::move(coin); | ||
} | ||
else { | ||
return error("%s: unable to read value", __func__); | ||
} | ||
pcursor->Next(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of that was based on another location where the set of outputs is created, likely from the total supply field in the rpc command |
||
|
||
// Current supply | ||
CAmount nCirculatingSupply = 0; | ||
for (const auto output : outputs) { | ||
nCirculatingSupply += output.second.out.nValue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. based on total supply field in the rpc command gettxoutsetinfo |
||
} | ||
|
||
// Theoretical Maximum Supply at given block | ||
CAmount nMaxSupply = 0; | ||
for (auto it = 0; it < nBlockHeight; it++) { | ||
|
||
// Get CBlockIndex pointer based on iterator | ||
CBlockIndex *pblock = chainActive[it]; | ||
|
||
// Add to the Max Supply the subsidy at each block | ||
nMaxSupply += GetCompleteBlockSubsidy(pblock->pprev->nBits, pblock->pprev->nHeight, Params().GetConsensus); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. based on other locations (I think) uses previous blocks since that is how our GetBlockSubsidy methods work |
||
} | ||
CAmount nPaymentsLimit = nMaxSupply - nCirculatingSupply; | ||
LogPrint("gobject", "CSuperblock::GetPaymentsLimit -- Valid superblock height %d, payments max %lld\n", nBlockHeight, nPaymentsLimit); | ||
|
||
return nPaymentsLimit; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,20 +84,20 @@ bool IsBlockValueValid(const CBlock& block, int nBlockHeight, CAmount blockRewar | |
bool isBlockRewardValueMet = (block.vtx[0]->GetValueOut() <= blockReward); | ||
if(fDebug) LogPrintf("block.vtx[0]->GetValueOut() %lld <= blockReward %lld\n", block.vtx[0]->GetValueOut(), blockReward); | ||
|
||
CAmount nSuperblockMaxValue = blockReward + CSuperblock::GetPaymentsLimit(nBlockHeight); | ||
bool isSuperblockMaxValueMet = (block.vtx[0]->GetValueOut() <= nSuperblockMaxValue); | ||
|
||
LogPrint("gobject", "block.vtx[0]->GetValueOut() %lld <= nSuperblockMaxValue %lld\n", block.vtx[0]->GetValueOut(), nSuperblockMaxValue); | ||
|
||
if (!CSuperblock::IsValidBlockHeight(nBlockHeight)) { | ||
// can't possibly be a superblock, so lets just check for block reward limits | ||
if (!isBlockRewardValueMet) { | ||
strErrorRet = strprintf("coinbase pays too much at height %d (actual=%d vs limit=%d), exceeded block reward, only regular blocks are allowed at this height", | ||
nBlockHeight, block.vtx[0]->GetValueOut(), blockReward); | ||
nBlockHeight, block.vtx[0]->GetValueOut(), blockReward); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. auto formatting based on clang file since I initially edited this line and then reverted |
||
} | ||
return isBlockRewardValueMet; | ||
} | ||
|
||
CAmount nSuperblockMaxValue = blockReward + CSuperblock::GetPaymentsLimit(nBlockHeight); | ||
bool isSuperblockMaxValueMet = (block.vtx[0]->GetValueOut() <= nSuperblockMaxValue); | ||
|
||
LogPrint("gobject", "block.vtx[0]->GetValueOut() %lld <= nSuperblockMaxValue %lld\n", block.vtx[0]->GetValueOut(), nSuperblockMaxValue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to increase efficiency since the new superblock limit calculations are more demanding and there is no point in calculating the limit if it is not a superblock |
||
|
||
// bail out in case superblock limits were exceeded | ||
if (!isSuperblockMaxValueMet) { | ||
strErrorRet = strprintf("coinbase pays too much at height %d (actual=%d vs limit=%d), exceeded superblock max value", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1318,49 +1318,61 @@ NOTE: unlike bitcoin we are using PREVIOUS block height here, | |
but current height to avoid confusion. | ||
*/ | ||
CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams, bool fSuperblockPartOnly) | ||
{ | ||
|
||
CAmount nSubsidy = GetCompleteBlockSubsidy(nPrevBits, nPrevHeight, consensusParams); | ||
|
||
// Hard fork to reduce the block reward by 10 extra percent (allowing budget/superblocks) | ||
CAmount nSuperblockPart = (nPrevHeight > consensusParams.nBudgetPaymentsStartBlock) ? nSubsidy / 10 : 0; | ||
|
||
return fSuperblockPartOnly ? nSuperblockPart : nSubsidy - nSuperblockPart; | ||
} | ||
|
||
// Returns the total subsidy, includes the miners, masternodes and treasury | ||
CAmount GetCompleteBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams) | ||
{ | ||
double dDiff; | ||
CAmount nSubsidyBase; | ||
|
||
if (nPrevHeight <= 4500 && Params().NetworkIDString() == CBaseChainParams::MAIN) { | ||
/* a bug which caused diff to not be correctly calculated */ | ||
dDiff = (double)0x0000ffff / (double)(nPrevBits & 0x00ffffff); | ||
} else { | ||
} | ||
else { | ||
dDiff = ConvertBitsToDouble(nPrevBits); | ||
} | ||
|
||
if (nPrevHeight < 5465) { | ||
// Early ages... | ||
// 1111/((x+1)^2) | ||
nSubsidyBase = (1111.0 / (pow((dDiff+1.0),2.0))); | ||
if(nSubsidyBase > 500) nSubsidyBase = 500; | ||
else if(nSubsidyBase < 1) nSubsidyBase = 1; | ||
} else if (nPrevHeight < 17000 || (dDiff <= 75 && nPrevHeight < 24000)) { | ||
nSubsidyBase = (1111.0 / (pow((dDiff + 1.0), 2.0))); | ||
if (nSubsidyBase > 500) nSubsidyBase = 500; | ||
else if (nSubsidyBase < 1) nSubsidyBase = 1; | ||
} | ||
else if (nPrevHeight < 17000 || (dDiff <= 75 && nPrevHeight < 24000)) { | ||
// CPU mining era | ||
// 11111/(((x+51)/6)^2) | ||
nSubsidyBase = (11111.0 / (pow((dDiff+51.0)/6.0,2.0))); | ||
if(nSubsidyBase > 500) nSubsidyBase = 500; | ||
else if(nSubsidyBase < 25) nSubsidyBase = 25; | ||
} else { | ||
nSubsidyBase = (11111.0 / (pow((dDiff + 51.0) / 6.0, 2.0))); | ||
if (nSubsidyBase > 500) nSubsidyBase = 500; | ||
else if (nSubsidyBase < 25) nSubsidyBase = 25; | ||
} | ||
else { | ||
// GPU/ASIC mining era | ||
// 2222222/(((x+2600)/9)^2) | ||
nSubsidyBase = (2222222.0 / (pow((dDiff+2600.0)/9.0,2.0))); | ||
if(nSubsidyBase > 25) nSubsidyBase = 25; | ||
else if(nSubsidyBase < 5) nSubsidyBase = 5; | ||
nSubsidyBase = (2222222.0 / (pow((dDiff + 2600.0) / 9.0, 2.0))); | ||
if (nSubsidyBase > 25) nSubsidyBase = 25; | ||
else if (nSubsidyBase < 5) nSubsidyBase = 5; | ||
} | ||
|
||
// LogPrintf("height %u diff %4.2f reward %d\n", nPrevHeight, dDiff, nSubsidyBase); | ||
CAmount nSubsidy = nSubsidyBase * COIN; | ||
|
||
// yearly decline of production by ~7.1% per year, projected ~18M coins max by year 2050+. | ||
for (int i = consensusParams.nSubsidyHalvingInterval; i <= nPrevHeight; i += consensusParams.nSubsidyHalvingInterval) { | ||
nSubsidy -= nSubsidy/14; | ||
nSubsidy -= nSubsidy / 14; | ||
} | ||
|
||
// Hard fork to reduce the block reward by 10 extra percent (allowing budget/superblocks) | ||
CAmount nSuperblockPart = (nPrevHeight > consensusParams.nBudgetPaymentsStartBlock) ? nSubsidy/10 : 0; | ||
|
||
return fSuperblockPartOnly ? nSuperblockPart : nSubsidy - nSuperblockPart; | ||
return nSubsidy; | ||
} | ||
|
||
CAmount GetMasternodePayment(int nHeight, CAmount blockValue) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry about the formatting changes in this file, again, due to copy/paste auto format was enabled and formatted based on clang file |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the necessity of this. It looked like it was used in another instance similar to this