Skip to content

Commit 631284f

Browse files
author
MarcoFalke
committed
Merge #19486: Remove unused constants CADDR_TIME_VERSION and GETHEADERS_VERSION
7bb6f9b [protocol] Remove unused GETHEADERS_VERSION (John Newbery) 37a934e [protocol] Remove unused CADDR_TIME_VERSION (John Newbery) Pull request description: These constants are no longer required and can be removed. Additional code comments are added to explain CAddress serialization. ACKs for top commit: MarcoFalke: ACK 7bb6f9b already an improvement, but maybe getting rid of INIT_PROTO_VERSION here would be an even stronger improvement (can be done later) jonatack: ACK 7bb6f9b vasild: ACK 7bb6f9b Tree-SHA512: 5382562c60fd677c86583754eca11aad3719064efe2e5ef4f307d693b583422ca8d385926c2582aaab899f502b151f2eb87a7ac23363b15f4fceaa06296f98e3
2 parents 4db44ac + 7bb6f9b commit 631284f

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
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: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,8 @@ static const int PROTOCOL_VERSION = 70015;
1414
//! initial proto version, to be increased after version/verack negotiation
1515
static const int INIT_PROTO_VERSION = 209;
1616

17-
//! In this version, 'getheaders' was introduced.
18-
static const int GETHEADERS_VERSION = 31800;
19-
2017
//! disconnect from peers older than this proto version
21-
static const int MIN_PEER_PROTO_VERSION = GETHEADERS_VERSION;
22-
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;
18+
static const int MIN_PEER_PROTO_VERSION = 31800;
2619

2720
//! BIP 0031, pong message, is enabled for all versions AFTER this one
2821
static const int BIP0031_VERSION = 60000;

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)