Bitcoin Compact Block Messages: sendcmpct, cmpctblock, getblocktxn and blocktxn
BIP152 defines a compact-block message exchange that can save bandwidth and shorten the time required to announce a new Bitcoin block. Understanding its four core messages helps developers distinguish network optimization from consensus validation.
1. Negotiate with sendcmpct
A peer sends sendcmpct to communicate whether it wants compact block announcements and which compact-block protocol version it supports. This message is about relay preferences between peers, not about which blocks are valid. Compact-block versions must not be confused with the block header's consensus version field.
2. Announce or provide cmpctblock
A cmpctblock contains the block header, short transaction IDs, and prefilled transactions. The short IDs encode a likely mapping to transactions already known by the receiver. They are not transaction IDs and are not sufficient to validate the block by themselves.
A high-bandwidth peer can proactively send a cmpctblock. A low-bandwidth peer can request one with getdata after a block announcement. Exact relay decisions depend on peer state and implementation policy.
3. Recover missing data with getblocktxn
If the receiver cannot fill every transaction position, it sends getblocktxn specifying the indexes it needs. The request is for positions in the candidate block, not arbitrary transaction hashes. It is possible for a node to need many missing transactions when the peers' mempools differ substantially.
4. Reply using blocktxn
The sending peer answers with blocktxn, containing the full transactions requested. The receiver reconstructs the block in its proper transaction order, checks the Merkle root and block structure, and performs normal consensus validation.
Practical failure cases
Short-ID collisions, unavailable transactions, malformed messages, or timeouts can prevent reconstruction. Implementations can recover by requesting missing data or using full-block relay. A compact-block protocol failure does not imply the underlying block is invalid.
Operational security
Do not assume the message sender is trusted. Peers can provide false or incomplete transport data. Full nodes must independently check proof of work, transaction validity, block limits, and other consensus requirements after reconstruction.
Primary references
BIP152 — Compact Block Relay: https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki
Bitcoin developer reference — P2P network: https://developer.bitcoin.org/reference/p2p_networking.html
