diff --git a/src/common.h b/src/common.h index b325476..b5fd167 100644 --- a/src/common.h +++ b/src/common.h @@ -51,6 +51,7 @@ #include #include #include +#include #include @@ -247,6 +248,8 @@ struct MinerData uint64_t already_generated_coins; uint64_t median_timestamp; std::vector tx_backlog; + + std::chrono::system_clock::time_point time_received; }; struct ChainMain diff --git a/src/log.cpp b/src/log.cpp index 672d430..bd2557c 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -17,7 +17,6 @@ #include "common.h" #include "uv_util.h" -#include #include #include diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index d85daf5..57ea7fb 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -1273,8 +1273,15 @@ bool P2PServer::P2PClient::on_block_broadcast(const uint8_t* buf, uint32_t size) if (peer_height < our_height) { if (our_height - peer_height < 5) { - LOGINFO(5, "peer " << static_cast(m_addrString) << " broadcasted a stale block (mainchain height " << peer_height << ", expected >= " << our_height << "), ignoring it"); - return true; + using namespace std::chrono; + const int64_t elapsed_ms = duration_cast(system_clock::now() - server->m_pool->miner_data().time_received).count(); + if ((our_height - peer_height > 1) || (elapsed_ms >= 1000)) { + LOGWARN(5, "peer " << static_cast(m_addrString) << " broadcasted a stale block (" << elapsed_ms << " ms late, mainchain height " << peer_height << ", expected >= " << our_height << "), ignoring it"); + return true; + } + else { + LOGINFO(5, "peer " << static_cast(m_addrString) << " broadcasted a stale block (" << elapsed_ms << " ms late, mainchain height " << peer_height << ", expected >= " << our_height << ")"); + } } else { LOGWARN(5, "peer " << static_cast(m_addrString) << " broadcasted an unreasonably stale block (mainchain height " << peer_height << ", expected >= " << our_height << ')'); diff --git a/src/p2pool.cpp b/src/p2pool.cpp index 338077c..bd7aae3 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -176,6 +176,7 @@ void p2pool::handle_miner_data(MinerData& data) } data.tx_backlog.clear(); + data.time_received = std::chrono::system_clock::now(); m_minerData = data; m_updateSeed = true; update_median_timestamp(); diff --git a/src/util.cpp b/src/util.cpp index 5d6471e..714d5d1 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -20,7 +20,6 @@ #include "uv_util.h" #include #include -#include #ifndef _WIN32 #include