mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-22 10:24:31 +00:00
P2PServer: tweaked invalid timestamp logic
This commit is contained in:
parent
45660e3d96
commit
c090b0cf62
1 changed files with 25 additions and 13 deletions
|
@ -2067,25 +2067,37 @@ bool P2PServer::P2PClient::handle_incoming_block_async(const PoolBlock* block, u
|
||||||
|
|
||||||
// Limit system clock difference between connected peers
|
// Limit system clock difference between connected peers
|
||||||
if (max_time_delta) {
|
if (max_time_delta) {
|
||||||
static uint64_t total_checks = 0;
|
static hash prev_checked_block;
|
||||||
static uint64_t failed_checks = 0;
|
if (block->m_sidechainId != prev_checked_block) {
|
||||||
|
prev_checked_block = block->m_sidechainId;
|
||||||
++total_checks;
|
|
||||||
|
|
||||||
const uint64_t t = time(nullptr);
|
const uint64_t t = time(nullptr);
|
||||||
if ((block->m_timestamp + max_time_delta < t) || (block->m_timestamp > t + max_time_delta)) {
|
const uint32_t failed = ((block->m_timestamp + max_time_delta < t) || (block->m_timestamp > t + max_time_delta)) ? 1 : 0;
|
||||||
|
|
||||||
|
static uint32_t failed_history = 0;
|
||||||
|
failed_history = (failed_history << 1) | failed;
|
||||||
|
|
||||||
|
if (failed) {
|
||||||
LOGWARN(4, "peer " << static_cast<char*>(m_addrString)
|
LOGWARN(4, "peer " << static_cast<char*>(m_addrString)
|
||||||
<< " sent a block (mined by " << block->m_minerWallet << ") with an invalid timestamp " << block->m_timestamp
|
<< " sent a block (mined by " << block->m_minerWallet << ") with an invalid timestamp " << block->m_timestamp
|
||||||
<< " (your local timestamp is " << t << ")");
|
<< " (your local timestamp is " << t << ")");
|
||||||
|
|
||||||
|
uint32_t failed_checks = 0;
|
||||||
|
|
||||||
|
for (uint32_t k = 1; k != 0; k <<= 1) {
|
||||||
|
if (failed_history & k) {
|
||||||
++failed_checks;
|
++failed_checks;
|
||||||
if ((total_checks > 10) && (failed_checks * 4 > total_checks * 3)) {
|
}
|
||||||
LOGWARN(1, "Your system clock might be invalid: " << failed_checks << " of " << total_checks << " blocks were rejected due to timestamp difference");
|
}
|
||||||
|
|
||||||
|
if (failed_checks > 16) {
|
||||||
|
LOGWARN(1, "Your system clock might be invalid: " << failed_checks << " of 32 last blocks were rejected due to timestamp difference");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (server->m_pool->side_chain().block_seen(*block)) {
|
if (server->m_pool->side_chain().block_seen(*block)) {
|
||||||
LOGINFO(6, "block " << block->m_sidechainId << " (nonce " << block->m_nonce << ", extra_nonce " << block->m_extraNonce << ") was received before, skipping it");
|
LOGINFO(6, "block " << block->m_sidechainId << " (nonce " << block->m_nonce << ", extra_nonce " << block->m_extraNonce << ") was received before, skipping it");
|
||||||
|
|
Loading…
Reference in a new issue