Miner: reset share counter when synchronized

This commit is contained in:
SChernykh 2022-06-30 12:13:17 +02:00
parent a1d1420ec3
commit deaf47155f
5 changed files with 27 additions and 5 deletions

View file

@ -112,7 +112,7 @@ void Miner::on_block(const BlockTemplate& block)
const double time_running = static_cast<double>(duration_cast<milliseconds>(cur_ts - m_startTimestamp).count()) / 1e3;
s << "{\"current_hashrate\":" << hr
<< ",\"total_hashes\":" << m_totalHashes
<< ",\"total_hashes\":" << m_totalHashes.load()
<< ",\"time_running\":" << time_running
<< ",\"shares_found\":" << m_sharesFound.load()
<< ",\"block_reward_share_percent\":" << block_reward_share_percent
@ -122,6 +122,12 @@ void Miner::on_block(const BlockTemplate& block)
}
}
void Miner::reset_share_counters()
{
m_totalHashes = 0;
m_sharesFound = 0;
}
void Miner::run(void* data)
{
WorkerData* d = static_cast<WorkerData*>(data);

View file

@ -33,6 +33,7 @@ public:
void print_status();
void on_block(const BlockTemplate& block);
void reset_share_counters();
private:
static void run(void* data);
@ -57,7 +58,7 @@ private:
std::chrono::high_resolution_clock::time_point m_nonceTimestamp;
const uint32_t m_extraNonce;
uint64_t m_totalHashes;
std::atomic<uint64_t> m_totalHashes;
std::atomic<uint32_t> m_sharesFound;
struct Job

View file

@ -1348,6 +1348,15 @@ 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)

View file

@ -91,6 +91,7 @@ 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; }

View file

@ -1475,9 +1475,14 @@ void SideChain::update_chain_tip(PoolBlock* block)
m_pool->update_block_template_async();
// Reset stratum share counters when switching to an alternative chain to avoid confusion
StratumServer* s = m_pool->stratum_server();
if (s && is_alternative) {
s->reset_share_counters();
if (is_alternative) {
StratumServer* s = m_pool->stratum_server();
if (s) {
s->reset_share_counters();
}
#ifdef WITH_RANDOMX
m_pool->reset_miner();
#endif
LOGINFO(0, log::LightCyan() << "SYNCHRONIZED");
}
}