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

[addrman] De-duplicate Add() function #22627

Closed

Conversation

amitiuttarwar
Copy link
Contributor

This PR merges the two definitions of this overloaded function to reduce code duplication.

When these functions were introduced in 5fee401, there were multiple places that invoked Add() with a single addr and a vector of addrs each, so it made sense to overload the function. I could see how the small difference in log statement was more meaningful when a peer was added via IRC :)

Now, the definition of Add() that takes in a single address is only invoked from the hidden/test-only RPC addpeeraddress. These changes should not cause any observable difference, and are covered by the existing tests that use this RPC endpoint.

@ghost
Copy link

ghost commented Aug 4, 2021

when a peer was added via IRC :)

IRC?

@sipa
Copy link
Member

sipa commented Aug 4, 2021

Before DNS seeds existed, bitcoin would connect to a specific IRC server, join a channel, and look for other nodes joining that channel, and then insert those to its IP address database.

@practicalswift
Copy link
Contributor

Concept ACK

+3 −17 is nice

@ghost
Copy link

ghost commented Aug 4, 2021

Before DNS seeds existed, bitcoin would connect to a specific IRC server, join a channel, and look for other nodes joining that channel, and then insert those to its IP address database.

Interesting. TIL. Thanks @sipa

I think Joinmarket does something similar for peers participating in coinjoin.

@Zero-1729
Copy link
Contributor

Concept ACK

Copy link
Contributor

@lsilva01 lsilva01 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 6ef302e

However this change breaks test\addrman_tests.cpp test.
Maybe keeping the removed Add(const CAddress &addr ...) method as a proxy to bool Add(const std::vector<CAddress> &vAddr, ...) can prevent this.

bool Add(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty = 0)
        EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
    std::vector<CAddress> vAddr{addr};
    return Add(vAddr, source, nTimePenalty);
}

@amitiuttarwar
Copy link
Contributor Author

oops, tests! marking as draft until I resolve 😛

@0xB10C
Copy link
Contributor

0xB10C commented Aug 5, 2021

Concept ACK

@bitcoin bitcoin deleted a comment from Dunlap28 Aug 5, 2021
@theStack
Copy link
Contributor

theStack commented Aug 5, 2021

Concept ACK

@amitiuttarwar
Copy link
Contributor Author

The two CI failures seem unrelated. They both fail with:

test/miner_tests.cpp:219:32: error: use of undeclared identifier 'VERSIONBITS_TOP_BITS'

This PR doesn't touch miner_tests, and that file does not call CAddrMan::Add(). It passes locally on this branch as well as rebased on master. I suspect its something strange with the auto-merge to master, since #22277 was just merged.

That said, I'm going to leave this in a draft so it doesn't cause conflict with #20233- that change is more important :)

@jnewbery
Copy link
Contributor

jnewbery commented Aug 5, 2021

Concept ACK

@mzumsande
Copy link
Contributor

mzumsande commented Aug 5, 2021

The CI failures were fixed with #22630.

Concept ACK

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 6, 2021

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #22697 (addrman: Remove CAddrMan::Clear() function by jnewbery)

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.

@jnewbery
Copy link
Contributor

#20233 has been merged. I'm happy to review this once it's been rebased on master.

Merge the two definitions of this overloaded function to reduce code
duplication.
@amitiuttarwar
Copy link
Contributor Author

rebased on master, ready for review!

@jnewbery
Copy link
Contributor

Code review ACK 60e0cbd

Nice cleanup

Copy link
Contributor

@Zero-1729 Zero-1729 left a comment

Choose a reason for hiding this comment

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

crACK 60e0cbd

LGTM 🧉

Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

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

ACK 60e0cbd

fanquake added a commit to bitcoin-core/gui that referenced this pull request Aug 17, 2021
60e0cbd [addrman] Merge the two Add() functions (Amiti Uttarwar)

Pull request description:

  This PR merges the two definitions of this overloaded function to reduce code duplication.

  When these functions were introduced in bitcoin/bitcoin@5fee401, there were multiple places that invoked `Add()` with a single addr and a vector of addrs each, so it made sense to overload the function. I could see how the small difference in log statement was more meaningful when a peer was added via IRC :)

  Now, the definition of `Add()` that takes in a single address is only invoked from the hidden/test-only RPC `addpeeraddress`. These changes should not cause any observable difference, and are covered by the existing tests that use this RPC endpoint.

ACKs for top commit:
  jnewbery:
    Code review ACK 60e0cbd
  Zero-1729:
    crACK 60e0cbd
  fanquake:
    ACK 60e0cbd

Tree-SHA512: 782fb2ac6d2d403ba7d7ff543197ca42b610b9a8806952d271e57e2ee3527ad1a94af4ebbad5371b5e95d77df07c56ccc8c1d5a2c82cdecb0d2b5085b3bdd5ee
@fanquake
Copy link
Member

This has been merged in f3dbd1c.

@fanquake fanquake closed this Aug 17, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 20, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 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