aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorstickies-v <stickies-v@protonmail.com>2024-03-07 11:23:00 +0000
committerstickies-v <stickies-v@protonmail.com>2024-04-10 17:01:27 +0200
commitee178dfcc1175e0af8163216c9c024f4bfc97965 (patch)
tree29d04d09dcc21862dcaf6627986a68b38f1e31bc /src/net_processing.cpp
parent55361a15d1aa6984051441bce88112000688fb43 (diff)
downloadbitcoin-ee178dfcc1175e0af8163216c9c024f4bfc97965.tar.xz
Add TimeOffsets helper class
This helper class is an alternative to CMedianFilter, but without a lot of the special logic and exceptions that we needed while it was still used for consensus.
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 363de48022..b549178677 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -23,6 +23,7 @@
#include <netbase.h>
#include <netmessagemaker.h>
#include <node/blockstorage.h>
+#include <node/timeoffsets.h>
#include <node/txreconciliation.h>
#include <policy/fees.h>
#include <policy/policy.h>
@@ -753,6 +754,8 @@ private:
/** Next time to check for stale tip */
std::chrono::seconds m_stale_tip_check_time GUARDED_BY(cs_main){0s};
+ TimeOffsets m_outbound_time_offsets;
+
const Options m_opts;
bool RejectIncomingTxs(const CNode& peer) const;
@@ -3673,9 +3676,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
peer->m_time_offset = NodeSeconds{std::chrono::seconds{nTime}} - Now<NodeSeconds>();
if (!pfrom.IsInboundConn()) {
- // Don't use timedata samples from inbound peers to make it
- // harder for others to tamper with our adjusted time.
+ // Don't use time offset samples from inbound peers to make it
+ // harder for others to create false warnings about our clock being out of sync.
AddTimeData(pfrom.addr, Ticks<std::chrono::seconds>(peer->m_time_offset.load()));
+ m_outbound_time_offsets.Add(peer->m_time_offset);
+ m_outbound_time_offsets.WarnIfOutOfSync();
}
// If the peer is old enough to have the old alert system, send it the final alert.