Skip to content

Commit 69f7f50

Browse files
author
MarcoFalke
committed
Merge #20993: test: store subversion (user agent) as string in msg_version
de85af5 test: store subversion (user agent) as string in msg_version (Sebastian Falbesoner) Pull request description: It seems more natural to treat the "subversion" field (=user agent string, see [BIP 14](https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki#Proposal)) of a node as pure string rather than a bytestring within the test framework. This is also suggested with the naming prefix in `msg_version.strSubVer`: one probably wouldn't expect a field starting with "str" to be a bytestring that needs further decoding to be useful. This PR moves the encoding/decoding parts to the serialization/deserialization routines so that the user doesn't have to bother with that anymore. Note that currently, in the master branch the `msg_version.strSubVer` is never read (only in `msg_version.__repr__`); However, one issue that is solved by this PR came up while testing #19509 (not merged yet): A decoding script for binary message capture files takes use of the functional test framework convert it into JSON format. Bytestrings will be convered to hexstrings, while pure strings will (surprise surprise) end up without modification in the file. So without this patch, we get: ``` $ jq . out.json | grep -m5 strSubVer "strSubVer": "2f5361746f7368693a32312e39392e302f" "strSubVer": "2f5361746f7368693a302e32302e312f" "strSubVer": "2f5361746f7368693a32312e39392e302f" "strSubVer": "2f5361746f7368693a302e32302e312f" "strSubVer": "2f5361746f7368693a32312e39392e302f" ``` After this patch: ``` $ jq . out2.json | grep -m5 strSubVer "strSubVer": "/Satoshi:21.99.0/" "strSubVer": "/Satoshi:0.20.1/" "strSubVer": "/Satoshi:21.99.0/" "strSubVer": "/Satoshi:0.20.1/" "strSubVer": "/Satoshi:21.99.0/" ``` ACKs for top commit: jnewbery: utACK de85af5 Tree-SHA512: ff23642705c858e8387a625537dfec82e6b8a15da6d99b8d12152560e52d243ba17431b602b26f60996d897e00e3f37dcf8dc8a303ffb1d544df29a5937080f9
2 parents 36be9b8 + de85af5 commit 69f7f50

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

test/functional/test_framework/messages.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
MIN_VERSION_SUPPORTED = 60001
3535
MY_VERSION = 70016 # past wtxid relay
36-
MY_SUBVERSION = b"/python-p2p-tester:0.0.3/"
36+
MY_SUBVERSION = "/python-p2p-tester:0.0.3/"
3737
MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)
3838

3939
MAX_LOCATOR_SZ = 101
@@ -1048,7 +1048,7 @@ def deserialize(self, f):
10481048
self.addrFrom = CAddress()
10491049
self.addrFrom.deserialize(f, with_time=False)
10501050
self.nNonce = struct.unpack("<Q", f.read(8))[0]
1051-
self.strSubVer = deser_string(f)
1051+
self.strSubVer = deser_string(f).decode('utf-8')
10521052

10531053
self.nStartingHeight = struct.unpack("<i", f.read(4))[0]
10541054

@@ -1069,7 +1069,7 @@ def serialize(self):
10691069
r += self.addrTo.serialize(with_time=False)
10701070
r += self.addrFrom.serialize(with_time=False)
10711071
r += struct.pack("<Q", self.nNonce)
1072-
r += ser_string(self.strSubVer)
1072+
r += ser_string(self.strSubVer.encode('utf-8'))
10731073
r += struct.pack("<i", self.nStartingHeight)
10741074
r += struct.pack("<b", self.nRelay)
10751075
return r

test/functional/test_framework/test_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ def addconnection_callback(address, port):
572572

573573
def num_test_p2p_connections(self):
574574
"""Return number of test framework p2p connections to the node."""
575-
return len([peer for peer in self.getpeerinfo() if peer['subver'] == MY_SUBVERSION.decode("utf-8")])
575+
return len([peer for peer in self.getpeerinfo() if peer['subver'] == MY_SUBVERSION])
576576

577577
def disconnect_p2ps(self):
578578
"""Close all p2p connections to the node."""

0 commit comments

Comments
 (0)