Compact Block Relay BIP



Summary:

The author has implemented a few suggestions and opened a formal pull request for the BIP at https://github.com/bitcoin/bips/pull/389 and the code at https://github.com/bitcoin/bitcoin/pull/8068. The post is in response to a BIP-formatted design spec for compact block relay designed to limit on wire bytes during block relay. Several new data structures are added to the P2P network to relay compact blocks: PrefilledTransaction, HeaderAndShortIDs, BlockTransactionsRequest, and BlockTransactions. CompactSize refers to the variable-length integer encoding used across the existing P2P protocol to encode array lengths, among other things, in 1, 3, 5 or 9 bytes. Variable-length integers: bytes are a MSB base-128 encoding of the number. The high bit in each byte signifies whether another digit follows. To make sure the encoding is one-to-one, one is subtracted from all but the last digit. A HeaderAndShortIDs structure is used to relay a block header, the short transactions IDs used for matching already-available transactions, and a select few transactions which we expect a peer may be missing.Short transaction IDs are used to represent a transaction without sending a full 256-bit hash. They are calculated by single-SHA256 hashing the block header with the nonce appended (in little-endian) XORing each 8-byte chunk of the double-SHA256 transaction hash with each corresponding 8-byte chunk of the hash from the previous step, Adding each of the XORed 8-byte chunks together (in little-endian) iteratively to find the short transaction ID.There are a few more heuristics that MAY be used to improve performance; Receivers should treat short txids in blocks that match multiple mempool transactions as non-matches, and request the transactions. This significantly reduces the failure to reconstruct. When constructing a compact block to send, the sender can verify it against its own mempool to check for collisions, and if so, choose to either try another nonce or increase the short txid length. Additionally, we should compare to the orphan pool (which apparently helps a lot).


Updated on: 2023-05-19T23:19:34.396941+00:00