Notify about new P2Pool versions

This commit is contained in:
SChernykh 2023-10-08 18:52:06 +02:00
parent 4d944d3dc3
commit 4e55f53fb4
5 changed files with 44 additions and 1 deletions

View file

@ -646,7 +646,7 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, const
// Layout: [software id, version, random number, sidechain extra_nonce] // Layout: [software id, version, random number, sidechain extra_nonce]
uint32_t* sidechain_extra = m_poolBlockTemplate->m_sidechainExtraBuf; uint32_t* sidechain_extra = m_poolBlockTemplate->m_sidechainExtraBuf;
sidechain_extra[0] = 0; sidechain_extra[0] = static_cast<uint32_t>(SoftwareID::P2Pool);
#ifdef P2POOL_SIDECHAIN_EXTRA_1 #ifdef P2POOL_SIDECHAIN_EXTRA_1
sidechain_extra[1] = P2POOL_SIDECHAIN_EXTRA_1; sidechain_extra[1] = P2POOL_SIDECHAIN_EXTRA_1;
#else #else

View file

@ -1081,6 +1081,7 @@ void P2PServer::on_timer()
update_peer_connections(); update_peer_connections();
check_host(); check_host();
check_block_template(); check_block_template();
check_for_updates();
api_update_local_stats(); api_update_local_stats();
} }
@ -1255,6 +1256,21 @@ void P2PServer::check_block_template()
} }
} }
void P2PServer::check_for_updates() const
{
if (m_timerCounter % (3600 / m_timerInterval) != 0) {
return;
}
const SideChain& s = m_pool->side_chain();
if (s.precalcFinished() && s.p2pool_update_available()) {
LOGINFO(0, log::LightCyan() << "********************************************************************************");
LOGINFO(0, log::LightCyan() << "* An updated P2Pool version is available, visit p2pool.io for more information *");
LOGINFO(0, log::LightCyan() << "********************************************************************************");
}
}
P2PServer::P2PClient::P2PClient() P2PServer::P2PClient::P2PClient()
: Client(m_p2pReadBuf, sizeof(m_p2pReadBuf)) : Client(m_p2pReadBuf, sizeof(m_p2pReadBuf))
, m_peerId(0) , m_peerId(0)

View file

@ -198,6 +198,7 @@ private:
void download_missing_blocks(); void download_missing_blocks();
void check_host(); void check_host();
void check_block_template(); void check_block_template();
void check_for_updates() const;
void update_peer_connections(); void update_peer_connections();
void update_peer_list(); void update_peer_list();
void send_peer_list_request(P2PClient* client, uint64_t cur_time); void send_peer_list_request(P2PClient* client, uint64_t cur_time);

View file

@ -1304,6 +1304,30 @@ bool SideChain::get_difficulty(const PoolBlock* tip, std::vector<DifficultyData>
return true; return true;
} }
bool SideChain::p2pool_update_available() const
{
constexpr uint32_t version = (P2POOL_VERSION_MAJOR << 16) | P2POOL_VERSION_MINOR;
difficulty_type total_p2pool_diff, newer_p2pool_diff;
{
ReadLock lock(m_sidechainLock);
const PoolBlock* cur = m_chainTip;
for (uint64_t i = 0; (i < m_chainWindowSize) && cur; ++i, cur = get_parent(cur)) {
if (cur->m_sidechainExtraBuf[0] == static_cast<uint32_t>(SoftwareID::P2Pool)) {
total_p2pool_diff += cur->m_difficulty;
if (cur->m_sidechainExtraBuf[1] > version) {
newer_p2pool_diff += cur->m_difficulty;
}
}
}
}
// Assume that a new version is out if >= 20% of hashrate is using it already
return newer_p2pool_diff * 5 >= total_p2pool_diff;
}
void SideChain::verify_loop(PoolBlock* block) void SideChain::verify_loop(PoolBlock* block)
{ {
// PoW is already checked at this point // PoW is already checked at this point

View file

@ -82,6 +82,8 @@ public:
const PoolBlock* chainTip() const { return m_chainTip; } const PoolBlock* chainTip() const { return m_chainTip; }
bool precalcFinished() const { return m_precalcFinished.load(); } bool precalcFinished() const { return m_precalcFinished.load(); }
bool p2pool_update_available() const;
#ifdef P2POOL_UNIT_TESTS #ifdef P2POOL_UNIT_TESTS
difficulty_type m_testMainChainDiff; difficulty_type m_testMainChainDiff;
const unordered_map<hash, PoolBlock*>& blocksById() const { return m_blocksById; } const unordered_map<hash, PoolBlock*>& blocksById() const { return m_blocksById; }