mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-03 09:19:24 +00:00
data api: check p2pool shares that come after a Monero block
This commit is contained in:
parent
06f39c3f4c
commit
899d5a82dd
5 changed files with 42 additions and 6 deletions
|
@ -220,7 +220,7 @@ void p2pool::handle_miner_data(MinerData& data)
|
|||
}
|
||||
}
|
||||
|
||||
static constexpr char BLOCK_FOUND[] = "\n\
|
||||
const char* BLOCK_FOUND = "\n\
|
||||
-----------------------------------------------------------------------------------------------\n\
|
||||
| ###### # ####### ##### # # ####### ####### # # # # ###### |\n\
|
||||
| # # # # # # # # # # # # # # ## # # # |\n\
|
||||
|
@ -269,9 +269,14 @@ void p2pool::handle_chain_main(ChainMain& data, const char* extra)
|
|||
", timestamp = " << log::Gray() << data.timestamp << log::NoColor() <<
|
||||
", reward = " << log::Gray() << log::XMRAmount(data.reward));
|
||||
|
||||
if (!sidechain_id.empty() && side_chain().has_block(sidechain_id)) {
|
||||
LOGINFO(0, log::LightGreen() << "BLOCK FOUND: main chain block at height " << data.height << " was mined by this p2pool" << BLOCK_FOUND);
|
||||
api_update_block_found(&data);
|
||||
if (!sidechain_id.empty()) {
|
||||
if (side_chain().has_block(sidechain_id)) {
|
||||
LOGINFO(0, log::LightGreen() << "BLOCK FOUND: main chain block at height " << data.height << " was mined by this p2pool" << BLOCK_FOUND);
|
||||
api_update_block_found(&data);
|
||||
}
|
||||
else {
|
||||
side_chain().watch_mainchain_block(data, sidechain_id);
|
||||
}
|
||||
}
|
||||
|
||||
api_update_network_stats();
|
||||
|
|
|
@ -72,6 +72,8 @@ public:
|
|||
|
||||
bool chainmain_get_by_hash(const hash& id, ChainMain& data) const;
|
||||
|
||||
void api_update_block_found(const ChainMain* data);
|
||||
|
||||
private:
|
||||
p2pool(const p2pool&) = delete;
|
||||
p2pool(p2pool&&) = delete;
|
||||
|
@ -115,7 +117,6 @@ private:
|
|||
|
||||
void api_update_network_stats();
|
||||
void api_update_pool_stats();
|
||||
void api_update_block_found(const ChainMain* data);
|
||||
|
||||
struct FoundBlock
|
||||
{
|
||||
|
|
|
@ -348,6 +348,8 @@ bool SideChain::block_seen(const PoolBlock& block)
|
|||
return !m_seenBlocks.insert(block.m_sidechainId).second;
|
||||
}
|
||||
|
||||
extern const char* BLOCK_FOUND;
|
||||
|
||||
bool SideChain::add_external_block(PoolBlock& block, std::vector<hash>& missing_blocks)
|
||||
{
|
||||
if (block.m_difficulty < m_minDifficulty) {
|
||||
|
@ -419,6 +421,8 @@ bool SideChain::add_external_block(PoolBlock& block, std::vector<hash>& missing_
|
|||
return false;
|
||||
}
|
||||
|
||||
bool block_found = false;
|
||||
|
||||
missing_blocks.clear();
|
||||
{
|
||||
MutexLock lock(m_sidechainLock);
|
||||
|
@ -431,6 +435,17 @@ bool SideChain::add_external_block(PoolBlock& block, std::vector<hash>& missing_
|
|||
missing_blocks.push_back(h);
|
||||
}
|
||||
}
|
||||
|
||||
if (block.m_sidechainId == m_watchBlockSidechainId) {
|
||||
LOGINFO(0, log::LightGreen() << "BLOCK FOUND: main chain block at height " << m_watchBlock.height << " was mined by this p2pool" << BLOCK_FOUND);
|
||||
m_watchBlockSidechainId = {};
|
||||
data = m_watchBlock;
|
||||
block_found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (block_found) {
|
||||
m_pool->api_update_block_found(&data);
|
||||
}
|
||||
|
||||
add_block(block);
|
||||
|
@ -487,6 +502,13 @@ bool SideChain::has_block(const hash& id)
|
|||
return m_blocksById.find(id) != m_blocksById.end();
|
||||
}
|
||||
|
||||
void SideChain::watch_mainchain_block(const ChainMain& data, const hash& possible_id)
|
||||
{
|
||||
MutexLock lock(m_sidechainLock);
|
||||
m_watchBlock = data;
|
||||
m_watchBlockSidechainId = possible_id;
|
||||
}
|
||||
|
||||
bool SideChain::get_block_blob(const hash& id, std::vector<uint8_t>& blob)
|
||||
{
|
||||
MutexLock lock(m_sidechainLock);
|
||||
|
@ -659,7 +681,6 @@ void SideChain::print_status()
|
|||
|
||||
difficulty_type SideChain::total_hashes() const
|
||||
{
|
||||
MutexLock lock(m_sidechainLock);
|
||||
return m_chainTip ? m_chainTip->m_cumulativeDifficulty : difficulty_type();
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ public:
|
|||
void get_missing_blocks(std::vector<hash>& missing_blocks);
|
||||
|
||||
bool has_block(const hash& 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_outputs_blob(PoolBlock* block, uint64_t total_reward, std::vector<uint8_t>& blob);
|
||||
|
||||
|
@ -109,6 +111,9 @@ private:
|
|||
std::vector<uint8_t> m_consensusId;
|
||||
|
||||
difficulty_type m_curDifficulty;
|
||||
|
||||
ChainMain m_watchBlock;
|
||||
hash m_watchBlockSidechainId;
|
||||
};
|
||||
|
||||
} // namespace p2pool
|
||||
|
|
|
@ -27,6 +27,10 @@ TEST(hash, constructor)
|
|||
hash h;
|
||||
uint8_t buf[HASH_SIZE]{};
|
||||
ASSERT_EQ(memcmp(h.h, buf, HASH_SIZE), 0);
|
||||
|
||||
memset(h.h, -1, HASH_SIZE);
|
||||
h = {};
|
||||
ASSERT_EQ(memcmp(h.h, buf, HASH_SIZE), 0);
|
||||
}
|
||||
|
||||
TEST(hash, compare)
|
||||
|
|
Loading…
Reference in a new issue