refactor: change flag fSuperblockPartOnly to a new function GetSuperblockSubsidyInner

This commit is contained in:
Konstantin Akimov 2023-10-16 20:59:57 +07:00 committed by PastaPastaPasta
parent 85287cfeaf
commit 6007180dbe
3 changed files with 17 additions and 4 deletions

View File

@ -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);

View File

@ -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;
@ -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)

View File

@ -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);