From 0d439e77121a2c84f6cc95b6b5dc4e1cdfa7050f Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 13 Sep 2021 10:14:53 +0200 Subject: [PATCH] SideChain: submit blocks to monerod in more cases --- src/p2pool.cpp | 20 ++++++++++++++------ src/p2pool.h | 2 ++ src/side_chain.cpp | 10 ++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/p2pool.cpp b/src/p2pool.cpp index 35af7af..986907e 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -1004,12 +1004,7 @@ void p2pool::api_update_block_found(const ChainMain* data) const difficulty_type total_hashes = m_sideChain->total_hashes(); difficulty_type diff; - if (data) { - { - ReadLock lock(m_mainchainLock); - diff = m_mainchainByHeight[data->height].difficulty; - } - + if (data && get_difficulty_at_height(data->height, diff)) { std::ofstream f(FOUND_BLOCKS_FILE, std::ios::app); if (f.is_open()) { f << cur_time << ' ' << data->height << ' ' << data->id << ' ' << diff << ' ' << total_hashes << '\n'; @@ -1047,6 +1042,19 @@ void p2pool::api_update_block_found(const ChainMain* data) api_update_stats_mod(); } +bool p2pool::get_difficulty_at_height(uint64_t height, difficulty_type& diff) +{ + ReadLock lock(m_mainchainLock); + + auto it = m_mainchainByHeight.find(height); + if (it == m_mainchainByHeight.end()) { + return false; + } + + diff = it->second.difficulty; + return true; +} + static void on_signal(uv_signal_t* handle, int signum) { p2pool* pool = reinterpret_cast(handle->data); diff --git a/src/p2pool.h b/src/p2pool.h index a551e15..10d0e1a 100644 --- a/src/p2pool.h +++ b/src/p2pool.h @@ -74,6 +74,8 @@ public: void api_update_block_found(const ChainMain* data); + bool get_difficulty_at_height(uint64_t height, difficulty_type& diff); + private: p2pool(const p2pool&) = delete; p2pool(p2pool&&) = delete; diff --git a/src/side_chain.cpp b/src/side_chain.cpp index c1a2dda..6e8e44a 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -416,6 +416,16 @@ bool SideChain::add_external_block(PoolBlock& block, std::vector& missing_ LOGINFO(0, log::LightGreen() << "add_external_block: block " << block.m_sidechainId << " has enough PoW for Monero network, submitting it"); m_pool->submit_block_async(block.m_mainChainData); } + else { + difficulty_type diff; + if (!m_pool->get_difficulty_at_height(block.m_txinGenHeight, diff)) { + LOGWARN(3, "add_external_block: couldn't get mainchain difficulty for height = " << block.m_txinGenHeight); + } + else if (diff.check_pow(pow_hash)) { + LOGINFO(0, log::LightGreen() << "add_external_block: block " << block.m_sidechainId << " has enough PoW for Monero height " << block.m_txinGenHeight << ", submitting it"); + m_pool->submit_block_async(block.m_mainChainData); + } + } if (!block.m_difficulty.check_pow(pow_hash)) { LOGWARN(3, "add_external_block: not enough PoW for height = " << block.m_sidechainHeight << ", mainchain height " << block.m_txinGenHeight);