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: add ASMap info in getrawaddrman RPC #30062

Merged
merged 2 commits into from May 23, 2024

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

src/rpc/net.cpp Outdated Show resolved Hide resolved
@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: 3733f6b
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

src/rpc/net.cpp Outdated Show resolved Hide resolved
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

src/rpc/net.cpp Outdated Show resolved Hide resolved
@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 2de765c

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

src/rpc/net.cpp Outdated Show resolved Hide resolved
test/functional/feature_asmap.py Outdated Show resolved Hide resolved
@DrahtBot DrahtBot requested review from 0xB10C and virtu May 22, 2024 09:23
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

@@ -118,6 +119,14 @@ def test_asmap_health_check(self):
msg = "ASMap Health Check: 4 clearnet peers are mapped to 3 ASNs with 0 peers being unmapped"
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
16 checks passed
@@ -1093,20 +1093,28 @@ static RPCHelpMan getaddrmaninfo()
};
}

UniValue AddrmanEntryToJSON(const AddrInfo& info)
UniValue AddrmanEntryToJSON(const AddrInfo& info, CConnman& connman)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is connman passed by reference, and not reference to const? It isn't modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, I will address it in a follow-up PR.

return ret;
}

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

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
Contributor

@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("port", info.GetPort());
ret.pushKV("services", (uint64_t)info.nServices);
ret.pushKV("time", int64_t{TicksSinceEpoch<std::chrono::seconds>(info.nTime)});
ret.pushKV("network", GetNetworkName(info.GetNetClass()));
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
Contributor

Choose a reason for hiding this comment

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

@@ -1133,12 +1141,14 @@ static RPCHelpMan getrawaddrman()
{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
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants