From eb3a3872ebc3a72f4bf10831605215e335fcbf26 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Thu, 12 May 2022 08:49:34 +0200 Subject: [PATCH] Fixed missing blocks download logic --- src/common.h | 2 ++ src/p2pool.cpp | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index e704946..5e507c6 100644 --- a/src/common.h +++ b/src/common.h @@ -209,6 +209,8 @@ struct difficulty_type FORCEINLINE double to_double() const { return static_cast(hi) * 18446744073709551616.0 + static_cast(lo); } + FORCEINLINE bool empty() const { return (lo == 0) && (hi == 0); } + // Finds a 64-bit target for mining (target = 2^64 / difficulty) and rounds up the result of division // Because of that, there's a very small chance that miners will find a hash that meets the target but is still wrong (hash * difficulty >= 2^256) // A proper difficulty check is in check_pow() diff --git a/src/p2pool.cpp b/src/p2pool.cpp index c88925f..e1e03fa 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -302,7 +302,8 @@ void p2pool::handle_miner_data(MinerData& data) WriteLock lock(m_mainchainLock); for (uint64_t h = data.height; h && (h + BLOCK_HEADERS_REQUIRED > data.height); --h) { - if (m_mainchainByHeight.find(h) == m_mainchainByHeight.end()) { + auto it = m_mainchainByHeight.find(h); + if ((it == m_mainchainByHeight.end()) || it->second.difficulty.empty()) { LOGWARN(3, "Mainchain data for height " << h << " is missing, requesting it from monerod again"); missing_heights.push_back(h); }