{"type":"rich","version":"1.0","author_name":"npub12jllrss5nmygfhg7j9ztk2te80t96kumx7cllfc29skut6phqh5qfhfxgj","author_url":"https://nostr.ae/npub12jllrss5nmygfhg7j9ztk2te80t96kumx7cllfc29skut6phqh5qfhfxgj","provider_name":"njump","provider_url":"https://nostr.ae","html":"📅 Original date posted:2020-05-11\n📝 Original message:Thanks for resurrecting this idea for discussion Will.\n\nI see three reasons for reducing block header bandwidth:\n\n 1. support for long range block header broadcast via alternative\ncommunication modalities like radio where every byte counts\n 2. where repurposed mobile devices with SPV wallets are used because\nmetered bandwidth and hardware costs are high relative to income\n 3. full nodes could potentially support twice as many header only peers\n(is that a thing?) for better eclipse protection\n\nNodes could also run an additional daemon (eg. electrs) that serves\ncompressed block headers to light clients, but then it would be less likely\nto see widespread use to reduce bandwidth between full nodes.\n\nWhat are the negatives?\n - higher computation? probably minimal compared to serving the same\nuncompressed headers.\n - memory for caching the last few versions? bounded to last seven, so not\ntoo large.\n - complexity/bugs? minor and opt in for node operators, though you could\nargue the gain isn't worth any kind of change for nodes with high bandwidth\nconnections.\n - use of low-bandwidth light clients should not be encouraged? that is a\nseparate discussion, but I do not currently see any proposals to remove\nlight client support.\n\nI'm curious what other people think. Are the motivations enough to justify\na change to the protocol that produces a high percentage (but low absolute)\nbandwidth reduction for transmitting block headers?\n\n  -- Richard\n\nOn Fri, May 8, 2020 at 3:34 PM Will Clark via bitcoin-dev \u003c\nbitcoin-dev at lists.linuxfoundation.org\u003e wrote:\n\n\u003e Hello list,\n\u003e\n\u003e I would like to propose a compressed block header scheme for IBD and block\n\u003e announcements. This proposal is derivative of previous proposals found on\n\u003e this list (see links in spec below) with some modifications and\n\u003e clarifications.\n\u003e\n\u003e The below specification (also found at\n\u003e https://github.com/willcl-ark/compressed-block-headers/blob/v1.0/compressed-block-headers.adoc\n\u003e ) details the compression recommended along with the generated bandwidth\n\u003e savings in the best-case scenario.\n\u003e\n\u003e I look forward to any feedback anyone has to offer on the specification\n\u003e itself, as well as any additions or objections to the motivation.\n\u003e\n\u003e Cheers,\n\u003e Will\n\u003e\n\u003e\n\u003e = Compressed block headers\n\u003e Will Clark \u003cwill8clark at gmail.com\u003e\n\u003e v1.0, May 2020:\n\u003e :toc: preamble\n\u003e :toclevels: 4\n\u003e\n\u003e\n\u003e This work is a derivation of these mailing list posts:\n\u003e\n\u003e 1.\n\u003e https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-August/014876.html[bitcoin-dev:\n\u003e \"Compressed\" headers stream - 2017] (with resurrection\n\u003e https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-December/015385.html[here]\n\u003e )\n\u003e\n\u003e 2.\n\u003e https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-March/015851.html[bitcoin-dev:\n\u003e Optimized Header Sync]\n\u003e\n\u003e '''\n\u003e\n\u003e == Motivation\n\u003e\n\u003e Block headers as exchanged by nodes over the p2p network are currently 81\n\u003e bytes each.\n\u003e\n\u003e For low bandwidth nodes who are doing a headers-only sync, reducing the\n\u003e size of the headers can provide a significant bandwidth saving. Also, nodes\n\u003e can support more header-only peers for IBD and protection against eclipse\n\u003e attacks if header bandwidth is reduced.\n\u003e\n\u003e === Background\n\u003e\n\u003e Currently headers are sent over the p2p network as a vector of\n\u003e `block_headers`, which are composed of the following sized fields:\n\u003e\n\u003e [cols=\"\u003c,\u003e\"]\n\u003e |===\n\u003e |Field               |Size\n\u003e\n\u003e |Version             |4 bytes\n\u003e |Previous block hash |32 bytes\n\u003e |Merkle root hash    |32 bytes\n\u003e |Time                |4 bytes\n\u003e |nBits               |4 bytes\n\u003e |nonce               |4 bytes\n\u003e |txn_count           |1 byte\n\u003e |*Total*             |81 bytes\n\u003e |===\n\u003e\n\u003e Some fields can be removed completely, others can be compressed under\n\u003e certain conditions.\n\u003e\n\u003e == Proposed specification\n\u003e\n\u003e === block_header2 data type\n\u003e\n\u003e The following table illustrates the proposed `block_header2` data type\n\u003e specification.\n\u003e\n\u003e [cols=\"\u003c,\u003e,\u003e\"]\n\u003e |===\n\u003e |Field               |Size     |Compressed\n\u003e\n\u003e |Bitfield            |1 byte   | 1 byte\n\u003e |Version             |4 bytes  |0 \\| 4 bytes\n\u003e |Previous block hash |32 bytes |0 \\| 32 bytes\n\u003e |Merkle root hash    |32 bytes |32 bytes\n\u003e |Time                |4 bytes  |2 \\| 4 bytes\n\u003e |nBits               |4 bytes  |0 \\| 4 bytes\n\u003e |nonce               |4 bytes  |4 bytes\n\u003e |*Total*             |81 bytes |range: 39 - 81 bytes\n\u003e |===\n\u003e\n\u003e This compression results in a maximum reduction from an 81 byte header to\n\u003e best-case 39 byte header. With 629,474 blocks in the current blockchain, a\n\u003e continuous header sync from genesis (requiring a single full 81 byte header\n\u003e followed by only compressed `block_header2`) has been tested to have its\n\u003e required bandwidth reduced from 50.98MB down to 25.86MB, a saving of 49%.\n\u003e\n\u003e ==== Bitfield\n\u003e\n\u003e To make parsing of header messages easier and further increase header\n\u003e compression, a single byte bitfield was suggested by gmaxwell footnote:[\n\u003e https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-December/015397.html].\n\u003e We propose the following amended bitfield meanings (bits re-ordered to\n\u003e match `headers2` field order):\n\u003e\n\u003e [cols=\"\u003c,\u003c\"]\n\u003e |===\n\u003e |Bit |Meaning + field size to read\n\u003e\n\u003e |0 +\n\u003e 1 +\n\u003e 2    |version: same as the last *distinct* value 1st ... 7th (0 byte\n\u003e field) or a new 32bit distinct value (4 byte field).\n\u003e |3   |prev_block_hash: is omitted (0 byte field) or included (32 byte\n\u003e field)\n\u003e |4   |timestamp: as small offset (2 byte field) or full (4 byte field).\n\u003e |5   |nbits: same as last header (0 byte field) or new (4 byte field).\n\u003e |6   |possibly to signal \"more headers follow\" to make the encoding\n\u003e self-delimiting.\n\u003e |7   |currently undefined\n\u003e |===\n\u003e\n\u003e This bitfield adds 1 byte for every block in the chain, for a current\n\u003e total increase of 629,474B.\n\u003e\n\u003e ==== Version\n\u003e\n\u003e In most cases the Version field will be identical to one referenced in one\n\u003e of the previous 7 unique versions, as indicated by bits 0,1,2 of the\n\u003e Bitfield.\n\u003e\n\u003e To block 629,474 there were 616,137 blocks whose version was in the\n\u003e previous 7 distinct versions, and only 13,338 blocks whose version was not,\n\u003e this includes any version bit manipulation done via overt ASIC boost.\n\u003e\n\u003e [cols=\"\u003e,\u003e,\u003e,\u003e\"]\n\u003e |===\n\u003e |Genesis to block |Current (B) |Compressed (B) |Saving (%)\n\u003e\n\u003e |629,474          |2,517,896   |53,352         |98\n\u003e |===\n\u003e\n\u003e ==== Previous block hash\n\u003e\n\u003e The previous block hash will always be the\n\u003e `SHA256(SHA256(\u003cprevious_header\u003e))` so is redundant, presuming you have\n\u003e the previous header in the chain.\n\u003e\n\u003e [cols=\"\u003e,\u003e,\u003e,\u003e\"]\n\u003e |===\n\u003e |Genesis to block |Current (B) |Compressed (B) |Saving (%)\n\u003e\n\u003e |629,474          |20,143,168  |0              |100\n\u003e |===\n\u003e\n\u003e ==== Time\n\u003e\n\u003e The timestamp (in seconds) is consensus bound, based both on the time in\n\u003e the previous\n\u003e header: `MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60 = 7200`, and being greater\n\u003e than the `MedianTimePast` of the previous 11 blocks. Therefore this can be\n\u003e safely represented as an offset from the previous headers' timestamp using\n\u003e a 2 byte `signed short int`.\n\u003e\n\u003e [cols=\"\u003e,\u003e,\u003e,\u003e\"]\n\u003e |===\n\u003e |Genesis to block |Current (B) |Compressed (B) |Saving (%)\n\u003e\n\u003e |629,474          |2,517,896   |1,258,952      |50\n\u003e |===\n\u003e\n\u003e ==== nBits\n\u003e\n\u003e nBits currently changes once every 2016 blocks. It could be entirely\n\u003e calculated by the client from the timestamps of the previous 2015 blocks\n\u003e footnote:[2015 blocks are used in the adjustment calculation due to an\n\u003e off-by-one error:\n\u003e https://bitcointalk.org/index.php?topic=43692.msg521772#msg521772\"].\n\u003e\n\u003e To simplify 'light' client implementations which would otherwise require\n\u003e consensus-valid calculation of the adjustments, we propose to transmit this\n\u003e according to the \u003c\u003cBitfield\u003e\u003e specification above.\n\u003e\n\u003e To block 629,474 there have been 298 nBits adjustments (vs an expected 311\n\u003e -- there was none before block 32,256).\n\u003e\n\u003e [cols=\"\u003e,\u003e,\u003e,\u003e\"]\n\u003e |===\n\u003e |Genesis to block |Current (B) |Compressed (B) |Saving (%)\n\u003e\n\u003e |629,474          |2,517,896   |1,196          |99.6\n\u003e |===\n\u003e\n\u003e ==== txn_count\n\u003e\n\u003e txn_count is included to make parsing of these messages compatible with\n\u003e parsing of `block` messages footnote:[\n\u003e https://bitcoin.stackexchange.com/questions/2104/why-is-the-block-header-txn-count-field-always-zero].\n\u003e Therefore this field and its associated byte can be removed for\n\u003e transmission of compact headers.\n\u003e\n\u003e [cols=\"\u003e,\u003e,\u003e,\u003e\"]\n\u003e |===\n\u003e |Genesis to block |Current (B) |Compressed (B) |Saving (%)\n\u003e\n\u003e |629,474          |629,474     |0              |100\n\u003e |===\n\u003e\n\u003e === Service Bit\n\u003e\n\u003e A new service bit would be required so that the nodes can advertise their\n\u003e ability to supply compact headers.\n\u003e\n\u003e === P2P Messages\n\u003e\n\u003e Three new messages would be used by nodes that enable compact block header\n\u003e support, two query messages: `getheaders2` and `sendheaders2` and one\n\u003e response: `headers2`.\n\u003e\n\u003e ==== `getheaders2` -- Requesting compact headers\n\u003e\n\u003e The new p2p message required to request compact block headers would\n\u003e require the same fields as the current `getheaders` message:\n\u003e\n\u003e [cols=\"\u003e,\u003c,\u003c,\u003c\"]\n\u003e |===\n\u003e |Field Size |Description          |Data type |Comments\n\u003e\n\u003e |4          |version              |uint32_t  |the protocol version\n\u003e |1+         |hash count           |var_int   |number of block locator hash\n\u003e entries\n\u003e |32+        |block locator hashes |char[32]  |block locator object; newest\n\u003e back to genesis block (dense to start, but then sparse)\n\u003e |32         |hash_stop            |char[32]  |hash of the last desired\n\u003e block header; set to zero to get as many blocks as possible (2000)\n\u003e |===\n\u003e\n\u003e ==== `sendheaders2` -- Request compact header announcements\n\u003e\n\u003e Since\n\u003e https://github.com/bitcoin/bips/blob/master/bip-0130.mediawiki[BIP-130],\n\u003e nodes have been able to request to receive new headers directly in\n\u003e `headers` messages, rather than via an `inv` of the new block hash and\n\u003e subsequent `getheader` request and `headers` response (followed by a final\n\u003e `getdata` to get the tip block itself, if desired). This is requested by\n\u003e transmitting an empty `sendheaders` message after the version handshake is\n\u003e complete.]\n\u003e\n\u003e Upon receipt of this message, the node is permitted, but not required, to\n\u003e preemptively announce new headers with the `headers2` message (instead of\n\u003e `inv`). Preemptive header announcement is supported by the protocol version\n\u003e ≥ 70012 | Bitcoin Core version ≥ 0.12.0.\n\u003e\n\u003e For the motivational use-case it makes sense to also update this mechanism\n\u003e to support sending header updates using compact headers using a new message.\n\u003e\n\u003e ==== `headers2` -- Receiving compact headers\n\u003e\n\u003e A `headers2` message is returned in response to `getheaders2` or at new\n\u003e header announcement following a `sendheaders2` request. It contains both\n\u003e `length` and `headers` fields. The `headers` field contains a variable\n\u003e length vector of `block_header2`:\n\u003e\n\u003e |===\n\u003e |Field Size |Description |Data type       |Comments\n\u003e\n\u003e |1+         |length      |var_int         |Length of `headers`\n\u003e |39-81x?    |headers     |block_header2[] |Compressed block headers in\n\u003e \u003c\u003cblock_header2 data type\u003e\u003e format\n\u003e |===\n\u003e\n\u003e === Implementation\n\u003e\n\u003e * The first header in the first `block_header2[]` vector to a\n\u003e newly-connected client MUST contain the full nBits`, `timestamp`, `version`\n\u003e and `prev_block_hash` fields, along with a correctly populated `bitfield`\n\u003e byte.\n\u003e * Subsequent headers in a contiguous vector SHOULD follow the compressed\n\u003e \u003c\u003cblock_header2 data type\u003e\u003e format.\n\u003e * Subsequent compressed headers supplied to an already-connected client\n\u003e (requesting compressed headers), SHOULD follow the compressed\n\u003e \u003c\u003cblock_header2 data type\u003e\u003e format.\n\u003e\n\u003e\n\u003e\n\u003e\n\u003e\n\u003e _______________________________________________\n\u003e bitcoin-dev mailing list\n\u003e bitcoin-dev at lists.linuxfoundation.org\n\u003e https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev\n\u003e\n\n\n-- \nRichard Myers\nDecentralized Applications Engineer, goTenna\ngotenna.com\n@gotenna\n-------------- next part --------------\nAn HTML attachment was scrubbed...\nURL: \u003chttp://lists.linuxfoundation.org/pipermail/bitcoin-dev/attachments/20200511/dc570025/attachment-0001.html\u003e"}
