Make Equihash solvers cancellable

The miner only cancels the solver when chainActive.Tip() changes.

Closes #1055
This commit is contained in:
Jack Grigg
2016-07-20 19:06:49 +12:00
parent e117ff7651
commit 2dbabb1159
7 changed files with 83 additions and 36 deletions

View File

@@ -21,6 +21,7 @@
#ifdef ENABLE_WALLET
#include "crypto/equihash.h"
#include "wallet/wallet.h"
#include <functional>
#endif
#include "sodium.h"
@@ -519,7 +520,12 @@ void static BitcoinMiner(CWallet *pwallet)
LogPrint("pow", "Running Equihash solver with nNonce = %s\n",
pblock->nNonce.ToString());
std::set<std::vector<unsigned int>> solns;
EhOptimisedSolve(n, k, curr_state, solns);
try {
std::function<bool()> cancelled = [pindexPrev] { return pindexPrev != chainActive.Tip(); };
EhOptimisedSolve(n, k, curr_state, solns, cancelled);
} catch (EhSolverCancelledException&) {
LogPrint("pow", "Equihash solver cancelled\n");
}
LogPrint("pow", "Solutions: %d\n", solns.size());
// Write the solution to the hash and compute the result.