Tari: fill in merge mining hash and difficulty

This commit is contained in:
SChernykh 2024-04-29 21:59:44 +02:00
parent 5f62069590
commit a5f3e1e2ee
2 changed files with 33 additions and 21 deletions

View file

@ -219,8 +219,9 @@ struct
#endif #endif
difficulty_type difficulty_type
{ {
FORCEINLINE constexpr difficulty_type() : lo(0), hi(0) {} FORCEINLINE constexpr difficulty_type() noexcept : lo(0), hi(0) {}
FORCEINLINE constexpr difficulty_type(uint64_t a, uint64_t b) : lo(a), hi(b) {} FORCEINLINE explicit constexpr difficulty_type(uint64_t a) noexcept : lo(a), hi(0) {}
FORCEINLINE constexpr difficulty_type(uint64_t a, uint64_t b) noexcept : lo(a), hi(b) {}
uint64_t lo; uint64_t lo;
uint64_t hi; uint64_t hi;

View file

@ -178,30 +178,41 @@ void MergeMiningClientTari::run()
} }
} }
else { else {
bool aux_id_empty; const std::string& id = response.tari_unique_id();
{ const std::string& mm_hash = response.merge_mining_hash();
ReadLock lock2(m_chainParamsLock);
aux_id_empty = m_chainParams.aux_id.empty(); bool ok = true;
if (id.size() != HASH_SIZE) {
LOGERR(1, "Tari unique_id has invalid size (" << id.size() << ')');
ok = false;
} }
if (aux_id_empty) { if (mm_hash.size() != HASH_SIZE) {
const std::string& id = response.tari_unique_id(); LOGERR(1, "Tari merge mining hash has invalid size (" << mm_hash.size() << ')');
LOGINFO(1, m_hostStr << " uses chain_id " << log::LightCyan() << log::hex_buf(id.data(), id.size())); ok = false;
}
if (id.size() == HASH_SIZE) { if (ok) {
{
WriteLock lock2(m_chainParamsLock); WriteLock lock2(m_chainParamsLock);
std::copy(id.begin(), id.end(), m_chainParams.aux_id.h);
}
else {
LOGERR(1, "Tari unique_id has invalid size (" << id.size() << ')');
}
}
LOGINFO(6, "Tari block template: height = " << response.block().header().height() if (m_chainParams.aux_id.empty()) {
<< ", diff = " << response.miner_data().target_difficulty() LOGINFO(1, m_hostStr << " uses chain_id " << log::LightCyan() << log::hex_buf(id.data(), id.size()));
<< ", reward = " << response.miner_data().reward() std::copy(id.begin(), id.end(), m_chainParams.aux_id.h);
<< ", fees = " << response.miner_data().total_fees() }
);
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());
}
LOGINFO(6, "Tari block template: height = " << response.block().header().height()
<< ", diff = " << response.miner_data().target_difficulty()
<< ", reward = " << response.miner_data().reward()
<< ", fees = " << response.miner_data().total_fees()
<< ", hash = " << log::hex_buf(mm_hash.data(), mm_hash.size())
);
}
} }
const int64_t timeout = std::max<int64_t>(500'000'000 - duration_cast<nanoseconds>(high_resolution_clock::now() - t1).count(), 1'000'000); const int64_t timeout = std::max<int64_t>(500'000'000 - duration_cast<nanoseconds>(high_resolution_clock::now() - t1).count(), 1'000'000);