Skip to content

Commit 37a934e

Browse files
committed
[protocol] Remove unused CADDR_TIME_VERSION
Add comments to CAddress serialization code explaining why it's no longer needed.
1 parent c0b0b02 commit 37a934e

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/protocol.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,13 @@ class CAddress : public CService
371371
READWRITE(nVersion);
372372
}
373373
if ((s.GetType() & SER_DISK) ||
374-
(nVersion >= CADDR_TIME_VERSION && !(s.GetType() & SER_GETHASH))) {
374+
(nVersion != INIT_PROTO_VERSION && !(s.GetType() & SER_GETHASH))) {
375+
// The only time we serialize a CAddress object without nTime is in
376+
// the initial VERSION messages which contain two CAddress records.
377+
// At that point, the serialization version is INIT_PROTO_VERSION.
378+
// After the version handshake, serialization version is >=
379+
// MIN_PEER_PROTO_VERSION and all ADDR messages are serialized with
380+
// nTime.
375381
READWRITE(obj.nTime);
376382
}
377383
READWRITE(Using<CustomUintFormatter<8>>(obj.nServices));

src/version.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ static const int GETHEADERS_VERSION = 31800;
2020
//! disconnect from peers older than this proto version
2121
static const int MIN_PEER_PROTO_VERSION = GETHEADERS_VERSION;
2222

23-
//! nTime field added to CAddress, starting with this version;
24-
//! if possible, avoid requesting addresses nodes older than this
25-
static const int CADDR_TIME_VERSION = 31402;
26-
2723
//! BIP 0031, pong message, is enabled for all versions AFTER this one
2824
static const int BIP0031_VERSION = 60000;
2925

test/functional/test_framework/messages.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,19 @@ def __init__(self):
207207
self.ip = "0.0.0.0"
208208
self.port = 0
209209

210-
def deserialize(self, f, with_time=True):
210+
def deserialize(self, f, *, with_time=True):
211211
if with_time:
212+
# VERSION messages serialize CAddress objects without time
212213
self.time = struct.unpack("<i", f.read(4))[0]
213214
self.nServices = struct.unpack("<Q", f.read(8))[0]
214215
self.pchReserved = f.read(12)
215216
self.ip = socket.inet_ntoa(f.read(4))
216217
self.port = struct.unpack(">H", f.read(2))[0]
217218

218-
def serialize(self, with_time=True):
219+
def serialize(self, *, with_time=True):
219220
r = b""
220221
if with_time:
222+
# VERSION messages serialize CAddress objects without time
221223
r += struct.pack("<i", self.time)
222224
r += struct.pack("<Q", self.nServices)
223225
r += self.pchReserved
@@ -973,10 +975,10 @@ def deserialize(self, f):
973975
self.nServices = struct.unpack("<Q", f.read(8))[0]
974976
self.nTime = struct.unpack("<q", f.read(8))[0]
975977
self.addrTo = CAddress()
976-
self.addrTo.deserialize(f, False)
978+
self.addrTo.deserialize(f, with_time=False)
977979

978980
self.addrFrom = CAddress()
979-
self.addrFrom.deserialize(f, False)
981+
self.addrFrom.deserialize(f, with_time=False)
980982
self.nNonce = struct.unpack("<Q", f.read(8))[0]
981983
self.strSubVer = deser_string(f)
982984

@@ -996,8 +998,8 @@ def serialize(self):
996998
r += struct.pack("<i", self.nVersion)
997999
r += struct.pack("<Q", self.nServices)
9981000
r += struct.pack("<q", self.nTime)
999-
r += self.addrTo.serialize(False)
1000-
r += self.addrFrom.serialize(False)
1001+
r += self.addrTo.serialize(with_time=False)
1002+
r += self.addrFrom.serialize(with_time=False)
10011003
r += struct.pack("<Q", self.nNonce)
10021004
r += ser_string(self.strSubVer)
10031005
r += struct.pack("<i", self.nStartingHeight)

0 commit comments

Comments
 (0)