-
Notifications
You must be signed in to change notification settings - Fork 36.5k
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
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
ping @0xB10C |
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.
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.
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 |
This information can be used to check bucketing logic. Github-Pull: bitcoin#30062 Rebased-From: 3733f6b
There was a problem hiding this 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
f80c47c
to
2de765c
Compare
Force-pushed:
|
There was a problem hiding this 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.
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.
2de765c
to
1e54d61
Compare
Code review ACK 1e54d61 |
There was a problem hiding this 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.
ACK 1e54d61 Successfully re-ran all previously mentioned tests. |
There was a problem hiding this 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 = [] |
There was a problem hiding this comment.
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?
return ret; | ||
} | ||
|
||
UniValue AddrmanTableToJSON(const std::vector<std::pair<AddrInfo, AddressPosition>>& tableInfos) | ||
UniValue AddrmanTableToJSON(const std::vector<std::pair<AddrInfo, AddressPosition>>& tableInfos, CConnman& connman) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here as https://github.com/bitcoin/bitcoin/pull/30062/files#r1612272793
{ | ||
UniValue ret(UniValue::VOBJ); | ||
ret.pushKV("address", info.ToStringAddr()); | ||
const auto mapped_as{connman.GetMappedAS(info)}; | ||
if (mapped_as != 0) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here as https://github.com/bitcoin/bitcoin/pull/30062/files#r1612276581.
@@ -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"}, |
There was a problem hiding this comment.
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).
{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"}, |
Thanks for reviewing, @jonatack. I'm working on a follow-up. |
Github-Pull: bitcoin#30062 Rebased-From: 8c27149 (partial)
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
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.