mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-15 00:14:08 +02:00
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.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user