Skip to content

Conversation

@brunoerg
Copy link
Contributor

@brunoerg brunoerg commented May 8, 2024

This PR adds two new fields in getrawaddrman RPC: "mapped_as" and "source_mapped_as". These fields are used to return the ASN (Autonomous System Number) mapped to the peer and its source. With these informations we can have a better view of the bucketing logic with ASMap specially in projects like addrman-observer.

@DrahtBot
Copy link
Contributor

DrahtBot commented May 8, 2024

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, 0xB10C, virtu, glozow

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

@DrahtBot DrahtBot added the P2P label May 8, 2024
@brunoerg
Copy link
Contributor Author

brunoerg commented May 8, 2024

ping @0xB10C

0xB10C added a commit to 0xB10C/addrman-observer that referenced this pull request May 8, 2024
With bitcoin/bitcoin#30062, the mapped_as
and source_mapped_as fields are introduced. These are handled here
as optional, since older Bitcoin Core versions might not have them
yet and it might never be merged.
0xB10C added a commit to 0xB10C/addrman-observer that referenced this pull request May 8, 2024
With bitcoin/bitcoin#30062, the mapped_as
and source_mapped_as fields are introduced. These are handled here
as optional, since older Bitcoin Core versions might not have them
yet and it might never be merged.
@0xB10C
Copy link
Contributor

0xB10C commented May 8, 2024

Cool! Concept ACK.

I've added prelimarly support for this in the static HTML page on https://addrman.observer. You can now load the new getrawaddrman dumps and it will show you the AS and source AS. You can also mouse-over highlight by AS and source ASN.

image

@brunoerg
Copy link
Contributor Author

brunoerg commented May 9, 2024

cc: @virtu @fjahr

luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request May 13, 2024
This information can be used to check bucketing
logic.

Github-Pull: bitcoin#30062
Rebased-From: 3733f6b8119e89c5a6498c5781bf5b8ec8e795a1
Copy link
Contributor

@virtu virtu left a comment

Choose a reason for hiding this comment

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

Concept ACK

Also did some light testing:

  • Some sanity checks on getrawaddrman output (everything mapped to zero when asmap is disabled; almost all addresses mapped to non-zero when enabled)
  • Functional tests

Copy link
Contributor

@fjahr fjahr left a comment

Choose a reason for hiding this comment

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

Concept ACK

@brunoerg brunoerg force-pushed the 2024-04-asmap-getrawaddrman branch from f80c47c to 2de765c Compare May 22, 2024 09:11
@brunoerg
Copy link
Contributor Author

Force-pushed:

Copy link
Contributor

@fjahr fjahr 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 2de765c25017e566777d927d86452d96082592a1

Feel free to ignore the nits but I can re-review quickly if you address them.

@DrahtBot DrahtBot requested review from 0xB10C and virtu May 22, 2024 09:23
brunoerg added 2 commits May 22, 2024 07:57
This information can be used to check bucketing
logic.
Test addresses are being mapped according to the ASMap
file provided properly. Compare the result of the `getrawaddrman`
RPC with the result from the ASMap Health Check.
@brunoerg brunoerg force-pushed the 2024-04-asmap-getrawaddrman branch from 2de765c to 1e54d61 Compare May 22, 2024 10:58
@fjahr
Copy link
Contributor

fjahr commented May 22, 2024

Code review ACK 1e54d61

Copy link
Contributor

@0xB10C 0xB10C left a comment

Choose a reason for hiding this comment

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

ACK 1e54d61

I've played around with the getrawaddrman RPC with and without an asmap file loaded. Also loaded a json dump into addrman-observer. Works as expected.

@virtu
Copy link
Contributor

virtu commented May 23, 2024

ACK 1e54d61

Successfully re-ran all previously mentioned tests.

Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

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

ACK 1e54d61

with self.node.assert_debug_log(expected_msgs=[msg]):
self.start_node(0, extra_args=['-asmap'])
raw_addrman = self.node.getrawaddrman()
asns = []
Copy link
Member

Choose a reason for hiding this comment

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

nit: this could have been a set?

@glozow glozow merged commit 83ae1ba into bitcoin:master May 23, 2024
}

UniValue AddrmanTableToJSON(const std::vector<std::pair<AddrInfo, AddressPosition>>& tableInfos)
UniValue AddrmanTableToJSON(const std::vector<std::pair<AddrInfo, AddressPosition>>& tableInfos, CConnman& connman)
Copy link
Member

Choose a reason for hiding this comment

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

UniValue ret(UniValue::VOBJ);
ret.pushKV("address", info.ToStringAddr());
const auto mapped_as{connman.GetMappedAS(info)};
if (mapped_as != 0) {
Copy link
Member

@jonatack jonatack May 23, 2024

Choose a reason for hiding this comment

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

Using auto here requires looking up GetMappedAS to know the type (at least, for people using simple editors and not fancier IDEs). Using the actual type in this case would have been clearer to the reader. The conditional could also have been simpler, though that's arguably a style nit.

-    const auto mapped_as{connman.GetMappedAS(info)};
-    if (mapped_as != 0) {
+    const uint32_t mapped_as{connman.GetMappedAS(info)};
+    if (mapped_as) {

ret.pushKV("source", info.source.ToStringAddr());
ret.pushKV("source_network", GetNetworkName(info.source.GetNetClass()));
const auto source_mapped_as{connman.GetMappedAS(info.source)};
if (source_mapped_as != 0) {
Copy link
Member

Choose a reason for hiding this comment

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

{RPCResult::Type::OBJ_DYN, "table", "buckets with addresses in the address manager table ( new, tried )", {
{RPCResult::Type::OBJ, "bucket/position", "the location in the address manager table (<bucket>/<position>)", {
{RPCResult::Type::STR, "address", "The address of the node"},
{RPCResult::Type::NUM, "mapped_as", /*optional=*/true, "The ASN mapped to the IP of this peer per our current ASMap"},
Copy link
Member

@jonatack jonatack May 23, 2024

Choose a reason for hiding this comment

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

Here and in the other new help below, the reason for the optional nature of this field could perhaps be mentioned (as simply as , if present, or perhaps in more detail).

Suggested change
{RPCResult::Type::NUM, "mapped_as", /*optional=*/true, "The ASN mapped to the IP of this peer per our current ASMap"},
{RPCResult::Type::NUM, "mapped_as", /*optional=*/true, "The ASN mapped to the IP of this peer per our current ASMap, if present"},

@brunoerg
Copy link
Contributor Author

Thanks for reviewing, @jonatack. I'm working on a follow-up.

luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Jun 13, 2024
fanquake added a commit that referenced this pull request Oct 22, 2024
a16917f rpc, net: improve `mapped_as` doc for getrawaddrman/getpeerinfo (brunoerg)
bdad024 rpc, net: getrawaddrman "mapped_as" follow-ups (brunoerg)

Pull request description:

  - Change `addrman` to reference to const since it isn't modified (#30062 (comment)).
  - Improve documentation of `mapped_as`/`source_mapped_as` in `getrawaddrman` RPC by mentioning that both fields will be only available if asmap flag is set. It is the same message for `mapped_as` field in `getpeerinfo`.

ACKs for top commit:
  fjahr:
    re-ACK a16917f
  0xB10C:
    re-ACK a16917f
  laanwj:
    re-ACK  a16917f

Tree-SHA512: c66b2ee9d24da93d443be83f6ef3b2d39fd5bf3f73e2974574cad238ffb82035704cf4fbf1bac22a63734948e285e8e091c2884bb640202efdb473315e770233
@bitcoin bitcoin locked and limited conversation to collaborators May 23, 2025
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.

7 participants