Skip to content

Commit 365f108

Browse files
committed
Merge #19112: rpc: Remove special case for unknown service flags
fa1433a rpc: Remove special case for unknown service flags (MarcoFalke) Pull request description: The special case to return a bit as an integer is clumsy and undocumented. Probably also irrelevant because there shouldn't currently be a non-misbehaving client that connects to Bitcoin Core and advertises an unknown service flag. Thus, simply remove the code. ACKs for top commit: laanwj: ACK fa1433a Tree-SHA512: 942de6a577a9ee076ce12c92be121617640d53ee8c3424064c45a30a7ff789555d3722a4203670768faf81da2a40adfed3ec5cdeb5da06f04be81ddb53b9db7e
2 parents 011fe00 + fa1433a commit 365f108

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/protocol.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
#include <protocol.h>
77

8-
#include <util/system.h>
98
#include <util/strencodings.h>
9+
#include <util/system.h>
1010

1111
#ifndef WIN32
1212
# include <arpa/inet.h>
@@ -220,11 +220,7 @@ static std::string serviceFlagToStr(size_t bit)
220220
std::ostringstream stream;
221221
stream.imbue(std::locale::classic());
222222
stream << "UNKNOWN[";
223-
if (bit < 8) {
224-
stream << service_flag;
225-
} else {
226-
stream << "2^" << bit;
227-
}
223+
stream << "2^" << bit;
228224
stream << "]";
229225
return stream.str();
230226
}

test/functional/rpc_net.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
NODE_WITNESS,
2929
)
3030

31+
3132
def assert_net_servicesnames(servicesflag, servicenames):
3233
"""Utility that checks if all flags are correctly decoded in
3334
`getpeerinfo` and `getnetworkinfo`.
@@ -40,6 +41,7 @@ def assert_net_servicesnames(servicesflag, servicenames):
4041
servicesflag_generated |= getattr(test_framework.messages, 'NODE_' + servicename)
4142
assert servicesflag_generated == servicesflag
4243

44+
4345
class NetTest(BitcoinTestFramework):
4446
def set_test_params(self):
4547
self.setup_clean_chain = True
@@ -57,6 +59,7 @@ def run_test(self):
5759
self._test_getnetworkinfo()
5860
self._test_getaddednodeinfo()
5961
self._test_getpeerinfo()
62+
self.test_service_flags()
6063
self._test_getnodeaddresses()
6164

6265
def _test_connection_count(self):
@@ -139,6 +142,11 @@ def _test_getpeerinfo(self):
139142
for info in peer_info:
140143
assert_net_servicesnames(int(info[0]["services"], 0x10), info[0]["servicesnames"])
141144

145+
def test_service_flags(self):
146+
self.nodes[0].add_p2p_connection(P2PInterface(), services=(1 << 4) | (1 << 63))
147+
assert_equal(['UNKNOWN[2^4]', 'UNKNOWN[2^63]'], self.nodes[0].getpeerinfo()[-1]['servicesnames'])
148+
self.nodes[0].disconnect_p2ps()
149+
142150
def _test_getnodeaddresses(self):
143151
self.nodes[0].add_p2p_connection(P2PInterface())
144152

@@ -174,5 +182,6 @@ def _test_getnodeaddresses(self):
174182
node_addresses = self.nodes[0].getnodeaddresses(LARGE_REQUEST_COUNT)
175183
assert_greater_than(LARGE_REQUEST_COUNT, len(node_addresses))
176184

185+
177186
if __name__ == '__main__':
178187
NetTest().main()

0 commit comments

Comments
 (0)