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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
@@ -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))) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I think this can be taken separately from @sipa's suggested change. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
ACK 7bb6f9b already an improvement, but maybe getting rid of INIT_PROTO_VERSION here would be an even stronger improvement (can be done later) |
I agree that'd be good. Let's save it until after the various version fields in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 7bb6f9b
Concept ACK: less cruft is good |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 7bb6f9b
I think this is ready for merge. Three ACKs on the current HEAD: vasild (#19486 (review)) plus one ACK on a previous HEAD: empact (#19486 (comment)) |
… `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
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
These constants are no longer required and can be removed.
Additional code comments are added to explain CAddress serialization.