From a5f3e1e2ee56e9a29515acc87a03e7701952b002 Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Mon, 29 Apr 2024 21:59:44 +0200 Subject: [PATCH] Tari: fill in merge mining hash and difficulty --- src/common.h | 5 ++-- src/merge_mining_client_tari.cpp | 49 +++++++++++++++++++------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/common.h b/src/common.h index 05dcae7..90355c3 100644 --- a/src/common.h +++ b/src/common.h @@ -219,8 +219,9 @@ struct #endif difficulty_type { - FORCEINLINE constexpr difficulty_type() : lo(0), hi(0) {} - FORCEINLINE constexpr difficulty_type(uint64_t a, uint64_t b) : lo(a), hi(b) {} + FORCEINLINE constexpr difficulty_type() noexcept : lo(0), hi(0) {} + 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 hi; diff --git a/src/merge_mining_client_tari.cpp b/src/merge_mining_client_tari.cpp index a6185f5..ca7d580 100644 --- a/src/merge_mining_client_tari.cpp +++ b/src/merge_mining_client_tari.cpp @@ -178,30 +178,41 @@ void MergeMiningClientTari::run() } } else { - bool aux_id_empty; - { - ReadLock lock2(m_chainParamsLock); - aux_id_empty = m_chainParams.aux_id.empty(); + const std::string& id = response.tari_unique_id(); + const std::string& mm_hash = response.merge_mining_hash(); + + bool ok = true; + + if (id.size() != HASH_SIZE) { + LOGERR(1, "Tari unique_id has invalid size (" << id.size() << ')'); + ok = false; } - if (aux_id_empty) { - const std::string& id = response.tari_unique_id(); - LOGINFO(1, m_hostStr << " uses chain_id " << log::LightCyan() << log::hex_buf(id.data(), id.size())); + if (mm_hash.size() != HASH_SIZE) { + LOGERR(1, "Tari merge mining hash has invalid size (" << mm_hash.size() << ')'); + ok = false; + } - if (id.size() == HASH_SIZE) { + if (ok) { + { 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() - << ", diff = " << response.miner_data().target_difficulty() - << ", reward = " << response.miner_data().reward() - << ", fees = " << response.miner_data().total_fees() - ); + if (m_chainParams.aux_id.empty()) { + LOGINFO(1, m_hostStr << " uses chain_id " << log::LightCyan() << log::hex_buf(id.data(), id.size())); + std::copy(id.begin(), id.end(), m_chainParams.aux_id.h); + } + + std::copy(mm_hash.begin(), mm_hash.end(), m_chainParams.aux_hash.h); + m_chainParams.aux_diff = static_cast(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(500'000'000 - duration_cast(high_resolution_clock::now() - t1).count(), 1'000'000);