Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused constants CADDR_TIME_VERSION and GETHEADERS_VERSION #19486

Merged
merged 2 commits into from Jul 13, 2020

Conversation

jnewbery
Copy link
Contributor

These constants are no longer required and can be removed.

Additional code comments are added to explain CAddress serialization.

@Empact
Copy link
Member

Empact commented Jul 10, 2020

Code review ACK 158f28d

See also #14033.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

test/functional/test_framework/messages.py Outdated Show resolved Hide resolved
@@ -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))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style-nit: the python code reads much nicer, so I'd slightly prefer if the C++ code was also easy to read. Not blocking of course, but for example passing down an option with_time per #19477 (comment) would be nice.

Copy link
Member

@sipa sipa Jul 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on that. In a branch I'm working on I have this patch that make another (vaguely related) readability improvement:

diff --git a/src/protocol.h b/src/protocol.h
index 985f44640b..b74a24e007 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -359,6 +359,11 @@ class CAddress : public CService
 {
     static constexpr uint32_t TIME_INIT{100000000};
 
+    /** The disk serialization for CAddress includes a version number.
+     *  Traditionally the number CLIENT_VERSION was used, but has since
+     *  been disentangled from it. */
+    static constexpr int DISK_VERSION{201000};
+
 public:
     CAddress() : CService{} {};
     explicit CAddress(CService ipIn, ServiceFlags nServicesIn) : CService{ipIn}, nServices{nServicesIn} {};
@@ -366,13 +371,14 @@ public:
     SERIALIZE_METHODS(CAddress, obj)
     {
         SER_READ(obj, obj.nTime = TIME_INIT);
-        int nVersion = s.GetVersion();
         if (s.GetType() & SER_DISK) {
-            READWRITE(nVersion);
-        }
-        if ((s.GetType() & SER_DISK) ||
-            (nVersion >= CADDR_TIME_VERSION && !(s.GetType() & SER_GETHASH))) {
+            int disk_version = DISK_VERSION;
+            READWRITE(disk_version);
             READWRITE(obj.nTime);
+        } else if (s.GetType() & SER_NETWORK) {
+            if (s.GetVersion() >= CADDR_TIME_VERSION) {
+                READWRITE(obj.nTime);
+            }
         }
         READWRITE(Using<CustomUintFormatter<8>>(obj.nServices));
         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).

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.
@jnewbery
Copy link
Contributor Author

I think this can be taken separately from @sipa's suggested change.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 11, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

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.

@maflcko
Copy link
Member

maflcko commented Jul 11, 2020

ACK 7bb6f9b already an improvement, but maybe getting rid of INIT_PROTO_VERSION here would be an even stronger improvement (can be done later)

@jnewbery
Copy link
Contributor Author

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)

Copy link
Contributor

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 7bb6f9b

@practicalswift
Copy link
Contributor

Concept ACK: less cruft is good

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 7bb6f9b

@jnewbery
Copy link
Contributor Author

I think this is ready for merge. Three ACKs on the current HEAD:

vasild (#19486 (review))
jonatack (#19486 (review))
MarcoFalke (#19486 (comment))

plus one ACK on a previous HEAD:

empact (#19486 (comment))

@maflcko maflcko merged commit 631284f into bitcoin:master Jul 13, 2020
@jnewbery jnewbery deleted the pr14033.1 branch July 13, 2020 10:09
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 14, 2020
… `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
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 24, 2020
Summary:
```
These constants are no longer required and can be removed.

Additional code comments are added to explain CAddress serialization.
```

Backport of core [[bitcoin/bitcoin#19486 | PR19486]].

Depends on D8514.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D8515
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants