mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-03 17:29:24 +00:00
RandomX: try to recover after an error
This commit is contained in:
parent
8d65a99fe4
commit
bc0634a541
5 changed files with 32 additions and 12 deletions
|
@ -288,7 +288,7 @@ template<> struct log::Stream::Entry<const_buf>
|
||||||
|
|
||||||
struct hex_buf
|
struct hex_buf
|
||||||
{
|
{
|
||||||
FORCEINLINE hex_buf(const uint8_t* data, size_t size) : m_data(data), m_size(size) {}
|
FORCEINLINE hex_buf(const void* data, size_t size) : m_data(reinterpret_cast<const uint8_t*>(data)), m_size(size) {}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
explicit FORCEINLINE hex_buf(const T* data) : m_data(reinterpret_cast<const uint8_t*>(data)), m_size(sizeof(T)) {}
|
explicit FORCEINLINE hex_buf(const T* data) : m_data(reinterpret_cast<const uint8_t*>(data)), m_size(sizeof(T)) {}
|
||||||
|
|
|
@ -224,7 +224,16 @@ void Miner::run(WorkerData* data)
|
||||||
job[index].set_nonce(static_cast<uint32_t>(full_nonce), static_cast<uint32_t>(full_nonce >> 32));
|
job[index].set_nonce(static_cast<uint32_t>(full_nonce), static_cast<uint32_t>(full_nonce >> 32));
|
||||||
|
|
||||||
hash h;
|
hash h;
|
||||||
randomx_calculate_hash_next(vm, job[index].m_blob, job[index].m_blobSize, &h);
|
try {
|
||||||
|
randomx_calculate_hash_next(vm, job[index].m_blob, job[index].m_blobSize, &h);
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
LOGERR(0, "Failed to calculate RandomX hash: exception \"" << e.what() << "\". Is your CPU/RAM unstable?" <<
|
||||||
|
"\nFailed RandomX hash input: " << log::hex_buf(j.m_blob, j.m_blobSize));
|
||||||
|
|
||||||
|
// Make the result hash all FF's to fail difficulty checks
|
||||||
|
memset(h.h, -1, HASH_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
if (j.m_diff.check_pow(h)) {
|
if (j.m_diff.check_pow(h)) {
|
||||||
LOGINFO(0, log::Green() << "worker thread " << data->m_index << '/' << data->m_count << " found a mainchain block at height " << j.m_height << ", submitting it");
|
LOGINFO(0, log::Green() << "worker thread " << data->m_index << '/' << data->m_count << " found a mainchain block at height " << j.m_height << ", submitting it");
|
||||||
|
|
|
@ -1691,8 +1691,7 @@ int p2pool::run()
|
||||||
m_ZMQReader = nullptr;
|
m_ZMQReader = nullptr;
|
||||||
}
|
}
|
||||||
catch (const std::exception& e) {
|
catch (const std::exception& e) {
|
||||||
const char* s = e.what();
|
LOGERR(1, "exception " << e.what());
|
||||||
LOGERR(1, "exception " << s);
|
|
||||||
PANIC_STOP();
|
PANIC_STOP();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -393,8 +393,7 @@ int PoolBlock::deserialize(const uint8_t* data, size_t size, const SideChain& si
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception& e) {
|
catch (std::exception& e) {
|
||||||
const char* msg = e.what();
|
LOGERR(0, "Exception in PoolBlock::deserialize(): " << e.what());
|
||||||
LOGERR(0, "Exception in PoolBlock::deserialize(): " << (msg ? msg : "unknown exception"));
|
|
||||||
return __LINE__;
|
return __LINE__;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -322,6 +322,22 @@ void RandomX_Hasher::sync_wait()
|
||||||
ReadLock lock2(m_cacheLock);
|
ReadLock lock2(m_cacheLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool randomx_calculate_hash_safe(randomx_vm* machine, const void* input, size_t inputSize, void* output)
|
||||||
|
{
|
||||||
|
// Try to calculate the hash again if something went wrong the first time (for example, because of an unstable CPU)
|
||||||
|
for (size_t i = 0; i < 2; ++i) {
|
||||||
|
try {
|
||||||
|
randomx_calculate_hash(machine, input, inputSize, output);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
LOGERR(0, "Failed to calculate RandomX hash: exception \"" << e.what() << "\". Is your CPU/RAM unstable?" <<
|
||||||
|
"\nFailed RandomX hash input: " << log::hex_buf(input, inputSize));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool RandomX_Hasher::calculate(const void* data, size_t size, uint64_t /*height*/, const hash& seed, hash& result, bool force_light_mode)
|
bool RandomX_Hasher::calculate(const void* data, size_t size, uint64_t /*height*/, const hash& seed, hash& result, bool force_light_mode)
|
||||||
{
|
{
|
||||||
// First try to use the dataset if it's ready
|
// First try to use the dataset if it's ready
|
||||||
|
@ -335,8 +351,7 @@ bool RandomX_Hasher::calculate(const void* data, size_t size, uint64_t /*height*
|
||||||
MutexLock lock(m_vm[FULL_DATASET_VM].mutex);
|
MutexLock lock(m_vm[FULL_DATASET_VM].mutex);
|
||||||
|
|
||||||
if (m_vm[FULL_DATASET_VM].vm && (seed == m_seed[m_index])) {
|
if (m_vm[FULL_DATASET_VM].vm && (seed == m_seed[m_index])) {
|
||||||
randomx_calculate_hash(m_vm[FULL_DATASET_VM].vm, data, size, &result);
|
return randomx_calculate_hash_safe(m_vm[FULL_DATASET_VM].vm, data, size, &result);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,8 +365,7 @@ bool RandomX_Hasher::calculate(const void* data, size_t size, uint64_t /*height*
|
||||||
{
|
{
|
||||||
MutexLock lock2(m_vm[m_index].mutex);
|
MutexLock lock2(m_vm[m_index].mutex);
|
||||||
if (m_vm[m_index].vm && (seed == m_seed[m_index])) {
|
if (m_vm[m_index].vm && (seed == m_seed[m_index])) {
|
||||||
randomx_calculate_hash(m_vm[m_index].vm, data, size, &result);
|
return randomx_calculate_hash_safe(m_vm[m_index].vm, data, size, &result);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,8 +374,7 @@ bool RandomX_Hasher::calculate(const void* data, size_t size, uint64_t /*height*
|
||||||
MutexLock lock2(m_vm[prev_index].mutex);
|
MutexLock lock2(m_vm[prev_index].mutex);
|
||||||
|
|
||||||
if (m_vm[prev_index].vm && (seed == m_seed[prev_index])) {
|
if (m_vm[prev_index].vm && (seed == m_seed[prev_index])) {
|
||||||
randomx_calculate_hash(m_vm[prev_index].vm, data, size, &result);
|
return randomx_calculate_hash_safe(m_vm[prev_index].vm, data, size, &result);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue