Skip to content

Commit

Permalink
Fix skipping of static rewards (#3110)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar authored Nov 5, 2024
1 parent bd0177d commit 2af7598
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
26 changes: 10 additions & 16 deletions src/dfi/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1563,15 +1563,16 @@ void ConsolidateRewards(CCustomCSView &view,
int height,
const std::unordered_set<CScript, CScriptHasher> &owners,
bool interruptOnShutdown,
int numWorkers,
bool skipStatic) {
int nWorkers = numWorkers < 1 ? RewardConsolidationWorkersCount() : numWorkers;
const auto nWorkers = RewardConsolidationWorkersCount();
auto rewardsTime = GetTimeMicros();
boost::asio::thread_pool workerPool(nWorkers);
boost::asio::thread_pool mergeWorker(1);
std::atomic<uint64_t> tasksCompleted{0};
std::atomic<uint64_t> reportedTs{0};

LogPrintf("%s: address count: %d concurrency: %d\n", __func__, owners.size(), nWorkers);

for (auto &owner : owners) {
// See https://github.com/DeFiCh/ain/pull/1291
// https://github.com/DeFiCh/ain/pull/1291#issuecomment-1137638060
Expand Down Expand Up @@ -1778,12 +1779,10 @@ static Res PoolSplits(CCustomCSView &view,
for (auto &[owner, _] : balancesToMigrate) {
ownersToConsolidate.emplace(owner);
}
auto nWorkers = RewardConsolidationWorkersCount();
LogPrintf("Pool migration: Consolidating rewards (count: %d, total: %d, concurrency: %d)..\n",
LogPrintf("Pool migration: Consolidating rewards (count: %d, total: %d)..\n",
ownersToConsolidate.size(),
totalAccounts,
nWorkers);
ConsolidateRewards(view, pindex->nHeight, ownersToConsolidate, false, nWorkers);
totalAccounts);
ConsolidateRewards(view, pindex->nHeight, ownersToConsolidate, false);
}

// Special case. No liquidity providers in a previously used pool.
Expand Down Expand Up @@ -3383,11 +3382,8 @@ static Res ForceCloseAllLoans(const CBlockIndex *pindex, CCustomCSView &cache, B
return true;
});

auto nWorkers = RewardConsolidationWorkersCount();
LogPrintf("Token Lock: Consolidating rewards before payback. total: %d, concurrency: %d..\n",
ownersToMigrate.size(),
nWorkers);
ConsolidateRewards(cache, pindex->nHeight, ownersToMigrate, false, nWorkers);
LogPrintf("Token Lock: Consolidating rewards before payback. total: %d\n", ownersToMigrate.size());
ConsolidateRewards(cache, pindex->nHeight, ownersToMigrate, false);

LogPrintf("paying back %d loans with owner balance\n", directPaybacks.size());
uint64_t reportedTs = 0;
Expand Down Expand Up @@ -3672,10 +3668,8 @@ static Res ConvertAllLoanTokenForTokenLock(const CBlock &block,
}
return true;
});
auto nWorkers = RewardConsolidationWorkersCount();
LogPrintf(
"Token Lock: Consolidating rewards. total: %d, concurrency: %d..\n", poolOwnersToMigrate.size(), nWorkers);
ConsolidateRewards(cache, pindex->nHeight, poolOwnersToMigrate, false, nWorkers);
LogPrintf("Token Lock: Consolidating rewards. total: %d\n", poolOwnersToMigrate.size());
ConsolidateRewards(cache, pindex->nHeight, poolOwnersToMigrate, false);

// Execute Splits on tokens (without pools)
bool splitSuccess = true;
Expand Down
9 changes: 3 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2254,10 +2254,6 @@ bool AppInitMain(InitInterfaces& interfaces)
}

if (gArgs.IsArgSet("-consolidaterewards")) {
// 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 @@ -2283,7 +2279,7 @@ bool AppInitMain(InitInterfaces& interfaces)
}
return true;
});
ConsolidateRewards(*pcustomcsview, ::ChainActive().Height(), ownersToConsolidate, true, skipStatic);
ConsolidateRewards(*pcustomcsview, ::ChainActive().Height(), ownersToConsolidate, true, true);
} 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 @@ -2303,9 +2299,10 @@ bool AppInitMain(InitInterfaces& interfaces)
return true;
});
}
ConsolidateRewards(*pcustomcsview, ::ChainActive().Height(), ownersToConsolidate, true, skipStatic);
ConsolidateRewards(*pcustomcsview, ::ChainActive().Height(), ownersToConsolidate, true, true);
}
pcustomcsview->Flush();
pcustomcsDB->Flush();

{
auto [hashHex, hashHexNoUndo] = GetDVMDBHashes(*pcustomcsview);
Expand Down
1 change: 0 additions & 1 deletion src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,6 @@ void ConsolidateRewards(CCustomCSView &view,
int height,
const std::unordered_set<CScript, CScriptHasher> &owners,
bool interruptOnShutdown,
int numWorkers = 0,
bool skipStatic = false);

extern std::map<CScript, CBalances> mapBurnAmounts;
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_consolidate_rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def pre_fork24_consolidate(self):
self.stop_node(1)

# Start node with consolidation
self.args.append(f"-consolidaterewards={self.symbolGD}")
self.args.append(f"-consolidaterewards={self.symbolGOOGL}")
self.start_node(1, self.args)
connect_nodes_bi(self.nodes, 0, 1)

Expand Down Expand Up @@ -208,7 +208,7 @@ def post_fork24_consolidate(self):
self.stop_node(1)

# Start node with consolidation
self.args.append(f"-consolidaterewards={self.symbolGD}")
self.args.append(f"-consolidaterewards={self.symbolGOOGL}")
self.start_node(1, self.args)
connect_nodes_bi(self.nodes, 0, 1)

Expand Down

0 comments on commit 2af7598

Please sign in to comment.