Skip to main content

Module compact_blocks

Module compact_blocks 

Source
Expand description

Compact Block Relay (BIP152)

Implements the compact block protocol that allows peers to relay blocks using short transaction IDs rather than full transactions. Since most transactions in a new block are already in the receiver’s mempool, only a compact summary needs to be sent.

§Protocol Flow

  1. Sender constructs a CompactBlock from a full block:

    • Header + nonce
    • Short transaction IDs (first 6 bytes of SipHash)
    • A few “prefilled” transactions (always the coinbase, plus any the sender guesses the receiver doesn’t have)
  2. Receiver matches short IDs against its mempool:

    • If all transactions are found → reconstruct the full block
    • If some are missing → send GetBlockTxn to request them
    • Sender replies with BlockTxn containing the missing transactions

§References

Structs§

BlockTransactions
Response with the missing transactions.
CompactBlock
A compact block (BIP152 cmpctblock).
GetBlockTransactions
A request for missing transactions from a compact block.
PrefilledTransaction
A prefilled transaction: index in the block + the full transaction.

Enums§

ReconstructResult
Result of attempting to reconstruct a block from a compact block.

Functions§

compute_short_txid
Compute a 6-byte short transaction ID for a given txid.

Type Aliases§

ShortTxId
A 6-byte short transaction ID used in compact blocks.