From 86f3db32dc53cc19670e92a3fcdac202fd2e00e5 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Sat, 4 Mar 2023 00:40:34 +0800 Subject: [PATCH] Fix getburninfo consortium and result allocations --- src/masternodes/rpc_accounts.cpp | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/masternodes/rpc_accounts.cpp b/src/masternodes/rpc_accounts.cpp index 5a483291c8..578c59621f 100644 --- a/src/masternodes/rpc_accounts.cpp +++ b/src/masternodes/rpc_accounts.cpp @@ -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()); } } std::shared_ptr Acquire() { - LOCK(syncFlag); - auto res = std::make_shared(pool.back()); + CLockFreeGuard lock{syncFlag}; + auto res = pool.back(); pool.pop_back(); - return res; } void Release(std::shared_ptr res) { - LOCK(syncFlag); - pool.push_back(*res); + CLockFreeGuard lock{syncFlag}; + pool.push_back(res); } - std::vector &GetContainer() { + std::vector> &GetContainer() { return pool; } private: - CCriticalSection syncFlag; - std::vector pool; + std::atomic_bool syncFlag{}; + std::vector> pool; }; auto nWorkers = DfTxTaskPool->GetAvailableThreads(); @@ -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{}); @@ -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); }