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

[Net] asmap to improve IP bucketing in addrman - backports #2480

Merged
merged 23 commits into from
Jul 30, 2021

Conversation

furszy
Copy link

@furszy furszy commented Jul 15, 2021

Decoupled from #2411, built on top of #2479. Probably the last decouple from the "road to Tor" work.

Focused on porting the ASN nodes bucketing functionality. The hearth of this work is bitcoin#16702.

Providing an asmap file that contains the IP->ASN mapping, nodes will be bucketed by AS they belong to, in order to make impossible for a node to connect to several nodes hosted in a single AS.
This is done in response to Erebus attack, but also to generally diversify the connections every node creates, especially useful when a large fraction of nodes operate under a couple of cloud providers.

List of PRs:

PRs for a follow up PR:

@furszy furszy self-assigned this Jul 15, 2021
@furszy furszy added this to the 6.0.0 milestone Jul 15, 2021
@furszy furszy force-pushed the 2021_ASN_IP_based_bucketing branch 2 times, most recently from 33ae75b to 7fead2c Compare July 21, 2021 16:39
@furszy
Copy link
Author

furszy commented Jul 21, 2021

rebased on master, ready to go.

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

Light code review ACK (with the last 2 test cases of feature_asmap fixed).
Will do some more testing.

src/serialize.h Outdated Show resolved Hide resolved
test/functional/feature_asmap.py Outdated Show resolved Hide resolved
test/functional/feature_asmap.py Outdated Show resolved Hide resolved
@random-zebra random-zebra added the Needs Release Notes Placeholder tag for anything needing mention in the "Notable Changes" section of release notes label Jul 23, 2021
@furszy furszy force-pushed the 2021_ASN_IP_based_bucketing branch from 7fead2c to 334df2e Compare July 23, 2021 13:59
@furszy
Copy link
Author

furszy commented Jul 23, 2021

Updated per zebra's feedback 👌, fixed the two commented test cases :).

@furszy furszy force-pushed the 2021_ASN_IP_based_bucketing branch 2 times, most recently from 13915de to 97e0497 Compare July 26, 2021 09:11
random-zebra
random-zebra previously approved these changes Jul 26, 2021
Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

Tested (also with demo.map from sipa's repo) ACK 97e0497

Nit:
Commit 63b6f99 should be split/squashed into 1e9a856 + a69b82d

@furszy
Copy link
Author

furszy commented Jul 26, 2021

done, squashed. I missed it between all of the open works.

random-zebra
random-zebra previously approved these changes Jul 26, 2021
Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

utACK a7138cf

@Fuzzbawls
Copy link
Collaborator

IMHO, I think eb3eba0 should be dropped and the issue fixed directly in upstream.

The extra indentation goes against the styling policies/guidelines for both us and upstream, and I would prefer to avoid intentionally (re-)introducing a policy violation that had been explicitly fixed in the past for a marginal improvement in ease of cherry-picking, especially being relatively close to upstream's HEAD in this particular file; which, given a quick glance, seems to be one of, if not the only file that has this styling discrepancy.

@Fuzzbawls
Copy link
Collaborator

Upstream PR addressing the indentation issue can be found at bitcoin#22562

@furszy
Copy link
Author

furszy commented Jul 27, 2021

yeah, it's the only file with text indentation discrepancies.

I made it because after, literally, more than two hundred commits back ported and adapted to our sources, it was becoming a pain in the ass to struggle against the same text indentation issue over and over, (with literally no benefits as it's just text indentation that can be re-added all at once at the end). Conflicting most of the file most of the times.

Saying that, now that the road to Tor path is clear (In netaddress.h history this is at 12 commits from the HEAD in #2411), it shouldn't take me much to drop the indentation change and apply the changes to every posterior commit. Will give it a quick look. It's one of those "meh" changes that no one in upstream really cared about for all of this years that we can have first for sure.

naumenkogs and others added 20 commits July 28, 2021 10:40
The scripts for creating a compact IP->ASN mapping are here:
https://github.com/sipa/asmap

Co-authored-by: Pieter Wuille <pieter.wuille@gmail.com>
Instead of using /16 netgroups to bucket nodes in Addrman for connection
diversification, ASN, which better represents an actor in terms
of network-layer infrastructure, is used.
For testing, asmap.raw is used. It represents a minimal
asmap needed for testing purposes.

Adaptation of btc@ec45646de9e62b3d42c85716bfeb06d8f2b507dc with the latest version of the asmap.raw file.
-BEGIN VERIFY SCRIPT-

sed --in-place'' --expression='s/NET_TOR/NET_ONION/g' $(git grep -I --files-with-matches 'NET_TOR')

-END VERIFY SCRIPT-

The --in-place'' hack is required for sed on macOS to edit files in-place without passing a backup extension.
If ASN bucketing is used, return a corresponding AS
used in bucketing for a given peer.
to verify node behaviour and debug log when launching bitcoind in these cases:

1. `bitcoind` with no -asmap arg, using /16 prefix for IP bucketing

2. `bitcoind -asmap=<relative path>`, using the unit test skeleton asmap

3. `bitcoind -asmap/-asmap=` with no file specified, using the default asmap

4. `bitcoind -asmap` with no file specified, and a missing default asmap file

The tests are order-independent. The slowest test (missing default asmap file)
is placed last.
- allow passing an absolute file path to the -asmap config arg

- update the -asmap config help

- add a functional test in feature_asmap.py
This is now testable after separating the asmap finding and parsing checks in the previous commit.
- move asmap #includes to sorted positions in addrman and init (move-only)

- remove redundant quotes in asmap InitError, update test

- remove full stops from asmap logging to be consistent with debug logging,
  update tests
Remove redundant public declaration and mention if mapped_as is only available if the asmap config flag is set.
and update feature_asmap.py and test_runner.py

This commit moves the asmap init.cpp code from the end of "Step 12: start node"
to "Step 6: network initialization" to provide feedback on passing an -asmap
config arg much more quickly. This change speeds up the feature_asmap.py
functional test file from 60 to 5 seconds by accelerating the 2 tests that use
`assert_start_raises_init_error`.

Credit to Wladimir J. van der Laan for the suggestion.
@furszy furszy force-pushed the 2021_ASN_IP_based_bucketing branch from 011d033 to 16791f2 Compare July 28, 2021 13:42
@furszy
Copy link
Author

furszy commented Jul 28, 2021

rebased again, conflict solved. Ready to go.

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

re-utACK 16791f2

Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

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

ACK 16791f2

@random-zebra random-zebra merged commit 85f000e into PIVX-Project:master Jul 30, 2021
@random-zebra random-zebra removed the Needs Release Notes Placeholder tag for anything needing mention in the "Notable Changes" section of release notes label Aug 24, 2021
@furszy furszy deleted the 2021_ASN_IP_based_bucketing branch November 29, 2022 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants