<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <updated>2023-06-07T01:58:42Z</updated>
  <generator>https://nostr.ae</generator>

  <title>Nostr notes by Will Clark [ARCHIVE]</title>
  <author>
    <name>Will Clark [ARCHIVE]</name>
  </author>
  <link rel="self" type="application/atom+xml" href="https://nostr.ae/npub12nc7sue8vluy3k0pp3njlmrt5hkrv292n3es07dfqqv6zca3mm5qwx835c.rss" />
  <link href="https://nostr.ae/npub12nc7sue8vluy3k0pp3njlmrt5hkrv292n3es07dfqqv6zca3mm5qwx835c" />
  <id>https://nostr.ae/npub12nc7sue8vluy3k0pp3njlmrt5hkrv292n3es07dfqqv6zca3mm5qwx835c</id>
  <icon></icon>
  <logo></logo>




  <entry>
    <id>https://nostr.ae/nevent1qqsqkmyn0w26ffp2tlrfy8ddl9v2hnwgmqjezpm3296euftc5elpd4gzyp20r6rnyanlsjxeuyxxwtlvdwj7cd3g42w8xple4yqpngtrk80ws6ggdhw</id>
    
      <title type="html">📅 Original date posted:2020-05-08 📝 Original message:Hello ...</title>
    
    <link rel="alternate" href="https://nostr.ae/nevent1qqsqkmyn0w26ffp2tlrfy8ddl9v2hnwgmqjezpm3296euftc5elpd4gzyp20r6rnyanlsjxeuyxxwtlvdwj7cd3g42w8xple4yqpngtrk80ws6ggdhw" />
    <content type="html">
      In reply to &lt;a href=&#39;/nevent1qqsfujfmpk5m53dfruspk89xlqkhw4wcmyjjzk9rrqp2s8tcdknqnys0d9azd&#39;&gt;nevent1q…9azd&lt;/a&gt;&lt;br/&gt;_________________________&lt;br/&gt;&lt;br/&gt;📅 Original date posted:2020-05-08&lt;br/&gt;📝 Original message:Hello list,&lt;br/&gt;&lt;br/&gt;I would like to propose a compressed block header scheme for IBD and block announcements. This proposal is derivative of previous proposals found on this list (see links in spec below) with some modifications and clarifications.&lt;br/&gt;&lt;br/&gt;The below specification (also found at &lt;a href=&#34;https://github.com/willcl-ark/compressed-block-headers/blob/v1.0/compressed-block-headers.adoc&#34;&gt;https://github.com/willcl-ark/compressed-block-headers/blob/v1.0/compressed-block-headers.adoc&lt;/a&gt; ) details the compression recommended along with the generated bandwidth savings in the best-case scenario.&lt;br/&gt;&lt;br/&gt;I look forward to any feedback anyone has to offer on the specification itself, as well as any additions or objections to the motivation.&lt;br/&gt;&lt;br/&gt;Cheers,&lt;br/&gt;Will&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;= Compressed block headers&lt;br/&gt;Will Clark &amp;lt;will8clark at gmail.com&amp;gt;&lt;br/&gt;v1.0, May 2020:&lt;br/&gt;:toc: preamble&lt;br/&gt;:toclevels: 4&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;This work is a derivation of these mailing list posts:&lt;br/&gt;&lt;br/&gt;1. &lt;a href=&#34;https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-August/014876.html&#34;&gt;https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-August/014876.html&lt;/a&gt;[bitcoin-dev: &amp;#34;Compressed&amp;#34; headers stream - 2017] (with resurrection &lt;a href=&#34;https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-December/015385.html[here]&#34;&gt;https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-December/015385.html[here]&lt;/a&gt;)&lt;br/&gt;&lt;br/&gt;2. &lt;a href=&#34;https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-March/015851.html&#34;&gt;https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-March/015851.html&lt;/a&gt;[bitcoin-dev: Optimized Header Sync]&lt;br/&gt;&lt;br/&gt;&amp;#39;&amp;#39;&amp;#39;&lt;br/&gt;&lt;br/&gt;== Motivation&lt;br/&gt;&lt;br/&gt;Block headers as exchanged by nodes over the p2p network are currently 81 bytes each.&lt;br/&gt;&lt;br/&gt;For low bandwidth nodes who are doing a headers-only sync, reducing the size of the headers can provide a significant bandwidth saving. Also, nodes can support more header-only peers for IBD and protection against eclipse attacks if header bandwidth is reduced.&lt;br/&gt;&lt;br/&gt;=== Background&lt;br/&gt;&lt;br/&gt;Currently headers are sent over the p2p network as a vector of `block_headers`, which are composed of the following sized fields:&lt;br/&gt;&lt;br/&gt;[cols=&amp;#34;&amp;lt;,&amp;gt;&amp;#34;]&lt;br/&gt;|===&lt;br/&gt;|Field               |Size&lt;br/&gt;&lt;br/&gt;|Version             |4 bytes&lt;br/&gt;|Previous block hash |32 bytes&lt;br/&gt;|Merkle root hash    |32 bytes&lt;br/&gt;|Time                |4 bytes&lt;br/&gt;|nBits               |4 bytes&lt;br/&gt;|nonce               |4 bytes&lt;br/&gt;|txn_count           |1 byte&lt;br/&gt;|*Total*             |81 bytes&lt;br/&gt;|===&lt;br/&gt;&lt;br/&gt;Some fields can be removed completely, others can be compressed under certain conditions.&lt;br/&gt;&lt;br/&gt;== Proposed specification&lt;br/&gt;&lt;br/&gt;=== block_header2 data type&lt;br/&gt;&lt;br/&gt;The following table illustrates the proposed `block_header2` data type specification.&lt;br/&gt;&lt;br/&gt;[cols=&amp;#34;&amp;lt;,&amp;gt;,&amp;gt;&amp;#34;]&lt;br/&gt;|===&lt;br/&gt;|Field               |Size     |Compressed&lt;br/&gt;&lt;br/&gt;|Bitfield            |1 byte   | 1 byte&lt;br/&gt;|Version             |4 bytes  |0 \| 4 bytes&lt;br/&gt;|Previous block hash |32 bytes |0 \| 32 bytes&lt;br/&gt;|Merkle root hash    |32 bytes |32 bytes&lt;br/&gt;|Time                |4 bytes  |2 \| 4 bytes&lt;br/&gt;|nBits               |4 bytes  |0 \| 4 bytes&lt;br/&gt;|nonce               |4 bytes  |4 bytes&lt;br/&gt;|*Total*             |81 bytes |range: 39 - 81 bytes&lt;br/&gt;|===&lt;br/&gt;&lt;br/&gt;This compression results in a maximum reduction from an 81 byte header to best-case 39 byte header. With 629,474 blocks in the current blockchain, a continuous header sync from genesis (requiring a single full 81 byte header followed by only compressed `block_header2`) has been tested to have its required bandwidth reduced from 50.98MB down to 25.86MB, a saving of 49%.&lt;br/&gt;&lt;br/&gt;==== Bitfield&lt;br/&gt;&lt;br/&gt;To make parsing of header messages easier and further increase header compression, a single byte bitfield was suggested by gmaxwell footnote:[&lt;a href=&#34;https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-December/015397.html&#34;&gt;https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-December/015397.html&lt;/a&gt;]. We propose the following amended bitfield meanings (bits re-ordered to match `headers2` field order):&lt;br/&gt;&lt;br/&gt;[cols=&amp;#34;&amp;lt;,&amp;lt;&amp;#34;]&lt;br/&gt;|===&lt;br/&gt;|Bit |Meaning &#43; field size to read&lt;br/&gt;&lt;br/&gt;|0 &#43;&lt;br/&gt;1 &#43;&lt;br/&gt;2    |version: same as the last *distinct* value 1st ... 7th (0 byte field) or a new 32bit distinct value (4 byte field).&lt;br/&gt;|3   |prev_block_hash: is omitted (0 byte field) or included (32 byte field)&lt;br/&gt;|4   |timestamp: as small offset (2 byte field) or full (4 byte field).&lt;br/&gt;|5   |nbits: same as last header (0 byte field) or new (4 byte field).&lt;br/&gt;|6   |possibly to signal &amp;#34;more headers follow&amp;#34; to make the encoding self-delimiting.&lt;br/&gt;|7   |currently undefined&lt;br/&gt;|===&lt;br/&gt;&lt;br/&gt;This bitfield adds 1 byte for every block in the chain, for a current total increase of 629,474B.&lt;br/&gt;&lt;br/&gt;==== Version&lt;br/&gt;&lt;br/&gt;In most cases the Version field will be identical to one referenced in one of the previous 7 unique versions, as indicated by bits 0,1,2 of the Bitfield.&lt;br/&gt;&lt;br/&gt;To block 629,474 there were 616,137 blocks whose version was in the previous 7 distinct versions, and only 13,338 blocks whose version was not, this includes any version bit manipulation done via overt ASIC boost.&lt;br/&gt;&lt;br/&gt;[cols=&amp;#34;&amp;gt;,&amp;gt;,&amp;gt;,&amp;gt;&amp;#34;]&lt;br/&gt;|===&lt;br/&gt;|Genesis to block |Current (B) |Compressed (B) |Saving (%)&lt;br/&gt;&lt;br/&gt;|629,474          |2,517,896   |53,352         |98&lt;br/&gt;|===&lt;br/&gt;&lt;br/&gt;==== Previous block hash&lt;br/&gt;&lt;br/&gt;The previous block hash will always be the&lt;br/&gt;`SHA256(SHA256(&amp;lt;previous_header&amp;gt;))` so is redundant, presuming you have the previous header in the chain.&lt;br/&gt;&lt;br/&gt;[cols=&amp;#34;&amp;gt;,&amp;gt;,&amp;gt;,&amp;gt;&amp;#34;]&lt;br/&gt;|===&lt;br/&gt;|Genesis to block |Current (B) |Compressed (B) |Saving (%)&lt;br/&gt;&lt;br/&gt;|629,474          |20,143,168  |0              |100&lt;br/&gt;|===&lt;br/&gt;&lt;br/&gt;==== Time&lt;br/&gt;&lt;br/&gt;The timestamp (in seconds) is consensus bound, based both on the time in the previous&lt;br/&gt;header: `MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60 = 7200`, and being greater than the `MedianTimePast` of the previous 11 blocks. Therefore this can be safely represented as an offset from the previous headers&amp;#39; timestamp using a 2 byte `signed short int`.&lt;br/&gt;&lt;br/&gt;[cols=&amp;#34;&amp;gt;,&amp;gt;,&amp;gt;,&amp;gt;&amp;#34;]&lt;br/&gt;|===&lt;br/&gt;|Genesis to block |Current (B) |Compressed (B) |Saving (%)&lt;br/&gt;&lt;br/&gt;|629,474          |2,517,896   |1,258,952      |50&lt;br/&gt;|===&lt;br/&gt;&lt;br/&gt;==== nBits&lt;br/&gt;&lt;br/&gt;nBits currently changes once every 2016 blocks. It could be entirely calculated by the client from the timestamps of the previous 2015 blocks footnote:[2015 blocks are used in the adjustment calculation due to an off-by-one error: &lt;a href=&#34;https://bitcointalk.org/index.php?topic=43692.msg521772#msg521772&amp;#34&#34;&gt;https://bitcointalk.org/index.php?topic=43692.msg521772#msg521772&amp;#34&lt;/a&gt;;].&lt;br/&gt;&lt;br/&gt;To simplify &amp;#39;light&amp;#39; client implementations which would otherwise require consensus-valid calculation of the adjustments, we propose to transmit this according to the &amp;lt;&amp;lt;Bitfield&amp;gt;&amp;gt; specification above.&lt;br/&gt;&lt;br/&gt;To block 629,474 there have been 298 nBits adjustments (vs an expected 311 -- there was none before block 32,256).&lt;br/&gt;&lt;br/&gt;[cols=&amp;#34;&amp;gt;,&amp;gt;,&amp;gt;,&amp;gt;&amp;#34;]&lt;br/&gt;|===&lt;br/&gt;|Genesis to block |Current (B) |Compressed (B) |Saving (%)&lt;br/&gt;&lt;br/&gt;|629,474          |2,517,896   |1,196          |99.6&lt;br/&gt;|===&lt;br/&gt;&lt;br/&gt;==== txn_count&lt;br/&gt;&lt;br/&gt;txn_count is included to make parsing of these messages compatible with parsing of `block` messages footnote:[&lt;a href=&#34;https://bitcoin.stackexchange.com/questions/2104/why-is-the-block-header-txn-count-field-always-zero&#34;&gt;https://bitcoin.stackexchange.com/questions/2104/why-is-the-block-header-txn-count-field-always-zero&lt;/a&gt;]. Therefore this field and its associated byte can be removed for transmission of compact headers.&lt;br/&gt;&lt;br/&gt;[cols=&amp;#34;&amp;gt;,&amp;gt;,&amp;gt;,&amp;gt;&amp;#34;]&lt;br/&gt;|===&lt;br/&gt;|Genesis to block |Current (B) |Compressed (B) |Saving (%)&lt;br/&gt;&lt;br/&gt;|629,474          |629,474     |0              |100&lt;br/&gt;|===&lt;br/&gt;&lt;br/&gt;=== Service Bit&lt;br/&gt;&lt;br/&gt;A new service bit would be required so that the nodes can advertise their ability to supply compact headers.&lt;br/&gt;&lt;br/&gt;=== P2P Messages&lt;br/&gt;&lt;br/&gt;Three new messages would be used by nodes that enable compact block header support, two query messages: `getheaders2` and `sendheaders2` and one response: `headers2`.&lt;br/&gt;&lt;br/&gt;==== `getheaders2` -- Requesting compact headers&lt;br/&gt;&lt;br/&gt;The new p2p message required to request compact block headers would require the same fields as the current `getheaders` message:&lt;br/&gt;&lt;br/&gt;[cols=&amp;#34;&amp;gt;,&amp;lt;,&amp;lt;,&amp;lt;&amp;#34;]&lt;br/&gt;|===&lt;br/&gt;|Field Size |Description          |Data type |Comments&lt;br/&gt;&lt;br/&gt;|4          |version              |uint32_t  |the protocol version&lt;br/&gt;|1&#43;         |hash count           |var_int   |number of block locator hash entries&lt;br/&gt;|32&#43;        |block locator hashes |char[32]  |block locator object; newest back to genesis block (dense to start, but then sparse)&lt;br/&gt;|32         |hash_stop            |char[32]  |hash of the last desired block header; set to zero to get as many blocks as possible (2000)&lt;br/&gt;|===&lt;br/&gt;&lt;br/&gt;==== `sendheaders2` -- Request compact header announcements&lt;br/&gt;&lt;br/&gt;Since &lt;a href=&#34;https://github.com/bitcoin/bips/blob/master/bip-0130.mediawiki[BIP-130]&#34;&gt;https://github.com/bitcoin/bips/blob/master/bip-0130.mediawiki[BIP-130]&lt;/a&gt;, nodes have been able to request to receive new headers directly in `headers` messages, rather than via an `inv` of the new block hash and subsequent `getheader` request and `headers` response (followed by a final `getdata` to get the tip block itself, if desired). This is requested by transmitting an empty `sendheaders` message after the version handshake is complete.]&lt;br/&gt;&lt;br/&gt;Upon receipt of this message, the node is permitted, but not required, to preemptively announce new headers with the `headers2` message (instead of `inv`). Preemptive header announcement is supported by the protocol version ≥ 70012 | Bitcoin Core version ≥ 0.12.0.&lt;br/&gt;&lt;br/&gt;For the motivational use-case it makes sense to also update this mechanism to support sending header updates using compact headers using a new message.&lt;br/&gt;&lt;br/&gt;==== `headers2` -- Receiving compact headers&lt;br/&gt;&lt;br/&gt;A `headers2` message is returned in response to `getheaders2` or at new header announcement following a `sendheaders2` request. It contains both `length` and `headers` fields. The `headers` field contains a variable length vector of `block_header2`:&lt;br/&gt;&lt;br/&gt;|===&lt;br/&gt;|Field Size |Description |Data type       |Comments&lt;br/&gt;&lt;br/&gt;|1&#43;         |length      |var_int         |Length of `headers`&lt;br/&gt;|39-81x?    |headers     |block_header2[] |Compressed block headers in &amp;lt;&amp;lt;block_header2 data type&amp;gt;&amp;gt; format&lt;br/&gt;|===&lt;br/&gt;&lt;br/&gt;=== Implementation&lt;br/&gt;&lt;br/&gt;* The first header in the first `block_header2[]` vector to a newly-connected client MUST contain the full nBits`, `timestamp`, `version` and `prev_block_hash` fields, along with a correctly populated `bitfield` byte.&lt;br/&gt;* Subsequent headers in a contiguous vector SHOULD follow the compressed &amp;lt;&amp;lt;block_header2 data type&amp;gt;&amp;gt; format.&lt;br/&gt;* Subsequent compressed headers supplied to an already-connected client (requesting compressed headers), SHOULD follow the compressed &amp;lt;&amp;lt;block_header2 data type&amp;gt;&amp;gt; format.
    </content>
    <updated>2023-06-07T18:24:32Z</updated>
  </entry>

</feed>