Skip to content

Commit 8fba5df

Browse files
committed
Merge bitcoin/bitcoin#27529: test: fix feature_addrman.py on big-endian systems
53c990a test: fix `feature_addrman.py` on big-endian systems (Sebastian Falbesoner) Pull request description: The test `feature_addrman.py` currently serializes the addrdb without specifying endianness for `int`s, so the machine's native byte order is used (see https://docs.python.org/3/library/struct.html#byte-order-size-and-alignment) and the generated `peers.dat` would be invalid on big-endian systems (our internal (de)serializers always use little-endian, see `ser_{read,write}data32`). Fix this by explicitly specifying little-endian serialization via the `<` character in `struct.pack(...)`. This is not detected by CI as we unfortunately don't run functional tests on big-endian systems there (I think we definitely should!). ACKs for top commit: MarcoFalke: lgtm ACK 53c990a 🔚 Tree-SHA512: 513af6f1f785a713e7a8ef3a57fcd3fe2520a7d537f63a9c8e1f4bdea4c2f605fd4c35001623d6b13458883dbc256f24943684ab8f224055c22bf8d8eeee5fe2
2 parents 95d523f + 53c990a commit 8fba5df

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

test/functional/feature_addrman.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ def serialize_addrman(
3232
r += struct.pack("B", format)
3333
r += struct.pack("B", INCOMPATIBILITY_BASE + lowest_compatible)
3434
r += ser_uint256(bucket_key)
35-
r += struct.pack("i", len_new or len(new))
36-
r += struct.pack("i", len_tried or len(tried))
35+
r += struct.pack("<i", len_new or len(new))
36+
r += struct.pack("<i", len_tried or len(tried))
3737
ADDRMAN_NEW_BUCKET_COUNT = 1 << 10
38-
r += struct.pack("i", ADDRMAN_NEW_BUCKET_COUNT ^ (1 << 30))
38+
r += struct.pack("<i", ADDRMAN_NEW_BUCKET_COUNT ^ (1 << 30))
3939
for _ in range(ADDRMAN_NEW_BUCKET_COUNT):
40-
r += struct.pack("i", 0)
40+
r += struct.pack("<i", 0)
4141
checksum = hash256(r)
4242
r += mock_checksum or checksum
4343
return r

0 commit comments

Comments
 (0)