data api: check p2pool shares that come after a Monero block

pull/22/head
SChernykh 3 years ago
parent 06f39c3f4c
commit 899d5a82dd

@ -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\ | ###### # ####### ##### # # ####### ####### # # # # ###### |\n\
| # # # # # # # # # # # # # # ## # # # |\n\ | # # # # # # # # # # # # # # ## # # # |\n\
@ -269,9 +269,14 @@ void p2pool::handle_chain_main(ChainMain& data, const char* extra)
", timestamp = " << log::Gray() << data.timestamp << log::NoColor() << ", timestamp = " << log::Gray() << data.timestamp << log::NoColor() <<
", reward = " << log::Gray() << log::XMRAmount(data.reward)); ", reward = " << log::Gray() << log::XMRAmount(data.reward));
if (!sidechain_id.empty() && side_chain().has_block(sidechain_id)) { if (!sidechain_id.empty()) {
LOGINFO(0, log::LightGreen() << "BLOCK FOUND: main chain block at height " << data.height << " was mined by this p2pool" << BLOCK_FOUND); if (side_chain().has_block(sidechain_id)) {
api_update_block_found(&data); 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(); api_update_network_stats();

@ -72,6 +72,8 @@ public:
bool chainmain_get_by_hash(const hash& id, ChainMain& data) const; bool chainmain_get_by_hash(const hash& id, ChainMain& data) const;
void api_update_block_found(const ChainMain* data);
private: private:
p2pool(const p2pool&) = delete; p2pool(const p2pool&) = delete;
p2pool(p2pool&&) = delete; p2pool(p2pool&&) = delete;
@ -115,7 +117,6 @@ private:
void api_update_network_stats(); void api_update_network_stats();
void api_update_pool_stats(); void api_update_pool_stats();
void api_update_block_found(const ChainMain* data);
struct FoundBlock struct FoundBlock
{ {

@ -348,6 +348,8 @@ bool SideChain::block_seen(const PoolBlock& block)
return !m_seenBlocks.insert(block.m_sidechainId).second; 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) bool SideChain::add_external_block(PoolBlock& block, std::vector<hash>& missing_blocks)
{ {
if (block.m_difficulty < m_minDifficulty) { if (block.m_difficulty < m_minDifficulty) {
@ -419,6 +421,8 @@ bool SideChain::add_external_block(PoolBlock& block, std::vector<hash>& missing_
return false; return false;
} }
bool block_found = false;
missing_blocks.clear(); missing_blocks.clear();
{ {
MutexLock lock(m_sidechainLock); MutexLock lock(m_sidechainLock);
@ -431,6 +435,17 @@ bool SideChain::add_external_block(PoolBlock& block, std::vector<hash>& missing_
missing_blocks.push_back(h); 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); add_block(block);
@ -487,6 +502,13 @@ bool SideChain::has_block(const hash& id)
return m_blocksById.find(id) != m_blocksById.end(); 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) bool SideChain::get_block_blob(const hash& id, std::vector<uint8_t>& blob)
{ {
MutexLock lock(m_sidechainLock); MutexLock lock(m_sidechainLock);
@ -659,7 +681,6 @@ void SideChain::print_status()
difficulty_type SideChain::total_hashes() const difficulty_type SideChain::total_hashes() const
{ {
MutexLock lock(m_sidechainLock);
return m_chainTip ? m_chainTip->m_cumulativeDifficulty : difficulty_type(); return m_chainTip ? m_chainTip->m_cumulativeDifficulty : difficulty_type();
} }

@ -52,6 +52,8 @@ public:
void get_missing_blocks(std::vector<hash>& missing_blocks); void get_missing_blocks(std::vector<hash>& missing_blocks);
bool has_block(const hash& id); 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_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); 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; std::vector<uint8_t> m_consensusId;
difficulty_type m_curDifficulty; difficulty_type m_curDifficulty;
ChainMain m_watchBlock;
hash m_watchBlockSidechainId;
}; };
} // namespace p2pool } // namespace p2pool

@ -27,6 +27,10 @@ TEST(hash, constructor)
hash h; hash h;
uint8_t buf[HASH_SIZE]{}; uint8_t buf[HASH_SIZE]{};
ASSERT_EQ(memcmp(h.h, buf, HASH_SIZE), 0); 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) TEST(hash, compare)

Loading…
Cancel
Save