Skip to content

Commit

Permalink
fix reward formula
Browse files Browse the repository at this point in the history
  • Loading branch information
RosenKrumov committed Apr 25, 2024
1 parent 003c8cd commit 6c75630
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1489,34 +1489,50 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
dgp.fillBlockRewardBlocksInfo();
dgp.fillBlockRewardPercentageInfo();

if (nHeight > 5100) {
while (dgp.blockRewardVoteBlocks.size() == 0) {
dgp.fillBlockRewardBlocksInfo();
dgp.fillBlockRewardPercentageInfo();
int a = 0;
while (a < 5000000)
a++;
}
}

CAmount prevTotalSupplay = consensusParams.initialCoinsSupply * 100;
CAmount blocksPerYear = consensusParams.blocksPerYear * 100;
int lastPercentage = 20; // dgp.blockRewardVotePercentages[0];
int lastHeight = 5001; // dgp.blockRewardVoteBlocks[0];

if (dgp.blockRewardVoteBlocks.size() > 0) {
lastPercentage = dgp.blockRewardVotePercentages[dgp.blockRewardVotePercentages.size() - 1];
lastHeight = dgp.blockRewardVoteBlocks[dgp.blockRewardVoteBlocks.size() - 1];
if (dgp.blockRewardVoteBlocks.size() == 0) {
dgp.blockRewardVoteBlocks.push_back(5001);
dgp.blockRewardVotePercentages.push_back(20);
}

for (int i = 1; i < dgp.blockRewardVotePercentages.size(); i++) {
for (int j = dgp.blockRewardVoteBlocks[i - 1]; i < dgp.blockRewardVoteBlocks[i]; i++) {
prevTotalSupplay += (dgp.blockRewardVotePercentages[i] * prevTotalSupplay) / blocksPerYear;
for (int i = 0; i < dgp.blockRewardVotePercentages.size(); i++) {
int lastHeight = 0;
if (i == dgp.blockRewardVotePercentages.size() - 1) {
lastHeight = nHeight;
} else {
lastHeight = dgp.blockRewardVoteBlocks[i + 1];
}
}

for (int i = lastHeight; i < nHeight; i++) {
if (i >= consensusParams.nRewardFixHeight) {
prevTotalSupplay += (lastPercentage * prevTotalSupplay) / (blocksPerYear * 4);
} else {
prevTotalSupplay += (lastPercentage * prevTotalSupplay) / blocksPerYear;
for (int j = dgp.blockRewardVoteBlocks[i]; j < lastHeight; j++) {
if (j >= consensusParams.nRewardFixHeight) {
prevTotalSupplay += (dgp.blockRewardVotePercentages[i] * prevTotalSupplay) / (blocksPerYear * 4);
} else {
prevTotalSupplay += (dgp.blockRewardVotePercentages[i] * prevTotalSupplay) / blocksPerYear;
}
}
}

if (nHeight >= consensusParams.nRewardOffsetHeight) {
prevTotalSupplay -= consensusParams.nRewardOffsetAmount;
}

int lastPercentage = 0;
for (int i = 0; i < dgp.blockRewardVoteBlocks.size(); i++) {
if (nHeight >= dgp.blockRewardVoteBlocks[i]) lastPercentage = dgp.blockRewardVotePercentages[i];
}

CAmount reward = (lastPercentage * prevTotalSupplay) / blocksPerYear;

return reward / (100 * blocktimeDownscaleFactor);
Expand Down Expand Up @@ -2502,10 +2518,6 @@ bool CheckReward(const CBlock& block, CValidationState& state, int nHeight, cons
error("CheckReward(): coinstake pays too much (actual=%d vs limit=%d)",
nActualStakeReward, blockReward),
REJECT_INVALID, "bad-cs-amount");
uint64_t actualReward = nValueOut - nValueIn;
if (actualReward != subsidy - coinAmountThatSouldBeBurned)
return state.DoS(100, error("CheckReward(): Unknown error caused actual block reward to be different than the expected one"),
REJECT_INVALID, "incorrect-block-reward");

// The first proof-of-stake blocks get full reward, the rest of them are split between recipients
int rewardRecipients = 1;
Expand Down

0 comments on commit 6c75630

Please sign in to comment.