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

Torv2 removal followups #22179

Merged
merged 3 commits into from Jul 8, 2021
Merged

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Jun 7, 2021

  • Simplify some code, now that we know CNetAddr::IsRFC4193() and CNetAddr::IsTor() cannot be true at the same time.
  • Drop Tor v2 addresses when loading addrman from peers.dat - they would have been loaded as dummy-all-zeros IPv6 addresses and linger in addrman, wasting space.

Reduce the condition `IsRFC4193() && !IsTor()` to `IsRFC4193()`. We know
that if `IsRFC4193()` is `true` then, for sure, the address is not Tor,
so `!IsTor()` is also `true`.
If an address classifies as `IsRFC4193()`, then it cannot be
`NET_ONION` (Tor v3), thus remove that condition from the assert.
@vasild
Copy link
Contributor Author

vasild commented Jun 7, 2021

cc @jonatack

@fanquake fanquake added the P2P label Jun 7, 2021
@jonatack
Copy link
Contributor

jonatack commented Jun 7, 2021

Thanks! Will have a look after tomorrow (Chaincode seminar, Optech writing and work interviews today and tomorrow).

@jonatack
Copy link
Contributor

jonatack commented Jun 7, 2021

Concept ACK

The Tor v2 addresses, left over from when Tor v2 was supported will be
unserialized as a dummy, invalid `::` (all zeros) IPv6 address. Remove
them so that they do not take up space in addrman.
@vasild
Copy link
Contributor Author

vasild commented Jun 7, 2021

26227ae770...00b875ba94: fix test mishap

@laanwj
Copy link
Member

laanwj commented Jun 7, 2021

Concept ACK

they would have been loaded as dummy-all-zeros IPv6 addresses and linger in addrman, wasting space.

Good catch.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 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:

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 Jun 8, 2021

ACK 00b875b. Reviewed the code, and tested with -DDEBUG_ADDRMAN (unit tests + mainnet run with peers.dat that contained v2 onions).

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 00b875b reviewed, debug-built with -DEBUG_ADDRMAN rebased to current master, restarted node on mainnet/signet/testnet and verified that on each chain -addrinfo shows no change in address counts (as expected). Added some sanity check asserts, rebuilt/re-ran test. Checked that the new test fails on master with "test/addrman_tests.cpp(824): error: in "addrman_tests/remove_invalid": check addrman.size() == 2 has failed [4 != 2]"

@naumenkogs
Copy link
Member

Concept ACK.

@0xB10C
Copy link
Contributor

0xB10C commented Jun 22, 2021

Concept ACK

Copy link
Member

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

ACK 00b875b

Cherry-picked each commit on top of master, and test compile + run unit tests. Tested on Linux and macOS connected through tor.

Notes on commits

  • a164cd3
    • checking for !isTor() is in fact redundant as IsRFC4193 calls IsIPV6. Since we've already determined that m_net is NET_IPV6, it is redundant to then check that it is not NET_ONION
  • bdb6209
    • makes sense to remove this here 🥃
    • code review ack only, did not fuzz
  • 00b875b
    • Code Review ACK
    • copied and pasted the test added here in addrman_tests.cpp onto master and confirm that the test would fail
      •  test/addrman_tests.cpp(824): error: in "addrman_tests/remove_invalid": check addrman.size() == 2 has failed [4 != 2]
        

@laanwj
Copy link
Member

laanwj commented Jul 8, 2021

Code review and lightly tested ACK 00b875b

@laanwj laanwj merged commit d968616 into bitcoin:master Jul 8, 2021
@vasild vasild deleted the torv2_removal_followup branch July 8, 2021 15:22
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 10, 2021
fanquake added a commit that referenced this pull request Aug 3, 2021
65332b1 [addrman] Remove RemoveInvalid() (John Newbery)

Pull request description:

  PRs #22179 and #22112 (EDIT: later reverted in #22497) added hotfix code to addrman to remove invalid addresses and mutate the ports of I2P entries after entering into addrman. Those hotfixes included at least two addrman data corruption bugs:

  - #22467 (Assertion `nRndPos1 < vRandom.size() && nRndPos2 < vRandom.size()' failed)
  - #22470 (Changing I2P ports in addrman may wronly skip some entries from "new" buckets)

  Hotfixing addrman is inherently dangerous. There are many members that have implicit assumptions on each others' state, and mutating those directly can lead to violating addrman's internal invariants.

  Instead of trying to hotfix addrman, just don't insert any invalid addresses. For now, those are addresses which fail `CNetAddr::IsValid()`.

ACKs for top commit:
  sipa:
    utACK 65332b1. I tried to reason through scenarios that could introduce inconsistencies with this code, but can't find any.
  fanquake:
    ACK 65332b1 - Skipping the addition of invalid addresses (this code was initially added for Tor addrs) rather than adding all the invalids then removing them all when finishing unserializing seems like an improvement. Especially if it can be achieved with less code.

Tree-SHA512: 023113764cb475572f15da7bf9824b62b79e10a7e359af2eee59017df354348d2aeed88de0fd4ad7a9f89a0dad10827f99d70af6f1cb20abb0eca2714689c8d7
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants