From 336349e1891deb257207c687f496e84563c96de9 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 25 Aug 2021 11:13:38 +0200 Subject: [PATCH] Show hashrate estimate in status --- src/block_template.cpp | 3 +++ src/block_template.h | 2 ++ src/log.h | 21 ++++++++++++++------- src/side_chain.cpp | 10 +++++++++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/block_template.cpp b/src/block_template.cpp index 1102a40..fb1aa9a 100644 --- a/src/block_template.cpp +++ b/src/block_template.cpp @@ -51,6 +51,7 @@ BlockTemplate::BlockTemplate(p2pool* pool) , m_seedHash{} , m_timestamp(0) , m_poolBlockTemplate(new PoolBlock()) + , m_finalReward(0) , m_nextPayout(0) { uv_rwlock_init_checked(&m_lock); @@ -121,6 +122,7 @@ BlockTemplate& BlockTemplate::operator=(const BlockTemplate& b) m_txkeyPub = b.m_txkeyPub; m_txkeySec = b.m_txkeySec; *m_poolBlockTemplate = *b.m_poolBlockTemplate; + m_finalReward = b.m_finalReward; m_nextPayout = b.m_nextPayout; m_minerTx.clear(); @@ -414,6 +416,7 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, Wallet return; } + m_finalReward = final_reward; m_nextPayout = 0; for (size_t i = 0, n = m_shares.size(); i < n; ++i) { if (*m_shares[i].m_wallet == m_pool->params().m_wallet) { diff --git a/src/block_template.h b/src/block_template.h index 2dace29..1a8f890 100644 --- a/src/block_template.h +++ b/src/block_template.h @@ -54,6 +54,7 @@ public: void submit_sidechain_block(uint32_t template_id, uint32_t nonce, uint32_t extra_nonce); + FORCEINLINE uint64_t final_reward() const { return m_finalReward; } FORCEINLINE uint64_t next_payout() const { return m_nextPayout; } private: @@ -95,6 +96,7 @@ private: BlockTemplate* m_oldTemplates[4] = {}; + uint64_t m_finalReward; uint64_t m_nextPayout; // Temp vectors, will be cleaned up after use and skipped in copy constructor/assignment operators diff --git a/src/log.h b/src/log.h index 7099d20..4cc194d 100644 --- a/src/log.h +++ b/src/log.h @@ -308,16 +308,23 @@ template<> struct log::Stream::Entry static constexpr const char* units[] = { "H/s", "KH/s", "MH/s", "GH/s", "TH/s", "PH/s", "EH/s" }; - size_t k = 0; - double magnitude = 1.0; + int n; + char buf[32]; + if (value.m_data < 1000) { + n = snprintf(buf, sizeof(buf), "%u %s", static_cast(value.m_data), units[0]); + } + else { + size_t k = 0; + double magnitude = 1.0; - while ((x >= magnitude * 1e3) && (k < array_size(units) - 1)) { - magnitude *= 1e3; - ++k; + while ((x >= magnitude * 1e3) && (k < array_size(units) - 1)) { + magnitude *= 1e3; + ++k; + } + + n = snprintf(buf, sizeof(buf), "%.3f %s", x / magnitude, units[k]); } - char buf[32]; - int n = snprintf(buf, sizeof(buf), "%.3f %s", x / magnitude, units[k]); if (n > 0) { if (n > static_cast(sizeof(buf)) - 1) { n = static_cast(sizeof(buf)) - 1; diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 496a8c3..34314cc 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -615,14 +615,22 @@ void SideChain::print_status() } } + const uint64_t block_reward = m_pool->block_template().final_reward(); + const uint64_t next_payout = m_pool->block_template().next_payout(); + + uint64_t product[2]; + product[0] = umul128(pool_hashrate, next_payout, &product[1]); + const uint64_t hashrate_est = udiv128(product[1], product[0], block_reward, &rem); + LOGINFO(0, "status" << "\nMain chain height = " << m_pool->block_template().height() << "\nMain chain hashrate = " << log::Hashrate(network_hashrate) << "\nSide chain height = " << tip_height + 1 << "\nSide chain hashrate = " << log::Hashrate(pool_hashrate) << + "\nYour hashrate (est) = " << log::Hashrate(hashrate_est) << "\nPPLNS window = " << total_blocks_in_window << " blocks (+" << total_uncles_in_window << " uncles, " << total_orphans << " orphans)" "\nYour shares = " << our_blocks_in_window << " blocks (+" << our_uncles_in_window << " uncles, " << our_orphans << " orphans)" - "\nNext payout = " << log::XMRAmount(m_pool->block_template().next_payout()) + "\nNext payout = " << log::XMRAmount(next_payout) ); }