dash/src/bls/bls_worker.cpp

912 lines
32 KiB
C++
Raw Normal View History

// Copyright (c) 2018-2022 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
Backport 11651 (#3358) * scripted-diff: Replace #include "" with #include <> (ryanofsky) -BEGIN VERIFY SCRIPT- for f in \ src/*.cpp \ src/*.h \ src/bench/*.cpp \ src/bench/*.h \ src/compat/*.cpp \ src/compat/*.h \ src/consensus/*.cpp \ src/consensus/*.h \ src/crypto/*.cpp \ src/crypto/*.h \ src/crypto/ctaes/*.h \ src/policy/*.cpp \ src/policy/*.h \ src/primitives/*.cpp \ src/primitives/*.h \ src/qt/*.cpp \ src/qt/*.h \ src/qt/test/*.cpp \ src/qt/test/*.h \ src/rpc/*.cpp \ src/rpc/*.h \ src/script/*.cpp \ src/script/*.h \ src/support/*.cpp \ src/support/*.h \ src/support/allocators/*.h \ src/test/*.cpp \ src/test/*.h \ src/wallet/*.cpp \ src/wallet/*.h \ src/wallet/test/*.cpp \ src/wallet/test/*.h \ src/zmq/*.cpp \ src/zmq/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT- Signed-off-by: Pasta <pasta@dashboost.org> * scripted-diff: Replace #include "" with #include <> (Dash Specific) -BEGIN VERIFY SCRIPT- for f in \ src/bls/*.cpp \ src/bls/*.h \ src/evo/*.cpp \ src/evo/*.h \ src/governance/*.cpp \ src/governance/*.h \ src/llmq/*.cpp \ src/llmq/*.h \ src/masternode/*.cpp \ src/masternode/*.h \ src/privatesend/*.cpp \ src/privatesend/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT- Signed-off-by: Pasta <pasta@dashboost.org> * build: Remove -I for everything but project root Remove -I from build system for everything but the project root, and built-in dependencies. Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/Makefile.test.include * qt: refactor: Use absolute include paths in .ui files * qt: refactor: Changes to make include paths absolute This makes all include paths in the GUI absolute. Many changes are involved as every single source file in src/qt/ assumes to be able to use relative includes. Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/qt/dash.cpp # src/qt/optionsmodel.cpp # src/qt/test/rpcnestedtests.cpp * test: refactor: Use absolute include paths for test data files * Recommend #include<> syntax in developer notes * refactor: Include obj/build.h instead of build.h * END BACKPORT #11651 Remove trailing whitespace causing travis failure * fix backport 11651 Signed-off-by: Pasta <pasta@dashboost.org> * More of 11651 * fix blockchain.cpp Signed-off-by: pasta <pasta@dashboost.org> * Add missing "qt/" in includes * Add missing "test/" in includes * Fix trailing whitespaces Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com> Co-authored-by: Russell Yanofsky <russ@yanofsky.org> Co-authored-by: MeshCollider <dobsonsa68@gmail.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2020-03-19 23:46:56 +01:00
#include <bls/bls_worker.h>
#include <hash.h>
#include <serialize.h>
#include <util/ranges.h>
merge bitcoin#14555: Move util files to directory (script modified to account for Dash backports, doesn't account for rebasing) ------------- BEGIN SCRIPT --------------- mkdir -p src/util git mv src/util.h src/util/system.h git mv src/util.cpp src/util/system.cpp git mv src/utilmemory.h src/util/memory.h git mv src/utilmoneystr.h src/util/moneystr.h git mv src/utilmoneystr.cpp src/util/moneystr.cpp git mv src/utilstrencodings.h src/util/strencodings.h git mv src/utilstrencodings.cpp src/util/strencodings.cpp git mv src/utiltime.h src/util/time.h git mv src/utiltime.cpp src/util/time.cpp git mv src/utilasmap.h src/util/asmap.h git mv src/utilasmap.cpp src/util/asmap.cpp git mv src/utilstring.h src/util/string.h git mv src/utilstring.cpp src/util/string.cpp gsed -i 's/<util\.h>/<util\/system\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilmemory\.h>/<util\/memory\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilmoneystr\.h>/<util\/moneystr\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilstrencodings\.h>/<util\/strencodings\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utiltime\.h>/<util\/time\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilasmap\.h>/<util\/asmap\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilstring\.h>/<util\/string\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/BITCOIN_UTIL_H/BITCOIN_UTIL_SYSTEM_H/g' src/util/system.h gsed -i 's/BITCOIN_UTILMEMORY_H/BITCOIN_UTIL_MEMORY_H/g' src/util/memory.h gsed -i 's/BITCOIN_UTILMONEYSTR_H/BITCOIN_UTIL_MONEYSTR_H/g' src/util/moneystr.h gsed -i 's/BITCOIN_UTILSTRENCODINGS_H/BITCOIN_UTIL_STRENCODINGS_H/g' src/util/strencodings.h gsed -i 's/BITCOIN_UTILTIME_H/BITCOIN_UTIL_TIME_H/g' src/util/time.h gsed -i 's/BITCOIN_UTILASMAP_H/BITCOIN_UTIL_ASMAP_H/g' src/util/asmap.h gsed -i 's/BITCOIN_UTILSTRING_H/BITCOIN_UTIL_STRING_H/g' src/util/string.h gsed -i 's/ util\.\(h\|cpp\)/ util\/system\.\1/g' src/Makefile.am gsed -i 's/utilmemory\.\(h\|cpp\)/util\/memory\.\1/g' src/Makefile.am gsed -i 's/utilmoneystr\.\(h\|cpp\)/util\/moneystr\.\1/g' src/Makefile.am gsed -i 's/utilstrencodings\.\(h\|cpp\)/util\/strencodings\.\1/g' src/Makefile.am gsed -i 's/utiltime\.\(h\|cpp\)/util\/time\.\1/g' src/Makefile.am gsed -i 's/utilasmap\.\(h\|cpp\)/util\/asmap\.\1/g' src/Makefile.am gsed -i 's/utilstring\.\(h\|cpp\)/util\/string\.\1/g' src/Makefile.am gsed -i 's/-> util ->/-> util\/system ->/' test/lint/lint-circular-dependencies.sh gsed -i 's/src\/util\.cpp/src\/util\/system\.cpp/g' test/lint/lint-format-strings.py test/lint/lint-locale-dependence.sh gsed -i 's/src\/utilmoneystr\.cpp/src\/util\/moneystr\.cpp/g' test/lint/lint-locale-dependence.sh gsed -i 's/src\/utilstrencodings\.\(h\|cpp\)/src\/util\/strencodings\.\1/g' test/lint/lint-locale-dependence.sh ------------- END SCRIPT ---------------
2021-06-27 08:33:13 +02:00
#include <util/system.h>
#include <memory>
#include <utility>
template <typename T>
bool VerifyVectorHelper(const std::vector<T>& vec, size_t start, size_t count)
{
if (start == 0 && count == 0) {
count = vec.size();
}
std::set<uint256> set;
for (size_t i = start; i < start + count; i++) {
if (!vec[i].IsValid())
return false;
// check duplicates
if (!set.emplace(vec[i].GetHash()).second) {
return false;
}
}
return true;
}
// Creates a doneCallback and a future. The doneCallback simply finishes the future
template <typename T>
std::pair<std::function<void(const T&)>, std::future<T> > BuildFutureDoneCallback()
{
auto p = std::make_shared<std::promise<T> >();
std::function<void(const T&)> f = [p](const T& v) {
p->set_value(v);
};
return std::make_pair(std::move(f), p->get_future());
}
template <typename T>
std::pair<std::function<void(T)>, std::future<T> > BuildFutureDoneCallback2()
{
auto p = std::make_shared<std::promise<T> >();
std::function<void(const T&)> f = [p](T v) {
p->set_value(v);
};
return std::make_pair(std::move(f), p->get_future());
}
/////
CBLSWorker::CBLSWorker() = default;
CBLSWorker::~CBLSWorker()
{
Stop();
}
void CBLSWorker::Start()
{
int workerCount = std::thread::hardware_concurrency() / 2;
workerCount = std::max(std::min(1, workerCount), 4);
workerPool.resize(workerCount);
RenameThreadPool(workerPool, "bls-work");
}
void CBLSWorker::Stop()
{
workerPool.clear_queue();
workerPool.stop(true);
}
bool CBLSWorker::GenerateContributions(int quorumThreshold, const BLSIdVector& ids, BLSVerificationVectorPtr& vvecRet, BLSSecretKeyVector& skSharesRet)
{
auto svec = BLSSecretKeyVector((size_t)quorumThreshold);
vvecRet = std::make_shared<BLSVerificationVector>((size_t)quorumThreshold);
skSharesRet.resize(ids.size());
for (int i = 0; i < quorumThreshold; i++) {
svec[i].MakeNewKey();
}
size_t batchSize = 8;
std::vector<std::future<bool>> futures;
futures.reserve((quorumThreshold / batchSize + ids.size() / batchSize) + 2);
for (size_t i = 0; i < size_t(quorumThreshold); i += batchSize) {
size_t start = i;
size_t count = std::min(batchSize, quorumThreshold - start);
auto f = [&, start, count](int threadId) {
for (size_t j = start; j < start + count; j++) {
(*vvecRet)[j] = svec[j].GetPublicKey();
}
return true;
};
futures.emplace_back(workerPool.push(f));
}
for (size_t i = 0; i < ids.size(); i += batchSize) {
size_t start = i;
size_t count = std::min(batchSize, ids.size() - start);
auto f = [&, start, count](int threadId) {
for (size_t j = start; j < start + count; j++) {
if (!skSharesRet[j].SecretKeyShare(svec, ids[j])) {
return false;
}
}
return true;
};
futures.emplace_back(workerPool.push(f));
}
return ranges::all_of(futures, [](auto& f){
return f.get();
});
}
// aggregates a single vector of BLS objects in parallel
// the input vector is split into batches and each batch is aggregated in parallel
// when enough batches are finished to form a new batch, the new batch is queued for further parallel aggregation
// when no more batches can be created from finished batch results, the final aggregated is created and the doneCallback
// called.
// The Aggregator object needs to be created on the heap, and it will delete itself after calling the doneCallback
// The input vector is not copied into the Aggregator but instead a vector of pointers to the original entries from the
// input vector is stored. This means that the input vector must stay alive for the whole lifetime of the Aggregator
template <typename T>
struct Aggregator : public std::enable_shared_from_this<Aggregator<T>> {
size_t batchSize{16};
std::shared_ptr<std::vector<const T*> > inputVec;
bool parallel;
ctpl::thread_pool& workerPool;
std::mutex m;
// items in the queue are all intermediate aggregation results of finished batches.
// The intermediate results must be deleted by us again (which we do in SyncAggregateAndPushAggQueue)
ctpl::detail::Queue<T*> aggQueue;
std::atomic<size_t> aggQueueSize{0};
// keeps track of currently queued/in-progress batches. If it reaches 0, we are done
std::atomic<size_t> waitCount{0};
using DoneCallback = std::function<void(const T& agg)>;
DoneCallback doneCallback;
// TP can either be a pointer or a reference
template <typename TP>
Aggregator(const std::vector<TP>& _inputVec,
size_t start, size_t count,
bool _parallel,
ctpl::thread_pool& _workerPool,
DoneCallback _doneCallback) :
inputVec(std::make_shared<std::vector<const T*>>(count)),
parallel(_parallel),
fix: resolve numerous compilation warnings under -Wall (#4599) * fix: compilation warnings ./validation.h:266:13: warning: ‘bool AcceptToMemoryPoolWithTime(const CChainParams&, CTxMemPool&, CValidationState&, const CTransactionRef&, bool*, int64_t, bool, CAmount, bool)’ declared ‘static’ but never defined [-Wunused-function] static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, ^~~~~~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings ./coinjoin/client.h: In constructor ‘CCoinJoinClientManager::CCoinJoinClientManager(CWallet&)’: ./coinjoin/client.h:199:10: warning: ‘CCoinJoinClientManager::fCreateAutoBackups’ will be initialized after [-Wreorder] bool fCreateAutoBackups; // builtin support for automatic backups ^~~~~~~~~~~~~~~~~~ ./coinjoin/client.h:187:14: warning: ‘CWallet& CCoinJoinClientManager::mixingWallet’ [-Wreorder] CWallet& mixingWallet; ^~~~~~~~~~~~ ./coinjoin/client.h:205:14: warning: when initialized here [-Wreorder] explicit CCoinJoinClientManager(CWallet& wallet) : ^~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings interfaces/wallet.cpp: In constructor ‘interfaces::{anonymous}::WalletImpl::WalletImpl(const std::shared_ptr<CWallet>&)’: interfaces/wallet.cpp:594:30: warning: ‘interfaces::{anonymous}::WalletImpl::m_wallet’ will be initialized after [-Wreorder] std::shared_ptr<CWallet> m_wallet; ^~~~~~~~ interfaces/wallet.cpp:191:18: warning: ‘interfaces::{anonymous}::CoinJoinImpl interfaces::{anonymous}::WalletImpl::m_coinjoin’ [-Wreorder] CoinJoinImpl m_coinjoin; ^~~~~~~~~~ interfaces/wallet.cpp:193:14: warning: when initialized here [-Wreorder] explicit WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_wallet(wallet), m_coinjoin(wallet) {} ^~~~~~~~~~ * fix: compilation warnings validation.cpp:165:13: warning: ‘void CheckBlockIndex(const Consensus::Params&)’ declared ‘static’ but never defined [-Wunused-function] static void CheckBlockIndex(const Consensus::Params& consensusParams); ^~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp: In constructor ‘ContributionVerifier::ContributionVerifier(CBLSId, const std::vector<std::shared_ptr<std::vector<CBLSPublicKey> > >&, const BLSSecretKeyVector&, size_t, bool, bool, ctpl::thread_pool&, std::function<void(const std::vector<bool>&)>)’: bls/bls_worker.cpp:425:51: warning: ‘ContributionVerifier::doneCallback’ will be initialized after [-Wreorder] std::function<void(const std::vector<bool>&)> doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:420:12: warning: ‘size_t ContributionVerifier::batchCount’ [-Wreorder] size_t batchCount; ^~~~~~~~~~ bls/bls_worker.cpp:427:5: warning: when initialized here [-Wreorder] ContributionVerifier(CBLSId _forId, const std::vector<BLSVerificationVectorPtr>& _vvecs, ^~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:342:10: warning: ‘VectorAggregator<CBLSPublicKey>::parallel’ will be initialized after [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:340:12: warning: ‘size_t VectorAggregator<CBLSPublicKey>::start’ [-Wreorder] size_t start; ^~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ bls/bls_worker.cpp:343:24: warning: ‘VectorAggregator<CBLSPublicKey>::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:337:18: warning: ‘VectorAggregator<CBLSPublicKey>::DoneCallback VectorAggregator<CBLSPublicKey>::doneCallback’ [-Wreorder] DoneCallback doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:494:235: required from here bls/bls_worker.cpp:136:24: warning: ‘Aggregator<CBLSSecretKey>::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:135:10: warning: ‘bool Aggregator<CBLSSecretKey>::parallel’ [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:152:5: warning: when initialized here [-Wreorder] Aggregator(const std::vector<TP>& _inputVec, ^~~~~~~~~~ * fix: compilation warnings bench/string_cast.cpp: In lambda function: bench/string_cast.cpp:22:13: warning: statement has no effect [-Wunused-value] atoi("1"); ~~~~^~~~~ * fix: compilation warnings ./llmq/dkgsessionhandler.h: In constructor ‘llmq::CDKGPendingMessages::CDKGPendingMessages(size_t, int)’: ./llmq/dkgsessionhandler.h:48:12: warning: ‘llmq::CDKGPendingMessages::maxMessagesPerNode’ will be initialized after [-Wreorder] size_t maxMessagesPerNode GUARDED_BY(cs); ^~~~~~~~~~~~~~~~~~ ./llmq/dkgsessionhandler.h:47:15: warning: ‘const int llmq::CDKGPendingMessages::invType’ [-Wreorder] const int invType; ^~~~~~~ llmq/dkgsessionhandler.cpp:23:1: warning: when initialized here [-Wreorder] CDKGPendingMessages::CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType) : ^~~~~~~~~~~~~~~~~~~ * fix: compilation warnings Not sure this one is correct, but I believe so. Seems like the `!= 0` is completely not needed rpc/masternode.cpp: In function ‘UniValue masternode_payments(const JSONRPCRequest&)’: rpc/masternode.cpp:442:31: warning: suggest parentheses around comparison in operand of ‘!=’ [-Wparentheses] while (vecPayments.size() < std::abs(nCount) != 0 && pindex != nullptr) { ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ * fix: compilation warnings test/cachemultimap_tests.cpp:14:13: warning: ‘void cachemultimap_tests::DumpMap(const CacheMultiMap<int, int>&)’ defined but not used [-Wunused-function] static void DumpMap(const CacheMultiMap<int,int>& cmmap) ^~~~~~~ * fix: compilation warnings In file included from qt/appearancewidget.cpp:11: ./qt/appearancewidget.h: In constructor ‘AppearanceWidget::AppearanceWidget(QWidget*)’: ./qt/appearancewidget.h:52:25: warning: ‘AppearanceWidget::prevFontFamily’ will be initialized after [-Wreorder] GUIUtil::FontFamily prevFontFamily; ^~~~~~~~~~~~~~ ./qt/appearancewidget.h:51:9: warning: ‘int AppearanceWidget::prevScale’ [-Wreorder] int prevScale; ^~~~~~~~~ qt/appearancewidget.cpp:21:1: warning: when initialized here [-Wreorder] AppearanceWidget::AppearanceWidget(QWidget* parent) : ^~~~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/bitcoingui.cpp:6: ./qt/bitcoingui.h: In constructor ‘BitcoinGUI::BitcoinGUI(interfaces::Node&, const NetworkStyle*, QWidget*)’: ./qt/bitcoingui.h:212:31: warning: ‘BitcoinGUI::m_network_style’ will be initialized after [-Wreorder] const NetworkStyle* const m_network_style; ^~~~~~~~~~~~~~~ ./qt/bitcoingui.h:172:34: warning: ‘const std::unique_ptr<QMenu> BitcoinGUI::trayIconMenu’ [-Wreorder] const std::unique_ptr<QMenu> trayIconMenu; ^~~~~~~~~~~~ qt/bitcoingui.cpp:81:1: warning: when initialized here [-Wreorder] BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle, QWidget* parent) : ^~~~~~~~~~ * fix: compilation warnings In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h: In constructor ‘MasternodeList::MasternodeList(QWidget*)’: ./qt/masternodelist.h:66:18: warning: ‘MasternodeList::walletModel’ will be initialized after [-Wreorder] WalletModel* walletModel; ^~~~~~~~~~~ ./qt/masternodelist.h:61:10: warning: ‘bool MasternodeList::fFilterUpdatedDIP3’ [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h:61:10: warning: ‘MasternodeList::fFilterUpdatedDIP3’ will be initialized after [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ ./qt/masternodelist.h:59:13: warning: ‘int64_t MasternodeList::nTimeFilterUpdatedDIP3’ [-Wreorder] int64_t nTimeFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/paymentserver.cpp:10: ./qt/paymentserver.h: In constructor ‘PaymentServer::PaymentServer(QObject*, bool)’: ./qt/paymentserver.h:156:28: warning: ‘PaymentServer::netManager’ will be initialized after [-Wreorder] QNetworkAccessManager* netManager; // Used to fetch payment requests ^~~~~~~~~~ ./qt/paymentserver.h:147:19: warning: ‘OptionsModel* PaymentServer::optionsModel’ [-Wreorder] OptionsModel *optionsModel; ^~~~~~~~~~~~ qt/paymentserver.cpp:197:1: warning: when initialized here [-Wreorder] PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : ^~~~~~~~~~~~~
2021-12-01 20:59:34 +01:00
workerPool(_workerPool),
doneCallback(std::move(_doneCallback))
{
for (size_t i = 0; i < count; i++) {
(*inputVec)[i] = pointer(_inputVec[start + i]);
}
}
const T* pointer(const T& v) { return &v; }
const T* pointer(const T* v) { return v; }
// Starts aggregation.
// If parallel=true, then this will return fast, otherwise this will block until aggregation is done
void Start()
{
size_t batchCount = (inputVec->size() + batchSize - 1) / batchSize;
if (!parallel) {
if (inputVec->size() == 1) {
doneCallback(*(*inputVec)[0]);
} else {
doneCallback(SyncAggregate(*inputVec, 0, inputVec->size()));
}
return;
}
if (batchCount == 1) {
// just a single batch of work, take a shortcut.
auto self(this->shared_from_this());
PushWork([this, self](int threadId) {
if (inputVec->size() == 1) {
doneCallback(*(*inputVec)[0]);
} else {
doneCallback(SyncAggregate(*inputVec, 0, inputVec->size()));
}
});
return;
}
// increment wait counter as otherwise the first finished async aggregation might signal that we're done
IncWait();
for (size_t i = 0; i < batchCount; i++) {
size_t start = i * batchSize;
size_t count = std::min(batchSize, inputVec->size() - start);
AsyncAggregateAndPushAggQueue(inputVec, start, count, false);
}
// this will decrement the wait counter and in most cases NOT finish, as async work is still in progress
CheckDone();
}
void IncWait()
{
++waitCount;
}
void CheckDone()
{
if (--waitCount == 0) {
Finish();
}
}
void Finish()
{
// All async work is done, but we might have items in the aggQueue which are the results of the async
// work. This is the case when these did not add up to a new batch. In this case, we have to aggregate
// the items into the final result
std::vector<T*> rem(aggQueueSize);
for (size_t i = 0; i < rem.size(); i++) {
T* p = nullptr;
bool s = aggQueue.pop(p);
assert(s);
rem[i] = p;
}
T r;
if (rem.size() == 1) {
// just one intermediate result, which is actually the final result
r = *rem[0];
} else {
// multiple intermediate results left which did not add up to a new batch. aggregate them now
r = SyncAggregate(rem, 0, rem.size());
}
// all items which are left in the queue are intermediate results, so we must delete them
for (size_t i = 0; i < rem.size(); i++) {
delete rem[i];
}
doneCallback(r);
}
void AsyncAggregateAndPushAggQueue(const std::shared_ptr<std::vector<const T*>>& vec, size_t start, size_t count, bool del)
{
IncWait();
auto self(this->shared_from_this());
PushWork([self, vec, start, count, del](int threadId){
self->SyncAggregateAndPushAggQueue(vec, start, count, del);
});
}
void SyncAggregateAndPushAggQueue(const std::shared_ptr<std::vector<const T*>>& vec, size_t start, size_t count, bool del)
{
// aggregate vec and push the intermediate result onto the work queue
PushAggQueue(SyncAggregate(*vec, start, count));
if (del) {
for (size_t i = 0; i < count; i++) {
delete (*vec)[start + i];
}
}
CheckDone();
}
void PushAggQueue(const T& v)
{
auto copyT = new T(v);
try {
aggQueue.push(copyT);
} catch (...) {
delete copyT;
throw;
}
if (++aggQueueSize >= batchSize) {
// we've collected enough intermediate results to form a new batch.
std::shared_ptr<std::vector<const T*> > newBatch;
{
std::unique_lock<std::mutex> l(m);
if (aggQueueSize < batchSize) {
// some other worker thread grabbed this batch
return;
}
newBatch = std::make_shared<std::vector<const T*> >(batchSize);
// collect items for new batch
for (size_t i = 0; i < batchSize; i++) {
T* p = nullptr;
bool s = aggQueue.pop(p);
assert(s);
(*newBatch)[i] = p;
}
aggQueueSize -= batchSize;
}
// push new batch to work queue. del=true this time as these items are intermediate results and need to be deleted
// after aggregation is done
AsyncAggregateAndPushAggQueue(newBatch, 0, newBatch->size(), true);
}
}
template <typename TP>
T SyncAggregate(const std::vector<TP>& vec, size_t start, size_t count)
{
T result = *vec[start];
for (size_t j = 1; j < count; j++) {
result.AggregateInsecure(*vec[start + j]);
}
return result;
}
template <typename Callable>
void PushWork(Callable&& f)
{
workerPool.push(f);
}
};
// Aggregates multiple input vectors into a single output vector
// Inputs are in the following form:
// [
// [a1, b1, c1, d1],
// [a2, b2, c2, d2],
// [a3, b3, c3, d3],
// [a4, b4, c4, d4],
// ]
// The result is in the following form:
// [ a1+a2+a3+a4, b1+b2+b3+b4, c1+c2+c3+c4, d1+d2+d3+d4]
// Same rules for the input vectors apply to the VectorAggregator as for the Aggregator (they must stay alive)
template <typename T>
struct VectorAggregator : public std::enable_shared_from_this<VectorAggregator<T>> {
using AggregatorType = Aggregator<T>;
using VectorType = std::vector<T>;
using VectorPtrType = std::shared_ptr<VectorType>;
using VectorVectorType = std::vector<VectorPtrType>;
using DoneCallback = std::function<void(const VectorPtrType& agg)>;
DoneCallback doneCallback;
const VectorVectorType& vecs;
size_t start;
size_t count;
bool parallel;
ctpl::thread_pool& workerPool;
fix: resolve numerous compilation warnings under -Wall (#4599) * fix: compilation warnings ./validation.h:266:13: warning: ‘bool AcceptToMemoryPoolWithTime(const CChainParams&, CTxMemPool&, CValidationState&, const CTransactionRef&, bool*, int64_t, bool, CAmount, bool)’ declared ‘static’ but never defined [-Wunused-function] static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, ^~~~~~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings ./coinjoin/client.h: In constructor ‘CCoinJoinClientManager::CCoinJoinClientManager(CWallet&)’: ./coinjoin/client.h:199:10: warning: ‘CCoinJoinClientManager::fCreateAutoBackups’ will be initialized after [-Wreorder] bool fCreateAutoBackups; // builtin support for automatic backups ^~~~~~~~~~~~~~~~~~ ./coinjoin/client.h:187:14: warning: ‘CWallet& CCoinJoinClientManager::mixingWallet’ [-Wreorder] CWallet& mixingWallet; ^~~~~~~~~~~~ ./coinjoin/client.h:205:14: warning: when initialized here [-Wreorder] explicit CCoinJoinClientManager(CWallet& wallet) : ^~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings interfaces/wallet.cpp: In constructor ‘interfaces::{anonymous}::WalletImpl::WalletImpl(const std::shared_ptr<CWallet>&)’: interfaces/wallet.cpp:594:30: warning: ‘interfaces::{anonymous}::WalletImpl::m_wallet’ will be initialized after [-Wreorder] std::shared_ptr<CWallet> m_wallet; ^~~~~~~~ interfaces/wallet.cpp:191:18: warning: ‘interfaces::{anonymous}::CoinJoinImpl interfaces::{anonymous}::WalletImpl::m_coinjoin’ [-Wreorder] CoinJoinImpl m_coinjoin; ^~~~~~~~~~ interfaces/wallet.cpp:193:14: warning: when initialized here [-Wreorder] explicit WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_wallet(wallet), m_coinjoin(wallet) {} ^~~~~~~~~~ * fix: compilation warnings validation.cpp:165:13: warning: ‘void CheckBlockIndex(const Consensus::Params&)’ declared ‘static’ but never defined [-Wunused-function] static void CheckBlockIndex(const Consensus::Params& consensusParams); ^~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp: In constructor ‘ContributionVerifier::ContributionVerifier(CBLSId, const std::vector<std::shared_ptr<std::vector<CBLSPublicKey> > >&, const BLSSecretKeyVector&, size_t, bool, bool, ctpl::thread_pool&, std::function<void(const std::vector<bool>&)>)’: bls/bls_worker.cpp:425:51: warning: ‘ContributionVerifier::doneCallback’ will be initialized after [-Wreorder] std::function<void(const std::vector<bool>&)> doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:420:12: warning: ‘size_t ContributionVerifier::batchCount’ [-Wreorder] size_t batchCount; ^~~~~~~~~~ bls/bls_worker.cpp:427:5: warning: when initialized here [-Wreorder] ContributionVerifier(CBLSId _forId, const std::vector<BLSVerificationVectorPtr>& _vvecs, ^~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:342:10: warning: ‘VectorAggregator<CBLSPublicKey>::parallel’ will be initialized after [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:340:12: warning: ‘size_t VectorAggregator<CBLSPublicKey>::start’ [-Wreorder] size_t start; ^~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ bls/bls_worker.cpp:343:24: warning: ‘VectorAggregator<CBLSPublicKey>::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:337:18: warning: ‘VectorAggregator<CBLSPublicKey>::DoneCallback VectorAggregator<CBLSPublicKey>::doneCallback’ [-Wreorder] DoneCallback doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:494:235: required from here bls/bls_worker.cpp:136:24: warning: ‘Aggregator<CBLSSecretKey>::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:135:10: warning: ‘bool Aggregator<CBLSSecretKey>::parallel’ [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:152:5: warning: when initialized here [-Wreorder] Aggregator(const std::vector<TP>& _inputVec, ^~~~~~~~~~ * fix: compilation warnings bench/string_cast.cpp: In lambda function: bench/string_cast.cpp:22:13: warning: statement has no effect [-Wunused-value] atoi("1"); ~~~~^~~~~ * fix: compilation warnings ./llmq/dkgsessionhandler.h: In constructor ‘llmq::CDKGPendingMessages::CDKGPendingMessages(size_t, int)’: ./llmq/dkgsessionhandler.h:48:12: warning: ‘llmq::CDKGPendingMessages::maxMessagesPerNode’ will be initialized after [-Wreorder] size_t maxMessagesPerNode GUARDED_BY(cs); ^~~~~~~~~~~~~~~~~~ ./llmq/dkgsessionhandler.h:47:15: warning: ‘const int llmq::CDKGPendingMessages::invType’ [-Wreorder] const int invType; ^~~~~~~ llmq/dkgsessionhandler.cpp:23:1: warning: when initialized here [-Wreorder] CDKGPendingMessages::CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType) : ^~~~~~~~~~~~~~~~~~~ * fix: compilation warnings Not sure this one is correct, but I believe so. Seems like the `!= 0` is completely not needed rpc/masternode.cpp: In function ‘UniValue masternode_payments(const JSONRPCRequest&)’: rpc/masternode.cpp:442:31: warning: suggest parentheses around comparison in operand of ‘!=’ [-Wparentheses] while (vecPayments.size() < std::abs(nCount) != 0 && pindex != nullptr) { ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ * fix: compilation warnings test/cachemultimap_tests.cpp:14:13: warning: ‘void cachemultimap_tests::DumpMap(const CacheMultiMap<int, int>&)’ defined but not used [-Wunused-function] static void DumpMap(const CacheMultiMap<int,int>& cmmap) ^~~~~~~ * fix: compilation warnings In file included from qt/appearancewidget.cpp:11: ./qt/appearancewidget.h: In constructor ‘AppearanceWidget::AppearanceWidget(QWidget*)’: ./qt/appearancewidget.h:52:25: warning: ‘AppearanceWidget::prevFontFamily’ will be initialized after [-Wreorder] GUIUtil::FontFamily prevFontFamily; ^~~~~~~~~~~~~~ ./qt/appearancewidget.h:51:9: warning: ‘int AppearanceWidget::prevScale’ [-Wreorder] int prevScale; ^~~~~~~~~ qt/appearancewidget.cpp:21:1: warning: when initialized here [-Wreorder] AppearanceWidget::AppearanceWidget(QWidget* parent) : ^~~~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/bitcoingui.cpp:6: ./qt/bitcoingui.h: In constructor ‘BitcoinGUI::BitcoinGUI(interfaces::Node&, const NetworkStyle*, QWidget*)’: ./qt/bitcoingui.h:212:31: warning: ‘BitcoinGUI::m_network_style’ will be initialized after [-Wreorder] const NetworkStyle* const m_network_style; ^~~~~~~~~~~~~~~ ./qt/bitcoingui.h:172:34: warning: ‘const std::unique_ptr<QMenu> BitcoinGUI::trayIconMenu’ [-Wreorder] const std::unique_ptr<QMenu> trayIconMenu; ^~~~~~~~~~~~ qt/bitcoingui.cpp:81:1: warning: when initialized here [-Wreorder] BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle, QWidget* parent) : ^~~~~~~~~~ * fix: compilation warnings In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h: In constructor ‘MasternodeList::MasternodeList(QWidget*)’: ./qt/masternodelist.h:66:18: warning: ‘MasternodeList::walletModel’ will be initialized after [-Wreorder] WalletModel* walletModel; ^~~~~~~~~~~ ./qt/masternodelist.h:61:10: warning: ‘bool MasternodeList::fFilterUpdatedDIP3’ [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h:61:10: warning: ‘MasternodeList::fFilterUpdatedDIP3’ will be initialized after [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ ./qt/masternodelist.h:59:13: warning: ‘int64_t MasternodeList::nTimeFilterUpdatedDIP3’ [-Wreorder] int64_t nTimeFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/paymentserver.cpp:10: ./qt/paymentserver.h: In constructor ‘PaymentServer::PaymentServer(QObject*, bool)’: ./qt/paymentserver.h:156:28: warning: ‘PaymentServer::netManager’ will be initialized after [-Wreorder] QNetworkAccessManager* netManager; // Used to fetch payment requests ^~~~~~~~~~ ./qt/paymentserver.h:147:19: warning: ‘OptionsModel* PaymentServer::optionsModel’ [-Wreorder] OptionsModel *optionsModel; ^~~~~~~~~~~~ qt/paymentserver.cpp:197:1: warning: when initialized here [-Wreorder] PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : ^~~~~~~~~~~~~
2021-12-01 20:59:34 +01:00
std::atomic<size_t> doneCount{0};
VectorPtrType result;
size_t vecSize;
VectorAggregator(const VectorVectorType& _vecs,
size_t _start, size_t _count,
bool _parallel, ctpl::thread_pool& _workerPool,
DoneCallback _doneCallback) :
fix: resolve numerous compilation warnings under -Wall (#4599) * fix: compilation warnings ./validation.h:266:13: warning: ‘bool AcceptToMemoryPoolWithTime(const CChainParams&, CTxMemPool&, CValidationState&, const CTransactionRef&, bool*, int64_t, bool, CAmount, bool)’ declared ‘static’ but never defined [-Wunused-function] static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, ^~~~~~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings ./coinjoin/client.h: In constructor ‘CCoinJoinClientManager::CCoinJoinClientManager(CWallet&)’: ./coinjoin/client.h:199:10: warning: ‘CCoinJoinClientManager::fCreateAutoBackups’ will be initialized after [-Wreorder] bool fCreateAutoBackups; // builtin support for automatic backups ^~~~~~~~~~~~~~~~~~ ./coinjoin/client.h:187:14: warning: ‘CWallet& CCoinJoinClientManager::mixingWallet’ [-Wreorder] CWallet& mixingWallet; ^~~~~~~~~~~~ ./coinjoin/client.h:205:14: warning: when initialized here [-Wreorder] explicit CCoinJoinClientManager(CWallet& wallet) : ^~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings interfaces/wallet.cpp: In constructor ‘interfaces::{anonymous}::WalletImpl::WalletImpl(const std::shared_ptr<CWallet>&)’: interfaces/wallet.cpp:594:30: warning: ‘interfaces::{anonymous}::WalletImpl::m_wallet’ will be initialized after [-Wreorder] std::shared_ptr<CWallet> m_wallet; ^~~~~~~~ interfaces/wallet.cpp:191:18: warning: ‘interfaces::{anonymous}::CoinJoinImpl interfaces::{anonymous}::WalletImpl::m_coinjoin’ [-Wreorder] CoinJoinImpl m_coinjoin; ^~~~~~~~~~ interfaces/wallet.cpp:193:14: warning: when initialized here [-Wreorder] explicit WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_wallet(wallet), m_coinjoin(wallet) {} ^~~~~~~~~~ * fix: compilation warnings validation.cpp:165:13: warning: ‘void CheckBlockIndex(const Consensus::Params&)’ declared ‘static’ but never defined [-Wunused-function] static void CheckBlockIndex(const Consensus::Params& consensusParams); ^~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp: In constructor ‘ContributionVerifier::ContributionVerifier(CBLSId, const std::vector<std::shared_ptr<std::vector<CBLSPublicKey> > >&, const BLSSecretKeyVector&, size_t, bool, bool, ctpl::thread_pool&, std::function<void(const std::vector<bool>&)>)’: bls/bls_worker.cpp:425:51: warning: ‘ContributionVerifier::doneCallback’ will be initialized after [-Wreorder] std::function<void(const std::vector<bool>&)> doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:420:12: warning: ‘size_t ContributionVerifier::batchCount’ [-Wreorder] size_t batchCount; ^~~~~~~~~~ bls/bls_worker.cpp:427:5: warning: when initialized here [-Wreorder] ContributionVerifier(CBLSId _forId, const std::vector<BLSVerificationVectorPtr>& _vvecs, ^~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:342:10: warning: ‘VectorAggregator<CBLSPublicKey>::parallel’ will be initialized after [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:340:12: warning: ‘size_t VectorAggregator<CBLSPublicKey>::start’ [-Wreorder] size_t start; ^~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ bls/bls_worker.cpp:343:24: warning: ‘VectorAggregator<CBLSPublicKey>::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:337:18: warning: ‘VectorAggregator<CBLSPublicKey>::DoneCallback VectorAggregator<CBLSPublicKey>::doneCallback’ [-Wreorder] DoneCallback doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:494:235: required from here bls/bls_worker.cpp:136:24: warning: ‘Aggregator<CBLSSecretKey>::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:135:10: warning: ‘bool Aggregator<CBLSSecretKey>::parallel’ [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:152:5: warning: when initialized here [-Wreorder] Aggregator(const std::vector<TP>& _inputVec, ^~~~~~~~~~ * fix: compilation warnings bench/string_cast.cpp: In lambda function: bench/string_cast.cpp:22:13: warning: statement has no effect [-Wunused-value] atoi("1"); ~~~~^~~~~ * fix: compilation warnings ./llmq/dkgsessionhandler.h: In constructor ‘llmq::CDKGPendingMessages::CDKGPendingMessages(size_t, int)’: ./llmq/dkgsessionhandler.h:48:12: warning: ‘llmq::CDKGPendingMessages::maxMessagesPerNode’ will be initialized after [-Wreorder] size_t maxMessagesPerNode GUARDED_BY(cs); ^~~~~~~~~~~~~~~~~~ ./llmq/dkgsessionhandler.h:47:15: warning: ‘const int llmq::CDKGPendingMessages::invType’ [-Wreorder] const int invType; ^~~~~~~ llmq/dkgsessionhandler.cpp:23:1: warning: when initialized here [-Wreorder] CDKGPendingMessages::CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType) : ^~~~~~~~~~~~~~~~~~~ * fix: compilation warnings Not sure this one is correct, but I believe so. Seems like the `!= 0` is completely not needed rpc/masternode.cpp: In function ‘UniValue masternode_payments(const JSONRPCRequest&)’: rpc/masternode.cpp:442:31: warning: suggest parentheses around comparison in operand of ‘!=’ [-Wparentheses] while (vecPayments.size() < std::abs(nCount) != 0 && pindex != nullptr) { ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ * fix: compilation warnings test/cachemultimap_tests.cpp:14:13: warning: ‘void cachemultimap_tests::DumpMap(const CacheMultiMap<int, int>&)’ defined but not used [-Wunused-function] static void DumpMap(const CacheMultiMap<int,int>& cmmap) ^~~~~~~ * fix: compilation warnings In file included from qt/appearancewidget.cpp:11: ./qt/appearancewidget.h: In constructor ‘AppearanceWidget::AppearanceWidget(QWidget*)’: ./qt/appearancewidget.h:52:25: warning: ‘AppearanceWidget::prevFontFamily’ will be initialized after [-Wreorder] GUIUtil::FontFamily prevFontFamily; ^~~~~~~~~~~~~~ ./qt/appearancewidget.h:51:9: warning: ‘int AppearanceWidget::prevScale’ [-Wreorder] int prevScale; ^~~~~~~~~ qt/appearancewidget.cpp:21:1: warning: when initialized here [-Wreorder] AppearanceWidget::AppearanceWidget(QWidget* parent) : ^~~~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/bitcoingui.cpp:6: ./qt/bitcoingui.h: In constructor ‘BitcoinGUI::BitcoinGUI(interfaces::Node&, const NetworkStyle*, QWidget*)’: ./qt/bitcoingui.h:212:31: warning: ‘BitcoinGUI::m_network_style’ will be initialized after [-Wreorder] const NetworkStyle* const m_network_style; ^~~~~~~~~~~~~~~ ./qt/bitcoingui.h:172:34: warning: ‘const std::unique_ptr<QMenu> BitcoinGUI::trayIconMenu’ [-Wreorder] const std::unique_ptr<QMenu> trayIconMenu; ^~~~~~~~~~~~ qt/bitcoingui.cpp:81:1: warning: when initialized here [-Wreorder] BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle, QWidget* parent) : ^~~~~~~~~~ * fix: compilation warnings In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h: In constructor ‘MasternodeList::MasternodeList(QWidget*)’: ./qt/masternodelist.h:66:18: warning: ‘MasternodeList::walletModel’ will be initialized after [-Wreorder] WalletModel* walletModel; ^~~~~~~~~~~ ./qt/masternodelist.h:61:10: warning: ‘bool MasternodeList::fFilterUpdatedDIP3’ [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h:61:10: warning: ‘MasternodeList::fFilterUpdatedDIP3’ will be initialized after [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ ./qt/masternodelist.h:59:13: warning: ‘int64_t MasternodeList::nTimeFilterUpdatedDIP3’ [-Wreorder] int64_t nTimeFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/paymentserver.cpp:10: ./qt/paymentserver.h: In constructor ‘PaymentServer::PaymentServer(QObject*, bool)’: ./qt/paymentserver.h:156:28: warning: ‘PaymentServer::netManager’ will be initialized after [-Wreorder] QNetworkAccessManager* netManager; // Used to fetch payment requests ^~~~~~~~~~ ./qt/paymentserver.h:147:19: warning: ‘OptionsModel* PaymentServer::optionsModel’ [-Wreorder] OptionsModel *optionsModel; ^~~~~~~~~~~~ qt/paymentserver.cpp:197:1: warning: when initialized here [-Wreorder] PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : ^~~~~~~~~~~~~
2021-12-01 20:59:34 +01:00
doneCallback(std::move(_doneCallback)),
vecs(_vecs),
start(_start),
count(_count),
fix: resolve numerous compilation warnings under -Wall (#4599) * fix: compilation warnings ./validation.h:266:13: warning: ‘bool AcceptToMemoryPoolWithTime(const CChainParams&, CTxMemPool&, CValidationState&, const CTransactionRef&, bool*, int64_t, bool, CAmount, bool)’ declared ‘static’ but never defined [-Wunused-function] static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, ^~~~~~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings ./coinjoin/client.h: In constructor ‘CCoinJoinClientManager::CCoinJoinClientManager(CWallet&)’: ./coinjoin/client.h:199:10: warning: ‘CCoinJoinClientManager::fCreateAutoBackups’ will be initialized after [-Wreorder] bool fCreateAutoBackups; // builtin support for automatic backups ^~~~~~~~~~~~~~~~~~ ./coinjoin/client.h:187:14: warning: ‘CWallet& CCoinJoinClientManager::mixingWallet’ [-Wreorder] CWallet& mixingWallet; ^~~~~~~~~~~~ ./coinjoin/client.h:205:14: warning: when initialized here [-Wreorder] explicit CCoinJoinClientManager(CWallet& wallet) : ^~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings interfaces/wallet.cpp: In constructor ‘interfaces::{anonymous}::WalletImpl::WalletImpl(const std::shared_ptr<CWallet>&)’: interfaces/wallet.cpp:594:30: warning: ‘interfaces::{anonymous}::WalletImpl::m_wallet’ will be initialized after [-Wreorder] std::shared_ptr<CWallet> m_wallet; ^~~~~~~~ interfaces/wallet.cpp:191:18: warning: ‘interfaces::{anonymous}::CoinJoinImpl interfaces::{anonymous}::WalletImpl::m_coinjoin’ [-Wreorder] CoinJoinImpl m_coinjoin; ^~~~~~~~~~ interfaces/wallet.cpp:193:14: warning: when initialized here [-Wreorder] explicit WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_wallet(wallet), m_coinjoin(wallet) {} ^~~~~~~~~~ * fix: compilation warnings validation.cpp:165:13: warning: ‘void CheckBlockIndex(const Consensus::Params&)’ declared ‘static’ but never defined [-Wunused-function] static void CheckBlockIndex(const Consensus::Params& consensusParams); ^~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp: In constructor ‘ContributionVerifier::ContributionVerifier(CBLSId, const std::vector<std::shared_ptr<std::vector<CBLSPublicKey> > >&, const BLSSecretKeyVector&, size_t, bool, bool, ctpl::thread_pool&, std::function<void(const std::vector<bool>&)>)’: bls/bls_worker.cpp:425:51: warning: ‘ContributionVerifier::doneCallback’ will be initialized after [-Wreorder] std::function<void(const std::vector<bool>&)> doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:420:12: warning: ‘size_t ContributionVerifier::batchCount’ [-Wreorder] size_t batchCount; ^~~~~~~~~~ bls/bls_worker.cpp:427:5: warning: when initialized here [-Wreorder] ContributionVerifier(CBLSId _forId, const std::vector<BLSVerificationVectorPtr>& _vvecs, ^~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:342:10: warning: ‘VectorAggregator<CBLSPublicKey>::parallel’ will be initialized after [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:340:12: warning: ‘size_t VectorAggregator<CBLSPublicKey>::start’ [-Wreorder] size_t start; ^~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ bls/bls_worker.cpp:343:24: warning: ‘VectorAggregator<CBLSPublicKey>::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:337:18: warning: ‘VectorAggregator<CBLSPublicKey>::DoneCallback VectorAggregator<CBLSPublicKey>::doneCallback’ [-Wreorder] DoneCallback doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:494:235: required from here bls/bls_worker.cpp:136:24: warning: ‘Aggregator<CBLSSecretKey>::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:135:10: warning: ‘bool Aggregator<CBLSSecretKey>::parallel’ [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:152:5: warning: when initialized here [-Wreorder] Aggregator(const std::vector<TP>& _inputVec, ^~~~~~~~~~ * fix: compilation warnings bench/string_cast.cpp: In lambda function: bench/string_cast.cpp:22:13: warning: statement has no effect [-Wunused-value] atoi("1"); ~~~~^~~~~ * fix: compilation warnings ./llmq/dkgsessionhandler.h: In constructor ‘llmq::CDKGPendingMessages::CDKGPendingMessages(size_t, int)’: ./llmq/dkgsessionhandler.h:48:12: warning: ‘llmq::CDKGPendingMessages::maxMessagesPerNode’ will be initialized after [-Wreorder] size_t maxMessagesPerNode GUARDED_BY(cs); ^~~~~~~~~~~~~~~~~~ ./llmq/dkgsessionhandler.h:47:15: warning: ‘const int llmq::CDKGPendingMessages::invType’ [-Wreorder] const int invType; ^~~~~~~ llmq/dkgsessionhandler.cpp:23:1: warning: when initialized here [-Wreorder] CDKGPendingMessages::CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType) : ^~~~~~~~~~~~~~~~~~~ * fix: compilation warnings Not sure this one is correct, but I believe so. Seems like the `!= 0` is completely not needed rpc/masternode.cpp: In function ‘UniValue masternode_payments(const JSONRPCRequest&)’: rpc/masternode.cpp:442:31: warning: suggest parentheses around comparison in operand of ‘!=’ [-Wparentheses] while (vecPayments.size() < std::abs(nCount) != 0 && pindex != nullptr) { ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ * fix: compilation warnings test/cachemultimap_tests.cpp:14:13: warning: ‘void cachemultimap_tests::DumpMap(const CacheMultiMap<int, int>&)’ defined but not used [-Wunused-function] static void DumpMap(const CacheMultiMap<int,int>& cmmap) ^~~~~~~ * fix: compilation warnings In file included from qt/appearancewidget.cpp:11: ./qt/appearancewidget.h: In constructor ‘AppearanceWidget::AppearanceWidget(QWidget*)’: ./qt/appearancewidget.h:52:25: warning: ‘AppearanceWidget::prevFontFamily’ will be initialized after [-Wreorder] GUIUtil::FontFamily prevFontFamily; ^~~~~~~~~~~~~~ ./qt/appearancewidget.h:51:9: warning: ‘int AppearanceWidget::prevScale’ [-Wreorder] int prevScale; ^~~~~~~~~ qt/appearancewidget.cpp:21:1: warning: when initialized here [-Wreorder] AppearanceWidget::AppearanceWidget(QWidget* parent) : ^~~~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/bitcoingui.cpp:6: ./qt/bitcoingui.h: In constructor ‘BitcoinGUI::BitcoinGUI(interfaces::Node&, const NetworkStyle*, QWidget*)’: ./qt/bitcoingui.h:212:31: warning: ‘BitcoinGUI::m_network_style’ will be initialized after [-Wreorder] const NetworkStyle* const m_network_style; ^~~~~~~~~~~~~~~ ./qt/bitcoingui.h:172:34: warning: ‘const std::unique_ptr<QMenu> BitcoinGUI::trayIconMenu’ [-Wreorder] const std::unique_ptr<QMenu> trayIconMenu; ^~~~~~~~~~~~ qt/bitcoingui.cpp:81:1: warning: when initialized here [-Wreorder] BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle, QWidget* parent) : ^~~~~~~~~~ * fix: compilation warnings In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h: In constructor ‘MasternodeList::MasternodeList(QWidget*)’: ./qt/masternodelist.h:66:18: warning: ‘MasternodeList::walletModel’ will be initialized after [-Wreorder] WalletModel* walletModel; ^~~~~~~~~~~ ./qt/masternodelist.h:61:10: warning: ‘bool MasternodeList::fFilterUpdatedDIP3’ [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h:61:10: warning: ‘MasternodeList::fFilterUpdatedDIP3’ will be initialized after [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ ./qt/masternodelist.h:59:13: warning: ‘int64_t MasternodeList::nTimeFilterUpdatedDIP3’ [-Wreorder] int64_t nTimeFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/paymentserver.cpp:10: ./qt/paymentserver.h: In constructor ‘PaymentServer::PaymentServer(QObject*, bool)’: ./qt/paymentserver.h:156:28: warning: ‘PaymentServer::netManager’ will be initialized after [-Wreorder] QNetworkAccessManager* netManager; // Used to fetch payment requests ^~~~~~~~~~ ./qt/paymentserver.h:147:19: warning: ‘OptionsModel* PaymentServer::optionsModel’ [-Wreorder] OptionsModel *optionsModel; ^~~~~~~~~~~~ qt/paymentserver.cpp:197:1: warning: when initialized here [-Wreorder] PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : ^~~~~~~~~~~~~
2021-12-01 20:59:34 +01:00
parallel(_parallel),
workerPool(_workerPool)
{
assert(!vecs.empty());
vecSize = vecs[0]->size();
result = std::make_shared<VectorType>(vecSize);
}
void Start()
{
for (size_t i = 0; i < vecSize; i++) {
std::vector<const T*> tmp(count);
for (size_t j = 0; j < count; j++) {
tmp[j] = &(*vecs[start + j])[i];
}
auto self(this->shared_from_this());
auto aggregator = std::make_shared<AggregatorType>(std::move(tmp), 0, count, parallel, workerPool, [self, i](const T& agg) {self->CheckDone(agg, i);});
aggregator->Start();
}
}
void CheckDone(const T& agg, size_t idx)
{
(*result)[idx] = agg;
if (++doneCount == vecSize) {
doneCallback(result);
}
}
};
// See comment of AsyncVerifyContributionShares for a description on what this does
// Same rules as in Aggregator apply for the inputs
struct ContributionVerifier : public std::enable_shared_from_this<ContributionVerifier> {
struct BatchState {
size_t start;
size_t count;
BLSVerificationVectorPtr vvec;
CBLSSecretKey skShare;
// starts with 0 and is incremented if either vvec or skShare aggregation finishes. If it reaches 2, we know
// that aggregation for this batch is fully done. We can then start verification.
std::unique_ptr<std::atomic<int> > aggDone;
// we can't directly update a vector<bool> in parallel
// as vector<bool> is not thread safe (uses bitsets internally)
// so we must use vector<char> temporarily and concatenate/convert
// each batch result into a final vector<bool>
std::vector<char> verifyResults;
};
CBLSId forId;
const std::vector<BLSVerificationVectorPtr>& vvecs;
const BLSSecretKeyVector& skShares;
size_t batchSize;
bool parallel;
bool aggregated;
ctpl::thread_pool& workerPool;
fix: resolve numerous compilation warnings under -Wall (#4599) * fix: compilation warnings ./validation.h:266:13: warning: ‘bool AcceptToMemoryPoolWithTime(const CChainParams&, CTxMemPool&, CValidationState&, const CTransactionRef&, bool*, int64_t, bool, CAmount, bool)’ declared ‘static’ but never defined [-Wunused-function] static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, ^~~~~~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings ./coinjoin/client.h: In constructor ‘CCoinJoinClientManager::CCoinJoinClientManager(CWallet&)’: ./coinjoin/client.h:199:10: warning: ‘CCoinJoinClientManager::fCreateAutoBackups’ will be initialized after [-Wreorder] bool fCreateAutoBackups; // builtin support for automatic backups ^~~~~~~~~~~~~~~~~~ ./coinjoin/client.h:187:14: warning: ‘CWallet& CCoinJoinClientManager::mixingWallet’ [-Wreorder] CWallet& mixingWallet; ^~~~~~~~~~~~ ./coinjoin/client.h:205:14: warning: when initialized here [-Wreorder] explicit CCoinJoinClientManager(CWallet& wallet) : ^~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings interfaces/wallet.cpp: In constructor ‘interfaces::{anonymous}::WalletImpl::WalletImpl(const std::shared_ptr<CWallet>&)’: interfaces/wallet.cpp:594:30: warning: ‘interfaces::{anonymous}::WalletImpl::m_wallet’ will be initialized after [-Wreorder] std::shared_ptr<CWallet> m_wallet; ^~~~~~~~ interfaces/wallet.cpp:191:18: warning: ‘interfaces::{anonymous}::CoinJoinImpl interfaces::{anonymous}::WalletImpl::m_coinjoin’ [-Wreorder] CoinJoinImpl m_coinjoin; ^~~~~~~~~~ interfaces/wallet.cpp:193:14: warning: when initialized here [-Wreorder] explicit WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_wallet(wallet), m_coinjoin(wallet) {} ^~~~~~~~~~ * fix: compilation warnings validation.cpp:165:13: warning: ‘void CheckBlockIndex(const Consensus::Params&)’ declared ‘static’ but never defined [-Wunused-function] static void CheckBlockIndex(const Consensus::Params& consensusParams); ^~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp: In constructor ‘ContributionVerifier::ContributionVerifier(CBLSId, const std::vector<std::shared_ptr<std::vector<CBLSPublicKey> > >&, const BLSSecretKeyVector&, size_t, bool, bool, ctpl::thread_pool&, std::function<void(const std::vector<bool>&)>)’: bls/bls_worker.cpp:425:51: warning: ‘ContributionVerifier::doneCallback’ will be initialized after [-Wreorder] std::function<void(const std::vector<bool>&)> doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:420:12: warning: ‘size_t ContributionVerifier::batchCount’ [-Wreorder] size_t batchCount; ^~~~~~~~~~ bls/bls_worker.cpp:427:5: warning: when initialized here [-Wreorder] ContributionVerifier(CBLSId _forId, const std::vector<BLSVerificationVectorPtr>& _vvecs, ^~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:342:10: warning: ‘VectorAggregator<CBLSPublicKey>::parallel’ will be initialized after [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:340:12: warning: ‘size_t VectorAggregator<CBLSPublicKey>::start’ [-Wreorder] size_t start; ^~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ bls/bls_worker.cpp:343:24: warning: ‘VectorAggregator<CBLSPublicKey>::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:337:18: warning: ‘VectorAggregator<CBLSPublicKey>::DoneCallback VectorAggregator<CBLSPublicKey>::doneCallback’ [-Wreorder] DoneCallback doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:494:235: required from here bls/bls_worker.cpp:136:24: warning: ‘Aggregator<CBLSSecretKey>::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:135:10: warning: ‘bool Aggregator<CBLSSecretKey>::parallel’ [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:152:5: warning: when initialized here [-Wreorder] Aggregator(const std::vector<TP>& _inputVec, ^~~~~~~~~~ * fix: compilation warnings bench/string_cast.cpp: In lambda function: bench/string_cast.cpp:22:13: warning: statement has no effect [-Wunused-value] atoi("1"); ~~~~^~~~~ * fix: compilation warnings ./llmq/dkgsessionhandler.h: In constructor ‘llmq::CDKGPendingMessages::CDKGPendingMessages(size_t, int)’: ./llmq/dkgsessionhandler.h:48:12: warning: ‘llmq::CDKGPendingMessages::maxMessagesPerNode’ will be initialized after [-Wreorder] size_t maxMessagesPerNode GUARDED_BY(cs); ^~~~~~~~~~~~~~~~~~ ./llmq/dkgsessionhandler.h:47:15: warning: ‘const int llmq::CDKGPendingMessages::invType’ [-Wreorder] const int invType; ^~~~~~~ llmq/dkgsessionhandler.cpp:23:1: warning: when initialized here [-Wreorder] CDKGPendingMessages::CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType) : ^~~~~~~~~~~~~~~~~~~ * fix: compilation warnings Not sure this one is correct, but I believe so. Seems like the `!= 0` is completely not needed rpc/masternode.cpp: In function ‘UniValue masternode_payments(const JSONRPCRequest&)’: rpc/masternode.cpp:442:31: warning: suggest parentheses around comparison in operand of ‘!=’ [-Wparentheses] while (vecPayments.size() < std::abs(nCount) != 0 && pindex != nullptr) { ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ * fix: compilation warnings test/cachemultimap_tests.cpp:14:13: warning: ‘void cachemultimap_tests::DumpMap(const CacheMultiMap<int, int>&)’ defined but not used [-Wunused-function] static void DumpMap(const CacheMultiMap<int,int>& cmmap) ^~~~~~~ * fix: compilation warnings In file included from qt/appearancewidget.cpp:11: ./qt/appearancewidget.h: In constructor ‘AppearanceWidget::AppearanceWidget(QWidget*)’: ./qt/appearancewidget.h:52:25: warning: ‘AppearanceWidget::prevFontFamily’ will be initialized after [-Wreorder] GUIUtil::FontFamily prevFontFamily; ^~~~~~~~~~~~~~ ./qt/appearancewidget.h:51:9: warning: ‘int AppearanceWidget::prevScale’ [-Wreorder] int prevScale; ^~~~~~~~~ qt/appearancewidget.cpp:21:1: warning: when initialized here [-Wreorder] AppearanceWidget::AppearanceWidget(QWidget* parent) : ^~~~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/bitcoingui.cpp:6: ./qt/bitcoingui.h: In constructor ‘BitcoinGUI::BitcoinGUI(interfaces::Node&, const NetworkStyle*, QWidget*)’: ./qt/bitcoingui.h:212:31: warning: ‘BitcoinGUI::m_network_style’ will be initialized after [-Wreorder] const NetworkStyle* const m_network_style; ^~~~~~~~~~~~~~~ ./qt/bitcoingui.h:172:34: warning: ‘const std::unique_ptr<QMenu> BitcoinGUI::trayIconMenu’ [-Wreorder] const std::unique_ptr<QMenu> trayIconMenu; ^~~~~~~~~~~~ qt/bitcoingui.cpp:81:1: warning: when initialized here [-Wreorder] BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle, QWidget* parent) : ^~~~~~~~~~ * fix: compilation warnings In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h: In constructor ‘MasternodeList::MasternodeList(QWidget*)’: ./qt/masternodelist.h:66:18: warning: ‘MasternodeList::walletModel’ will be initialized after [-Wreorder] WalletModel* walletModel; ^~~~~~~~~~~ ./qt/masternodelist.h:61:10: warning: ‘bool MasternodeList::fFilterUpdatedDIP3’ [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h:61:10: warning: ‘MasternodeList::fFilterUpdatedDIP3’ will be initialized after [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ ./qt/masternodelist.h:59:13: warning: ‘int64_t MasternodeList::nTimeFilterUpdatedDIP3’ [-Wreorder] int64_t nTimeFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/paymentserver.cpp:10: ./qt/paymentserver.h: In constructor ‘PaymentServer::PaymentServer(QObject*, bool)’: ./qt/paymentserver.h:156:28: warning: ‘PaymentServer::netManager’ will be initialized after [-Wreorder] QNetworkAccessManager* netManager; // Used to fetch payment requests ^~~~~~~~~~ ./qt/paymentserver.h:147:19: warning: ‘OptionsModel* PaymentServer::optionsModel’ [-Wreorder] OptionsModel *optionsModel; ^~~~~~~~~~~~ qt/paymentserver.cpp:197:1: warning: when initialized here [-Wreorder] PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : ^~~~~~~~~~~~~
2021-12-01 20:59:34 +01:00
size_t batchCount{1};
size_t verifyCount;
std::vector<BatchState> batchStates;
std::atomic<size_t> verifyDoneCount{0};
std::function<void(const std::vector<bool>&)> doneCallback;
ContributionVerifier(CBLSId _forId, const std::vector<BLSVerificationVectorPtr>& _vvecs,
const BLSSecretKeyVector& _skShares, size_t _batchSize,
bool _parallel, bool _aggregated, ctpl::thread_pool& _workerPool,
std::function<void(const std::vector<bool>&)> _doneCallback) :
forId(std::move(_forId)),
vvecs(_vvecs),
skShares(_skShares),
batchSize(_batchSize),
parallel(_parallel),
aggregated(_aggregated),
workerPool(_workerPool),
fix: resolve numerous compilation warnings under -Wall (#4599) * fix: compilation warnings ./validation.h:266:13: warning: ‘bool AcceptToMemoryPoolWithTime(const CChainParams&, CTxMemPool&, CValidationState&, const CTransactionRef&, bool*, int64_t, bool, CAmount, bool)’ declared ‘static’ but never defined [-Wunused-function] static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, ^~~~~~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings ./coinjoin/client.h: In constructor ‘CCoinJoinClientManager::CCoinJoinClientManager(CWallet&)’: ./coinjoin/client.h:199:10: warning: ‘CCoinJoinClientManager::fCreateAutoBackups’ will be initialized after [-Wreorder] bool fCreateAutoBackups; // builtin support for automatic backups ^~~~~~~~~~~~~~~~~~ ./coinjoin/client.h:187:14: warning: ‘CWallet& CCoinJoinClientManager::mixingWallet’ [-Wreorder] CWallet& mixingWallet; ^~~~~~~~~~~~ ./coinjoin/client.h:205:14: warning: when initialized here [-Wreorder] explicit CCoinJoinClientManager(CWallet& wallet) : ^~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings interfaces/wallet.cpp: In constructor ‘interfaces::{anonymous}::WalletImpl::WalletImpl(const std::shared_ptr<CWallet>&)’: interfaces/wallet.cpp:594:30: warning: ‘interfaces::{anonymous}::WalletImpl::m_wallet’ will be initialized after [-Wreorder] std::shared_ptr<CWallet> m_wallet; ^~~~~~~~ interfaces/wallet.cpp:191:18: warning: ‘interfaces::{anonymous}::CoinJoinImpl interfaces::{anonymous}::WalletImpl::m_coinjoin’ [-Wreorder] CoinJoinImpl m_coinjoin; ^~~~~~~~~~ interfaces/wallet.cpp:193:14: warning: when initialized here [-Wreorder] explicit WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_wallet(wallet), m_coinjoin(wallet) {} ^~~~~~~~~~ * fix: compilation warnings validation.cpp:165:13: warning: ‘void CheckBlockIndex(const Consensus::Params&)’ declared ‘static’ but never defined [-Wunused-function] static void CheckBlockIndex(const Consensus::Params& consensusParams); ^~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp: In constructor ‘ContributionVerifier::ContributionVerifier(CBLSId, const std::vector<std::shared_ptr<std::vector<CBLSPublicKey> > >&, const BLSSecretKeyVector&, size_t, bool, bool, ctpl::thread_pool&, std::function<void(const std::vector<bool>&)>)’: bls/bls_worker.cpp:425:51: warning: ‘ContributionVerifier::doneCallback’ will be initialized after [-Wreorder] std::function<void(const std::vector<bool>&)> doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:420:12: warning: ‘size_t ContributionVerifier::batchCount’ [-Wreorder] size_t batchCount; ^~~~~~~~~~ bls/bls_worker.cpp:427:5: warning: when initialized here [-Wreorder] ContributionVerifier(CBLSId _forId, const std::vector<BLSVerificationVectorPtr>& _vvecs, ^~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:342:10: warning: ‘VectorAggregator<CBLSPublicKey>::parallel’ will be initialized after [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:340:12: warning: ‘size_t VectorAggregator<CBLSPublicKey>::start’ [-Wreorder] size_t start; ^~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ bls/bls_worker.cpp:343:24: warning: ‘VectorAggregator<CBLSPublicKey>::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:337:18: warning: ‘VectorAggregator<CBLSPublicKey>::DoneCallback VectorAggregator<CBLSPublicKey>::doneCallback’ [-Wreorder] DoneCallback doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:494:235: required from here bls/bls_worker.cpp:136:24: warning: ‘Aggregator<CBLSSecretKey>::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:135:10: warning: ‘bool Aggregator<CBLSSecretKey>::parallel’ [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:152:5: warning: when initialized here [-Wreorder] Aggregator(const std::vector<TP>& _inputVec, ^~~~~~~~~~ * fix: compilation warnings bench/string_cast.cpp: In lambda function: bench/string_cast.cpp:22:13: warning: statement has no effect [-Wunused-value] atoi("1"); ~~~~^~~~~ * fix: compilation warnings ./llmq/dkgsessionhandler.h: In constructor ‘llmq::CDKGPendingMessages::CDKGPendingMessages(size_t, int)’: ./llmq/dkgsessionhandler.h:48:12: warning: ‘llmq::CDKGPendingMessages::maxMessagesPerNode’ will be initialized after [-Wreorder] size_t maxMessagesPerNode GUARDED_BY(cs); ^~~~~~~~~~~~~~~~~~ ./llmq/dkgsessionhandler.h:47:15: warning: ‘const int llmq::CDKGPendingMessages::invType’ [-Wreorder] const int invType; ^~~~~~~ llmq/dkgsessionhandler.cpp:23:1: warning: when initialized here [-Wreorder] CDKGPendingMessages::CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType) : ^~~~~~~~~~~~~~~~~~~ * fix: compilation warnings Not sure this one is correct, but I believe so. Seems like the `!= 0` is completely not needed rpc/masternode.cpp: In function ‘UniValue masternode_payments(const JSONRPCRequest&)’: rpc/masternode.cpp:442:31: warning: suggest parentheses around comparison in operand of ‘!=’ [-Wparentheses] while (vecPayments.size() < std::abs(nCount) != 0 && pindex != nullptr) { ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ * fix: compilation warnings test/cachemultimap_tests.cpp:14:13: warning: ‘void cachemultimap_tests::DumpMap(const CacheMultiMap<int, int>&)’ defined but not used [-Wunused-function] static void DumpMap(const CacheMultiMap<int,int>& cmmap) ^~~~~~~ * fix: compilation warnings In file included from qt/appearancewidget.cpp:11: ./qt/appearancewidget.h: In constructor ‘AppearanceWidget::AppearanceWidget(QWidget*)’: ./qt/appearancewidget.h:52:25: warning: ‘AppearanceWidget::prevFontFamily’ will be initialized after [-Wreorder] GUIUtil::FontFamily prevFontFamily; ^~~~~~~~~~~~~~ ./qt/appearancewidget.h:51:9: warning: ‘int AppearanceWidget::prevScale’ [-Wreorder] int prevScale; ^~~~~~~~~ qt/appearancewidget.cpp:21:1: warning: when initialized here [-Wreorder] AppearanceWidget::AppearanceWidget(QWidget* parent) : ^~~~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/bitcoingui.cpp:6: ./qt/bitcoingui.h: In constructor ‘BitcoinGUI::BitcoinGUI(interfaces::Node&, const NetworkStyle*, QWidget*)’: ./qt/bitcoingui.h:212:31: warning: ‘BitcoinGUI::m_network_style’ will be initialized after [-Wreorder] const NetworkStyle* const m_network_style; ^~~~~~~~~~~~~~~ ./qt/bitcoingui.h:172:34: warning: ‘const std::unique_ptr<QMenu> BitcoinGUI::trayIconMenu’ [-Wreorder] const std::unique_ptr<QMenu> trayIconMenu; ^~~~~~~~~~~~ qt/bitcoingui.cpp:81:1: warning: when initialized here [-Wreorder] BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle, QWidget* parent) : ^~~~~~~~~~ * fix: compilation warnings In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h: In constructor ‘MasternodeList::MasternodeList(QWidget*)’: ./qt/masternodelist.h:66:18: warning: ‘MasternodeList::walletModel’ will be initialized after [-Wreorder] WalletModel* walletModel; ^~~~~~~~~~~ ./qt/masternodelist.h:61:10: warning: ‘bool MasternodeList::fFilterUpdatedDIP3’ [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h:61:10: warning: ‘MasternodeList::fFilterUpdatedDIP3’ will be initialized after [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ ./qt/masternodelist.h:59:13: warning: ‘int64_t MasternodeList::nTimeFilterUpdatedDIP3’ [-Wreorder] int64_t nTimeFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/paymentserver.cpp:10: ./qt/paymentserver.h: In constructor ‘PaymentServer::PaymentServer(QObject*, bool)’: ./qt/paymentserver.h:156:28: warning: ‘PaymentServer::netManager’ will be initialized after [-Wreorder] QNetworkAccessManager* netManager; // Used to fetch payment requests ^~~~~~~~~~ ./qt/paymentserver.h:147:19: warning: ‘OptionsModel* PaymentServer::optionsModel’ [-Wreorder] OptionsModel *optionsModel; ^~~~~~~~~~~~ qt/paymentserver.cpp:197:1: warning: when initialized here [-Wreorder] PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : ^~~~~~~~~~~~~
2021-12-01 20:59:34 +01:00
verifyCount(_vvecs.size()),
doneCallback(std::move(_doneCallback))
{
}
void Start()
{
if (!aggregated) {
// treat all inputs as one large batch
batchSize = vvecs.size();
} else {
batchCount = (vvecs.size() + batchSize - 1) / batchSize;
}
batchStates.resize(batchCount);
for (size_t i = 0; i < batchCount; i++) {
auto& batchState = batchStates[i];
batchState.aggDone = std::make_unique<std::atomic<int>>(0);
batchState.start = i * batchSize;
batchState.count = std::min(batchSize, vvecs.size() - batchState.start);
batchState.verifyResults.assign(batchState.count, 0);
}
if (aggregated) {
size_t batchCount2 = batchCount; // 'this' might get deleted while we're still looping
for (size_t i = 0; i < batchCount2; i++) {
AsyncAggregate(i);
}
} else {
// treat all inputs as a single batch and verify one-by-one
AsyncVerifyBatchOneByOne(0);
}
}
void Finish()
{
size_t batchIdx = 0;
std::vector<bool> result(vvecs.size());
for (size_t i = 0; i < vvecs.size(); i += batchSize) {
auto& batchState = batchStates[batchIdx++];
for (size_t j = 0; j < batchState.count; j++) {
result[batchState.start + j] = batchState.verifyResults[j] != 0;
}
}
doneCallback(result);
}
void AsyncAggregate(size_t batchIdx)
{
auto& batchState = batchStates[batchIdx];
// aggregate vvecs and skShares of batch in parallel
auto self(this->shared_from_this());
auto vvecAgg = std::make_shared<VectorAggregator<CBLSPublicKey>>(vvecs, batchState.start, batchState.count, parallel, workerPool, [this, self, batchIdx] (const BLSVerificationVectorPtr& vvec) {HandleAggVvecDone(batchIdx, vvec);});
auto skShareAgg = std::make_shared<Aggregator<CBLSSecretKey>>(skShares, batchState.start, batchState.count, parallel, workerPool, [this, self, batchIdx] (const CBLSSecretKey& skShare) {HandleAggSkShareDone(batchIdx, skShare);});
vvecAgg->Start();
skShareAgg->Start();
}
void HandleAggVvecDone(size_t batchIdx, const BLSVerificationVectorPtr& vvec)
{
auto& batchState = batchStates[batchIdx];
batchState.vvec = vvec;
if (++(*batchState.aggDone) == 2) {
HandleAggDone(batchIdx);
}
}
void HandleAggSkShareDone(size_t batchIdx, const CBLSSecretKey& skShare)
{
auto& batchState = batchStates[batchIdx];
batchState.skShare = skShare;
if (++(*batchState.aggDone) == 2) {
HandleAggDone(batchIdx);
}
}
void HandleVerifyDone(size_t count)
{
size_t c = verifyDoneCount += count;
if (c == verifyCount) {
Finish();
}
}
void HandleAggDone(size_t batchIdx)
{
auto& batchState = batchStates[batchIdx];
if (batchState.vvec == nullptr || batchState.vvec->empty() || !batchState.skShare.IsValid()) {
// something went wrong while aggregating and there is nothing we can do now except mark the whole batch as failed
// this can only happen if inputs were invalid in some way
batchState.verifyResults.assign(batchState.count, 0);
HandleVerifyDone(batchState.count);
return;
}
AsyncAggregatedVerifyBatch(batchIdx);
}
void AsyncAggregatedVerifyBatch(size_t batchIdx)
{
auto self(this->shared_from_this());
auto f = [this, self, batchIdx](int threadId) {
auto& batchState = batchStates[batchIdx];
bool result = Verify(batchState.vvec, batchState.skShare);
if (result) {
// whole batch is valid
batchState.verifyResults.assign(batchState.count, 1);
HandleVerifyDone(batchState.count);
} else {
// at least one entry in the batch is invalid, revert to per-contribution verification (but parallelized)
AsyncVerifyBatchOneByOne(batchIdx);
}
};
PushOrDoWork(std::move(f));
}
void AsyncVerifyBatchOneByOne(size_t batchIdx)
{
size_t count = batchStates[batchIdx].count;
batchStates[batchIdx].verifyResults.assign(count, 0);
for (size_t i = 0; i < count; i++) {
auto self(this->shared_from_this());
auto f = [this, self, i, batchIdx](int threadId) {
auto& batchState = batchStates[batchIdx];
batchState.verifyResults[i] = Verify(vvecs[batchState.start + i], skShares[batchState.start + i]);
HandleVerifyDone(1);
};
PushOrDoWork(std::move(f));
}
}
bool Verify(const BLSVerificationVectorPtr& vvec, const CBLSSecretKey& skShare) const
{
CBLSPublicKey pk1;
if (!pk1.PublicKeyShare(*vvec, forId)) {
return false;
}
CBLSPublicKey pk2 = skShare.GetPublicKey();
return pk1 == pk2;
}
template <typename Callable>
void PushOrDoWork(Callable&& f)
{
if (parallel) {
workerPool.push(std::forward<Callable>(f));
} else {
f(0);
}
}
};
void CBLSWorker::AsyncBuildQuorumVerificationVector(const std::vector<BLSVerificationVectorPtr>& vvecs,
size_t start, size_t count, bool parallel,
std::function<void(const BLSVerificationVectorPtr&)> doneCallback)
{
if (start == 0 && count == 0) {
count = vvecs.size();
}
if (vvecs.empty() || count == 0 || start > vvecs.size() || start + count > vvecs.size()) {
doneCallback(nullptr);
return;
}
if (!VerifyVerificationVectors(vvecs, start, count)) {
doneCallback(nullptr);
return;
}
auto agg = std::make_shared<VectorAggregator<CBLSPublicKey>>(vvecs, start, count, parallel, workerPool, std::move(doneCallback));
agg->Start();
}
std::future<BLSVerificationVectorPtr> CBLSWorker::AsyncBuildQuorumVerificationVector(const std::vector<BLSVerificationVectorPtr>& vvecs,
size_t start, size_t count, bool parallel)
{
auto p = BuildFutureDoneCallback<BLSVerificationVectorPtr>();
AsyncBuildQuorumVerificationVector(vvecs, start, count, parallel, std::move(p.first));
return std::move(p.second);
}
BLSVerificationVectorPtr CBLSWorker::BuildQuorumVerificationVector(const std::vector<BLSVerificationVectorPtr>& vvecs,
size_t start, size_t count, bool parallel)
{
return AsyncBuildQuorumVerificationVector(vvecs, start, count, parallel).get();
}
template <typename T>
void AsyncAggregateHelper(ctpl::thread_pool& workerPool,
const std::vector<T>& vec, size_t start, size_t count, bool parallel,
std::function<void(const T&)> doneCallback)
{
if (start == 0 && count == 0) {
count = vec.size();
}
if (vec.empty() || count == 0 || start > vec.size() || start + count > vec.size()) {
doneCallback(T());
return;
}
if (!VerifyVectorHelper(vec, start, count)) {
doneCallback(T());
return;
}
auto agg = std::make_shared<Aggregator<T>>(vec, start, count, parallel, workerPool, std::move(doneCallback));
agg->Start();
}
void CBLSWorker::AsyncAggregateSecretKeys(const BLSSecretKeyVector& secKeys,
size_t start, size_t count, bool parallel,
std::function<void(const CBLSSecretKey&)> doneCallback)
{
AsyncAggregateHelper(workerPool, secKeys, start, count, parallel, std::move(doneCallback));
}
std::future<CBLSSecretKey> CBLSWorker::AsyncAggregateSecretKeys(const BLSSecretKeyVector& secKeys,
size_t start, size_t count, bool parallel)
{
auto p = BuildFutureDoneCallback<CBLSSecretKey>();
AsyncAggregateSecretKeys(secKeys, start, count, parallel, std::move(p.first));
return std::move(p.second);
}
CBLSSecretKey CBLSWorker::AggregateSecretKeys(const BLSSecretKeyVector& secKeys,
size_t start, size_t count, bool parallel)
{
return AsyncAggregateSecretKeys(secKeys, start, count, parallel).get();
}
void CBLSWorker::AsyncAggregatePublicKeys(const BLSPublicKeyVector& pubKeys,
size_t start, size_t count, bool parallel,
std::function<void(const CBLSPublicKey&)> doneCallback)
{
AsyncAggregateHelper(workerPool, pubKeys, start, count, parallel, std::move(doneCallback));
}
std::future<CBLSPublicKey> CBLSWorker::AsyncAggregatePublicKeys(const BLSPublicKeyVector& pubKeys,
size_t start, size_t count, bool parallel)
{
auto p = BuildFutureDoneCallback<CBLSPublicKey>();
AsyncAggregatePublicKeys(pubKeys, start, count, parallel, std::move(p.first));
return std::move(p.second);
}
void CBLSWorker::AsyncAggregateSigs(const BLSSignatureVector& sigs,
size_t start, size_t count, bool parallel,
std::function<void(const CBLSSignature&)> doneCallback)
{
AsyncAggregateHelper(workerPool, sigs, start, count, parallel, std::move(doneCallback));
}
std::future<CBLSSignature> CBLSWorker::AsyncAggregateSigs(const BLSSignatureVector& sigs,
size_t start, size_t count, bool parallel)
{
auto p = BuildFutureDoneCallback<CBLSSignature>();
AsyncAggregateSigs(sigs, start, count, parallel, std::move(p.first));
return std::move(p.second);
}
CBLSPublicKey CBLSWorker::BuildPubKeyShare(const BLSVerificationVectorPtr& vvec, const CBLSId& id)
{
CBLSPublicKey pkShare;
pkShare.PublicKeyShare(*vvec, id);
return pkShare;
}
void CBLSWorker::AsyncVerifyContributionShares(const CBLSId& forId, const std::vector<BLSVerificationVectorPtr>& vvecs, const BLSSecretKeyVector& skShares,
bool parallel, bool aggregated, std::function<void(const std::vector<bool>&)> doneCallback)
{
if (!forId.IsValid() || !VerifyVerificationVectors(vvecs)) {
std::vector<bool> result;
result.assign(vvecs.size(), false);
doneCallback(result);
return;
}
auto verifier = std::make_shared<ContributionVerifier>(forId, vvecs, skShares, 8, parallel, aggregated, workerPool, std::move(doneCallback));
verifier->Start();
}
std::future<std::vector<bool> > CBLSWorker::AsyncVerifyContributionShares(const CBLSId& forId, const std::vector<BLSVerificationVectorPtr>& vvecs, const BLSSecretKeyVector& skShares,
bool parallel, bool aggregated)
{
auto p = BuildFutureDoneCallback<std::vector<bool> >();
AsyncVerifyContributionShares(forId, vvecs, skShares, parallel, aggregated, std::move(p.first));
return std::move(p.second);
}
std::vector<bool> CBLSWorker::VerifyContributionShares(const CBLSId& forId, const std::vector<BLSVerificationVectorPtr>& vvecs, const BLSSecretKeyVector& skShares,
bool parallel, bool aggregated)
{
return AsyncVerifyContributionShares(forId, vvecs, skShares, parallel, aggregated).get();
}
std::future<bool> CBLSWorker::AsyncVerifyContributionShare(const CBLSId& forId,
const BLSVerificationVectorPtr& vvec,
const CBLSSecretKey& skContribution)
{
if (!forId.IsValid() || !VerifyVerificationVector(*vvec)) {
auto p = BuildFutureDoneCallback<bool>();
p.first(false);
return std::move(p.second);
}
auto f = [&forId, &vvec, &skContribution](int threadId) {
CBLSPublicKey pk1;
if (!pk1.PublicKeyShare(*vvec, forId)) {
return false;
}
CBLSPublicKey pk2 = skContribution.GetPublicKey();
return pk1 == pk2;
};
return workerPool.push(f);
}
bool CBLSWorker::VerifyVerificationVector(const BLSVerificationVector& vvec, size_t start, size_t count)
{
return VerifyVectorHelper(vvec, start, count);
}
bool CBLSWorker::VerifyVerificationVectors(const std::vector<BLSVerificationVectorPtr>& vvecs,
size_t start, size_t count)
{
if (start == 0 && count == 0) {
count = vvecs.size();
}
std::set<uint256> set;
for (size_t i = 0; i < count; i++) {
auto& vvec = vvecs[start + i];
if (vvec == nullptr) {
return false;
}
if (vvec->size() != vvecs[start]->size()) {
return false;
}
for (size_t j = 0; j < vvec->size(); j++) {
if (!(*vvec)[j].IsValid()) {
return false;
}
// check duplicates
if (!set.emplace((*vvec)[j].GetHash()).second) {
return false;
}
}
}
return true;
}
void CBLSWorker::AsyncSign(const CBLSSecretKey& secKey, const uint256& msgHash, const CBLSWorker::SignDoneCallback& doneCallback)
{
workerPool.push([secKey, msgHash, doneCallback](int threadId) {
doneCallback(secKey.Sign(msgHash));
});
}
void CBLSWorker::AsyncVerifySig(const CBLSSignature& sig, const CBLSPublicKey& pubKey, const uint256& msgHash,
CBLSWorker::SigVerifyDoneCallback doneCallback, CancelCond cancelCond)
{
if (!sig.IsValid() || !pubKey.IsValid()) {
doneCallback(false);
return;
}
std::unique_lock<std::mutex> l(sigVerifyMutex);
bool foundDuplicate = ranges::any_of(sigVerifyQueue, [&msgHash](const auto& job){
return job.msgHash == msgHash;
});
if (foundDuplicate) {
// batched/aggregated verification does not allow duplicate hashes, so we push what we currently have and start
// with a fresh batch
PushSigVerifyBatch();
}
sigVerifyQueue.emplace_back(std::move(doneCallback), std::move(cancelCond), sig, pubKey, msgHash);
if (sigVerifyBatchesInProgress == 0 || sigVerifyQueue.size() >= SIG_VERIFY_BATCH_SIZE) {
PushSigVerifyBatch();
}
}
std::future<bool> CBLSWorker::AsyncVerifySig(const CBLSSignature& sig, const CBLSPublicKey& pubKey, const uint256& msgHash, CancelCond cancelCond)
{
auto p = BuildFutureDoneCallback2<bool>();
AsyncVerifySig(sig, pubKey, msgHash, std::move(p.first), std::move(cancelCond));
return std::move(p.second);
}
bool CBLSWorker::IsAsyncVerifyInProgress()
{
std::unique_lock<std::mutex> l(sigVerifyMutex);
return sigVerifyBatchesInProgress != 0;
}
// sigVerifyMutex must be held while calling
void CBLSWorker::PushSigVerifyBatch()
{
auto f = [this](int threadId, const std::shared_ptr<std::vector<SigVerifyJob> >& _jobs) {
auto& jobs = *_jobs;
if (jobs.size() == 1) {
const auto& job = jobs[0];
if (!job.cancelCond()) {
bool valid = job.sig.VerifyInsecure(job.pubKey, job.msgHash);
job.doneCallback(valid);
}
std::unique_lock<std::mutex> l(sigVerifyMutex);
sigVerifyBatchesInProgress--;
if (!sigVerifyQueue.empty()) {
PushSigVerifyBatch();
}
return;
}
CBLSSignature aggSig;
std::vector<size_t> indexes;
std::vector<CBLSPublicKey> pubKeys;
std::vector<uint256> msgHashes;
indexes.reserve(jobs.size());
pubKeys.reserve(jobs.size());
msgHashes.reserve(jobs.size());
for (size_t i = 0; i < jobs.size(); i++) {
auto& job = jobs[i];
if (job.cancelCond()) {
continue;
}
if (pubKeys.empty()) {
aggSig = job.sig;
} else {
aggSig.AggregateInsecure(job.sig);
}
indexes.emplace_back(i);
pubKeys.emplace_back(job.pubKey);
msgHashes.emplace_back(job.msgHash);
}
if (!pubKeys.empty()) {
bool allValid = aggSig.VerifyInsecureAggregated(pubKeys, msgHashes);
if (allValid) {
for (size_t i = 0; i < pubKeys.size(); i++) {
jobs[indexes[i]].doneCallback(true);
}
} else {
// one or more sigs were not valid, revert to per-sig verification
// TODO this could be improved if we would cache pairing results in some way as the previous aggregated verification already calculated all the pairings for the hashes
for (size_t i = 0; i < pubKeys.size(); i++) {
const auto& job = jobs[indexes[i]];
bool valid = job.sig.VerifyInsecure(job.pubKey, job.msgHash);
job.doneCallback(valid);
}
}
}
std::unique_lock<std::mutex> l(sigVerifyMutex);
sigVerifyBatchesInProgress--;
if (!sigVerifyQueue.empty()) {
PushSigVerifyBatch();
}
};
auto batch = std::make_shared<std::vector<SigVerifyJob> >(std::move(sigVerifyQueue));
sigVerifyQueue.reserve(SIG_VERIFY_BATCH_SIZE);
sigVerifyBatchesInProgress++;
workerPool.push(f, batch);
}