These constants are no longer required and can be removed.
Additional code comments are added to explain CAddress serialization.
CADDR_TIME_VERSION
and GETHEADERS_VERSION
#19486
These constants are no longer required and can be removed.
Additional code comments are added to explain CAddress serialization.
218@@ -218,6 +219,7 @@ def deserialize(self, f, with_time=True):
219 def serialize(self, with_time=True):
style-nit: Passing pod literals without a name makes code harder to read. My preference would be to rule out the possibility to pass without name.
0 def serialize(self, *, with_time=True):
Same for unserialize, see #14033 (comment)
True
or 1
. Not sure what the right term for that is
Code review ACK https://github.com/bitcoin/bitcoin/pull/19486/commits/158f28d9faf8105b6ed2e3440f21691e5e9ff75b
See also #14033.
Add comments to CAddress serialization code explaining why
it's no longer needed.
GETHEADERS_VERSION is unused. No need to keep it in the codebase
for just its historic comment.
370@@ -371,7 +371,13 @@ class CAddress : public CService
371 READWRITE(nVersion);
372 }
373 if ((s.GetType() & SER_DISK) ||
374- (nVersion >= CADDR_TIME_VERSION && !(s.GetType() & SER_GETHASH))) {
375+ (nVersion != INIT_PROTO_VERSION && !(s.GetType() & SER_GETHASH))) {
with_time
per #19477 (comment) would be nice.
I’m working on that. In a branch I’m working on I have this patch that make another (vaguely related) readability improvement:
0diff --git a/src/protocol.h b/src/protocol.h
1index 985f44640b..b74a24e007 100644
2--- a/src/protocol.h
3+++ b/src/protocol.h
4@@ -359,6 +359,11 @@ class CAddress : public CService
5 {
6 static constexpr uint32_t TIME_INIT{100000000};
7
8+ /** The disk serialization for CAddress includes a version number.
9+ * Traditionally the number CLIENT_VERSION was used, but has since
10+ * been disentangled from it. */
11+ static constexpr int DISK_VERSION{201000};
12+
13 public:
14 CAddress() : CService{} {};
15 explicit CAddress(CService ipIn, ServiceFlags nServicesIn) : CService{ipIn}, nServices{nServicesIn} {};
16@@ -366,13 +371,14 @@ public:
17 SERIALIZE_METHODS(CAddress, obj)
18 {
19 SER_READ(obj, obj.nTime = TIME_INIT);
20- int nVersion = s.GetVersion();
21 if (s.GetType() & SER_DISK) {
22- READWRITE(nVersion);
23- }
24- if ((s.GetType() & SER_DISK) ||
25- (nVersion >= CADDR_TIME_VERSION && !(s.GetType() & SER_GETHASH))) {
26+ int disk_version = DISK_VERSION;
27+ READWRITE(disk_version);
28 READWRITE(obj.nTime);
29+ } else if (s.GetType() & SER_NETWORK) {
30+ if (s.GetVersion() >= CADDR_TIME_VERSION) {
31+ READWRITE(obj.nTime);
32+ }
33 }
34 READWRITE(Using<CustomUintFormatter<8>>(obj.nServices));
35 READWRITEAS(CService, obj);
Which makes it clear that the version constant being compared to has nothing to do with the client version (and never has).
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
getting rid of INIT_PROTO_VERSION here would be an even stronger improvement
I agree that’d be good. Let’s save it until after the various version fields in CNode
are unified (#17785)
I think this is ready for merge. Three ACKs on the current HEAD:
vasild (https://github.com/bitcoin/bitcoin/pull/19486#pullrequestreview-447018856) jonatack (https://github.com/bitcoin/bitcoin/pull/19486#pullrequestreview-446803209) MarcoFalke (https://github.com/bitcoin/bitcoin/pull/19486#issuecomment-657032601)
plus one ACK on a previous HEAD:
empact (https://github.com/bitcoin/bitcoin/pull/19486#issuecomment-656874195)