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

grpc: GetPeerInfo and GetNetworkInfo are not well defined #425

Closed
b00f opened this issue Nov 16, 2022 · 1 comment · Fixed by #898
Closed

grpc: GetPeerInfo and GetNetworkInfo are not well defined #425

b00f opened this issue Nov 16, 2022 · 1 comment · Fixed by #898
Assignees

Comments

@b00f
Copy link
Collaborator

b00f commented Nov 16, 2022

We try our best to define gRPC APIs as much as possible close to the Bitcoin JSON-RPC APIs. It looks the GetNetworkInfo and GetPeerInfo in our proto file are not well defined.

GetNetworkInfo

In Bitcoin, getnetworkinfo is designed to "Returns an object containing various state info regarding P2P networking".
For example, here is the result of calling getnetworkinfo in my local machine.

{
  "version": 220000,
  "subversion": "/Satoshi:22.0.0/",
  "protocolversion": 70016,
  "localservices": "0000000000000408",
  "localservicesnames": [
    "WITNESS",
    "NETWORK_LIMITED"
  ],
  "localrelay": true,
  "timeoffset": 0,
  "networkactive": true,
  "connections": 3,
  "connections_in": 0,
  "connections_out": 3,
  "networks": [
    {
      "name": "ipv4",
      "limited": false,
      "reachable": true,
      "proxy": "",
      "proxy_randomize_credentials": false
    },
    {
      "name": "ipv6",
      "limited": false,
      "reachable": true,
      "proxy": "",
      "proxy_randomize_credentials": false
    },
    {
      "name": "onion",
      "limited": true,
      "reachable": false,
      "proxy": "",
      "proxy_randomize_credentials": false
    },
    {
      "name": "i2p",
      "limited": true,
      "reachable": false,
      "proxy": "",
      "proxy_randomize_credentials": false
    }
  ],
  "relayfee": 0.00001000,
  "incrementalfee": 0.00001000,
  "localaddresses": [
    {
      "address": "....",
      "port": 8333,
      "score": 1
    },
    {
      "address": "....",
      "port": 8333,
      "score": 1
    }
  ],
  "warnings": ""
}

GetNetworkInfo in our proto returns the list of peers info. It is not compatible with the getnetworkinfo. So we need to redefine the GetNetworkInfoResponse properly.
We should be able to get information about the network from libp2p. We can do it in another PR, but it should be accessible in this gRPC call.

GetPeerInfo

In Bitcoin, getpeerinfo is designed to "Returns data about each connected network node as a json array of objects.".
For example, here is the result of calling getpeerinfo in my local machine.

[
  {
    "id": 0,
    "addr": "69.228.134.38:8333",
    "addrbind": "192.168.1.203:50606",
    "addrlocal": "115.134.6.105:50606",
    "network": "ipv4",
    "services": "0000000000000409",
    "servicesnames": [
      "NETWORK",
      "WITNESS",
      "NETWORK_LIMITED"
    ],
    "relaytxes": false,
    "lastsend": 1668569765,
    "lastrecv": 1668569765,
    "last_transaction": 0,
    "last_block": 1668569765,
    "bytessent": 9082,
    "bytesrecv": 118829731,
    "conntime": 1668569714,
    "timeoffset": -2,
    "pingtime": 0.253437,
    "minping": 0.253437,
    "version": 70016,
    "subver": "/Satoshi:23.0.0/",
    "inbound": false,
    "bip152_hb_to": false,
    "bip152_hb_from": false,
    "startingheight": 763371,
    "synced_headers": 763371,
    "synced_blocks": 512398,
    "inflight": [
      512566,
      512569,
      512570,
      512571,
      512574,
      512576,
      512579,
      512581,
      512582,
      512584,
      512587,
      512588,
      512591,
      512593,
      512611,
      512614
    ],
    "addr_processed": 0,
    "addr_rate_limited": 0,
    "permissions": [
    ],
    "minfeefilter": 0.00000000,
    "bytessent_per_msg": {
      "getdata": 7677,
      "getheaders": 1053,
      "ping": 32,
      "pong": 32,
      "sendaddrv2": 24,
      "sendcmpct": 66,
      "sendheaders": 24,
      "verack": 24,
      "version": 126,
      "wtxidrelay": 24
    },
    "bytesrecv_per_msg": {
      "block": 118362994,
      "feefilter": 32,
      "getheaders": 1053,
      "headers": 106,
      "ping": 32,
      "pong": 32,
      "sendaddrv2": 24,
      "sendcmpct": 66,
      "sendheaders": 24,
      "verack": 24,
      "version": 126,
      "wtxidrelay": 24
    },
    "connection_type": "block-relay-only"
  },
  {
    "id": 1,
    ...
  },
  {
    "id": 4,
    ...
  },
  {
    "id": 5,
    ...
  },
  {
    "id": 7,
   ...
  }
]

GetPeerInfo in our proto returns our local node info. It is not compatible with the getpeerinfo. So we need to redefine the GetPeerInfoResponse like:

message GetPeerInfoResponse {
  repeated PeerInfo peers = 1;
}

It should return the list of connected peers to our local node. The PeerInfo struct can be used here, but not for GetNetworkInfo. They might have some common fields like version, but they are not the same.

@b00f
Copy link
Collaborator Author

b00f commented Nov 16, 2022

related to #424

@b00f b00f changed the title gRPC: GetPeerInfo and GetNetworkInfo are not well defined grpc: GetPeerInfo and GetNetworkInfo are not well defined Nov 19, 2022
@kehiy kehiy self-assigned this Jan 3, 2024
@b00f b00f closed this as completed in #898 Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants