From f6a285de87b672041ea0b7951e213e248a5f4cc7 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 28 Mar 2023 13:28:34 +0200 Subject: [PATCH] API: added PPLNS window size to pool stats --- src/p2pool.cpp | 9 +++++++-- src/side_chain.cpp | 22 +++++++++++++++++++--- src/side_chain.h | 1 + 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/p2pool.cpp b/src/p2pool.cpp index 4b2ae7f..f2c7693 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -1251,9 +1251,13 @@ void p2pool::api_update_pool_stats() return; } + const PoolBlock* tip = m_sideChain->chainTip(); + const uint64_t bottom_height = m_sideChain->bottom_height(tip); + const uint64_t pplns_window_size = (tip && bottom_height) ? (tip->m_sidechainHeight - bottom_height + 1U) : m_sideChain->chain_window_size(); + uint64_t t; const difficulty_type diff = m_sideChain->difficulty(); - const uint64_t height = m_sideChain->chainTip() ? m_sideChain->chainTip()->m_sidechainHeight : 0; + const uint64_t height = tip ? tip->m_sidechainHeight : 0; const uint64_t hashrate = udiv128(diff.hi, diff.lo, m_sideChain->block_time(), &t); const uint64_t miners = std::max(m_sideChain->miner_count(), m_p2pServer ? m_p2pServer->peer_list_size() : 0U); const difficulty_type total_hashes = m_sideChain->total_hashes(); @@ -1275,7 +1279,7 @@ void p2pool::api_update_pool_stats() } m_api->set(p2pool_api::Category::POOL, "stats", - [hashrate, miners, &total_hashes, last_block_found_time, last_block_found_height, total_blocks_found, &pplns_weight, diff, height](log::Stream& s) + [hashrate, miners, &total_hashes, last_block_found_time, last_block_found_height, total_blocks_found, &pplns_weight, pplns_window_size, diff, height](log::Stream& s) { s << "{\"pool_list\":[\"pplns\"],\"pool_statistics\":{\"hashRate\":" << hashrate << ",\"miners\":" << miners @@ -1284,6 +1288,7 @@ void p2pool::api_update_pool_stats() << ",\"lastBlockFound\":" << last_block_found_height << ",\"totalBlocksFound\":" << total_blocks_found << ",\"pplnsWeight\":" << pplns_weight + << ",\"pplnsWindowSize\":" << pplns_window_size << ",\"sidechainDifficulty\":" << diff << ",\"sidechainHeight\":" << height << "}}"; diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 1b25bea..d8a9fc2 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -869,12 +869,12 @@ void SideChain::print_status(bool obtain_sidechain_lock) const const PoolBlock* tip = m_chainTip; std::vector shares; - uint64_t bottom_height = 0; + uint64_t bh = 0; if (tip) { - get_shares(tip, shares, &bottom_height, true); + get_shares(tip, shares, &bh, true); } - const uint64_t window_size = (tip && bottom_height) ? (tip->m_sidechainHeight - bottom_height + 1U) : m_chainWindowSize; + const uint64_t window_size = (tip && bh) ? (tip->m_sidechainHeight - bh + 1U) : m_chainWindowSize; uint64_t block_depth = 0; const PoolBlock* cur = tip; @@ -1113,6 +1113,22 @@ bool SideChain::is_mini() const return (memcmp(m_consensusId.data(), mini_consensus_id, HASH_SIZE) == 0); } +uint64_t SideChain::bottom_height(const PoolBlock* tip) const +{ + if (!tip) { + return 0; + } + + uint64_t bottom_height; + std::vector shares; + + if (!get_shares(tip, shares, &bottom_height, true)) { + return 0; + } + + return bottom_height; +} + bool SideChain::split_reward(uint64_t reward, const std::vector& shares, std::vector& rewards) { const size_t num_shares = shares.size(); diff --git a/src/side_chain.h b/src/side_chain.h index 4cda4f2..bf8f2c3 100644 --- a/src/side_chain.h +++ b/src/side_chain.h @@ -75,6 +75,7 @@ public: uint64_t last_updated() const; bool is_default() const; bool is_mini() const; + uint64_t bottom_height(const PoolBlock* tip) const; const PoolBlock* chainTip() const { return m_chainTip; } bool precalcFinished() const { return m_precalcFinished.load(); }