Get closer to deciding if a block is valid in randomx solver
This commit is contained in:
@@ -986,6 +986,19 @@ CBlockIndex *get_chainactive(int32_t height)
|
||||
|
||||
int32_t gotinvalid;
|
||||
|
||||
class RandomXSolverCanceledException : public std::exception
|
||||
{
|
||||
virtual const char* what() const throw() {
|
||||
return "RandomX solver was canceled";
|
||||
}
|
||||
};
|
||||
|
||||
enum RandomXSolverCancelCheck
|
||||
{
|
||||
Reason1,
|
||||
Reason2
|
||||
};
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
void static RandomXMiner(CWallet *pwallet)
|
||||
#else
|
||||
@@ -1222,7 +1235,7 @@ void static RandomXMiner()
|
||||
h = UintToArith256(B.GetHash());
|
||||
//for (z=31; z>=0; z--)
|
||||
// fprintf(stderr,"%02x",((uint8_t *)&h)[z]);
|
||||
fprintf(stderr," Invalid block mined, try again\n");
|
||||
fprintf(stderr,"Invalid randomx block mined, try again\n");
|
||||
gotinvalid = 1;
|
||||
return(false);
|
||||
}
|
||||
@@ -1247,8 +1260,28 @@ void static RandomXMiner()
|
||||
}
|
||||
return true;
|
||||
};
|
||||
std::function<bool(RandomXSolverCancelCheck)> cancelled = [&m_cs, &cancelSolver](RandomXSolverCancelCheck pos) {
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
return cancelSolver;
|
||||
};
|
||||
// TODO: solver specific stuff
|
||||
// TODO: Convert solution indices to byte array (decompress) and pass it to validBlock method.
|
||||
try {
|
||||
// TODO: Convert solution to byte array (decompress) and pass it to validBlock method.
|
||||
std::vector<unsigned char> sol_char; // = GetMinimalFromIndices(index_vector, DIGITBITS);
|
||||
bool found = validBlock(sol_char);
|
||||
if (found) {
|
||||
LogPrintf("HushRandomXMiner found solution!\n");
|
||||
// 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 {
|
||||
fprintf(stderr,"HushRandomXMiner solution not found, validBlock=false");
|
||||
}
|
||||
} catch (RandomXSolverCanceledException&) {
|
||||
LogPrintf("HushRandomXMiner solver canceled\n");
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
cancelSolver = false;
|
||||
}
|
||||
|
||||
boost::this_thread::interruption_point();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user