mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-22 02:14:30 +00:00
Ban peers with stuck or lagging monerod
This commit is contained in:
parent
2a77695832
commit
b2f86a5f6b
2 changed files with 17 additions and 1 deletions
|
@ -1030,6 +1030,7 @@ P2PServer::P2PClient::P2PClient()
|
||||||
, m_peerListPendingRequests(0)
|
, m_peerListPendingRequests(0)
|
||||||
, m_pingTime(0)
|
, m_pingTime(0)
|
||||||
, m_blockPendingRequests(0)
|
, m_blockPendingRequests(0)
|
||||||
|
, m_chainTipBlockRequest(false)
|
||||||
, m_lastAlive(0)
|
, m_lastAlive(0)
|
||||||
, m_lastBroadcastTimestamp(0)
|
, m_lastBroadcastTimestamp(0)
|
||||||
, m_lastBlockrequestTimestamp(0)
|
, m_lastBlockrequestTimestamp(0)
|
||||||
|
@ -1059,6 +1060,7 @@ void P2PServer::P2PClient::reset()
|
||||||
m_peerListPendingRequests = 0;
|
m_peerListPendingRequests = 0;
|
||||||
m_pingTime = 0;
|
m_pingTime = 0;
|
||||||
m_blockPendingRequests = 0;
|
m_blockPendingRequests = 0;
|
||||||
|
m_chainTipBlockRequest = false;
|
||||||
m_lastAlive = 0;
|
m_lastAlive = 0;
|
||||||
m_lastBroadcastTimestamp = 0;
|
m_lastBroadcastTimestamp = 0;
|
||||||
m_lastBlockrequestTimestamp = 0;
|
m_lastBlockrequestTimestamp = 0;
|
||||||
|
@ -1642,6 +1644,7 @@ void P2PServer::P2PClient::on_after_handshake(uint8_t* &p)
|
||||||
p += HASH_SIZE;
|
p += HASH_SIZE;
|
||||||
|
|
||||||
++m_blockPendingRequests;
|
++m_blockPendingRequests;
|
||||||
|
m_chainTipBlockRequest = true;
|
||||||
m_lastBroadcastTimestamp = seconds_since_epoch();
|
m_lastBroadcastTimestamp = seconds_since_epoch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1714,6 +1717,18 @@ bool P2PServer::P2PClient::on_block_response(const uint8_t* buf, uint32_t size)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_chainTipBlockRequest) {
|
||||||
|
m_chainTipBlockRequest = false;
|
||||||
|
|
||||||
|
const uint64_t peer_height = server->m_block->m_txinGenHeight;
|
||||||
|
const uint64_t our_height = server->m_pool->miner_data().height;
|
||||||
|
|
||||||
|
if (peer_height + 2 < our_height) {
|
||||||
|
LOGWARN(4, "peer " << static_cast<char*>(m_addrString) << " is mining on top of a stale block (mainchain height " << peer_height << ", expected >= " << our_height << ')');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return handle_incoming_block_async(server->m_block);
|
return handle_incoming_block_async(server->m_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1756,7 +1771,7 @@ bool P2PServer::P2PClient::on_block_broadcast(const uint8_t* buf, uint32_t size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOGWARN(5, "peer " << static_cast<char*>(m_addrString) << " broadcasted an unreasonably stale block (mainchain height " << peer_height << ", expected >= " << our_height << ')');
|
LOGWARN(4, "peer " << static_cast<char*>(m_addrString) << " broadcasted an unreasonably stale block (mainchain height " << peer_height << ", expected >= " << our_height << ')');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,7 @@ public:
|
||||||
int64_t m_pingTime;
|
int64_t m_pingTime;
|
||||||
|
|
||||||
int m_blockPendingRequests;
|
int m_blockPendingRequests;
|
||||||
|
bool m_chainTipBlockRequest;
|
||||||
|
|
||||||
uint64_t m_lastAlive;
|
uint64_t m_lastAlive;
|
||||||
uint64_t m_lastBroadcastTimestamp;
|
uint64_t m_lastBroadcastTimestamp;
|
||||||
|
|
Loading…
Reference in a new issue