Is there an existing issue for this?
- I have searched the existing issues
Current behaviour
PR #23471 added a note to ZMQ’s documentation page saying that:
[…] 32-byte hashes are in Little Endian and not in the Big Endian format that the RPC interface and block explorers use to display transaction and block hashes.
Also:
| hashtx | <32-byte transaction hash in Little Endian> | <uint32 sequence number in Little Endian>
| hashblock | <32-byte block hash in Little Endian> | <uint32 sequence number in Little Endian>
However, unless I am missing something, transaction and block hashes in both ZMQ and RPC appear in the same, reversed byte order (big endian).
If this is confirmed, I would like to prepare PR for the documentation.
Expected behaviour
Documentation would not contain references to hashes being in Little Endian.
Steps to reproduce
Start regtest with ZMQ hashblock:
0bitcoind -regtest -datadir=zmqtest -server --daemon -zmqpubhashblock=tcp://0.0.0.0:43441
1bitcoin-cli -regtest -datadir=zmqtest createwallet ""
Run independent ZMQ client in Python:
0 import zmq
1 import binascii
2
3 context = zmq.Context()
4 socket = context.socket(zmq.SUB)
5
6 socket.connect("tcp://localhost:43441")
7 socket.setsockopt_string(zmq.SUBSCRIBE, "hashblock")
8
9 topic = socket.recv()
10 data = socket.recv()
11 seq = socket.recv()
12
13 print(f"Topic: {topic}")
14 print(f"Data: {binascii.hexlify(data)}")
15 print(f"Seq: {binascii.hexlify(seq)}")
Generate block:
0bitcoin-cli -regtest -datadir=zmqtest -generate 1
0{
1 "address": "bcrt1qpjy0a3ply66pwpj6mp8sn36aslwr3gvdq727v6",
2 "blocks": [
3 "4f36a8e4e1ff6ebcc13f6bec62841e44a8b4c281f1f1346f148987735fb72e0e"
4 ]
5}
Output of ZMQ client:
0Topic: b'hashblock'
1Data: b'4f36a8e4e1ff6ebcc13f6bec62841e44a8b4c281f1f1346f148987735fb72e0e'
2Seq: b'00000000'
Calculate hash of the block header to crosscheck:
0 header=$(bitcoin-cli -regtest -datadir=zmqtest getblockheader 4f36a8e4e1ff6ebcc13f6bec62841e44a8b4c281f1f1346f148987735fb72e0e false)
1 echo $header | xxd -r -p | sha256sum | xxd -r -p | sha256sum
00e2eb75f738789146f34f1f181c2b4a8441e8462ec6b3fc1bc6effe1e4a8364f -
0e2eb75f738789146f34f1f181c2b4a8441e8462ec6b3fc1bc6effe1e4a8364f
← hash in natural order (output of SHA256; little endian)
4f36a8e4e1ff6ebcc13f6bec62841e44a8b4c281f1f1346f148987735fb72e0e
← hash in reversed order (ZMQ, RPC; big endian)
I assume hashes are printed by GetHex()
. The bytes are printed in reversed order:
To ZMQ, they are also sent in reversed order:
Relevant log output
No response
How did you obtain Bitcoin Core
Package manager
What version of Bitcoin Core are you using?
28.0.0
Operating system and version
Arch Linux, 6.12
Machine specifications
No response