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: Remove addrman hotfixes #22496

Merged
merged 1 commit into from
Aug 3, 2021

Conversation

jnewbery
Copy link
Contributor

@jnewbery jnewbery commented Jul 19, 2021

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:

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().

@fanquake fanquake added the P2P label Jul 19, 2021
@jnewbery jnewbery changed the title [addrman] Remove RemoveInvalid() and ResetI2PPorts() addrman: Remove RemoveInvalid() and ResetI2PPorts() Jul 19, 2021
@jnewbery jnewbery changed the title addrman: Remove RemoveInvalid() and ResetI2PPorts() addrman: Remove addrman hotfixes Jul 19, 2021
@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 19, 2021

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

Conflicts

No conflicts as of last run.

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.

Code Review ACK 5dc4a74.

As I2P support hasn't even been released yet, it's much simpler and safer not to insert I2P addresses where port! = 0.

@hebasto
Copy link
Member

hebasto commented Jul 19, 2021

Is this pr for 22.0 release?

@laanwj
Copy link
Member

laanwj commented Jul 19, 2021

As I2P support hasn't even been released yet, it's much simpler and safer not to insert I2P addresses where port! = 0.

The thing is that I2P does support ports other than 0, just not in the currently used SAM proxy version (3.1). But there is no reason future versions of bitcoin core, or other clients, couldn't support I2P with ports. So I'm kind of divided on ignoring them completely, as that will give problems with such addresses not propagating later. See previous discussion here: #21514 (comment) #21514 (comment) .

@vasild
Copy link
Contributor

vasild commented Jul 20, 2021

  • In the long term we should keep in addrman and relay I2P addresses with port != 0. If dropping I2P entries with port != 0 is deemed necessary, then it should be a temporary measure for the same reasons e0a2b39 was temporary. I am a little bit inclined to leave I2P ports as they are, now that ResetI2PPorts() has been removed.

  • This PR seems to be complicating the already complicated Unserialize(). Complexity is a maintenance killer and a source of bugs. I find the isolated/separate method RemoveInvalid() easier to assess and test. Also it can be called from other places if needed (maybe from Check()?).

Instead of deserializing addresses, placing them in the buckets, and
then removing them if they're invalid, check first and don't place in
the buckets if they're invalid.
@jnewbery
Copy link
Contributor Author

In the long term we should keep in addrman and relay I2P addresses with port != 0. If dropping I2P entries with port != 0 is deemed necessary, then it should be a temporary measure for the same reasons e0a2b39 was temporary. I am a little bit inclined to leave I2P ports as they are, now that ResetI2PPorts() has been removed.

I haven't been following the I2P work closely, but I really don't understand the motivation for adding code to addrman in #22112. There are only a handful of people using (pre-release) I2P support, so why was code added to master to patch their addrmans if the intention was to remove that code before release?

I don't understand why we'd want to keep I2P addresses in addrman before bitcoind supports them. With the original version of this PR, it would have been easy to implement that - as soon as bitcoind supports non-port-0 I2P addresses, just remove the line from IsValidForAddrman() that disallows them.

In any case, #22497 was opened shortly after this PR and quickly merged, removing all of the I2P-specific code from addrman, so I've dropped the first commit.

This PR seems to be complicating the already complicated Unserialize(). Complexity is a maintenance killer and a source of bugs. I find the isolated/separate method RemoveInvalid() easier to assess and test. Also it can be called from other places if needed (maybe from Check()?).

This PR is +7/-40 and makes the addrman code simpler rather than more complicated. Currently, addresses are deserialized from peers.dat, added into buckets, and then removed if they're invalid. It's much simpler to just not add them into those buckets if they're invalid.

@jnewbery
Copy link
Contributor Author

Removing the v22 milestone. Now that the changes from #22112 have been reverted, this isn't urgent.

@jnewbery jnewbery removed this from the 22.0 milestone Jul 20, 2021
@maflcko
Copy link
Member

maflcko commented Jul 21, 2021

Needs OP adjusted?

@jnewbery
Copy link
Contributor Author

Needs OP adjusted?

Done

@vasild
Copy link
Contributor

vasild commented Jul 22, 2021

... so why was code added to master to patch their addrmans if the intention was to remove that code before release?

Just to answer the question: the intention was to include it in 22.0, see the commit message of e0a2b39. The reasons why it was removed earlier are stated in the commit message of the removal: d4b67c8.

@sipa
Copy link
Member

sipa commented Jul 22, 2021

utACK 65332b1. I tried to reason through scenarios that could introduce inconsistencies with this code, but can't find any.

I'm also working on a POC that replaces addrman's representation with something multiindex based, which is hopefully more easily reviewable for correctness/consistencies. But I'd like the existing addrman PRs in the pipeline to settle first.

@practicalswift
Copy link
Contributor

Concept ACK

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 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.

@fanquake fanquake merged commit 5cf28d5 into bitcoin:master Aug 3, 2021
@laanwj
Copy link
Member

laanwj commented Aug 3, 2021

Post-merge ACK.

@jnewbery jnewbery deleted the 2021-07-remove-addrman-hotfix branch August 3, 2021 07:49
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 4, 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.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants