Skip to content

Commit

Permalink
Skip setting height for skipStatic if not per-block update happened
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Oct 21, 2024
1 parent 0bfc5ef commit 8bc1a3f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/dfi/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,12 @@ bool CCustomCSView::CalculateOwnerRewards(const CScript &owner, uint32_t targetH
if (balanceHeight >= targetHeight) {
return false;
}

// Calculate per-block rewards up to the fork height
const auto targetPerBlockHeight =
targetHeight >= Params().GetConsensus().DF24Height ? Params().GetConsensus().DF24Height : targetHeight;
bool perBlockUpdated{};

ForEachPoolId([&](DCT_ID const &poolId) {
auto height = GetShare(poolId, owner);
if (!height || *height >= targetHeight) {
Expand All @@ -990,10 +996,8 @@ bool CCustomCSView::CalculateOwnerRewards(const CScript &owner, uint32_t targetH
};

if (beginHeight < Params().GetConsensus().DF24Height) {
// Calculate just up to the fork height
const auto targetNewHeight =
targetHeight >= Params().GetConsensus().DF24Height ? Params().GetConsensus().DF24Height : targetHeight;
CalculatePoolRewards(poolId, onLiquidity, beginHeight, targetNewHeight, onReward);
perBlockUpdated = true;
CalculatePoolRewards(poolId, onLiquidity, beginHeight, targetPerBlockHeight, onReward);
}

if (!skipStatic && targetHeight >= Params().GetConsensus().DF24Height) {
Expand All @@ -1007,7 +1011,14 @@ bool CCustomCSView::CalculateOwnerRewards(const CScript &owner, uint32_t targetH
return true;
});

return UpdateBalancesHeight(owner, targetHeight);
// If no per-block update to occured then do not update the height.
if (skipStatic && !perBlockUpdated) {
return true;
}

const auto updateHeight = skipStatic ? targetPerBlockHeight : targetHeight;

return UpdateBalancesHeight(owner, updateHeight);
}

double CVaultAssets::calcRatio(uint64_t maxRatio) const {
Expand Down

0 comments on commit 8bc1a3f

Please sign in to comment.