mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-11-16 15:57:39 +00:00
Fixed block reward share calculation
This commit is contained in:
parent
9e7666d12f
commit
111087d96a
3 changed files with 34 additions and 12 deletions
|
@ -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<double>(w) * 100.0) / static_cast<double>(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)
|
||||
|
|
|
@ -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<double>(reward) / static_cast<double>(total_reward)) : 0.0;
|
||||
}
|
||||
|
||||
difficulty_type SideChain::total_hashes() const
|
||||
{
|
||||
const PoolBlock* tip = m_chainTip;
|
||||
|
|
|
@ -58,6 +58,7 @@ public:
|
|||
bool get_outputs_blob(PoolBlock* block, uint64_t total_reward, std::vector<uint8_t>& 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
|
||||
|
|
Loading…
Reference in a new issue