Fix: don't use outdated merge mining data
And warn the user in the log
This commit is contained in:
@@ -28,10 +28,17 @@ class IMergeMiningClient
|
||||
public:
|
||||
struct ChainParameters
|
||||
{
|
||||
ChainParameters() : last_updated(0) {}
|
||||
|
||||
enum {
|
||||
EXPIRE_TIME = 1800,
|
||||
};
|
||||
|
||||
hash aux_id;
|
||||
hash aux_hash;
|
||||
std::vector<uint8_t> aux_blob;
|
||||
difficulty_type aux_diff;
|
||||
uint64_t last_updated;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
@@ -281,6 +281,7 @@ bool MergeMiningClientJSON_RPC::parse_merge_mining_get_aux_block(const char* dat
|
||||
m_chainParams.aux_hash = h;
|
||||
m_chainParams.aux_diff.lo = result["aux_diff"].GetUint64();
|
||||
m_chainParams.aux_diff.hi = 0;
|
||||
m_chainParams.last_updated = seconds_since_epoch();
|
||||
|
||||
changed = true;
|
||||
|
||||
@@ -334,12 +335,19 @@ void MergeMiningClientJSON_RPC::print_status() const
|
||||
|
||||
bool MergeMiningClientJSON_RPC::get_params(ChainParameters& out_params) const
|
||||
{
|
||||
const uint64_t t = seconds_since_epoch();
|
||||
|
||||
ReadLock lock(m_lock);
|
||||
|
||||
if (m_chainParams.aux_id.empty() || m_chainParams.aux_diff.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t >= m_chainParams.last_updated + ChainParameters::EXPIRE_TIME) {
|
||||
LOGWARN(4, m_host << ':' << m_port << " merge mining data is outdated (" << (t - m_chainParams.last_updated) << " seconds old)");
|
||||
return false;
|
||||
}
|
||||
|
||||
out_params = m_chainParams;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -132,12 +132,19 @@ MergeMiningClientTari::~MergeMiningClientTari()
|
||||
|
||||
bool MergeMiningClientTari::get_params(ChainParameters& out_params) const
|
||||
{
|
||||
const uint64_t t = seconds_since_epoch();
|
||||
|
||||
ReadLock lock(m_chainParamsLock);
|
||||
|
||||
if (m_chainParams.aux_id.empty() || m_chainParams.aux_diff.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t >= m_chainParams.last_updated + ChainParameters::EXPIRE_TIME) {
|
||||
LOGWARN(4, m_hostStr << " merge mining data is outdated (" << (t - m_chainParams.last_updated) << " seconds old)");
|
||||
return false;
|
||||
}
|
||||
|
||||
out_params = m_chainParams;
|
||||
return true;
|
||||
}
|
||||
@@ -659,6 +666,7 @@ void MergeMiningClientTari::run()
|
||||
std::copy(mm_hash.begin(), mm_hash.end(), m_chainParams.aux_hash.h);
|
||||
|
||||
m_chainParams.aux_diff = static_cast<difficulty_type>(response.miner_data().target_difficulty());
|
||||
m_chainParams.last_updated = seconds_since_epoch();
|
||||
|
||||
m_tariBlock = response.block();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user