diff --git a/src/miner.cpp b/src/miner.cpp index 0f95636..e6974dd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -102,18 +102,7 @@ void Miner::on_block(const BlockTemplate& block) m_totalHashes += hash_count; if (m_pool->api() && m_pool->params().m_localStats) { - const hash& key = m_pool->params().m_wallet.spend_public_key(); - uint64_t w = 0; - uint64_t total = 0; - - for (const MinerShare& s : block.shares()) { - total += s.m_weight; - if (s.m_wallet->spend_public_key() == key) { - w = s.m_weight; - } - } - - const double block_reward_share_percent = total ? ((static_cast(w) * 100.0) / static_cast(total)) : 0.0; + const double block_reward_share_percent = m_pool->side_chain().get_reward_share(m_pool->params().m_wallet) * 100.0; m_pool->api()->set(p2pool_api::Category::LOCAL, "miner", [cur_ts, hash_count, dt, block_reward_share_percent, this](log::Stream& s) diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 85ffc51..04c9e3a 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -832,6 +832,38 @@ void SideChain::print_status() const ); } +double SideChain::get_reward_share(const Wallet& w) const +{ + uint64_t reward = 0; + uint64_t total_reward = 0; + { + ReadLock lock(m_sidechainLock); + + const PoolBlock* tip = m_chainTip; + if (tip) { + hash eph_public_key; + for (size_t i = 0, n = tip->m_outputs.size(); i < n; ++i) { + const PoolBlock::TxOutput& out = tip->m_outputs[i]; + if (!reward) { + if (out.m_txType == TXOUT_TO_TAGGED_KEY) { + if (w.get_eph_public_key_with_view_tag(tip->m_txkeySec, i, eph_public_key, out.m_viewTag) && (out.m_ephPublicKey == eph_public_key)) { + reward = out.m_reward; + } + } + else { + uint8_t view_tag; + if (w.get_eph_public_key(tip->m_txkeySec, i, eph_public_key, view_tag) && (out.m_ephPublicKey == eph_public_key)) { + reward = out.m_reward; + } + } + } + total_reward += out.m_reward; + } + } + } + return total_reward ? (static_cast(reward) / static_cast(total_reward)) : 0.0; +} + difficulty_type SideChain::total_hashes() const { const PoolBlock* tip = m_chainTip; diff --git a/src/side_chain.h b/src/side_chain.h index aaf0723..60bc6b0 100644 --- a/src/side_chain.h +++ b/src/side_chain.h @@ -58,6 +58,7 @@ public: bool get_outputs_blob(PoolBlock* block, uint64_t total_reward, std::vector& blob) const; void print_status() const; + double get_reward_share(const Wallet& w) const; // Consensus ID can be used to spawn independent P2Pools with their own sidechains // It's never sent over the network to avoid revealing it to the possible man in the middle