Skip to content

Conversation

jnewbery
Copy link
Contributor

@jnewbery jnewbery commented Sep 7, 2021

The asmap data is currently owned by addrman, but is used by both addrman and connman. #22791 made the data const and private (so that it can't be updated by other components), but it is still passed out of addrman as a reference to const, and used by CNetAddress to calculate the group and AS of the net address.

This RFC PR proposes to move all asmap data and logic into a new NetGroupManager component. This is initialized at startup, and the client components addrman and connman simply call NetGroupManager::GetGroup(const CAddress&) and NetGroupManager::GetMappedAS(const CAddress&) to get the net group and AS of an address.

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 7, 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:

  • #24925 (refactor: make GetRand a template, remove GetRandInt by PastaPastaPasta by PastaPastaPasta)
  • #23531 (Add Yggdrasil support by prusnak)
  • #22563 (addrman: treat Tor/I2P/CJDNS as a single group by vasild)
  • #21878 (Make all networking code mockable by vasild)
  • #19860 (p2p: Improve diversification of new connections by naumenkogs)
  • #13462 (Make SER_GETHASH implicit for CHashWriter and SerializeHash by Empact)

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.

@sipa
Copy link
Member

sipa commented Sep 7, 2021

Concept ACK (just judging the PR description)

@practicalswift
Copy link
Contributor

Concept ACK

@naumenkogs
Copy link
Member

Concept ACK, light code review ACK d70b354

Copy link
Contributor

@mzumsande mzumsande 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

fanquake added a commit that referenced this pull request Sep 10, 2021
853c4ed [net] Remove asmap argument from CNode::CopyStats() (John Newbery)
9fd5618 [asmap] Make DecodeAsmap() a utility function (John Newbery)
bfdf4ef [asmap] Remove SanityCheckASMap() from netaddress (John Newbery)
07a9ecc [net] Remove CConnman::Options.m_asmap (John Newbery)

Pull request description:

  These small cleanups to the asmap code are the first 4 commits from #22910. They're minor improvements that are independently useful whether or not 22910 is merged.

ACKs for top commit:
  naumenkogs:
    ACK 853c4ed
  theStack:
    Concept and code-review ACK 853c4ed 🗺️
  fanquake:
    ACK 853c4ed

Tree-SHA512: 64783743182592ac165df6ff8d18870b63861e9204ed722c207fca6938687aac43232a5ac4d8228cf8b92130ab0349de1b410a2467bb5a9d60dd9a7221b3b85b
@jnewbery jnewbery force-pushed the 2021-08-netgroupmgr branch 2 times, most recently from 54f6a6a to 3de73f1 Compare September 10, 2021 09:49
@jnewbery
Copy link
Contributor Author

Rebased and fixed #22910 (comment)

@jnewbery
Copy link
Contributor Author

rerebased

@amitiuttarwar
Copy link
Contributor

concept ACK

@jnewbery jnewbery force-pushed the 2021-08-netgroupmgr branch from 14ec5f5 to 3149a8c Compare April 19, 2022 10:08
@jnewbery
Copy link
Contributor Author

Rebased

These currently call through to the CNetAddr methods. The logic will be moved in a future commit.
…d GetGroup()

Also change parameter/variable names. This makes the next commit mostly
move-only.
Reviewer hint: use:

`git diff --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space`
asmap no longer needs to be exposed anywhere outside NetGroupManager.
@mzumsande
Copy link
Contributor

Code Review ACK 36f814c

Did some light sanity testing, and didn't run into any problems.

@jnewbery jnewbery force-pushed the 2021-08-netgroupmgr branch 2 times, most recently from fa4c923 to 36f814c Compare April 21, 2022 12:37
@jnewbery
Copy link
Contributor Author

jnewbery commented Apr 21, 2022

CI failure seems spurious. I rebased onto latest master to trigger a new CI run, but whilst I was doing that, mzumsande ACKed 36f814c, so I've reverted to that.

Copy link
Member

@dergoegge dergoegge left a comment

Choose a reason for hiding this comment

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

Code review ACK 36f814c

} else if (address.IsInternal()) {
// All internal-usage addresses get their own group.
// Skip over the INTERNAL_IN_IPV6_PREFIX returned by CAddress::GetAddrBytes().
nStartByte = INTERNAL_IN_IPV6_PREFIX.size();
Copy link
Member

Choose a reason for hiding this comment

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

nit: i think it would also be possible to keep the prefix and set nBits = (INTERNAL_IN_IPV6_PREFIX.size() + ADDR_INTERNAL_SIZE) * 8;. Then we wouldn't need to reintroduce nStartByte, which was previously also used for other address types.

// ...for the last byte, push nBits and for the rest of the byte push 1's
if (nBits > 0) {
assert(num_bytes < addr_bytes.size());
vchRet.push_back(addr_bytes[num_bytes] | ((1 << (8 - nBits)) - 1));
Copy link
Member

Choose a reason for hiding this comment

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

If nStartByte is ever used for other address types again it might be necessary to do the following:

Suggested change
vchRet.push_back(addr_bytes[num_bytes] | ((1 << (8 - nBits)) - 1));
vchRet.push_back(addr_bytes[num_bytes + nStartByte] | ((1 << (8 - nBits)) - 1));

See:

vchRet.push_back(GetByte(15 - nStartByte) | ((1 << (8 - nBits)) - 1));

@fanquake
Copy link
Member

@dergoegge you might want to open a followup with any suggestions / changes.
@jnewbery fyi I've edited your comment above to remove the @. Otherwise the ACK was being picked up and included in the merge message.

@fanquake fanquake merged commit 505ba39 into bitcoin:master Apr 22, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 22, 2022
@jnewbery jnewbery deleted the 2021-08-netgroupmgr branch April 22, 2022 21:33
@fjahr
Copy link
Contributor

fjahr commented Apr 24, 2022

post-merge code review ACK 36f814c

fanquake added a commit to bitcoin-core/gui that referenced this pull request May 4, 2022
e5d1831 [netgroup] Use nStartByte as offset for the last byte of the group (dergoegge)

Pull request description:

  This addresses my review [comments](bitcoin/bitcoin#22910 (comment)) I left on #22910.

  This has no effect on the current logic as `nStartByte` is only used for internal addresses which only ever add 10 whole bytes to the returned group. However to avoid future bugs, I think we should use `nStartByte` as offset for the last byte as well, in case we ever add a new address type that makes makes use of `nStartByte` and adds fractional bytes to the group.

ACKs for top commit:
  jnewbery:
    Code review ACK e5d1831
  theStack:
    Concept and code-review ACK e5d1831

Tree-SHA512: 4c08c7d6cb38b553e998798b3e3b790177aaa2141a48e277dfd538e01a7fccadf644329e93c5b0fb5e7e4037494c8dfe061b94eb52c6b31dc21bdf99eb0e311a
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 4, 2022
e5d1831 [netgroup] Use nStartByte as offset for the last byte of the group (dergoegge)

Pull request description:

  This addresses my review [comments](bitcoin#22910 (comment)) I left on bitcoin#22910.

  This has no effect on the current logic as `nStartByte` is only used for internal addresses which only ever add 10 whole bytes to the returned group. However to avoid future bugs, I think we should use `nStartByte` as offset for the last byte as well, in case we ever add a new address type that makes makes use of `nStartByte` and adds fractional bytes to the group.

ACKs for top commit:
  jnewbery:
    Code review ACK e5d1831
  theStack:
    Concept and code-review ACK e5d1831

Tree-SHA512: 4c08c7d6cb38b553e998798b3e3b790177aaa2141a48e277dfd538e01a7fccadf644329e93c5b0fb5e7e4037494c8dfe061b94eb52c6b31dc21bdf99eb0e311a
kouloumos added a commit to kouloumos/onboarding-to-bitcoin-core that referenced this pull request Feb 1, 2023
- add NetGroupManager as part of node
 p2p components after bitcoin/bitcoin#22910
 - update AddrMan description
@bitcoin bitcoin locked and limited conversation to collaborators Apr 24, 2023
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.