mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-03 09:19:24 +00:00
Display payout amount when a block is found
This commit is contained in:
parent
cf184295b4
commit
8767ef9e19
6 changed files with 36 additions and 5 deletions
|
@ -32,6 +32,7 @@
|
||||||
#include "console_commands.h"
|
#include "console_commands.h"
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
#include "p2pool_api.h"
|
#include "p2pool_api.h"
|
||||||
|
#include "pool_block.h"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
@ -339,8 +340,13 @@ void p2pool::handle_chain_main(ChainMain& data, const char* extra)
|
||||||
", reward = " << log::Gray() << log::XMRAmount(data.reward));
|
", reward = " << log::Gray() << log::XMRAmount(data.reward));
|
||||||
|
|
||||||
if (!sidechain_id.empty()) {
|
if (!sidechain_id.empty()) {
|
||||||
if (side_chain().has_block(sidechain_id)) {
|
PoolBlock* block = side_chain().find_block(sidechain_id);
|
||||||
|
if (block) {
|
||||||
LOGINFO(0, log::LightGreen() << "BLOCK FOUND: main chain block at height " << data.height << " was mined by this p2pool" << BLOCK_FOUND);
|
LOGINFO(0, log::LightGreen() << "BLOCK FOUND: main chain block at height " << data.height << " was mined by this p2pool" << BLOCK_FOUND);
|
||||||
|
const uint64_t payout = block->get_payout(params().m_wallet);
|
||||||
|
if (payout) {
|
||||||
|
LOGINFO(0, log::LightCyan() << "You received a payout of " << log::LightGreen() << log::XMRAmount(payout) << log::LightCyan() << " in block " << log::LightGreen() << data.height);
|
||||||
|
}
|
||||||
api_update_block_found(&data);
|
api_update_block_found(&data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -298,4 +298,16 @@ bool PoolBlock::get_pow_hash(RandomX_Hasher_Base* hasher, uint64_t height, const
|
||||||
return hasher->calculate(blob, blob_size, height, seed_hash, pow_hash);
|
return hasher->calculate(blob, blob_size, height, seed_hash, pow_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t PoolBlock::get_payout(const Wallet& w) const
|
||||||
|
{
|
||||||
|
for (size_t i = 0, n = m_outputs.size(); i < n; ++i) {
|
||||||
|
hash eph_public_key;
|
||||||
|
if ((w.get_eph_public_key(m_txkeySec, i, eph_public_key)) && (eph_public_key == m_outputs[i].m_ephPublicKey)) {
|
||||||
|
return m_outputs[i].m_reward;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace p2pool
|
} // namespace p2pool
|
||||||
|
|
|
@ -137,6 +137,8 @@ struct PoolBlock
|
||||||
|
|
||||||
int deserialize(const uint8_t* data, size_t size, SideChain& sidechain);
|
int deserialize(const uint8_t* data, size_t size, SideChain& sidechain);
|
||||||
bool get_pow_hash(RandomX_Hasher_Base* hasher, uint64_t height, const hash& seed_hash, hash& pow_hash);
|
bool get_pow_hash(RandomX_Hasher_Base* hasher, uint64_t height, const hash& seed_hash, hash& pow_hash);
|
||||||
|
|
||||||
|
uint64_t get_payout(const Wallet& w) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace p2pool
|
} // namespace p2pool
|
||||||
|
|
|
@ -481,6 +481,11 @@ bool SideChain::add_external_block(PoolBlock& block, std::vector<hash>& missing_
|
||||||
m_watchBlockSidechainId = {};
|
m_watchBlockSidechainId = {};
|
||||||
data = m_watchBlock;
|
data = m_watchBlock;
|
||||||
block_found = true;
|
block_found = true;
|
||||||
|
|
||||||
|
const uint64_t payout = block.get_payout(m_pool->params().m_wallet);
|
||||||
|
if (payout) {
|
||||||
|
LOGINFO(0, log::LightCyan() << "You received a payout of " << log::LightGreen() << log::XMRAmount(payout) << log::LightCyan() << " in block " << log::LightGreen() << data.height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,10 +541,16 @@ void SideChain::add_block(const PoolBlock& block)
|
||||||
m_seenWallets[new_block->m_minerWallet.spend_public_key()] = new_block->m_localTimestamp;
|
m_seenWallets[new_block->m_minerWallet.spend_public_key()] = new_block->m_localTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SideChain::has_block(const hash& id)
|
PoolBlock* SideChain::find_block(const hash& id)
|
||||||
{
|
{
|
||||||
MutexLock lock(m_sidechainLock);
|
MutexLock lock(m_sidechainLock);
|
||||||
return m_blocksById.find(id) != m_blocksById.end();
|
|
||||||
|
auto it = m_blocksById.find(id);
|
||||||
|
if (it != m_blocksById.end()) {
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SideChain::watch_mainchain_block(const ChainMain& data, const hash& possible_id)
|
void SideChain::watch_mainchain_block(const ChainMain& data, const hash& possible_id)
|
||||||
|
|
|
@ -51,7 +51,7 @@ public:
|
||||||
void add_block(const PoolBlock& block);
|
void add_block(const PoolBlock& block);
|
||||||
void get_missing_blocks(std::vector<hash>& missing_blocks);
|
void get_missing_blocks(std::vector<hash>& missing_blocks);
|
||||||
|
|
||||||
bool has_block(const hash& id);
|
PoolBlock* find_block(const hash& id);
|
||||||
void watch_mainchain_block(const ChainMain& data, const hash& possible_id);
|
void watch_mainchain_block(const ChainMain& data, const hash& possible_id);
|
||||||
|
|
||||||
bool get_block_blob(const hash& id, std::vector<uint8_t>& blob);
|
bool get_block_blob(const hash& id, std::vector<uint8_t>& blob);
|
||||||
|
|
|
@ -125,7 +125,7 @@ TEST(pool_block, verify)
|
||||||
p += n;
|
p += n;
|
||||||
|
|
||||||
sidechain.add_block(b);
|
sidechain.add_block(b);
|
||||||
ASSERT_TRUE(sidechain.has_block(b.m_sidechainId));
|
ASSERT_TRUE(sidechain.find_block(b.m_sidechainId) != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
const PoolBlock* tip = sidechain.chainTip();
|
const PoolBlock* tip = sidechain.chainTip();
|
||||||
|
|
Loading…
Reference in a new issue