From 37a934e6b35bea2125732d2c074998d9fe70633e Mon Sep 17 00:00:00 2001 From: John Newbery Date: Fri, 10 Jul 2020 16:48:20 +0100 Subject: [PATCH 1/2] [protocol] Remove unused CADDR_TIME_VERSION Add comments to CAddress serialization code explaining why it's no longer needed. --- src/protocol.h | 8 +++++++- src/version.h | 4 ---- test/functional/test_framework/messages.py | 14 ++++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/protocol.h b/src/protocol.h index 985f44640bd..9ab63a30fbf 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -371,7 +371,13 @@ public: READWRITE(nVersion); } if ((s.GetType() & SER_DISK) || - (nVersion >= CADDR_TIME_VERSION && !(s.GetType() & SER_GETHASH))) { + (nVersion != INIT_PROTO_VERSION && !(s.GetType() & SER_GETHASH))) { + // The only time we serialize a CAddress object without nTime is in + // the initial VERSION messages which contain two CAddress records. + // At that point, the serialization version is INIT_PROTO_VERSION. + // After the version handshake, serialization version is >= + // MIN_PEER_PROTO_VERSION and all ADDR messages are serialized with + // nTime. READWRITE(obj.nTime); } READWRITE(Using>(obj.nServices)); diff --git a/src/version.h b/src/version.h index d932b512d4b..d2a747fab3c 100644 --- a/src/version.h +++ b/src/version.h @@ -20,10 +20,6 @@ static const int GETHEADERS_VERSION = 31800; //! disconnect from peers older than this proto version static const int MIN_PEER_PROTO_VERSION = GETHEADERS_VERSION; -//! nTime field added to CAddress, starting with this version; -//! if possible, avoid requesting addresses nodes older than this -static const int CADDR_TIME_VERSION = 31402; - //! BIP 0031, pong message, is enabled for all versions AFTER this one static const int BIP0031_VERSION = 60000; diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index eb1244035f7..12302cdbc3d 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -207,17 +207,19 @@ class CAddress: self.ip = "0.0.0.0" self.port = 0 - def deserialize(self, f, with_time=True): + def deserialize(self, f, *, with_time=True): if with_time: + # VERSION messages serialize CAddress objects without time self.time = struct.unpack("H", f.read(2))[0] - def serialize(self, with_time=True): + def serialize(self, *, with_time=True): r = b"" if with_time: + # VERSION messages serialize CAddress objects without time r += struct.pack(" Date: Fri, 10 Jul 2020 16:52:05 +0100 Subject: [PATCH 2/2] [protocol] Remove unused GETHEADERS_VERSION GETHEADERS_VERSION is unused. No need to keep it in the codebase for just its historic comment. --- src/version.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/version.h b/src/version.h index d2a747fab3c..e5d1f5a7f99 100644 --- a/src/version.h +++ b/src/version.h @@ -14,11 +14,8 @@ static const int PROTOCOL_VERSION = 70015; //! initial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209; -//! In this version, 'getheaders' was introduced. -static const int GETHEADERS_VERSION = 31800; - //! disconnect from peers older than this proto version -static const int MIN_PEER_PROTO_VERSION = GETHEADERS_VERSION; +static const int MIN_PEER_PROTO_VERSION = 31800; //! BIP 0031, pong message, is enabled for all versions AFTER this one static const int BIP0031_VERSION = 60000;