Skip to content

Commit

Permalink
Fix getburninfo consortium and result allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
prasannavl committed Mar 3, 2023
1 parent 40eafe9 commit 86f3db3
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/masternodes/rpc_accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2019,30 +2019,29 @@ UniValue getburninfo(const JSONRPCRequest& request) {
explicit WorkerResultPool(size_t size) {
pool.reserve(size);
for (size_t i = 0; i < size; i++) {
pool.push_back(CGetBurnInfoResult{});
pool.push_back(std::make_shared<CGetBurnInfoResult>());
}
}

std::shared_ptr<CGetBurnInfoResult> Acquire() {
LOCK(syncFlag);
auto res = std::make_shared<CGetBurnInfoResult>(pool.back());
CLockFreeGuard lock{syncFlag};
auto res = pool.back();
pool.pop_back();

return res;
}

void Release(std::shared_ptr<CGetBurnInfoResult> res) {
LOCK(syncFlag);
pool.push_back(*res);
CLockFreeGuard lock{syncFlag};
pool.push_back(res);
}

std::vector<CGetBurnInfoResult> &GetContainer() {
std::vector<std::shared_ptr<CGetBurnInfoResult>> &GetContainer() {
return pool;
}

private:
CCriticalSection syncFlag;
std::vector<CGetBurnInfoResult> pool;
std::atomic_bool syncFlag{};
std::vector<std::shared_ptr<CGetBurnInfoResult>> pool;
};

auto nWorkers = DfTxTaskPool->GetAvailableThreads();
Expand Down Expand Up @@ -2152,15 +2151,17 @@ UniValue getburninfo(const JSONRPCRequest& request) {
g.WaitForCompletion();

for (const auto &r : resultsPool.GetContainer()) {
totalResult->burntDFI += r.burntDFI;
totalResult->burntFee += r.burntFee;
totalResult->auctionFee += r.auctionFee;
totalResult->burntTokens.AddBalances(r.burntTokens.balances);
totalResult->nonConsortiumTokens.AddBalances(r.nonConsortiumTokens.balances);
totalResult->dexfeeburn.AddBalances(r.dexfeeburn.balances);
totalResult->paybackFee.AddBalances(r.paybackFee.balances);
totalResult->burntDFI += r->burntDFI;
totalResult->burntFee += r->burntFee;
totalResult->auctionFee += r->auctionFee;
totalResult->burntTokens.AddBalances(r->burntTokens.balances);
totalResult->nonConsortiumTokens.AddBalances(r->nonConsortiumTokens.balances);
totalResult->dexfeeburn.AddBalances(r->dexfeeburn.balances);
totalResult->paybackFee.AddBalances(r->paybackFee.balances);
}

GetMemoizedResultCache().Set(request, {height, hash, *totalResult});

CDataStructureV0 liveKey = {AttributeTypes::Live, ParamIDs::Economy, EconomyKeys::ConsortiumMinted};
auto balances = attributes->GetValue(liveKey, CConsortiumGlobalMinted{});

Expand Down Expand Up @@ -2194,7 +2195,6 @@ UniValue getburninfo(const JSONRPCRequest& request) {
result.pushKV("dfip2203", AmountsToJSON(dfi2203Tokens.balances));
result.pushKV("dfip2206f", AmountsToJSON(dfiToDUSDTokens.balances));

GetMemoizedResultCache().Set(request, {height, hash, *totalResult});
return GetRPCResultCache()
.Set(request, result);
}
Expand Down

0 comments on commit 86f3db3

Please sign in to comment.