Solo mining: added job timeout (default is 15 seconds)

It's important to update jobs frequently to get new transactions into the block template. See https://rucknium.me/posts/monero-pool-transaction-delay/ for more details.
This commit is contained in:
SChernykh 2023-01-28 19:42:02 +01:00
parent 0ed4b35cd3
commit e2c58126e9
8 changed files with 43 additions and 1 deletions

View file

@ -303,6 +303,18 @@ void xmrig::DaemonClient::onHttpData(const HttpData &data)
void xmrig::DaemonClient::onTimer(const Timer *)
{
if (m_pool.zmq_port() >= 0) {
m_prevHash = nullptr;
m_blocktemplateRequestHash = nullptr;
send(kGetHeight);
return;
}
if (Chrono::steadyMSecs() >= m_jobSteadyMs + m_pool.jobTimeout()) {
m_prevHash = nullptr;
m_blocktemplateRequestHash = nullptr;
}
if (m_state == ConnectingState) {
connect();
}
@ -352,7 +364,7 @@ void xmrig::DaemonClient::onResolved(const DnsRecords &records, int status, cons
bool xmrig::DaemonClient::isOutdated(uint64_t height, const char *hash) const
{
return m_job.height() != height || m_prevHash != hash;
return m_job.height() != height || m_prevHash != hash || Chrono::steadyMSecs() >= m_jobSteadyMs + m_pool.jobTimeout();
}
@ -468,6 +480,7 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value &params, int *code)
m_job = std::move(job);
m_blocktemplateStr = std::move(blocktemplate);
m_prevHash = Json::getString(params, "prev_hash");
m_jobSteadyMs = Chrono::steadyMSecs();
if (m_state == ConnectingState) {
setState(ConnectedState);
@ -596,6 +609,10 @@ void xmrig::DaemonClient::setState(SocketState state)
const uint64_t interval = std::max<uint64_t>(20, m_pool.pollInterval());
m_timer->start(interval, interval);
}
else {
const uint64_t t = m_pool.jobTimeout();
m_timer->start(t, t);
}
}
break;
@ -865,7 +882,12 @@ void xmrig::DaemonClient::ZMQParse()
// Clear previous hash and check daemon height to guarantee that xmrig will call get_block_template RPC later
// We can't call get_block_template directly because daemon is not ready yet
m_prevHash = nullptr;
m_blocktemplateRequestHash = nullptr;
send(kGetHeight);
const uint64_t t = m_pool.jobTimeout();
m_timer->stop();
m_timer->start(t, t);
}