2022-06-08 01:36:46 +02:00
// Copyright (c) 2018-2022 The Dash Core developers
2018-05-24 13:51:48 +02:00
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2020-03-19 23:46:56 +01:00
# include <bls/bls_worker.h>
# include <hash.h>
# include <serialize.h>
2018-05-24 13:51:48 +02:00
2021-12-21 13:05:29 +01:00
# include <util/ranges.h>
2021-06-27 08:33:13 +02:00
# include <util/system.h>
2018-05-24 13:51:48 +02:00
2021-04-23 00:26:22 +02:00
# include <memory>
# include <utility>
2018-05-24 13:51:48 +02:00
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 ( ) ) ;
}
/////
2021-06-06 22:43:44 +02:00
CBLSWorker : : CBLSWorker ( ) = default ;
2018-05-24 13:51:48 +02:00
CBLSWorker : : ~ CBLSWorker ( )
{
Stop ( ) ;
}
2019-04-01 13:10:39 +02:00
void CBLSWorker : : Start ( )
{
int workerCount = std : : thread : : hardware_concurrency ( ) / 2 ;
workerCount = std : : max ( std : : min ( 1 , workerCount ) , 4 ) ;
workerPool . resize ( workerCount ) ;
2021-08-24 18:18:52 +02:00
RenameThreadPool ( workerPool , " bls-work " ) ;
2019-04-01 13:10:39 +02:00
}
2018-05-24 13:51:48 +02:00
void CBLSWorker : : Stop ( )
{
workerPool . clear_queue ( ) ;
workerPool . stop ( true ) ;
}
2020-08-27 11:51:31 +02:00
bool CBLSWorker : : GenerateContributions ( int quorumThreshold , const BLSIdVector & ids , BLSVerificationVectorPtr & vvecRet , BLSSecretKeyVector & skSharesRet )
2018-05-24 13:51:48 +02:00
{
2021-12-12 14:37:26 +01:00
auto svec = BLSSecretKeyVector ( ( size_t ) quorumThreshold ) ;
2018-05-24 13:51:48 +02:00
vvecRet = std : : make_shared < BLSVerificationVector > ( ( size_t ) quorumThreshold ) ;
2020-08-27 11:51:31 +02:00
skSharesRet . resize ( ids . size ( ) ) ;
2018-05-24 13:51:48 +02:00
for ( int i = 0 ; i < quorumThreshold ; i + + ) {
2021-12-12 14:37:26 +01:00
svec [ i ] . MakeNewKey ( ) ;
2018-05-24 13:51:48 +02:00
}
size_t batchSize = 8 ;
2021-12-12 14:37:26 +01:00
std : : vector < std : : future < bool > > futures ;
futures . reserve ( ( quorumThreshold / batchSize + ids . size ( ) / batchSize ) + 2 ) ;
2018-05-24 13:51:48 +02:00
2022-02-11 17:15:26 +01:00
for ( size_t i = 0 ; i < size_t ( quorumThreshold ) ; i + = batchSize ) {
2018-05-24 13:51:48 +02:00
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 + + ) {
2021-12-12 14:37:26 +01:00
( * vvecRet ) [ j ] = svec [ j ] . GetPublicKey ( ) ;
2018-05-24 13:51:48 +02:00
}
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 + + ) {
2021-12-12 14:37:26 +01:00
if ( ! skSharesRet [ j ] . SecretKeyShare ( svec , ids [ j ] ) ) {
2018-05-24 13:51:48 +02:00
return false ;
}
}
return true ;
} ;
futures . emplace_back ( workerPool . push ( f ) ) ;
}
2021-12-21 13:05:29 +01:00
return ranges : : all_of ( futures , [ ] ( auto & f ) {
2021-12-12 14:37:26 +01:00
return f . get ( ) ;
} ) ;
2018-05-24 13:51:48 +02:00
}
// 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.
2021-07-31 20:29:12 +02:00
// The Aggregator object needs to be created on the heap, and it will delete itself after calling the doneCallback
2018-05-24 13:51:48 +02:00
// 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 >
2021-07-12 05:25:27 +02:00
struct Aggregator : public std : : enable_shared_from_this < Aggregator < T > > {
2018-05-24 13:51:48 +02:00
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)
2021-07-12 05:25:27 +02:00
ctpl : : detail : : Queue < T * > aggQueue ;
2018-05-24 13:51:48 +02:00
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 } ;
2021-10-05 23:26:29 +02:00
using DoneCallback = std : : function < void ( const T & agg ) > ;
2018-05-24 13:51:48 +02:00
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 ) :
2022-02-11 17:15:26 +01:00
inputVec ( std : : make_shared < std : : vector < const T * > > ( count ) ) ,
2018-05-24 13:51:48 +02:00
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 ) ,
2022-02-11 17:15:26 +01:00
doneCallback ( std : : move ( _doneCallback ) )
2018-05-24 13:51:48 +02:00
{
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.
2021-07-12 05:25:27 +02:00
auto self ( this - > shared_from_this ( ) ) ;
PushWork ( [ this , self ] ( int threadId ) {
2018-05-24 13:51:48 +02:00
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 ) ;
}
2021-07-12 05:25:27 +02:00
void AsyncAggregateAndPushAggQueue ( const std : : shared_ptr < std : : vector < const T * > > & vec , size_t start , size_t count , bool del )
2018-05-24 13:51:48 +02:00
{
IncWait ( ) ;
2021-07-12 05:25:27 +02:00
auto self ( this - > shared_from_this ( ) ) ;
PushWork ( [ self , vec , start , count , del ] ( int threadId ) {
self - > SyncAggregateAndPushAggQueue ( vec , start , count , del ) ;
} ) ;
2018-05-24 13:51:48 +02:00
}
2021-07-12 05:25:27 +02:00
void SyncAggregateAndPushAggQueue ( const std : : shared_ptr < std : : vector < const T * > > & vec , size_t start , size_t count , bool del )
2018-05-24 13:51:48 +02:00
{
// 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 )
{
2022-08-05 19:13:42 +02:00
auto copyT = new T ( v ) ;
try {
aggQueue . push ( copyT ) ;
} catch ( . . . ) {
delete copyT ;
throw ;
}
2018-05-24 13:51:48 +02:00
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 >
2021-07-12 05:25:27 +02:00
struct VectorAggregator : public std : : enable_shared_from_this < VectorAggregator < T > > {
2021-10-05 23:26:29 +02:00
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 ) > ;
2018-05-24 13:51:48 +02:00
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 } ;
2018-05-24 13:51:48 +02:00
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 ) ) ,
2018-05-24 13:51:48 +02:00
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 )
2018-05-24 13:51:48 +02:00
{
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 ] ;
}
2021-07-12 05:25:27 +02:00
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 ( ) ;
2018-05-24 13:51:48 +02:00
}
}
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
2021-07-12 05:25:27 +02:00
struct ContributionVerifier : public std : : enable_shared_from_this < ContributionVerifier > {
2018-05-24 13:51:48 +02:00
struct BatchState {
size_t start ;
size_t count ;
BLSVerificationVectorPtr vvec ;
CBLSSecretKey skShare ;
2021-04-15 20:16:44 +02:00
// starts with 0 and is incremented if either vvec or skShare aggregation finishes. If it reaches 2, we know
2018-05-24 13:51:48 +02:00
// 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)
2021-04-15 20:16:44 +02:00
// so we must use vector<char> temporarily and concatenate/convert
2018-05-24 13:51:48 +02:00
// 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 } ;
2018-05-24 13:51:48 +02:00
size_t verifyCount ;
std : : vector < BatchState > batchStates ;
std : : atomic < size_t > verifyDoneCount { 0 } ;
std : : function < void ( const std : : vector < bool > & ) > doneCallback ;
2021-04-23 00:26:22 +02:00
ContributionVerifier ( CBLSId _forId , const std : : vector < BLSVerificationVectorPtr > & _vvecs ,
2018-05-24 13:51:48 +02:00
const BLSSecretKeyVector & _skShares , size_t _batchSize ,
bool _parallel , bool _aggregated , ctpl : : thread_pool & _workerPool ,
std : : function < void ( const std : : vector < bool > & ) > _doneCallback ) :
2021-04-23 00:26:22 +02:00
forId ( std : : move ( _forId ) ) ,
2018-05-24 13:51:48 +02:00
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 ) )
2018-05-24 13:51:48 +02:00
{
}
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 ] ;
2021-04-23 00:26:22 +02:00
batchState . aggDone = std : : make_unique < std : : atomic < int > > ( 0 ) ;
2018-05-24 13:51:48 +02:00
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
2021-07-12 05:25:27 +02:00
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 ) ; } ) ;
2018-05-24 13:51:48 +02:00
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 ) ;
}
}
2021-06-06 22:43:44 +02:00
void HandleVerifyDone ( size_t count )
2018-05-24 13:51:48 +02:00
{
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 ) ;
2021-06-06 22:43:44 +02:00
HandleVerifyDone ( batchState . count ) ;
2018-05-24 13:51:48 +02:00
return ;
}
AsyncAggregatedVerifyBatch ( batchIdx ) ;
}
void AsyncAggregatedVerifyBatch ( size_t batchIdx )
{
2021-07-12 05:25:27 +02:00
auto self ( this - > shared_from_this ( ) ) ;
auto f = [ this , self , batchIdx ] ( int threadId ) {
2018-05-24 13:51:48 +02:00
auto & batchState = batchStates [ batchIdx ] ;
bool result = Verify ( batchState . vvec , batchState . skShare ) ;
if ( result ) {
// whole batch is valid
batchState . verifyResults . assign ( batchState . count , 1 ) ;
2021-06-06 22:43:44 +02:00
HandleVerifyDone ( batchState . count ) ;
2018-05-24 13:51:48 +02:00
} 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 + + ) {
2021-07-12 05:25:27 +02:00
auto self ( this - > shared_from_this ( ) ) ;
auto f = [ this , self , i , batchIdx ] ( int threadId ) {
2018-05-24 13:51:48 +02:00
auto & batchState = batchStates [ batchIdx ] ;
batchState . verifyResults [ i ] = Verify ( vvecs [ batchState . start + i ] , skShares [ batchState . start + i ] ) ;
2021-06-06 22:43:44 +02:00
HandleVerifyDone ( 1 ) ;
2018-05-24 13:51:48 +02:00
} ;
PushOrDoWork ( std : : move ( f ) ) ;
}
}
2021-04-15 20:16:44 +02:00
bool Verify ( const BLSVerificationVectorPtr & vvec , const CBLSSecretKey & skShare ) const
2018-05-24 13:51:48 +02:00
{
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 ) {
2021-04-15 20:16:44 +02:00
workerPool . push ( std : : forward < Callable > ( f ) ) ;
2018-05-24 13:51:48 +02:00
} 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 ;
}
2021-07-12 05:25:27 +02:00
auto agg = std : : make_shared < VectorAggregator < CBLSPublicKey > > ( vvecs , start , count , parallel , workerPool , std : : move ( doneCallback ) ) ;
2018-05-24 13:51:48 +02:00
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 ;
}
2021-07-12 05:25:27 +02:00
auto agg = std : : make_shared < Aggregator < T > > ( vec , start , count , parallel , workerPool , std : : move ( doneCallback ) ) ;
2018-05-24 13:51:48 +02:00
agg - > Start ( ) ;
}
void CBLSWorker : : AsyncAggregateSecretKeys ( const BLSSecretKeyVector & secKeys ,
size_t start , size_t count , bool parallel ,
std : : function < void ( const CBLSSecretKey & ) > doneCallback )
{
2021-04-15 20:16:44 +02:00
AsyncAggregateHelper ( workerPool , secKeys , start , count , parallel , std : : move ( doneCallback ) ) ;
2018-05-24 13:51:48 +02:00
}
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 )
{
2021-04-15 20:16:44 +02:00
AsyncAggregateHelper ( workerPool , pubKeys , start , count , parallel , std : : move ( doneCallback ) ) ;
2018-05-24 13:51:48 +02:00
}
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 )
{
2021-04-15 20:16:44 +02:00
AsyncAggregateHelper ( workerPool , sigs , start , count , parallel , std : : move ( doneCallback ) ) ;
2018-05-24 13:51:48 +02:00
}
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 ;
}
2021-07-12 05:25:27 +02:00
auto verifier = std : : make_shared < ContributionVerifier > ( forId , vvecs , skShares , 8 , parallel , aggregated , workerPool , std : : move ( doneCallback ) ) ;
2018-05-24 13:51:48 +02:00
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 ) ;
}
2021-06-06 22:43:44 +02:00
auto f = [ & forId , & vvec , & skContribution ] ( int threadId ) {
2018-05-24 13:51:48 +02:00
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 ;
}
2021-04-15 20:16:44 +02:00
void CBLSWorker : : AsyncSign ( const CBLSSecretKey & secKey , const uint256 & msgHash , const CBLSWorker : : SignDoneCallback & doneCallback )
2018-05-24 13:51:48 +02:00
{
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 ) ;
2021-12-21 13:05:29 +01:00
bool foundDuplicate = ranges : : any_of ( sigVerifyQueue , [ & msgHash ] ( const auto & job ) {
return job . msgHash = = msgHash ;
} ) ;
2018-05-24 13:51:48 +02:00
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 > ( ) ;
2021-04-15 20:16:44 +02:00
AsyncVerifySig ( sig , pubKey , msgHash , std : : move ( p . first ) , std : : move ( cancelCond ) ) ;
2018-05-24 13:51:48 +02:00
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 ( )
{
2021-04-15 20:16:44 +02:00
auto f = [ this ] ( int threadId , const std : : shared_ptr < std : : vector < SigVerifyJob > > & _jobs ) {
2018-05-24 13:51:48 +02:00
auto & jobs = * _jobs ;
if ( jobs . size ( ) = = 1 ) {
2021-07-31 20:29:12 +02:00
const auto & job = jobs [ 0 ] ;
2018-05-24 13:51:48 +02:00
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 + + ) {
2021-07-31 20:29:12 +02:00
const auto & job = jobs [ indexes [ i ] ] ;
2018-05-24 13:51:48 +02:00
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 ) ;
}