Integrate Tromp solver into miner code and remove its dependency on extra BLAKE2b implementation.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "miner.h"
|
||||
#include "pow/tromp/equi_miner.h"
|
||||
|
||||
#include "amount.h"
|
||||
#include "chainparams.h"
|
||||
@@ -453,6 +454,9 @@ void static BitcoinMiner(CWallet *pwallet)
|
||||
unsigned int n = chainparams.EquihashN();
|
||||
unsigned int k = chainparams.EquihashK();
|
||||
|
||||
std::string solver = GetArg("-equihashsolver", "default");
|
||||
LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k);
|
||||
|
||||
std::mutex m_cs;
|
||||
bool cancelSolver = false;
|
||||
boost::signals2::connection c = uiInterface.NotifyBlockTip.connect(
|
||||
@@ -524,8 +528,8 @@ void static BitcoinMiner(CWallet *pwallet)
|
||||
pblock->nNonce.size());
|
||||
|
||||
// (x_1, x_2, ...) = A(I, V, n, k)
|
||||
LogPrint("pow", "Running Equihash solver with nNonce = %s\n",
|
||||
pblock->nNonce.ToString());
|
||||
LogPrint("pow", "Running Equihash solver \"%s\" with nNonce = %s\n",
|
||||
solver, pblock->nNonce.ToString());
|
||||
|
||||
std::function<bool(std::vector<unsigned char>)> validBlock =
|
||||
[&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams]
|
||||
@@ -559,14 +563,48 @@ void static BitcoinMiner(CWallet *pwallet)
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
return cancelSolver;
|
||||
};
|
||||
try {
|
||||
// If we find a valid block, we rebuild
|
||||
if (EhOptimisedSolve(n, k, curr_state, validBlock, cancelled))
|
||||
break;
|
||||
} catch (EhSolverCancelledException&) {
|
||||
LogPrint("pow", "Equihash solver cancelled\n");
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
cancelSolver = false;
|
||||
|
||||
if (solver == "tromp") {
|
||||
// Create solver and initialize it.
|
||||
equi eq(1);
|
||||
eq.setstate(&curr_state);
|
||||
|
||||
// Intialization done, start algo driver.
|
||||
eq.digit0(0);
|
||||
eq.xfull = eq.bfull = eq.hfull = 0;
|
||||
eq.showbsizes(0);
|
||||
for (u32 r = 1; r < WK; r++) {
|
||||
(r&1) ? eq.digitodd(r, 0) : eq.digiteven(r, 0);
|
||||
eq.xfull = eq.bfull = eq.hfull = 0;
|
||||
eq.showbsizes(r);
|
||||
}
|
||||
eq.digitK(0);
|
||||
|
||||
// Convert solution indices to byte array (decompress) and pass it to validBlock method.
|
||||
for (size_t s = 0; s < eq.nsols; s++) {
|
||||
LogPrint("pow", "Checking solution %d\n", s+1);
|
||||
std::vector<eh_index> index_vector(PROOFSIZE);
|
||||
for (size_t i = 0; i < PROOFSIZE; i++) {
|
||||
index_vector[i] = eq.sols[s][i];
|
||||
}
|
||||
std::vector<unsigned char> sol_char = GetMinimalFromIndices(index_vector, DIGITBITS);
|
||||
|
||||
if (validBlock(sol_char)) {
|
||||
// If we find a POW solution, do not try other solutions
|
||||
// because they become invalid as we created a new block in blockchain.
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
// If we find a valid block, we rebuild
|
||||
if (EhOptimisedSolve(n, k, curr_state, validBlock, cancelled))
|
||||
break;
|
||||
} catch (EhSolverCancelledException&) {
|
||||
LogPrint("pow", "Equihash solver cancelled\n");
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
cancelSolver = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for stop or if block needs to be rebuilt
|
||||
|
||||
Reference in New Issue
Block a user