Skip to content

Commit 33c466a

Browse files
committed
Merge #16787: rpc: Human readable network services
66740f4 doc: add a release note for the new field in 'getpeerinfo' and 'getnetworkinfo' (darosior) 6564f58 rpc/net: decode the services flags in a new entry (darosior) Pull request description: This is a reopen of bitcoin/bitcoin#15511 (comment) since there have been concept ACKs from sdaftuar and Sjors. This adds a new entry to `getpeerinfo` and `getnetworkinfo` which decodes the network services flags. Here is a truncated output of `getpeerinfo`: ``` "services": "000000000000040d", "servicesnames": "NODE_NETWORK | NODE_BLOOM | NODE_WITNESS | NODE_NETWORK_LIMITED", "relaytxes": true, ``` And one of `getnetworkinfo`: ``` "localservices": "0000000000000409", "localservicesnames": "NODE_NETWORK | NODE_WITNESS | NODE_NETWORK_LIMITED", "localrelay": true, ``` Fixes #16780. ACKs for top commit: MarcoFalke: unsigned ACK 66740f4 laanwj: ACK 66740f4 Tree-SHA512: 0acc37134b283f56004a41243903d7790cb01591ddf0342489bd05f3a2c780563075373ba5fd55180fa15632e8968ffa11a979b8afece75a6a2e891342601440
2 parents 59681be + 66740f4 commit 33c466a

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

doc/release-notes-16787.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RPC changes
2+
-----------
3+
The `getnetworkinfo` and `getpeerinfo` commands now contain a new field with decoded network service flags.

src/rpc/net.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
8282
" \"addrbind\":\"ip:port\", (string) Bind address of the connection to the peer\n"
8383
" \"addrlocal\":\"ip:port\", (string) Local address as reported by the peer\n"
8484
" \"services\":\"xxxxxxxxxxxxxxxx\", (string) The services offered\n"
85+
" \"servicesnames\":[ (array) the services offered, in human-readable form\n"
86+
" \"SERVICE_NAME\", (string) the service name if it is recognised\n"
87+
" ...\n"
88+
" ],\n"
8589
" \"relaytxes\":true|false, (boolean) Whether peer has asked us to relay transactions to it\n"
8690
" \"lastsend\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n"
8791
" \"lastrecv\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n"
@@ -147,6 +151,7 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
147151
if (stats.addrBind.IsValid())
148152
obj.pushKV("addrbind", stats.addrBind.ToString());
149153
obj.pushKV("services", strprintf("%016x", stats.nServices));
154+
obj.pushKV("servicesnames", GetServicesNames(stats.nServices));
150155
obj.pushKV("relaytxes", stats.fRelayTxes);
151156
obj.pushKV("lastsend", stats.nLastSend);
152157
obj.pushKV("lastrecv", stats.nLastRecv);
@@ -446,6 +451,10 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
446451
" \"subversion\": \"/Satoshi:x.x.x/\", (string) the server subversion string\n"
447452
" \"protocolversion\": xxxxx, (numeric) the protocol version\n"
448453
" \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the services we offer to the network\n"
454+
" \"localservicesnames\": [ (array) the services we offer to the network, in human-readable form\n"
455+
" \"SERVICE_NAME\", (string) the service name\n"
456+
" ...\n"
457+
" ],\n"
449458
" \"localrelay\": true|false, (bool) true if transaction relay is requested from peers\n"
450459
" \"timeoffset\": xxxxx, (numeric) the time offset\n"
451460
" \"connections\": xxxxx, (numeric) the number of connections\n"
@@ -484,8 +493,11 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
484493
obj.pushKV("version", CLIENT_VERSION);
485494
obj.pushKV("subversion", strSubVersion);
486495
obj.pushKV("protocolversion",PROTOCOL_VERSION);
487-
if(g_connman)
488-
obj.pushKV("localservices", strprintf("%016x", g_connman->GetLocalServices()));
496+
if (g_connman) {
497+
ServiceFlags services = g_connman->GetLocalServices();
498+
obj.pushKV("localservices", strprintf("%016x", services));
499+
obj.pushKV("localservicesnames", GetServicesNames(services));
500+
}
489501
obj.pushKV("localrelay", g_relay_txes);
490502
obj.pushKV("timeoffset", GetTimeOffset());
491503
if (g_connman) {

src/rpc/util.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,3 +733,21 @@ std::vector<CScript> EvalDescriptorStringOrObject(const UniValue& scanobject, Fl
733733
}
734734
return ret;
735735
}
736+
737+
UniValue GetServicesNames(ServiceFlags services)
738+
{
739+
UniValue servicesNames(UniValue::VARR);
740+
741+
if (services & NODE_NETWORK)
742+
servicesNames.push_back("NETWORK");
743+
if (services & NODE_GETUTXO)
744+
servicesNames.push_back("GETUTXO");
745+
if (services & NODE_BLOOM)
746+
servicesNames.push_back("BLOOM");
747+
if (services & NODE_WITNESS)
748+
servicesNames.push_back("WITNESS");
749+
if (services & NODE_NETWORK_LIMITED)
750+
servicesNames.push_back("NETWORK_LIMITED");
751+
752+
return servicesNames;
753+
}

src/rpc/util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <node/transaction.h>
99
#include <outputtype.h>
1010
#include <pubkey.h>
11+
#include <protocol.h>
1112
#include <rpc/protocol.h>
1213
#include <rpc/request.h>
1314
#include <script/script.h>
@@ -90,6 +91,9 @@ std::pair<int64_t, int64_t> ParseDescriptorRange(const UniValue& value);
9091
/** Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range of 1000. */
9192
std::vector<CScript> EvalDescriptorStringOrObject(const UniValue& scanobject, FlatSigningProvider& provider);
9293

94+
/** Returns, given services flags, a list of humanly readable (known) network services */
95+
UniValue GetServicesNames(ServiceFlags services);
96+
9397
struct RPCArg {
9498
enum class Type {
9599
OBJ,

0 commit comments

Comments
 (0)