contrib: asmap-tool - Compare ASMaps with respect to specific addresses #30246

pull virtu wants to merge 1 commits into bitcoin:master from virtu:2024-06-compare-asmaps changing 1 files +41 −0
  1. virtu commented at 12:59 pm on June 7, 2024: contributor

    Right now, we have no way to quantify the “degradation” of an ASMap over time in the context of Bitcoin’s P2P network in a meaningful way. However, such data would be useful for:

    1. Making sure the minimum shelf life of ASMaps is compatible with the release cycle (we wouldn’t want to start shipping ASMaps with releases before making sure ASMaps typically do not become obsolete before the time of the next release)
    2. Node operators eager to keep their ASMaps up-to-date between releases.

    While asmap-tool.py has a diff command to perform a prefix-based comparison of two ASMaps, it is hard to reason about whether an old ASMap still is “good enough” or should be replaced with a newer one based on a prefix-based diff such as the following:

    0$ ./asmap-tool.py diff 1704463200_asmap.dat 1710770400_asmap.dat
    1[...]
    2# 2c0f:fc98::/32 was AS37282
    3# 2c0f:fcb8::/32 was AS37323
    42c0f:ff18::/32 AS37044 # was unassigned
    52c0f:ff98::/32 AS37113 # was unassigned
    62c0f:ffa0::/32 AS37273 # was unassigned
    7# 76082350 (2^26.18) IPv4 addresses changed; 834271985742505274886878979424260 (2^109.36) IPv6 addresses changed
    

    One option for a more Bitcoin-centric ASMap comparison comprises comparing ASNs for the addresses of Bitcoin nodes and reporting on the number/share of addresses of nodes with disagreeing ASNs. By applying this approach to a node’s set of known peers, a node operator can estimate how many of the node’s peers are mapped to out-of-date AS when using the currently deployed and an up-to-date ASMap as input.

    This PR adds this functionality to asmap-tool.py by introducing a diff_addrs subcommand. In addition to two ASMaps, the subcommand reads addresses from a (getnodeaddresses-compatible) file, and computes statistics for those addresses:

    0$ ./asmap-tool.py diff_addrs 1704463200_asmap.dat 1710770400_asmap.dat <(bitcoin-cli getnodeaddresses 0)
    1275 address(es) reassigned from unassigned to AS51167
    284 address(es) reassigned from AS198949 to AS15557
    366 address(es) reassigned from AS45758 to AS45629
    433 address(es) reassigned from AS174 to AS212238
    5[...]
    61 address(es) reassigned from unassigned to AS399619
    7Summary: 919 (1.67%) of 54,901 addresses were reassigned.
    

    When the -s / --show-addresses flag is used, addresses subject to reassignment are included in the output.

  2. DrahtBot commented at 12:59 pm on June 7, 2024: contributor

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

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK fjahr, brunoerg, achow101
    Concept ACK sipa

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  3. DrahtBot added the label Scripts and tools on Jun 7, 2024
  4. DrahtBot added the label CI failed on Jun 7, 2024
  5. DrahtBot commented at 5:22 pm on June 7, 2024: contributor

    🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the documentation.

    Possibly this is due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    Leave a comment here, if you need help tracking down a confusing failure.

    Debug: https://github.com/bitcoin/bitcoin/runs/25942564631

  6. fjahr commented at 9:19 am on June 8, 2024: contributor
    Concept ACK
  7. DrahtBot removed the label CI failed on Jun 9, 2024
  8. brunoerg commented at 12:26 pm on June 10, 2024: contributor
    Concept ACK
  9. brunoerg commented at 12:43 pm on June 21, 2024: contributor

    I haven’t looked at the code yet but I just tested it with two asmap files a few months apart and with 25k addresses, looks fine:

      078 address(es) reassigned from unassigned to AS51167
      147 address(es) reassigned from AS198949 to AS15557
      238 address(es) reassigned from AS45758 to AS45629
      318 address(es) reassigned from AS12715 to AS12479
      415 address(es) reassigned from AS57269 to AS8708
      512 address(es) reassigned from AS174 to AS212238
      69 address(es) reassigned from AS41378 to AS60024
      77 address(es) reassigned from unassigned to AS212238
      86 address(es) reassigned from AS212238 to AS174
      96 address(es) reassigned from AS9009 to AS51167
     106 address(es) reassigned from unassigned to AS141995
     116 address(es) reassigned from AS64286 to AS137409
     125 address(es) reassigned from AS834 to AS51167
     135 address(es) reassigned from AS62240 to AS206092
     145 address(es) reassigned from AS42366 to AS147049
     155 address(es) reassigned from AS202685 to AS51396
     164 address(es) reassigned from AS8972 to AS20773
     174 address(es) reassigned from AS3758 to AS9506
     184 address(es) reassigned from AS20838 to AS12479
     193 address(es) reassigned from AS51167 to AS40021
     203 address(es) reassigned from AS28220 to AS53059
     213 address(es) reassigned from AS8972 to AS29066
     223 address(es) reassigned from AS60808 to AS38136
     233 address(es) reassigned from AS9664 to AS38136
     243 address(es) reassigned from unassigned to AS39351
     253 address(es) reassigned from unassigned to AS136787
     263 address(es) reassigned from AS30860 to AS6698
     273 address(es) reassigned from AS22394 to AS6167
     282 address(es) reassigned from AS34549 to AS212238
     292 address(es) reassigned from AS61317 to AS62240
     302 address(es) reassigned from AS12638 to AS6805
     312 address(es) reassigned from AS57169 to AS9009
     322 address(es) reassigned from unassigned to AS41745
     332 address(es) reassigned from AS17554 to AS24334
     342 address(es) reassigned from AS42366 to AS136787
     352 address(es) reassigned from AS43180 to AS6698
     362 address(es) reassigned from AS43146 to AS197695
     372 address(es) reassigned from AS135097 to AS142286
     382 address(es) reassigned from AS264228 to AS28656
     392 address(es) reassigned from AS56902 to AS35197
     401 address(es) reassigned from unassigned to AS47583
     411 address(es) reassigned from AS35154 to AS12668
     421 address(es) reassigned from AS49276 to AS47987
     431 address(es) reassigned from unassigned to AS40021
     441 address(es) reassigned from AS8781 to AS42298
     451 address(es) reassigned from unassigned to AS50666
     461 address(es) reassigned from AS20454 to AS49037
     471 address(es) reassigned from unassigned to AS215623
     481 address(es) reassigned from AS6128 to AS53488
     491 address(es) reassigned from AS63023 to AS400175
     501 address(es) reassigned from AS207375 to AS206238
     511 address(es) reassigned from unassigned to AS203446
     521 address(es) reassigned from AS6167 to AS22394
     531 address(es) reassigned from AS31257 to AS204137
     541 address(es) reassigned from AS14277 to AS31769
     551 address(es) reassigned from AS26479 to AS397872
     561 address(es) reassigned from AS63023 to AS61112
     571 address(es) reassigned from AS25577 to unassigned
     581 address(es) reassigned from AS21769 to AS215659
     591 address(es) reassigned from AS61317 to AS47583
     601 address(es) reassigned from AS48728 to AS19905
     611 address(es) reassigned from AS10429 to AS26599
     621 address(es) reassigned from AS203963 to AS212238
     631 address(es) reassigned from unassigned to AS216071
     641 address(es) reassigned from AS6703 to AS21497
     651 address(es) reassigned from unassigned to AS152485
     661 address(es) reassigned from AS49055 to AS198610
     671 address(es) reassigned from AS3356 to unassigned
     681 address(es) reassigned from AS12389 to AS21378
     691 address(es) reassigned from AS59077 to AS58466
     701 address(es) reassigned from AS47869 to AS6206
     711 address(es) reassigned from AS206003 to AS206264
     721 address(es) reassigned from AS834 to AS47583
     731 address(es) reassigned from AS174 to AS400618
     741 address(es) reassigned from AS4134 to AS58466
     751 address(es) reassigned from AS834 to AS216183
     761 address(es) reassigned from AS51765 to AS136258
     771 address(es) reassigned from AS13672 to AS13977
     781 address(es) reassigned from AS59711 to AS215467
     791 address(es) reassigned from AS15542 to AS15435
     801 address(es) reassigned from AS55577 to AS18209
     811 address(es) reassigned from AS834 to AS134143
     821 address(es) reassigned from AS14080 to AS10620
     831 address(es) reassigned from AS136787 to AS62240
     841 address(es) reassigned from AS8851 to unassigned
     851 address(es) reassigned from AS28968 to AS216363
     861 address(es) reassigned from AS2542 to AS25472
     871 address(es) reassigned from AS31034 to AS202613
     881 address(es) reassigned from AS21586 to AS27425
     891 address(es) reassigned from AS49348 to AS3280
     901 address(es) reassigned from unassigned to AS57043
     911 address(es) reassigned from AS174 to AS3257
     921 address(es) reassigned from AS61317 to AS212238
     931 address(es) reassigned from AS209984 to AS203936
     941 address(es) reassigned from AS133199 to AS133861
     951 address(es) reassigned from AS57427 to AS57523
     961 address(es) reassigned from unassigned to AS197695
     971 address(es) reassigned from AS203020 to AS136787
     981 address(es) reassigned from AS208599 to AS199087
     991 address(es) reassigned from AS25086 to AS8359
    100Summary: 391 (1.51%) of 25,875 addresses were reassigned
    

    Looking at the ASes into peering db, the reassignments make sense.

  10. brunoerg approved
  11. brunoerg commented at 12:54 pm on June 24, 2024: contributor
    ACK 42eb7b144c09f0404487f2f5d17ca1a3e91c9365
  12. DrahtBot requested review from fjahr on Jun 24, 2024
  13. in contrib/asmap/asmap-tool.py:7 in 42eb7b144c outdated
    5@@ -6,7 +6,9 @@
    6 import argparse
    7 import sys
    


    fjahr commented at 1:36 pm on June 24, 2024:
    nit: sys isn’t in the right alphabetical order here. You could reorder it while you are at it.

    virtu commented at 2:47 pm on June 27, 2024:
    Moving sys doesn’t fully fix the import block because it is separated from the next function definition by only one newline. If I added another newline below the import block fix it, I should probably also add additional newlines between function definitions for consistency’s sake. Not sure if any/how much refactoring should be included here. wdyt?

    fjahr commented at 12:27 pm on July 8, 2024:
    It’s fine to leave it as is. It was just a nit :)
  14. in contrib/asmap/asmap-tool.py:127 in 42eb7b144c outdated
    122+    parser_diff_addrs.add_argument("infile1", type=argparse.FileType("rb"),
    123+                                   help="first file to compare (text or binary)")
    124+    parser_diff_addrs.add_argument("infile2", type=argparse.FileType("rb"),
    125+                                   help="second file to compare (text or binary)")
    126+    parser_diff_addrs.add_argument("addrs_file", type=argparse.FileType("r"),
    127+                                   help="address file generated with getnodeaddresses to use in the comparison")
    


    fjahr commented at 1:39 pm on June 24, 2024:
    You should name the specific settings to run getnodeaddresses with so that the result is as expected. I guess that would be 0 and all (default) right? I fear that if people do it wrong they could get a result like “nothing was reassigned” and then think: oh great, the internet is so stable nowadays ;)
  15. in contrib/asmap/asmap-tool.py:186 in 42eb7b144c outdated
    181+            new_asn = f"AS{new_asn}" if new_asn else "unassigned"
    182+            opt = ": " + ", ".join(reassigned_addrs) if args.show_addresses else ""
    183+            print(f"{num_reassigned} address(es) reassigned from {old_asn} to {new_asn}{opt}")
    184+        num_reassignments = sum(len(addrs) for _, addrs in reassignments)
    185+        share = num_reassignments / len(addrs) if len(addrs) > 0 else 0
    186+        print(f"Summary: {num_reassignments:,} ({share:.2%}) of {len(addrs):,} addresses were reassigned.")
    


    fjahr commented at 1:44 pm on June 24, 2024:
    Maybe add the count of addresses that were unassigned here specifically in the summary. Those may be among the most interesting to look at so I think it could be highlighted.

    virtu commented at 2:49 pm on June 27, 2024:

    Good idea. Total change is now broken down into migrations (from one AS to another), assignments (previously unassigned, now assigned to an AS) and unassignments (vice versa).

    Summary: 371 (1.37%) of 27,050 addresses were reassigned (migrations=242, assignments=125, unassignments=4)

  16. fjahr commented at 1:46 pm on June 24, 2024: contributor
    Looks good to me, just some additional documentation on documentation on the addrs input file would be good to avoid people getting strange results.
  17. DrahtBot requested review from fjahr on Jun 24, 2024
  18. sipa commented at 4:56 pm on June 24, 2024: member
    Concept ACK
  19. Compare ASMaps with respect to specific addresses
    Introduce diff_addrs subcommand as means for a Bitcoin-centric
    comparison of two ASMaps.
    
    In addition to two ASMaps, the subcommand reads addresses from
    a (getnodeaddresses-compatible) file, and provides information on
    addresses that have mismatching ASN according to the two ASMaps.
    5215c925d1
  20. virtu force-pushed on Jun 27, 2024
  21. fjahr commented at 12:47 pm on July 8, 2024: contributor

    tACK 5215c925d1382e71c9e1d642fced8a152c629c7f

    I played around with a few different input files, results look reasonable and I think this is a very helpful for analysis of generated asmap files.

    For anyone who wants to test but is missing asmap files, you can use the ones here: https://github.com/fjahr/asmap-data

  22. DrahtBot requested review from sipa on Jul 8, 2024
  23. DrahtBot requested review from brunoerg on Jul 8, 2024
  24. brunoerg approved
  25. brunoerg commented at 1:47 pm on July 8, 2024: contributor

    reACK 5215c925d1382e71c9e1d642fced8a152c629c7f

    verified the changes since my last review, lgtm.

  26. achow101 commented at 8:16 pm on August 12, 2024: member
    ACK 5215c925d1382e71c9e1d642fced8a152c629c7f
  27. achow101 merged this on Aug 12, 2024
  28. achow101 closed this on Aug 12, 2024

  29. virtu deleted the branch on Sep 11, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-28 22:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me