Skip to content

Commit

Permalink
[protocol] Remove unused CADDR_TIME_VERSION
Browse files Browse the repository at this point in the history
Add comments to CAddress serialization code explaining why
it's no longer needed.
  • Loading branch information
jnewbery committed Jul 10, 2020
1 parent c0b0b02 commit 37a934e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
8 changes: 7 additions & 1 deletion src/protocol.h
Expand Up @@ -371,7 +371,13 @@ class CAddress : public CService
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<CustomUintFormatter<8>>(obj.nServices));
Expand Down
4 changes: 0 additions & 4 deletions src/version.h
Expand Up @@ -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;

Expand Down
14 changes: 8 additions & 6 deletions test/functional/test_framework/messages.py
Expand Up @@ -207,17 +207,19 @@ def __init__(self):
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("<i", f.read(4))[0]
self.nServices = struct.unpack("<Q", f.read(8))[0]
self.pchReserved = f.read(12)
self.ip = socket.inet_ntoa(f.read(4))
self.port = 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("<i", self.time)
r += struct.pack("<Q", self.nServices)
r += self.pchReserved
Expand Down Expand Up @@ -973,10 +975,10 @@ def deserialize(self, f):
self.nServices = struct.unpack("<Q", f.read(8))[0]
self.nTime = struct.unpack("<q", f.read(8))[0]
self.addrTo = CAddress()
self.addrTo.deserialize(f, False)
self.addrTo.deserialize(f, with_time=False)

self.addrFrom = CAddress()
self.addrFrom.deserialize(f, False)
self.addrFrom.deserialize(f, with_time=False)
self.nNonce = struct.unpack("<Q", f.read(8))[0]
self.strSubVer = deser_string(f)

Expand All @@ -996,8 +998,8 @@ def serialize(self):
r += struct.pack("<i", self.nVersion)
r += struct.pack("<Q", self.nServices)
r += struct.pack("<q", self.nTime)
r += self.addrTo.serialize(False)
r += self.addrFrom.serialize(False)
r += self.addrTo.serialize(with_time=False)
r += self.addrFrom.serialize(with_time=False)
r += struct.pack("<Q", self.nNonce)
r += ser_string(self.strSubVer)
r += struct.pack("<i", self.nStartingHeight)
Expand Down

0 comments on commit 37a934e

Please sign in to comment.