Skip to content

Commit

Permalink
Skip static reward consolidation
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Oct 21, 2024
1 parent bb0a0bb commit 0bfc5ef
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/dfi/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ bool CCustomCSView::CanSpend(const uint256 &txId, int height) const {
return !pair || pair->second.destructionTx != uint256{} || pair->second.IsPoolShare();
}

bool CCustomCSView::CalculateOwnerRewards(const CScript &owner, uint32_t targetHeight) {
bool CCustomCSView::CalculateOwnerRewards(const CScript &owner, uint32_t targetHeight, bool skipStatic) {
auto balanceHeight = GetBalancesHeight(owner);
if (balanceHeight >= targetHeight) {
return false;
Expand All @@ -996,7 +996,7 @@ bool CCustomCSView::CalculateOwnerRewards(const CScript &owner, uint32_t targetH
CalculatePoolRewards(poolId, onLiquidity, beginHeight, targetNewHeight, onReward);
}

if (targetHeight >= Params().GetConsensus().DF24Height) {
if (!skipStatic && targetHeight >= Params().GetConsensus().DF24Height) {
// Calculate from the fork height
const auto beginNewHeight = beginHeight < Params().GetConsensus().DF24Height
? Params().GetConsensus().DF24Height - 1
Expand Down
2 changes: 1 addition & 1 deletion src/dfi/masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ class CCustomCSView : public CMasternodesView,

bool CanSpend(const uint256 &txId, int height) const;

bool CalculateOwnerRewards(const CScript &owner, uint32_t height);
bool CalculateOwnerRewards(const CScript &owner, uint32_t height, bool skipStatic = false);

ResVal<CAmount> GetAmountInCurrency(CAmount amount,
CTokenCurrencyPair priceFeedId,
Expand Down
5 changes: 3 additions & 2 deletions src/dfi/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,8 @@ void ConsolidateRewards(CCustomCSView &view,
int height,
const std::unordered_set<CScript, CScriptHasher> &owners,
bool interruptOnShutdown,
int numWorkers) {
int numWorkers,
bool skipStatic) {
int nWorkers = numWorkers < 1 ? RewardConsolidationWorkersCount() : numWorkers;
auto rewardsTime = GetTimeMicros();
boost::asio::thread_pool workerPool(nWorkers);
Expand All @@ -1581,7 +1582,7 @@ void ConsolidateRewards(CCustomCSView &view,
return;
}
auto tempView = std::make_unique<CCustomCSView>(view);
tempView->CalculateOwnerRewards(account, height);
tempView->CalculateOwnerRewards(account, height, skipStatic);

boost::asio::post(mergeWorker, [&, tempView = std::move(tempView)]() {
if (interruptOnShutdown && ShutdownRequested()) {
Expand Down
11 changes: 6 additions & 5 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2253,9 +2253,10 @@ bool AppInitMain(InitInterfaces& interfaces)
}

if (gArgs.IsArgSet("-consolidaterewards")) {
if (::ChainActive().Height() >= chainparams.GetConsensus().DF24Height) {
return InitError("Consolidate rewards is not available after static rewards are active.\n");
}
// Due to higher precision reward consolidation after the DF24 fork consolidate rewards
// cannot be used. The following skipStatic flag is used to skip the static consolidation
// and only run the per-block consolidation.
const bool skipStatic = ::ChainActive().Height() >= chainparams.GetConsensus().DF24Height;
const std::vector<std::string> tokenSymbolArgs = gArgs.GetArgs("-consolidaterewards");
auto fullRewardConsolidation = false;
for (const auto &tokenSymbolInput : tokenSymbolArgs) {
Expand All @@ -2276,7 +2277,7 @@ bool AppInitMain(InitInterfaces& interfaces)
}
return true;
});
ConsolidateRewards(*pcustomcsview, ::ChainActive().Height(), ownersToConsolidate, true);
ConsolidateRewards(*pcustomcsview, ::ChainActive().Height(), ownersToConsolidate, true, skipStatic);
} else {
//one set for all tokens, ConsolidateRewards runs on the address, so no need to run multiple times for multiple token inputs
std::unordered_set<CScript, CScriptHasher> ownersToConsolidate;
Expand All @@ -2296,7 +2297,7 @@ bool AppInitMain(InitInterfaces& interfaces)
return true;
});
}
ConsolidateRewards(*pcustomcsview, ::ChainActive().Height(), ownersToConsolidate, true);
ConsolidateRewards(*pcustomcsview, ::ChainActive().Height(), ownersToConsolidate, true, skipStatic);
}
pcustomcsview->Flush();
pcustomcsDB->Flush();
Expand Down
3 changes: 2 additions & 1 deletion src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,8 @@ void ConsolidateRewards(CCustomCSView &view,
int height,
const std::unordered_set<CScript, CScriptHasher> &owners,
bool interruptOnShutdown,
int numWorkers = 0);
int numWorkers = 0,
bool skipStatic = false);

extern std::map<CScript, CBalances> mapBurnAmounts;

Expand Down

0 comments on commit 0bfc5ef

Please sign in to comment.