Good question. On master, this scenario would lead to a (confusing) error right now, since calling ser_uint256(...) with a non-integer type fails:
diff --git a/contrib/message-capture/message-capture-parser.py b/contrib/message-capture/message-capture-parser.py
index 9988478f1b..a6bac539de 100755
--- a/contrib/message-capture/message-capture-parser.py
+++ b/contrib/message-capture/message-capture-parser.py
@@ -168,6 +168,12 @@ def process_file(path: str, messages: List[Any], recv: bool, progress_bar: Optio
def main():
+ from test_framework.messages import msg_cfcheckpt
+ invalid_msg = msg_cfcheckpt()
+ invalid_msg.headers = [23, 42, "foobar"]
+ print(to_jsonable(invalid_msg))
+ return 1
+
parser = argparse.ArgumentParser(
description=__doc__,
epilog="EXAMPLE \n\t{0} -o out.json <data-dir>/message_capture/**/*.dat".format(sys.argv[0]),
$ ./contrib/message-capture/message-capture-parser.py
Traceback (most recent call last):
File "/home/honey/bitcoin/./contrib/message-capture/message-capture-parser.py", line 220, in <module>
main()
File "/home/honey/bitcoin/./contrib/message-capture/message-capture-parser.py", line 174, in main
print(to_jsonable(invalid_msg))
File "/home/honey/bitcoin/./contrib/message-capture/message-capture-parser.py", line 83, in to_jsonable
ret[slot] = [ser_uint256(a).hex() for a in val]
File "/home/honey/bitcoin/./contrib/message-capture/message-capture-parser.py", line 83, in <listcomp>
ret[slot] = [ser_uint256(a).hex() for a in val]
File "/home/honey/bitcoin/./contrib/message-capture/../../test/functional/test_framework/messages.py", line 117, in ser_uint256
rs += struct.pack("<I", u & 0xFFFFFFFF)
TypeError: unsupported operand type(s) for &: 'bytes' and 'int'
On the PR it falls through to to_jsonable:
$ ./contrib/message-capture/message-capture-parser.py
{'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)