From 4d931e389fc0e6c4b9dcc862dedf24ba9f85502f Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 23 Feb 2023 13:55:06 +0800 Subject: [PATCH 1/9] Reverts of Require in Sub/Add Balances --- src/masternodes/balances.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/masternodes/balances.h b/src/masternodes/balances.h index d369d092d2..5fda30ed89 100644 --- a/src/masternodes/balances.h +++ b/src/masternodes/balances.h @@ -57,9 +57,11 @@ struct CBalances { } Res SubBalances(const TAmounts &other) { - for (const auto &[tokenId, amount] : other) - Require(Sub(CTokenAmount{tokenId, amount})); - + for (const auto &[tokenId, amount] : other) { + if (auto res = Sub(CTokenAmount{tokenId, amount}); !res) { + return res; + } + } return Res::Ok(); } @@ -75,9 +77,11 @@ struct CBalances { } Res AddBalances(const TAmounts &other) { - for (const auto &[tokenId, amount] : other) - Require(Add(CTokenAmount{tokenId, amount})); - + for (const auto &[tokenId, amount] : other) { + if (auto res = Add(CTokenAmount{tokenId, amount}); !res) { + return res; + } + } return Res::Ok(); } From 6849d6e35c8371832a81cb7ab27d87a9c00845e7 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 23 Feb 2023 13:58:46 +0800 Subject: [PATCH 2/9] Revert ifs on Add/Sub --- src/masternodes/balances.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/masternodes/balances.h b/src/masternodes/balances.h index 5fda30ed89..49b1c0c0a2 100644 --- a/src/masternodes/balances.h +++ b/src/masternodes/balances.h @@ -18,7 +18,9 @@ struct CBalances { return Res::Ok(); } auto current = CTokenAmount{amount.nTokenId, balances[amount.nTokenId]}; - Require(current.Add(amount.nValue)); + if (auto res = current.Add(amount.nValue); !res) { + return res; + } if (current.nValue == 0) { balances.erase(amount.nTokenId); } else { @@ -32,7 +34,9 @@ struct CBalances { return Res::Ok(); } auto current = CTokenAmount{amount.nTokenId, balances[amount.nTokenId]}; - Require(current.Sub(amount.nValue)); + if (auto res = current.Sub(amount.nValue); !res) { + return res; + } if (current.nValue == 0) { balances.erase(amount.nTokenId); From 7a0bf14e182675fdd962cfb35b9fcee083ca9e6a Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 23 Feb 2023 15:02:14 +0800 Subject: [PATCH 3/9] Fix burninfo concurrency and switch to worker number agnostic queuing --- src/masternodes/rpc_accounts.cpp | 232 +++++++++++++++++++++++++++++-- src/masternodes/threadpool.h | 2 +- 2 files changed, 223 insertions(+), 11 deletions(-) diff --git a/src/masternodes/rpc_accounts.cpp b/src/masternodes/rpc_accounts.cpp index 459b8c31ee..f28fba99ba 100644 --- a/src/masternodes/rpc_accounts.cpp +++ b/src/masternodes/rpc_accounts.cpp @@ -2028,27 +2028,34 @@ UniValue getburninfo(const JSONRPCRequest& request) { } } - const auto nWorkers = DfTxTaskPool->GetAvailableThreads(); + auto nWorkers = DfTxTaskPool->GetAvailableThreads(); + if (height < nWorkers) { + nWorkers = height; + } + const auto chunks = height / nWorkers; const auto chunksRemainder = height % nWorkers; + auto processedHeight = 0; + auto i = 0; + TaskGroup g; std::vector> workerResults; - for (size_t i{}; i < nWorkers; ++i) { - uint32_t startHeight = (i + 1) * chunks; - uint32_t stopHeight = startHeight - chunks; - - if (i + 1 == nWorkers) { - startHeight += chunksRemainder; - stopHeight -= chunksRemainder; - } + auto &pool = DfTxTaskPool->pool; + for (auto i = 0; i <= chunks; i++) { auto result = std::make_shared(); workerResults.push_back(result); + } + + while (processedHeight < height) + { + auto startHeight = (chunks * (i + 1)); + auto stopHeight = (chunks * (i)); + auto result = workerResults[i]; g.AddTask(); - auto &pool = DfTxTaskPool->pool; boost::asio::post(pool, [result, startHeight, stopHeight, &g] { pburnHistoryDB->ForEachAccountHistory([result, stopHeight](const AccountHistoryKey &key, const AccountHistoryValue &value) { @@ -2122,6 +2129,10 @@ UniValue getburninfo(const JSONRPCRequest& request) { }, {}, startHeight, std::numeric_limits::max()); g.RemoveTask(); }); + + // perfect accuracy: processedHeight += (startHeight > height) ? chunksRemainder : chunks; + processedHeight += chunks; + i++; } g.WaitForCompletion(); @@ -2173,6 +2184,206 @@ UniValue getburninfo(const JSONRPCRequest& request) { .Set(request, result); } +UniValue getburninfo2(const JSONRPCRequest& request) { + RPCHelpMan{"getburninfo2", + "\nReturns burn address and burnt coin and token information.\n" + "Requires full acindex for correct amount, tokens and feeburn values.\n", + { + }, + RPCResult{ + "{\n" + " \"address\" : \"address\", (string) The defi burn address\n" + " \"amount\" : n.nnnnnnnn, (string) The amount of DFI burnt\n" + " \"tokens\" : [\n" + " { (array of burnt tokens)" + " \"name\" : \"name\"\n" + " \"amount\" : n.nnnnnnnn\n" + " ]\n" + " \"feeburn\" : n.nnnnnnnn, (string) The amount of fees burnt\n" + " \"emissionburn\" : n.nnnnnnnn, (string) The amount of non-utxo coinbase rewards burnt\n" + "}\n" + }, + RPCExamples{ + HelpExampleCli("getburninfo", "") + + HelpExampleRpc("getburninfo", "") + }, + }.Check(request); + + if (auto res = GetRPCResultCache().TryGet(request)) return *res; + + CAmount burntDFI{0}; + CAmount burntFee{0}; + CAmount auctionFee{0}; + CAmount dfiPaybackFee{0}; + CAmount burnt{0}; + + CBalances burntTokens; + CBalances consortiumTokens; + CBalances nonConsortiumTokens; + CBalances dexfeeburn; + CBalances paybackfees; + CBalances paybackFee; + CBalances paybacktokens; + CBalances dfi2203Tokens; + CBalances dfipaybacktokens; + CBalances dfiToDUSDTokens; + + LOCK(cs_main); + + auto height = ::ChainActive().Height(); + auto fortCanningHeight = Params().GetConsensus().FortCanningHeight; + auto burnAddress = Params().GetConsensus().burnAddress; + auto view = *pcustomcsview; + auto attributes = view.GetAttributes(); + + if (attributes) { + CDataStructureV0 liveKey{AttributeTypes::Live, ParamIDs::Economy, EconomyKeys::PaybackDFITokens}; + auto tokenBalances = attributes->GetValue(liveKey, CBalances{}); + for (const auto& balance : tokenBalances.balances) { + if (balance.first == DCT_ID{0}) { + dfiPaybackFee = balance.second; + } else { + dfipaybacktokens.Add({balance.first, balance.second}); + } + } + liveKey = {AttributeTypes::Live, ParamIDs::Economy, EconomyKeys::PaybackTokens}; + auto paybacks = attributes->GetValue(liveKey, CTokenPayback{}); + paybackfees = std::move(paybacks.tokensFee); + paybacktokens = std::move(paybacks.tokensPayback); + + liveKey = {AttributeTypes::Live, ParamIDs::Economy, EconomyKeys::DFIP2203Burned}; + dfi2203Tokens = attributes->GetValue(liveKey, CBalances{}); + + liveKey = {AttributeTypes::Live, ParamIDs::Economy, EconomyKeys::DFIP2206FBurned}; + dfiToDUSDTokens = attributes->GetValue(liveKey, CBalances{}); + } + + for (const auto& kv : Params().GetConsensus().newNonUTXOSubsidies) { + if (kv.first == CommunityAccountType::Unallocated || + kv.first == CommunityAccountType::IncentiveFunding || + (height >= fortCanningHeight && kv.first == CommunityAccountType::Loan)) { + burnt += view.GetCommunityBalance(kv.first); + } + } + + std::vector> workerResults; + auto result = std::make_shared(); + workerResults.push_back(result); + + pburnHistoryDB->ForEachAccountHistory([result](const AccountHistoryKey &key, const AccountHistoryValue &value) { + // UTXO burn + if (value.category == uint8_t(CustomTxType::None)) { + for (auto const & diff : value.diff) { + result->burntDFI += diff.second; + } + return true; + } + + // Fee burn + if (value.category == uint8_t(CustomTxType::CreateMasternode) + || value.category == uint8_t(CustomTxType::CreateToken) + || value.category == uint8_t(CustomTxType::Vault) + || value.category == uint8_t(CustomTxType::CreateCfp) + || value.category == uint8_t(CustomTxType::CreateVoc)) { + for (auto const & diff : value.diff) { + result->burntFee += diff.second; + } + return true; + } + + // withdraw burn + if (value.category == uint8_t(CustomTxType::PaybackLoan) + || value.category == uint8_t(CustomTxType::PaybackLoanV2) + || value.category == uint8_t(CustomTxType::PaybackWithCollateral)) { + for (const auto& [id, amount] : value.diff) { + result->paybackFee.Add({id, amount}); + } + return true; + } + + // auction burn + if (value.category == uint8_t(CustomTxType::AuctionBid)) { + for (auto const & diff : value.diff) { + result->auctionFee += diff.second; + } + return true; + } + + // dex fee burn + if (value.category == uint8_t(CustomTxType::PoolSwap) + || value.category == uint8_t(CustomTxType::PoolSwapV2)) { + for (auto const & diff : value.diff) { + result->dexfeeburn.Add({diff.first, diff.second}); + } + return true; + } + + // token burn with burnToken tx + if (value.category == uint8_t(CustomTxType::BurnToken)) + { + for (auto const & diff : value.diff) { + result->nonConsortiumTokens.Add({diff.first, diff.second}); + } + return true; + } + + // Token burn + for (auto const & diff : value.diff) { + result->burntTokens.Add({diff.first, diff.second}); + } + + return true; + }, {}, std::numeric_limits::max(), std::numeric_limits::max()); + + for (const auto &result : workerResults) { + burntDFI += result->burntDFI; + burntFee += result->burntFee; + auctionFee += result->auctionFee; + burntTokens.AddBalances(result->burntTokens.balances); + nonConsortiumTokens.AddBalances(result->nonConsortiumTokens.balances); + dexfeeburn.AddBalances(result->dexfeeburn.balances); + paybackFee.AddBalances(result->paybackFee.balances); + } + + CDataStructureV0 liveKey = {AttributeTypes::Live, ParamIDs::Economy, EconomyKeys::ConsortiumMinted}; + auto balances = attributes->GetValue(liveKey, CConsortiumGlobalMinted{}); + + for (const auto &token : nonConsortiumTokens.balances) { + TAmounts amount; + amount[token.first] = balances[token.first].burnt; + consortiumTokens.AddBalances(amount); + } + + nonConsortiumTokens.SubBalances(consortiumTokens.balances); + burntTokens.AddBalances(nonConsortiumTokens.balances); + + { + UniValue result(UniValue::VOBJ); + result.pushKV("address", ScriptToString(burnAddress)); + result.pushKV("amount", ValueFromAmount(burntDFI)); + + result.pushKV("tokens", AmountsToJSON(burntTokens.balances)); + result.pushKV("consortiumtokens", AmountsToJSON(consortiumTokens.balances)); + result.pushKV("feeburn", ValueFromAmount(burntFee)); + result.pushKV("auctionburn", ValueFromAmount(auctionFee)); + result.pushKV("paybackburn", AmountsToJSON(paybackFee.balances)); + result.pushKV("dexfeetokens", AmountsToJSON(dexfeeburn.balances)); + + result.pushKV("dfipaybackfee", ValueFromAmount(dfiPaybackFee)); + result.pushKV("dfipaybacktokens", AmountsToJSON(dfipaybacktokens.balances)); + + result.pushKV("paybackfees", AmountsToJSON(paybackfees.balances)); + result.pushKV("paybacktokens", AmountsToJSON(paybacktokens.balances)); + + result.pushKV("emissionburn", ValueFromAmount(burnt)); + result.pushKV("dfip2203", AmountsToJSON(dfi2203Tokens.balances)); + result.pushKV("dfip2206f", AmountsToJSON(dfiToDUSDTokens.balances)); + + return GetRPCResultCache() + .Set(request, result); + } +} + UniValue HandleSendDFIP2201DFIInput(const JSONRPCRequest& request, CWalletCoinsUnlocker pwallet, const std::pair& contractPair, CTokenAmount amount) { @@ -2780,6 +2991,7 @@ static const CRPCCommand commands[] = {"accounts", "listcommunitybalances", &listcommunitybalances, {}}, {"accounts", "sendtokenstoaddress", &sendtokenstoaddress, {"from", "to", "selectionMode"}}, {"accounts", "getburninfo", &getburninfo, {}}, + {"accounts", "getburninfo2", &getburninfo2, {}}, {"accounts", "executesmartcontract", &executesmartcontract, {"name", "amount", "inputs"}}, {"accounts", "futureswap", &futureswap, {"address", "amount", "destination", "inputs"}}, {"accounts", "withdrawfutureswap", &withdrawfutureswap, {"address", "amount", "destination", "inputs"}}, diff --git a/src/masternodes/threadpool.h b/src/masternodes/threadpool.h index 46374ef15e..6a8a7e8107 100644 --- a/src/masternodes/threadpool.h +++ b/src/masternodes/threadpool.h @@ -19,7 +19,7 @@ class TaskPool { public: explicit TaskPool(size_t size); void Shutdown(); - [[nodiscard]] size_t GetAvailableThreads() const { return size; } + size_t GetAvailableThreads() { return size; } boost::asio::thread_pool pool; private: From c5648e9900cbbd3605b869f607e1f0287d4fb19e Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 23 Feb 2023 15:05:55 +0800 Subject: [PATCH 4/9] Remove getburninfo2 used for testing --- src/masternodes/rpc_accounts.cpp | 202 ------------------------------- 1 file changed, 202 deletions(-) diff --git a/src/masternodes/rpc_accounts.cpp b/src/masternodes/rpc_accounts.cpp index f28fba99ba..24dac944b6 100644 --- a/src/masternodes/rpc_accounts.cpp +++ b/src/masternodes/rpc_accounts.cpp @@ -2184,207 +2184,6 @@ UniValue getburninfo(const JSONRPCRequest& request) { .Set(request, result); } -UniValue getburninfo2(const JSONRPCRequest& request) { - RPCHelpMan{"getburninfo2", - "\nReturns burn address and burnt coin and token information.\n" - "Requires full acindex for correct amount, tokens and feeburn values.\n", - { - }, - RPCResult{ - "{\n" - " \"address\" : \"address\", (string) The defi burn address\n" - " \"amount\" : n.nnnnnnnn, (string) The amount of DFI burnt\n" - " \"tokens\" : [\n" - " { (array of burnt tokens)" - " \"name\" : \"name\"\n" - " \"amount\" : n.nnnnnnnn\n" - " ]\n" - " \"feeburn\" : n.nnnnnnnn, (string) The amount of fees burnt\n" - " \"emissionburn\" : n.nnnnnnnn, (string) The amount of non-utxo coinbase rewards burnt\n" - "}\n" - }, - RPCExamples{ - HelpExampleCli("getburninfo", "") - + HelpExampleRpc("getburninfo", "") - }, - }.Check(request); - - if (auto res = GetRPCResultCache().TryGet(request)) return *res; - - CAmount burntDFI{0}; - CAmount burntFee{0}; - CAmount auctionFee{0}; - CAmount dfiPaybackFee{0}; - CAmount burnt{0}; - - CBalances burntTokens; - CBalances consortiumTokens; - CBalances nonConsortiumTokens; - CBalances dexfeeburn; - CBalances paybackfees; - CBalances paybackFee; - CBalances paybacktokens; - CBalances dfi2203Tokens; - CBalances dfipaybacktokens; - CBalances dfiToDUSDTokens; - - LOCK(cs_main); - - auto height = ::ChainActive().Height(); - auto fortCanningHeight = Params().GetConsensus().FortCanningHeight; - auto burnAddress = Params().GetConsensus().burnAddress; - auto view = *pcustomcsview; - auto attributes = view.GetAttributes(); - - if (attributes) { - CDataStructureV0 liveKey{AttributeTypes::Live, ParamIDs::Economy, EconomyKeys::PaybackDFITokens}; - auto tokenBalances = attributes->GetValue(liveKey, CBalances{}); - for (const auto& balance : tokenBalances.balances) { - if (balance.first == DCT_ID{0}) { - dfiPaybackFee = balance.second; - } else { - dfipaybacktokens.Add({balance.first, balance.second}); - } - } - liveKey = {AttributeTypes::Live, ParamIDs::Economy, EconomyKeys::PaybackTokens}; - auto paybacks = attributes->GetValue(liveKey, CTokenPayback{}); - paybackfees = std::move(paybacks.tokensFee); - paybacktokens = std::move(paybacks.tokensPayback); - - liveKey = {AttributeTypes::Live, ParamIDs::Economy, EconomyKeys::DFIP2203Burned}; - dfi2203Tokens = attributes->GetValue(liveKey, CBalances{}); - - liveKey = {AttributeTypes::Live, ParamIDs::Economy, EconomyKeys::DFIP2206FBurned}; - dfiToDUSDTokens = attributes->GetValue(liveKey, CBalances{}); - } - - for (const auto& kv : Params().GetConsensus().newNonUTXOSubsidies) { - if (kv.first == CommunityAccountType::Unallocated || - kv.first == CommunityAccountType::IncentiveFunding || - (height >= fortCanningHeight && kv.first == CommunityAccountType::Loan)) { - burnt += view.GetCommunityBalance(kv.first); - } - } - - std::vector> workerResults; - auto result = std::make_shared(); - workerResults.push_back(result); - - pburnHistoryDB->ForEachAccountHistory([result](const AccountHistoryKey &key, const AccountHistoryValue &value) { - // UTXO burn - if (value.category == uint8_t(CustomTxType::None)) { - for (auto const & diff : value.diff) { - result->burntDFI += diff.second; - } - return true; - } - - // Fee burn - if (value.category == uint8_t(CustomTxType::CreateMasternode) - || value.category == uint8_t(CustomTxType::CreateToken) - || value.category == uint8_t(CustomTxType::Vault) - || value.category == uint8_t(CustomTxType::CreateCfp) - || value.category == uint8_t(CustomTxType::CreateVoc)) { - for (auto const & diff : value.diff) { - result->burntFee += diff.second; - } - return true; - } - - // withdraw burn - if (value.category == uint8_t(CustomTxType::PaybackLoan) - || value.category == uint8_t(CustomTxType::PaybackLoanV2) - || value.category == uint8_t(CustomTxType::PaybackWithCollateral)) { - for (const auto& [id, amount] : value.diff) { - result->paybackFee.Add({id, amount}); - } - return true; - } - - // auction burn - if (value.category == uint8_t(CustomTxType::AuctionBid)) { - for (auto const & diff : value.diff) { - result->auctionFee += diff.second; - } - return true; - } - - // dex fee burn - if (value.category == uint8_t(CustomTxType::PoolSwap) - || value.category == uint8_t(CustomTxType::PoolSwapV2)) { - for (auto const & diff : value.diff) { - result->dexfeeburn.Add({diff.first, diff.second}); - } - return true; - } - - // token burn with burnToken tx - if (value.category == uint8_t(CustomTxType::BurnToken)) - { - for (auto const & diff : value.diff) { - result->nonConsortiumTokens.Add({diff.first, diff.second}); - } - return true; - } - - // Token burn - for (auto const & diff : value.diff) { - result->burntTokens.Add({diff.first, diff.second}); - } - - return true; - }, {}, std::numeric_limits::max(), std::numeric_limits::max()); - - for (const auto &result : workerResults) { - burntDFI += result->burntDFI; - burntFee += result->burntFee; - auctionFee += result->auctionFee; - burntTokens.AddBalances(result->burntTokens.balances); - nonConsortiumTokens.AddBalances(result->nonConsortiumTokens.balances); - dexfeeburn.AddBalances(result->dexfeeburn.balances); - paybackFee.AddBalances(result->paybackFee.balances); - } - - CDataStructureV0 liveKey = {AttributeTypes::Live, ParamIDs::Economy, EconomyKeys::ConsortiumMinted}; - auto balances = attributes->GetValue(liveKey, CConsortiumGlobalMinted{}); - - for (const auto &token : nonConsortiumTokens.balances) { - TAmounts amount; - amount[token.first] = balances[token.first].burnt; - consortiumTokens.AddBalances(amount); - } - - nonConsortiumTokens.SubBalances(consortiumTokens.balances); - burntTokens.AddBalances(nonConsortiumTokens.balances); - - { - UniValue result(UniValue::VOBJ); - result.pushKV("address", ScriptToString(burnAddress)); - result.pushKV("amount", ValueFromAmount(burntDFI)); - - result.pushKV("tokens", AmountsToJSON(burntTokens.balances)); - result.pushKV("consortiumtokens", AmountsToJSON(consortiumTokens.balances)); - result.pushKV("feeburn", ValueFromAmount(burntFee)); - result.pushKV("auctionburn", ValueFromAmount(auctionFee)); - result.pushKV("paybackburn", AmountsToJSON(paybackFee.balances)); - result.pushKV("dexfeetokens", AmountsToJSON(dexfeeburn.balances)); - - result.pushKV("dfipaybackfee", ValueFromAmount(dfiPaybackFee)); - result.pushKV("dfipaybacktokens", AmountsToJSON(dfipaybacktokens.balances)); - - result.pushKV("paybackfees", AmountsToJSON(paybackfees.balances)); - result.pushKV("paybacktokens", AmountsToJSON(paybacktokens.balances)); - - result.pushKV("emissionburn", ValueFromAmount(burnt)); - result.pushKV("dfip2203", AmountsToJSON(dfi2203Tokens.balances)); - result.pushKV("dfip2206f", AmountsToJSON(dfiToDUSDTokens.balances)); - - return GetRPCResultCache() - .Set(request, result); - } -} - - UniValue HandleSendDFIP2201DFIInput(const JSONRPCRequest& request, CWalletCoinsUnlocker pwallet, const std::pair& contractPair, CTokenAmount amount) { CUtxosToAccountMessage msg{}; @@ -2991,7 +2790,6 @@ static const CRPCCommand commands[] = {"accounts", "listcommunitybalances", &listcommunitybalances, {}}, {"accounts", "sendtokenstoaddress", &sendtokenstoaddress, {"from", "to", "selectionMode"}}, {"accounts", "getburninfo", &getburninfo, {}}, - {"accounts", "getburninfo2", &getburninfo2, {}}, {"accounts", "executesmartcontract", &executesmartcontract, {"name", "amount", "inputs"}}, {"accounts", "futureswap", &futureswap, {"address", "amount", "destination", "inputs"}}, {"accounts", "withdrawfutureswap", &withdrawfutureswap, {"address", "amount", "destination", "inputs"}}, From 49738c6c4bd22c3c2a3d092354a05dd4af702de5 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 23 Feb 2023 15:16:09 +0800 Subject: [PATCH 5/9] Optimize vector reservation --- src/masternodes/rpc_accounts.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/masternodes/rpc_accounts.cpp b/src/masternodes/rpc_accounts.cpp index 24dac944b6..eeaec89920 100644 --- a/src/masternodes/rpc_accounts.cpp +++ b/src/masternodes/rpc_accounts.cpp @@ -2036,19 +2036,24 @@ UniValue getburninfo(const JSONRPCRequest& request) { const auto chunks = height / nWorkers; const auto chunksRemainder = height % nWorkers; - auto processedHeight = 0; - auto i = 0; - TaskGroup g; - std::vector> workerResults; - auto &pool = DfTxTaskPool->pool; + std::vector> workerResults; + // Note this creates a massive amount of chunks as we go in mem. + // But this is fine for now. Most optimal impl is to return the future val + // and add it on receive. It requires a bit more changes, but for now + // this should do. + // However reserve in one-go to prevent numerous reallocations + workerResults.reserve(chunks); for (auto i = 0; i <= chunks; i++) { auto result = std::make_shared(); workerResults.push_back(result); } + auto &pool = DfTxTaskPool->pool; + auto processedHeight = 0; + auto i = 0; while (processedHeight < height) { auto startHeight = (chunks * (i + 1)); From d125ddf1dd443653c5d0c3ec7de1686a5cdd83c4 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 23 Feb 2023 15:18:22 +0800 Subject: [PATCH 6/9] Readd nodiscard --- src/masternodes/threadpool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/masternodes/threadpool.h b/src/masternodes/threadpool.h index 6a8a7e8107..2dbb0d862c 100644 --- a/src/masternodes/threadpool.h +++ b/src/masternodes/threadpool.h @@ -19,7 +19,7 @@ class TaskPool { public: explicit TaskPool(size_t size); void Shutdown(); - size_t GetAvailableThreads() { return size; } + [[nodiscard]] size_t GetAvailableThreads() { return size; } boost::asio::thread_pool pool; private: From 49ef48619c245557f1aa31eda7036d6ca31ff65a Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 23 Feb 2023 15:32:44 +0800 Subject: [PATCH 7/9] Readd const --- src/masternodes/threadpool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/masternodes/threadpool.h b/src/masternodes/threadpool.h index 2dbb0d862c..46374ef15e 100644 --- a/src/masternodes/threadpool.h +++ b/src/masternodes/threadpool.h @@ -19,7 +19,7 @@ class TaskPool { public: explicit TaskPool(size_t size); void Shutdown(); - [[nodiscard]] size_t GetAvailableThreads() { return size; } + [[nodiscard]] size_t GetAvailableThreads() const { return size; } boost::asio::thread_pool pool; private: From 051fd3069ef78b14f18128f2665b3130ad48233e Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 23 Feb 2023 15:34:24 +0800 Subject: [PATCH 8/9] Realign vector alloc --- src/masternodes/rpc_accounts.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/masternodes/rpc_accounts.cpp b/src/masternodes/rpc_accounts.cpp index eeaec89920..fd15487a1b 100644 --- a/src/masternodes/rpc_accounts.cpp +++ b/src/masternodes/rpc_accounts.cpp @@ -2044,7 +2044,7 @@ UniValue getburninfo(const JSONRPCRequest& request) { // and add it on receive. It requires a bit more changes, but for now // this should do. // However reserve in one-go to prevent numerous reallocations - workerResults.reserve(chunks); + workerResults.reserve(chunks + 1); for (auto i = 0; i <= chunks; i++) { auto result = std::make_shared(); From 8ae7ced8090638bd50dd0eb8b57b48025783f39c Mon Sep 17 00:00:00 2001 From: Bushstar Date: Thu, 23 Feb 2023 07:47:44 +0000 Subject: [PATCH 9/9] Fix compiler warnings --- src/masternodes/rpc_accounts.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/masternodes/rpc_accounts.cpp b/src/masternodes/rpc_accounts.cpp index fd15487a1b..903c4e58a7 100644 --- a/src/masternodes/rpc_accounts.cpp +++ b/src/masternodes/rpc_accounts.cpp @@ -2029,12 +2029,11 @@ UniValue getburninfo(const JSONRPCRequest& request) { } auto nWorkers = DfTxTaskPool->GetAvailableThreads(); - if (height < nWorkers) { + if (static_cast(height) < nWorkers) { nWorkers = height; } const auto chunks = height / nWorkers; - const auto chunksRemainder = height % nWorkers; TaskGroup g; @@ -2046,7 +2045,7 @@ UniValue getburninfo(const JSONRPCRequest& request) { // However reserve in one-go to prevent numerous reallocations workerResults.reserve(chunks + 1); - for (auto i = 0; i <= chunks; i++) { + for (size_t i = 0; i <= chunks; i++) { auto result = std::make_shared(); workerResults.push_back(result); }