Good question. On master, this scenario would lead to a (confusing) error right now, since calling ser_uint256(...)
with a non-integer type fails:
0diff --git a/contrib/message-capture/message-capture-parser.py b/contrib/message-capture/message-capture-parser.py
1index 9988478f1b..a6bac539de 100755
2--- a/contrib/message-capture/message-capture-parser.py
3+++ b/contrib/message-capture/message-capture-parser.py
4@@ -168,6 +168,12 @@ def process_file(path: str, messages: List[Any], recv: bool, progress_bar: Optio
5
6
7 def main():
8+ from test_framework.messages import msg_cfcheckpt
9+ invalid_msg = msg_cfcheckpt()
10+ invalid_msg.headers = [23, 42, "foobar"]
11+ print(to_jsonable(invalid_msg))
12+ return 1
13+
14 parser = argparse.ArgumentParser(
15 description=__doc__,
16 epilog="EXAMPLE \n\t{0} -o out.json <data-dir>/message_capture/**/*.dat".format(sys.argv[0]),
0$ ./contrib/message-capture/message-capture-parser.py
1Traceback (most recent call last):
2 File "/home/honey/bitcoin/./contrib/message-capture/message-capture-parser.py", line 220, in <module>
3 main()
4 File "/home/honey/bitcoin/./contrib/message-capture/message-capture-parser.py", line 174, in main
5 print(to_jsonable(invalid_msg))
6 File "/home/honey/bitcoin/./contrib/message-capture/message-capture-parser.py", line 83, in to_jsonable
7 ret[slot] = [ser_uint256(a).hex() for a in val]
8 File "/home/honey/bitcoin/./contrib/message-capture/message-capture-parser.py", line 83, in <listcomp>
9 ret[slot] = [ser_uint256(a).hex() for a in val]
10 File "/home/honey/bitcoin/./contrib/message-capture/../../test/functional/test_framework/messages.py", line 117, in ser_uint256
11 rs += struct.pack("<I", u & 0xFFFFFFFF)
12TypeError: unsupported operand type(s) for &: 'bytes' and 'int'
On the PR it falls through to to_jsonable
:
0$ ./contrib/message-capture/message-capture-parser.py
1{'filter_type': None, 'stop_hash': None, 'headers': [23, 42, 'foobar']}
Options that I can think of right now:
- keep the PR as it is (being more tolerant if some internal data types are not matching, but potentially also covering bugs)
- change the
all
predicate to any
to closely mimic the behaviour on master
- explicitly
assert
that all array elements have to be integers for the HASH_INT_VECTORS
types (seems right, but could have unintended consequences that I am not aware of)