Skip to content

Commit

Permalink
refactor: change flag fSuperblockPartOnly to a new function GetSuperb…
Browse files Browse the repository at this point in the history
…lockSubsidyInner
  • Loading branch information
knst committed Oct 16, 2023
1 parent 8937ca3 commit 4e5aa70
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/governance/classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ 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 = GetBlockSubsidyInner(nBits, nBlockHeight - 1, consensusParams, fMNRewardReallocated,true);
CAmount nSuperblockPartOfSubsidy = GetSuperblockSubsidyInner(nBits, nBlockHeight - 1, consensusParams, fMNRewardReallocated);
CAmount nPaymentsLimit = nSuperblockPartOfSubsidy * consensusParams.nSuperblockCycle;
LogPrint(BCLog::GOBJECT, "CSuperblock::GetPaymentsLimit -- Valid superblock height %d, payments max %lld\n", nBlockHeight, nPaymentsLimit);

Expand Down
16 changes: 14 additions & 2 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ NOTE: unlike bitcoin we are using PREVIOUS block height here,
might be a good idea to change this to use prev bits
but current height to avoid confusion.
*/
CAmount GetBlockSubsidyInner(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams, bool fMNRewardReallocated, bool fSuperblockPartOnly)
static std::pair<CAmount, CAmount> GetBlockSubsidyHelper(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams, bool fMNRewardReallocated)
{
double dDiff;
CAmount nSubsidyBase;
Expand Down Expand Up @@ -1171,7 +1171,19 @@ CAmount GetBlockSubsidyInner(int nPrevBits, int nPrevHeight, const Consensus::Pa
if (Params().NetworkIDString() == CBaseChainParams::TESTNET) fMNRewardReallocated = false;
nSuperblockPart = nSubsidy / (fMNRewardReallocated ? 5 : 10);
}
return fSuperblockPartOnly ? nSuperblockPart : nSubsidy - nSuperblockPart;
return {nSubsidy - nSuperblockPart, nSuperblockPart};
}

CAmount GetSuperblockSubsidyInner(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams, bool fMNRewardReallocated)
{
const auto [nSubsidy, nSuperblock] = GetBlockSubsidyHelper(nPrevBits, nPrevHeight, consensusParams, fMNRewardReallocated);
return nSuperblock;
}

CAmount GetBlockSubsidyInner(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams, bool fMNRewardReallocated)
{
const auto [nSubsidy, nSuperblock] = GetBlockSubsidyHelper(nPrevBits, nPrevHeight, consensusParams, fMNRewardReallocated);
return nSubsidy;
}

CAmount GetBlockSubsidy(const CBlockIndex* const pindex, const Consensus::Params& consensusParams)
Expand Down
3 changes: 2 additions & 1 deletion src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ double ConvertBitsToDouble(unsigned int nBits);
* When pindex points to a genesis block GetBlockSubsidy() returns a pre-calculated value.
* For other blocks it calls GetBlockSubsidyInner() using nBits and nHeight of a pindex->pprev block.
*/
CAmount GetBlockSubsidyInner(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams, bool fMNRewardReallocated, bool fSuperblockPartOnly = false);
CAmount GetBlockSubsidyInner(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams, bool fMNRewardReallocated);
CAmount GetSuperblockSubsidyInner(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams, bool fMNRewardReallocated);
CAmount GetBlockSubsidy(const CBlockIndex* const pindex, const Consensus::Params& consensusParams);
/** fMNRewardReallocated refers to Masternode Reward Location Reallocation activation. */
CAmount GetMasternodePayment(int nHeight, CAmount blockValue, bool fMNRewardReallocated);
Expand Down

0 comments on commit 4e5aa70

Please sign in to comment.