Skip to content

Conversation

@xanimo
Copy link
Member

@xanimo xanimo commented Feb 26, 2023

This is a backport of bitcoin's 16702 pull request with a minimal subset of other cherry-picks needed in order to get it up and running.

@patricklodder patricklodder added this to the 1.14.7 milestone Feb 26, 2023
@patricklodder patricklodder requested a review from a team February 26, 2023 22:24
@patricklodder
Copy link
Member

@xanimo am I correct in my assumption that this PR also has a peer.dat downgrade issue as we discussed in #3149 (comment)?

I think this PR would give us an additional reason to make sure that we release a patch to 1.14.6 once we're done with the build system upgrade - correct?

@xanimo
Copy link
Member Author

xanimo commented Feb 26, 2023

@patricklodder i've not tested that actually so will need to do that when I get home however yes I agree on the patch post build system upgrade.

@xanimo
Copy link
Member Author

xanimo commented Feb 27, 2023

@patricklodder Hmm not certain if I'm doing it right but it would appear there are no errors from 1.14.6 to 1.14.7 and vice versa with regards to the peers.dat issue found in #3149.

@patricklodder
Copy link
Member

Thank you, that is hopeful. I'll make it part of testing to be sure.

@xanimo
Copy link
Member Author

xanimo commented Feb 27, 2023

Tested from this branch:

2023-02-27 01:08:52 init message: Loading addresses...
2023-02-27 01:08:52 ERROR: Read: Failed to open file /home/bluezr/.dogecoin/peers.dat
2023-02-27 01:08:52 Invalid or missing peers.dat; recreating

to 1.14.6 with debugging:

2023-02-27 01:09:33 init message: Loading addresses...
2023-02-27 01:09:33 Loaded 4828 addresses from peers.dat  25ms

and vice versa (1.14.6):

2023-02-27 01:14:22 init message: Loading addresses...
2023-02-27 01:14:22 ERROR: Read: Failed to open file /home/bluezr/.dogecoin/peers.dat
2023-02-27 01:14:22 Invalid or missing peers.dat; recreating

to this branch:

2023-02-27 01:15:26 init message: Loading addresses...
2023-02-27 01:15:26 Loaded 1767 addresses from peers.dat  8ms

Am still not sure if I'm doing it right though 🤷 anyway hope this helps.

@patricklodder
Copy link
Member

@xanimo would you mind rebasing this on top of the current 1.14.7-dev (502a8a9 or later)?

@xanimo
Copy link
Member Author

xanimo commented Jun 28, 2023

@xanimo would you mind rebasing this on top of the current 1.14.7-dev (502a8a9 or later)?

absolutely, will do shortly!

@edtubbs
Copy link
Contributor

edtubbs commented Jul 28, 2023

Initial tests with make check and qa/pull-tester/rpc-tests.py look good. Need to complete the review of code changes and tests. Very cool!

@patricklodder patricklodder removed this from the 1.14.7 milestone Feb 16, 2024
@xanimo xanimo closed this Feb 28, 2024
@xanimo xanimo deleted the 1.14.7-dev-asmap branch February 28, 2024 09:16
@patricklodder
Copy link
Member

Are you resubmitting this later?

I was still reviewing this and trying to find solutions for observed problems. Spent over a month on it so far.

@xanimo
Copy link
Member Author

xanimo commented Feb 28, 2024

Are you resubmitting this later?

I was still reviewing this and trying to find solutions for observed problems. Spent over a month on it so far.

Ah my apologies. I'll reopen and rebase on the next applicable dev branch later.

@patricklodder
Copy link
Member

No worries. Apologies from my end for not giving quick feedback. The puzzle on this one has been real.

I'm currently at the point of backtracking everything I did to make it work because I was all over the place. Will comment when I've untangled my mess.

@xanimo
Copy link
Member Author

xanimo commented Feb 28, 2024

Sounds good to me, keep me posted. I'll reopen shortly.

@xanimo xanimo restored the 1.14.7-dev-asmap branch February 28, 2024 18:52
@xanimo xanimo reopened this Feb 28, 2024
@xanimo xanimo changed the base branch from 1.14.7-dev to 1.15.0-dev February 28, 2024 18:54
@patricklodder patricklodder added this to the 1.15.0 milestone Mar 9, 2024
Copy link
Member

@patricklodder patricklodder left a comment

Choose a reason for hiding this comment

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

Test results

I tested this extensively and there are a number of bugs that Bitcoin Core has fixed that need to be backported, because the proposed code contains a bug that jumps too far sometimes, with the result that I saw AWS nodes reported as if they are ran by the US military (which is how I spotted this because I was wondering why Naval bases on both the East and West coast were running dogecoind.)

There are also some known vulnerabilities in the code as ported still.

Commits from upstream that I'd like to see back ported into this, so that we're not in limbo with bad AS detection (that peering decisions are made upon):

Prereqs

At least 2 things backported here should be separated out, I think:


BOOST_AUTO_TEST_CASE(addrman_serialization)
{
std::vector<bool> asmap1 = FromBytes(asmap, sizeof(asmap) * 8);
Copy link
Member

Choose a reason for hiding this comment

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

asmap here has a scope issue with gcc 12 / boost 1.74, should be: asmap_raw

uint256 nKey2 = (uint256)(CHashWriter(SER_GETHASH, 0) << 2).GetHash();

BOOST_CHECK(info1.GetNewBucket(nKey1) == 786);
std::vector<bool> asmap1 = FromBytes(asmap, sizeof(asmap) * 8);
Copy link
Member

Choose a reason for hiding this comment

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

asmap here has a scope issue with gcc 12 / boost 1.74, should be: asmap_raw

uint256 nKey1 = (uint256)(CHashWriter(SER_GETHASH, 0) << 1).GetHash();
uint256 nKey2 = (uint256)(CHashWriter(SER_GETHASH, 0) << 2).GetHash();

std::vector<bool> asmap1 = FromBytes(asmap, sizeof(asmap) * 8);
Copy link
Member

Choose a reason for hiding this comment

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

asmap here has a scope issue with gcc 12 / boost 1.74, should be: asmap_raw

@xanimo
Copy link
Member Author

xanimo commented Mar 22, 2024

Awesome I'll get to work on this over the weekend. Thanks!

Also very interesting re east/west coast naval bases/military running dogecoind... :suspect:

@patricklodder
Copy link
Member

If you like, I can pick up the fs wrapper in parallel - it also helps with std++17 transition.

@xanimo
Copy link
Member Author

xanimo commented Apr 5, 2024

Force pushed after rebase of #3487 and #3511.

@xanimo xanimo force-pushed the 1.14.7-dev-asmap branch 2 times, most recently from dff6167 to f1f6062 Compare April 6, 2024 20:19
@xanimo xanimo force-pushed the 1.14.7-dev-asmap branch from f1f6062 to ffe68e0 Compare April 15, 2024 19:38
@patricklodder
Copy link
Member

I suspect that after merging #3521, this PR should be fully enabled (from 82f372d onward)? Is there anything else needed as a prerequisite?

@xanimo
Copy link
Member Author

xanimo commented Jun 19, 2024

I don't believe there are any remaining prerequisites. Going to rebase off #3521 and upstream/1.15.0-dev to verify.

@xanimo xanimo force-pushed the 1.14.7-dev-asmap branch from ffe68e0 to 3730899 Compare June 19, 2024 01:00
@xanimo
Copy link
Member Author

xanimo commented Jun 19, 2024

Just passed unit tests on x86_64-pc-linux-gnu so I think we're good to go 🤞

@patricklodder
Copy link
Member

Test plan:

  1. Spend some time with fjahr/kartograf and build a more reliable asmap file
  2. Test concurrently with less reliable asmap files built with other scripts in previous rounds
  3. Parse peers.dat and look up how reliably AS are recognized with this version
  4. Upgrade/downgrade re-checks

I'll share files/results.

@patricklodder patricklodder changed the base branch from 1.15.0-dev to master August 9, 2024 00:49
@patricklodder patricklodder removed this from the 1.15.0 milestone Oct 13, 2024
@patricklodder patricklodder moved this from 🚀 needs review to 🔨needs rework in Review & merge board Mar 31, 2025
theuni and others added 14 commits July 5, 2025 18:29
We currently do two resolves for dns seeds: one for the results, and one to
serve in addrman as the source for those addresses.

There's no requirement that the source hostname resolves to the stored
identifier, only that the mapping is unique. So rather than incurring the
second lookup, combine a private subnet with a hash of the hostname.

The resulting v6 ip is guaranteed not to be publicy routable, and has only a
negligible chance of colliding with a user's internal network (which would be
of no consequence anyway).

Cherry-picked from: 7f31762
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>

Cherry-picked from: 8feb4e4
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.

Cherry-picked from: ec45646
If ASN bucketing is used, return a corresponding AS
used in bucketing for a given peer.

Cherry-picked from: e4658aa
@xanimo xanimo force-pushed the 1.14.7-dev-asmap branch from 3730899 to bdb4884 Compare July 6, 2025 03:44
@patricklodder patricklodder moved this from 🔨needs rework to 🚀 needs review in Review & merge board Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: 🚀 needs review

Development

Successfully merging this pull request may close these issues.

9 participants