diff --git a/src/p2pool.cpp b/src/p2pool.cpp index 78a564a..c411270 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -596,13 +596,15 @@ void p2pool::submit_sidechain_block(uint32_t template_id, uint32_t nonce, uint32 m_blockTemplate->submit_sidechain_block(template_id, nonce, extra_nonce); } -void p2pool::update_block_template_async() +void p2pool::update_block_template_async(bool is_alternative_block) { // If p2pool is stopped, m_blockTemplateAsync is most likely already closed if (m_stopped) { return; } + m_isAlternativeBlock = is_alternative_block; + const int err = uv_async_send(&m_blockTemplateAsync); if (err) { LOGERR(1, "uv_async_send failed, error " << uv_err_name(err)); @@ -620,6 +622,16 @@ void p2pool::update_block_template() m_blockTemplate->update(data, *m_mempool, &m_params->m_wallet); stratum_on_block(); api_update_pool_stats(); + +#ifdef WITH_RANDOMX + if (m_isAlternativeBlock.exchange(false)) { + MutexLock lock(m_minerLock); + + if (m_miner) { + m_miner->reset_share_counters(); + } + } +#endif } void p2pool::download_block_headers(uint64_t current_height) @@ -1373,15 +1385,6 @@ void p2pool::stop_mining() m_miner = nullptr; } } - -void p2pool::reset_miner() -{ - MutexLock lock(m_minerLock); - - if (m_miner) { - m_miner->reset_share_counters(); - } -} #endif static void on_signal(uv_signal_t* handle, int signum) diff --git a/src/p2pool.h b/src/p2pool.h index 11c056e..6e044f1 100644 --- a/src/p2pool.h +++ b/src/p2pool.h @@ -77,7 +77,7 @@ public: void submit_block_async(const std::vector& blob); void submit_sidechain_block(uint32_t template_id, uint32_t nonce, uint32_t extra_nonce); - void update_block_template_async(); + void update_block_template_async(bool is_alternative_block = false); void update_block_template(); void download_block_headers(uint64_t current_height); @@ -91,7 +91,6 @@ public: #ifdef WITH_RANDOMX void start_mining(uint32_t threads); void stop_mining(); - void reset_miner(); #endif uint64_t zmq_last_active() const { return m_zmqLastActive; } @@ -198,6 +197,8 @@ private: uv_async_t m_blockTemplateAsync; uv_async_t m_stopAsync; + std::atomic m_isAlternativeBlock{ false }; + std::atomic m_zmqLastActive; uint64_t m_startTime; uv_async_t m_restartZMQAsync; diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 23805e0..a2042d3 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -1539,7 +1539,7 @@ void SideChain::update_chain_tip(const PoolBlock* block) block->m_wantBroadcast = true; if (m_pool) { - m_pool->update_block_template_async(); + m_pool->update_block_template_async(is_alternative); // Reset stratum share counters when switching to an alternative chain to avoid confusion if (is_alternative) { @@ -1547,9 +1547,6 @@ void SideChain::update_chain_tip(const PoolBlock* block) if (s) { s->reset_share_counters(); } -#ifdef WITH_RANDOMX - m_pool->reset_miner(); -#endif LOGINFO(0, log::LightCyan() << "SYNCHRONIZED"); } }