{ "title":"MERKLEBLOCK", "related":["/protocol", "/protocol/network/messages/filteradd"] }

Response: Merkle Block ("merkleblock")

Provides a block header and partial merkle proof tree to show that the selected transaction hashes exist in the block.

Transactions are selected by honest servers if they match the bloom filter installed by the client. However, note that servers can omit transactions and this cannot be detected except by receiving a merkleblock message from an honest server.

All selected transactions are subsequently sent as separate tx messages. Due to multi-threading on the server, clients should not assume that these transaction messages directly follow the merkleblock message.

Message Format

Field Length Format Description
block header 80 bytes block header The header of the block.
transaction count 4 bytes unsigned integer(LE) The number of transactions in the block.
hash count variable variable length integer The number of partial merkle tree hashes to follow.
hashes hash_count * 32 bytes bytes(LE) The hashes of the partial merkle tree nodes, in depth-first traversal order (a mix of matched transaction hashes and the hashes of subtrees containing no matches). See BIP-37: Partial Merkle Branch Format.
flag byte count variable variable length integer The number of flags bytes to follow.
flag bits flag_count bytes bytes Flag bits, collected into bytes (zero-padded to a full byte as necessary) indicating inclusion information with respect to traversal of the partial merkle tree of matches. See partial merkle tree flag bits.

The transaction count, hashes and flag bits together form the partial merkle tree. To use it, a client walks the flag bits depth-first from the root, consuming hashes as it goes: this recovers the hashes (TXIDs) of the matched transactions, along with a computed merkle root. If that root equals the merkle root in the block header, the matched transactions are proven to be part of the block, without the client having to download the hashes of all the other transactions.

Partial Merkle Tree Flag Bits

The partial merkle tree flag bits effectively create a variable-width bitfield, indicating which transaction hashes from the block the merkleblock message pertains to actually matched the client's bloom filter. If you picture the merkle tree root at the top, the flag bits represent a top-down yes/no approach to whether the a given branch (or leaf node) of the tree includes any matching transactions.

For full details, see BIP-37: Partial Merkle Branch Format.