Skip to content

Commit 14ba286

Browse files
committed
Merge bitcoin/bitcoin#23695: p2p: Always serialize local timestamp for version msg
fa1dc9b p2p: Always serialize local timestamp for version msg (MarcoFalke) Pull request description: Currently we serialize the local time when connecting to outbound connections and the "adjusted network" time when someone connects to us. I presume the reason is to avoid a fingerprint in case the local time is misconfigured. However, the fingerprint still exits when: * The local time goes out-of-sync after timedata is filled up, in which case the adjusted time is *not* adjusted. See comment in `src/timedata.cpp`. (In practise I expect no adjustment to happen after timedata is filled up by one entry more than half its size). * The local time is off by more than 70 minutes. See `DEFAULT_MAX_TIME_ADJUSTMENT`. While there is a warning in this case, the warning might be missed by the node operator. * The adjusted time is poisoned by an attacker. This is only a theoretical concern after commit e457513. Using the adjusted time does help in a the case where the local time is off by a constant less than 70 minutes and the node quickly connects to 5 outbound peers to retrieve the adjusted time. Still, I think using `GetAdjustedTime` here gives a false sense of security. It will be better for node operators to instead set the correct time. ACKs for top commit: naumenkogs: ACK fa1dc9b laanwj: Code review ACK fa1dc9b w0xlt: crACK fa1dc9b Tree-SHA512: 70a0f4ab3500e6ddcde291620e35273018cefd1d9e94b91ad333e360139ed18862718bb1a9854af2bf79990bf74b05d95492f77d0747c7b9bdd276c020116dcb
2 parents 784a21d + fa1dc9b commit 14ba286

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/net_processing.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ class PeerManagerImpl final : public PeerManager
386386
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
387387

388388
/** Send a version message to a peer */
389-
void PushNodeVersion(CNode& pnode, int64_t nTime);
389+
void PushNodeVersion(CNode& pnode);
390390

391391
/** Send a ping message every PING_INTERVAL or if requested via RPC. May
392392
* mark the peer to be disconnected if a ping has timed out.
@@ -1090,12 +1090,13 @@ void PeerManagerImpl::FindNextBlocksToDownload(NodeId nodeid, unsigned int count
10901090

10911091
} // namespace
10921092

1093-
void PeerManagerImpl::PushNodeVersion(CNode& pnode, int64_t nTime)
1093+
void PeerManagerImpl::PushNodeVersion(CNode& pnode)
10941094
{
10951095
// Note that pnode->GetLocalServices() is a reflection of the local
10961096
// services we were offering when the CNode object was created for this
10971097
// peer.
10981098
uint64_t my_services{pnode.GetLocalServices()};
1099+
const int64_t nTime{count_seconds(GetTime<std::chrono::seconds>())};
10991100
uint64_t nonce = pnode.GetLocalNonce();
11001101
const int nNodeStartingHeight{m_best_height};
11011102
NodeId nodeid = pnode.GetId();
@@ -1167,7 +1168,7 @@ void PeerManagerImpl::InitializeNode(CNode *pnode)
11671168
m_peer_map.emplace_hint(m_peer_map.end(), nodeid, std::move(peer));
11681169
}
11691170
if (!pnode->IsInboundConn()) {
1170-
PushNodeVersion(*pnode, GetTime());
1171+
PushNodeVersion(*pnode);
11711172
}
11721173
}
11731174

@@ -2599,7 +2600,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
25992600

26002601
// Inbound peers send us their version message when they connect.
26012602
// We send our version message in response.
2602-
if (pfrom.IsInboundConn()) PushNodeVersion(pfrom, GetAdjustedTime());
2603+
if (pfrom.IsInboundConn()) {
2604+
PushNodeVersion(pfrom);
2605+
}
26032606

26042607
// Change version
26052608
const int greatest_common_version = std::min(nVersion, PROTOCOL_VERSION);

0 commit comments

Comments
 (0)