2424#include " spork.h"
2525#include " primitives/deterministicmint.h"
2626#include < boost/assign/list_of.hpp>
27+ #include < boost/thread/thread.hpp>
2728
2829#include < univalue.h>
2930
@@ -3412,9 +3413,37 @@ UniValue dzpivstate(const UniValue& params, bool fHelp) {
34123413 return obj;
34133414}
34143415
3416+
3417+ void static SearchThread (CzPIVWallet* zwallet, int nCountStart, int nCountEnd)
3418+ {
3419+ LogPrintf (" %s: start=%d end=%d\n " , __func__, nCountStart, nCountEnd);
3420+ try {
3421+ uint256 seedMaster = zwallet->GetMasterSeed ();
3422+ for (int i = nCountStart; i < nCountEnd; i++) {
3423+ boost::this_thread::interruption_point ();
3424+ CDataStream ss (SER_GETHASH, 0 );
3425+ ss << seedMaster << i;
3426+ uint512 zerocoinSeed = Hash512 (ss.begin (), ss.end ());
3427+
3428+ CBigNum bnValue;
3429+ CBigNum bnSerial;
3430+ CBigNum bnRandomness;
3431+ CKey key;
3432+ zwallet->SeedToZPIV (zerocoinSeed, bnValue, bnSerial, bnRandomness, key);
3433+
3434+ uint256 hashPubcoin = GetPubCoinHash (bnValue);
3435+ zwallet->AddToMintPool (make_pair (hashPubcoin, i));
3436+ }
3437+ } catch (std::exception& e) {
3438+ LogPrintf (" SearchThread() exception" );
3439+ } catch (...) {
3440+ LogPrintf (" SearchThread() exception" );
3441+ }
3442+ }
3443+
34153444UniValue searchdzpiv (const UniValue& params, bool fHelp )
34163445{
3417- if (fHelp || params.size () != 2 )
3446+ if (fHelp || params.size () != 3 )
34183447 throw runtime_error (
34193448 " searchdzpiv\n "
34203449 " \n Make an extended search for deterministically generated zPIV that have not yet been recognized by the wallet.\n " +
@@ -3423,9 +3452,10 @@ UniValue searchdzpiv(const UniValue& params, bool fHelp)
34233452 " \n Arguments\n "
34243453 " 1. \" count\" (numeric) Which sequential zPIV to start with.\n "
34253454 " 2. \" range\" (numeric) How many zPIV to generate.\n "
3455+ " 3. \" threads\" (numeric) How many threads should this operation consume.\n "
34263456
34273457 " \n Examples\n " +
3428- HelpExampleCli (" searchdzpiv" , " 1, 100" ) + HelpExampleRpc (" searchdzpiv" , " 1, 100" ));
3458+ HelpExampleCli (" searchdzpiv" , " 1, 100, 2 " ) + HelpExampleRpc (" searchdzpiv" , " 1, 100, 2 " ));
34293459
34303460 EnsureWalletIsUnlocked ();
34313461
@@ -3437,8 +3467,23 @@ UniValue searchdzpiv(const UniValue& params, bool fHelp)
34373467 if (nRange < 1 )
34383468 throw JSONRPCError (RPC_INVALID_PARAMETER, " Range has to be at least 1" );
34393469
3470+ int nThreads = params[2 ].get_int ();
3471+
34403472 CzPIVWallet* zwallet = pwalletMain->zwalletMain ;
3441- zwallet->GenerateMintPool (nCount, nRange);
3473+
3474+ boost::thread_group* dzpivThreads = new boost::thread_group ();
3475+ int nRangePerThread = nRange / nThreads;
3476+
3477+ int nPrevThreadEnd = nCount - 1 ;
3478+ for (int i = 0 ; i < nThreads; i++) {
3479+ int nStart = nPrevThreadEnd + 1 ;;
3480+ int nEnd = nStart + nRangePerThread;
3481+ nPrevThreadEnd = nEnd;
3482+ dzpivThreads->create_thread (boost::bind (&SearchThread, zwallet, nStart, nEnd));
3483+ }
3484+
3485+ dzpivThreads->join_all ();
3486+
34423487 CzPIVTracker* tracker = pwalletMain->zpivTracker ;
34433488 zwallet->RemoveMintsFromPool (tracker->GetSerialHashes ());
34443489 zwallet->SyncWithChain (false );
0 commit comments