From 9cd9055913a2de0f7be0f86ec5acfb1e0d79b1e5 Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Mon, 3 Jun 2024 17:31:18 +0200 Subject: [PATCH] Print merge mining status --- src/console_commands.cpp | 3 +++ src/merge_mining_client.h | 2 ++ src/merge_mining_client_json_rpc.cpp | 11 ++++++++ src/merge_mining_client_json_rpc.h | 2 ++ src/merge_mining_client_tari.cpp | 39 ++++++++++++++++++++++++++++ src/merge_mining_client_tari.h | 4 ++- src/p2pool.cpp | 9 +++++++ src/p2pool.h | 2 ++ src/side_chain.cpp | 1 + 9 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/console_commands.cpp b/src/console_commands.cpp index 1a03c99..ffff8d1 100644 --- a/src/console_commands.cpp +++ b/src/console_commands.cpp @@ -211,6 +211,9 @@ static void do_status(p2pool *m_pool, const char * /* args */) #ifdef WITH_RANDOMX m_pool->print_miner_status(); #endif + + m_pool->print_merge_mining_status(); + bkg_jobs_tracker.print_status(); if (p2p) { diff --git a/src/merge_mining_client.h b/src/merge_mining_client.h index e36d296..8988d6c 100644 --- a/src/merge_mining_client.h +++ b/src/merge_mining_client.h @@ -39,6 +39,8 @@ public: [[nodiscard]] virtual bool get_params(ChainParameters& out_params) const = 0; virtual void submit_solution(const BlockTemplate* block_tpl, const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector& blob, const std::vector& merkle_proof, uint32_t merkle_proof_path) = 0; + + virtual void print_status() const = 0; }; } // namespace p2pool diff --git a/src/merge_mining_client_json_rpc.cpp b/src/merge_mining_client_json_rpc.cpp index 31ab831..ef6350d 100644 --- a/src/merge_mining_client_json_rpc.cpp +++ b/src/merge_mining_client_json_rpc.cpp @@ -317,6 +317,17 @@ void MergeMiningClientJSON_RPC::submit_solution(const BlockTemplate* /*block_tpl }, &m_loop); } +void MergeMiningClientJSON_RPC::print_status() const +{ + ReadLock lock(m_lock); + + LOGINFO(0, "status" << + "\nHost = " << m_host << ':' << m_port << + "\nWallet = " << m_auxWallet << + "\nDifficulty = " << m_chainParams.aux_diff + ); +} + bool MergeMiningClientJSON_RPC::get_params(ChainParameters& out_params) const { ReadLock lock(m_lock); diff --git a/src/merge_mining_client_json_rpc.h b/src/merge_mining_client_json_rpc.h index f59d329..423c3fa 100644 --- a/src/merge_mining_client_json_rpc.h +++ b/src/merge_mining_client_json_rpc.h @@ -32,6 +32,8 @@ public: bool get_params(ChainParameters& out_params) const override; void submit_solution(const BlockTemplate* block_tpl, const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector& blob, const std::vector& merkle_proof, uint32_t merkle_proof_path) override; + void print_status() const override; + private: static void loop(void* data); diff --git a/src/merge_mining_client_tari.cpp b/src/merge_mining_client_tari.cpp index ac2d155..144c766 100644 --- a/src/merge_mining_client_tari.cpp +++ b/src/merge_mining_client_tari.cpp @@ -285,6 +285,45 @@ void MergeMiningClientTari::submit_solution(const BlockTemplate* block_tpl, cons } } +struct TariAmount +{ + explicit FORCEINLINE TariAmount(uint64_t data) : m_data(data) {} + + uint64_t m_data; +}; + +template<> struct log::Stream::Entry +{ + static NOINLINE void put(TariAmount value, Stream* wrapper) + { + constexpr uint64_t denomination = 1000000ULL; + + const int w = wrapper->getNumberWidth(); + + wrapper->setNumberWidth(1); + *wrapper << value.m_data / denomination << '.'; + + wrapper->setNumberWidth(6); + *wrapper << value.m_data % denomination << " Minotari"; + + wrapper->setNumberWidth(w); + } +}; + +void MergeMiningClientTari::print_status() const +{ + ReadLock lock(m_chainParamsLock); + + LOGINFO(0, "status" << + "\nHost = " << m_hostStr << + "\nWallet = " << m_auxWallet << + "\nHeight = " << m_tariJobParams.height << + "\nDifficulty = " << m_tariJobParams.diff << + "\nReward = " << TariAmount(m_tariJobParams.reward) << + "\nFees = " << TariAmount(m_tariJobParams.fees) + ); +} + void MergeMiningClientTari::run_wrapper(void* arg) { reinterpret_cast(arg)->run(); diff --git a/src/merge_mining_client_tari.h b/src/merge_mining_client_tari.h index 976ac75..0ce51c5 100644 --- a/src/merge_mining_client_tari.h +++ b/src/merge_mining_client_tari.h @@ -30,10 +30,12 @@ public: MergeMiningClientTari(p2pool* pool, std::string host, const std::string& wallet); ~MergeMiningClientTari() override; + static constexpr char TARI_PREFIX[] = "tari://"; + bool get_params(ChainParameters& out_params) const override; void submit_solution(const BlockTemplate* block_tpl, const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector& blob, const std::vector& merkle_proof, uint32_t merkle_proof_path) override; - static constexpr char TARI_PREFIX[] = "tari://"; + void print_status() const override; private: mutable uv_rwlock_t m_chainParamsLock; diff --git a/src/p2pool.cpp b/src/p2pool.cpp index 5a7e4d6..b3ea200 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -311,6 +311,15 @@ void p2pool::print_miner_status() } #endif +void p2pool::print_merge_mining_status() const +{ + ReadLock lock(m_mergeMiningClientsLock); + + for (IMergeMiningClient* client : m_mergeMiningClients) { + client->print_status(); + } +} + void p2pool::handle_tx(TxMempoolData& tx) { if (!tx.weight || !tx.fee) { diff --git a/src/p2pool.h b/src/p2pool.h index e455baf..73a3b21 100644 --- a/src/p2pool.h +++ b/src/p2pool.h @@ -80,6 +80,8 @@ public: void print_miner_status(); #endif + void print_merge_mining_status() const; + virtual void handle_tx(TxMempoolData& tx) override; virtual void handle_miner_data(MinerData& data) override; virtual void handle_chain_main(ChainMain& data, const char* extra) override; diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 1c41c4e..b46e874 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -2189,6 +2189,7 @@ void SideChain::prune_old_blocks() } m_pool->print_hosts(); + m_pool->print_merge_mining_status(); bkg_jobs_tracker.print_status(); m_pool->stop(); }