Return-Path: Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6E70CC0176 for ; Wed, 20 May 2020 13:12:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 560CF8688A for ; Wed, 20 May 2020 13:12:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cj-5H8dXhcnZ for ; Wed, 20 May 2020 13:12:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 3499385F37 for ; Wed, 20 May 2020 13:12:16 +0000 (UTC) Received: by mail-wr1-f49.google.com with SMTP id e1so3097426wrt.5 for ; Wed, 20 May 2020 06:12:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotenna-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=7D0qDZG5QJ1/VpanjeO+DgLtqZ+kjrXwE5vCcmuNcfc=; b=PNP6YE+y8SB8oOCfC+Kv22k2LYOUDhyYzJE5SqVCEbA9HvLHt/bg+MYAh6dhYcx8xE 3JrL8x4fCZcSn3EiXvd6cxDE9ld7hlumfJU5kqzGCGPZgV9kpas8TTU6/GYRkrICwsdI Yey1RK5PB9jcE9Tm+bfMCsVZf+aGzLR6AaolclqYXiX8UlVgMdbBhOEpKbegF81ev6Bv NrwT6qmuGykjGkh2zYlvIVpAHEmDlmqbIbVw9nuUeBHE0CZHfCub83kfHPnVDbQBmqVi JGntTDVluJNRZSh7AfWeXVBlM7jau0yZZbNlH2Y9/WLzC7Jb+8TbPCoGpxz+x2turX3i cJqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=7D0qDZG5QJ1/VpanjeO+DgLtqZ+kjrXwE5vCcmuNcfc=; b=CJl16ayGaNYtLUcFoYTOH50CQM6FYt/M3sEYcwQ1owK1yRmC4Ahc8+co+F6GZ0zJIW xyBdYld74FptEW8t/4GjsMmj720toVMYQVU13FsFVJn330HAKF0+sDQexAKnQz6sBF4r pVi//oPs36UqS0O38LknncdxTnKfb/zP+McCS0A4sVSXl875i3Hog5Lo0BJIPLY8Y7vf jo2YLrIe0CSB171X20vPUVRNVxi8+Y+GY3Mv/xEHTBNmFIrpxD4qPHLCkbGTseJ8JRgT m8gp2lKaMjEwH5Yqu1L9Gul55SdSTFtJQ1Eo7vo+cdUgf7MqY9A5ODMlv56ZZBNPo1QW r5ew== X-Gm-Message-State: AOAM530d5Ybu2v08tFUg+8Qiz5I6ja1tMitulckd7dsNPsWeXsCkjFqe 0+aSMbAnz3qYNxrc2E9XANxCtvltA9ei6VvmYk0Gc2nhqxY= X-Google-Smtp-Source: ABdhPJwuPi7dllg0ZmdIP6SwPl4aOgxbN1rKC8wl14gqMl7aUPZ+Pt/4+BNjO9nTKXK6NhcHHcsbUL3STaHmeKqfy/M= X-Received: by 2002:a17:906:e08a:: with SMTP id gh10mr3861687ejb.512.1589979982082; Wed, 20 May 2020 06:06:22 -0700 (PDT) MIME-Version: 1.0 References: <40DB3DBE-A1C9-4D20-A3C7-F5660307D9D7@gmail.com> In-Reply-To: <40DB3DBE-A1C9-4D20-A3C7-F5660307D9D7@gmail.com> From: Richard Myers Date: Wed, 20 May 2020 15:06:11 +0200 Message-ID: To: Will Clark , Bitcoin Protocol Discussion Content-Type: multipart/alternative; boundary="000000000000084c8105a614106f" X-Mailman-Approved-At: Wed, 20 May 2020 13:21:59 +0000 Subject: Re: [bitcoin-dev] Compressed block headers X-BeenThere: bitcoin-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Bitcoin Protocol Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 May 2020 13:12:21 -0000 --000000000000084c8105a614106f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I've been looking at using compressed block headers from the perspective of a node that wants to use SMS messages to sync block headers. I realized that it would be helpful if sendheaders2 took a parameter for how often to send compact blockheaders. For example, in the case of an SMS transport layer, it would make sense to request 4 headers at a time to optimally fill a 160 byte SMS message. Although using SMS messages would be about the most expensive way to receive block headers, it is also the most universally available to smartphone users, even where mobile data might be expensive or unavailable. If we assume an SMS costs a bulk sender 0.025 USD per SMS, then sending 4 at a time (4 x 39 + 1 byte < 160 byte max SMS) reduces costs 1/4 to 252 instead of 1008 messages at a total weekly cost of ~7 instead of 26 USD. Still not ideal, but a huge savings. Since you're proposing a new message anyway, it doesn't break compatibility to add a parameter for how often sendheaders2 chunks up recent headers. On Fri, May 8, 2020 at 3:34 PM Will Clark via bitcoin-dev < bitcoin-dev@lists.linuxfoundation.org> wrote: > Hello list, > > I would like to propose a compressed block header scheme for IBD and bloc= k > announcements. This proposal is derivative of previous proposals found on > this list (see links in spec below) with some modifications and > clarifications. > > The below specification (also found at > https://github.com/willcl-ark/compressed-block-headers/blob/v1.0/compress= ed-block-headers.adoc > ) details the compression recommended along with the generated bandwidth > savings in the best-case scenario. > > I look forward to any feedback anyone has to offer on the specification > itself, as well as any additions or objections to the motivation. > > Cheers, > Will > > > =3D Compressed block headers > Will Clark > v1.0, May 2020: > :toc: preamble > :toclevels: 4 > > > This work is a derivation of these mailing list posts: > > 1. > https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-August/01487= 6.html[bitcoin-dev: > "Compressed" headers stream - 2017] (with resurrection > https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-December/015= 385.html[here] > ) > > 2. > https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-March/015851= .html[bitcoin-dev: > Optimized Header Sync] > > ''' > > =3D=3D Motivation > > Block headers as exchanged by nodes over the p2p network are currently 81 > bytes each. > > For low bandwidth nodes who are doing a headers-only sync, reducing the > size of the headers can provide a significant bandwidth saving. Also, nod= es > can support more header-only peers for IBD and protection against eclipse > attacks if header bandwidth is reduced. > > =3D=3D=3D Background > > Currently headers are sent over the p2p network as a vector of > `block_headers`, which are composed of the following sized fields: > > [cols=3D"<,>"] > |=3D=3D=3D > |Field |Size > > |Version |4 bytes > |Previous block hash |32 bytes > |Merkle root hash |32 bytes > |Time |4 bytes > |nBits |4 bytes > |nonce |4 bytes > |txn_count |1 byte > |*Total* |81 bytes > |=3D=3D=3D > > Some fields can be removed completely, others can be compressed under > certain conditions. > > =3D=3D Proposed specification > > =3D=3D=3D block_header2 data type > > The following table illustrates the proposed `block_header2` data type > specification. > > [cols=3D"<,>,>"] > |=3D=3D=3D > |Field |Size |Compressed > > |Bitfield |1 byte | 1 byte > |Version |4 bytes |0 \| 4 bytes > |Previous block hash |32 bytes |0 \| 32 bytes > |Merkle root hash |32 bytes |32 bytes > |Time |4 bytes |2 \| 4 bytes > |nBits |4 bytes |0 \| 4 bytes > |nonce |4 bytes |4 bytes > |*Total* |81 bytes |range: 39 - 81 bytes > |=3D=3D=3D > > 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 head= er > 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%. > > =3D=3D=3D=3D Bitfield > > To make parsing of header messages easier and further increase header > compression, a single byte bitfield was suggested by gmaxwell footnote:[ > https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-December/015= 397.html]. > We propose the following amended bitfield meanings (bits re-ordered to > match `headers2` field order): > > [cols=3D"<,<"] > |=3D=3D=3D > |Bit |Meaning + field size to read > > |0 + > 1 + > 2 |version: same as the last *distinct* value 1st ... 7th (0 byte > field) or a new 32bit distinct value (4 byte field). > |3 |prev_block_hash: is omitted (0 byte field) or included (32 byte > field) > |4 |timestamp: as small offset (2 byte field) or full (4 byte field). > |5 |nbits: same as last header (0 byte field) or new (4 byte field). > |6 |possibly to signal "more headers follow" to make the encoding > self-delimiting. > |7 |currently undefined > |=3D=3D=3D > > This bitfield adds 1 byte for every block in the chain, for a current > total increase of 629,474B. > > =3D=3D=3D=3D Version > > In most cases the Version field will be identical to one referenced in on= e > of the previous 7 unique versions, as indicated by bits 0,1,2 of the > Bitfield. > > 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 no= t, > this includes any version bit manipulation done via overt ASIC boost. > > [cols=3D">,>,>,>"] > |=3D=3D=3D > |Genesis to block |Current (B) |Compressed (B) |Saving (%) > > |629,474 |2,517,896 |53,352 |98 > |=3D=3D=3D > > =3D=3D=3D=3D Previous block hash > > The previous block hash will always be the > `SHA256(SHA256())` so is redundant, presuming you have > the previous header in the chain. > > [cols=3D">,>,>,>"] > |=3D=3D=3D > |Genesis to block |Current (B) |Compressed (B) |Saving (%) > > |629,474 |20,143,168 |0 |100 > |=3D=3D=3D > > =3D=3D=3D=3D Time > > The timestamp (in seconds) is consensus bound, based both on the time in > the previous > header: `MAX_FUTURE_BLOCK_TIME =3D 2 * 60 * 60 =3D 7200`, and being great= er > than the `MedianTimePast` of the previous 11 blocks. Therefore this can b= e > safely represented as an offset from the previous headers' timestamp usin= g > a 2 byte `signed short int`. > > [cols=3D">,>,>,>"] > |=3D=3D=3D > |Genesis to block |Current (B) |Compressed (B) |Saving (%) > > |629,474 |2,517,896 |1,258,952 |50 > |=3D=3D=3D > > =3D=3D=3D=3D nBits > > 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: > https://bitcointalk.org/index.php?topic=3D43692.msg521772#msg521772"]. > > To simplify 'light' client implementations which would otherwise require > consensus-valid calculation of the adjustments, we propose to transmit th= is > according to the <> specification above. > > To block 629,474 there have been 298 nBits adjustments (vs an expected 31= 1 > -- there was none before block 32,256). > > [cols=3D">,>,>,>"] > |=3D=3D=3D > |Genesis to block |Current (B) |Compressed (B) |Saving (%) > > |629,474 |2,517,896 |1,196 |99.6 > |=3D=3D=3D > > =3D=3D=3D=3D txn_count > > txn_count is included to make parsing of these messages compatible with > parsing of `block` messages footnote:[ > https://bitcoin.stackexchange.com/questions/2104/why-is-the-block-header-= txn-count-field-always-zero]. > Therefore this field and its associated byte can be removed for > transmission of compact headers. > > [cols=3D">,>,>,>"] > |=3D=3D=3D > |Genesis to block |Current (B) |Compressed (B) |Saving (%) > > |629,474 |629,474 |0 |100 > |=3D=3D=3D > > =3D=3D=3D Service Bit > > A new service bit would be required so that the nodes can advertise their > ability to supply compact headers. > > =3D=3D=3D P2P Messages > > Three new messages would be used by nodes that enable compact block heade= r > support, two query messages: `getheaders2` and `sendheaders2` and one > response: `headers2`. > > =3D=3D=3D=3D `getheaders2` -- Requesting compact headers > > The new p2p message required to request compact block headers would > require the same fields as the current `getheaders` message: > > [cols=3D">,<,<,<"] > |=3D=3D=3D > |Field Size |Description |Data type |Comments > > |4 |version |uint32_t |the protocol version > |1+ |hash count |var_int |number of block locator has= h > entries > |32+ |block locator hashes |char[32] |block locator object; newes= t > back to genesis block (dense to start, but then sparse) > |32 |hash_stop |char[32] |hash of the last desired > block header; set to zero to get as many blocks as possible (2000) > |=3D=3D=3D > > =3D=3D=3D=3D `sendheaders2` -- Request compact header announcements > > Since > https://github.com/bitcoin/bips/blob/master/bip-0130.mediawiki[BIP-130], > 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 fina= l > `getdata` to get the tip block itself, if desired). This is requested by > transmitting an empty `sendheaders` message after the version handshake i= s > complete.] > > 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 versi= on > =E2=89=A5 70012 | Bitcoin Core version =E2=89=A5 0.12.0. > > For the motivational use-case it makes sense to also update this mechanis= m > to support sending header updates using compact headers using a new messa= ge. > > =3D=3D=3D=3D `headers2` -- Receiving compact headers > > 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`: > > |=3D=3D=3D > |Field Size |Description |Data type |Comments > > |1+ |length |var_int |Length of `headers` > |39-81x? |headers |block_header2[] |Compressed block headers in > <> format > |=3D=3D=3D > > =3D=3D=3D Implementation > > * The first header in the first `block_header2[]` vector to a > newly-connected client MUST contain the full nBits`, `timestamp`, `versio= n` > and `prev_block_hash` fields, along with a correctly populated `bitfield` > byte. > * Subsequent headers in a contiguous vector SHOULD follow the compressed > <> format. > * Subsequent compressed headers supplied to an already-connected client > (requesting compressed headers), SHOULD follow the compressed > <> format. > > > > > > _______________________________________________ > bitcoin-dev mailing list > bitcoin-dev@lists.linuxfoundation.org > https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev > --=20 Richard Myers Decentralized Applications Engineer, goTenna gotenna.com @gotenna --000000000000084c8105a614106f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I've been looking at using compressed block headers fr= om the perspective of a node that wants to use SMS messages to sync block h= eaders. I realized that it would be helpful if sendheaders2 took a paramete= r for how often to send compact blockheaders. For example, in the case of a= n SMS transport layer, it would make sense to request 4 headers at a time t= o optimally fill a 160 byte SMS message.

Although using = SMS messages would be about the most expensive way to receive block headers= , it is also the most universally available to smartphone users, even where= mobile data might be expensive or unavailable. If we assume an SMS costs a= bulk sender 0.025 USD per SMS, then sending 4 at a time (4 x 39=C2=A0+ 1 b= yte < 160 byte max SMS) reduces costs 1/4 to 252 instead of 1008 message= s at a total weekly cost of ~7 instead of 26 USD.=C2=A0 Still not ideal, bu= t a huge savings.

Since you're proposing a new= message anyway, it doesn't break compatibility to add a parameter for = how often sendheaders2 chunks up recent headers.

On Fri, May 8, 2020 = at 3:34 PM Will Clark via bitcoin-dev <bitcoin-dev@lists.linuxfoundation= .org> wrote:
Hello list,

I would like to propose a compressed block header scheme for IBD and block = announcements. This proposal is derivative of previous proposals found on t= his list (see links in spec below) with some modifications and clarificatio= ns.

The below specification (also found at https://github.com/willcl-ark/compressed-= block-headers/blob/v1.0/compressed-block-headers.adoc ) details the com= pression recommended along with the generated bandwidth savings in the best= -case scenario.

I look forward to any feedback anyone has to offer on the specification its= elf, as well as any additions or objections to the motivation.

Cheers,
Will


=3D Compressed block headers
Will Clark <wi= ll8clark@gmail.com>
v1.0, May 2020:
:toc: preamble
:toclevels: 4


This work is a derivation of these mailing list posts:

1. http= s://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-August/014876.html= [bitcoin-dev: "Compressed" headers stream - 2017] (with resur= rection h= ttps://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-December/015385= .html[here])

2. https= ://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-March/015851.html[b= itcoin-dev: Optimized Header Sync]

'''

=3D=3D Motivation

Block headers as exchanged by nodes over the p2p network are currently 81 b= ytes each.

For low bandwidth nodes who are doing a headers-only sync, reducing the siz= e of the headers can provide a significant bandwidth saving. Also, nodes ca= n support more header-only peers for IBD and protection against eclipse att= acks if header bandwidth is reduced.

=3D=3D=3D Background

Currently headers are sent over the p2p network as a vector of `block_heade= rs`, which are composed of the following sized fields:

[cols=3D"<,>"]
|=3D=3D=3D
|Field=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|Size

|Version=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|4 bytes
|Previous block hash |32 bytes
|Merkle root hash=C2=A0 =C2=A0 |32 bytes
|Time=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |4 bytes
|nBits=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|4 bytes
|nonce=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|4 bytes
|txn_count=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|1 byte
|*Total*=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|81 bytes
|=3D=3D=3D

Some fields can be removed completely, others can be compressed under certa= in conditions.

=3D=3D Proposed specification

=3D=3D=3D block_header2 data type

The following table illustrates the proposed `block_header2` data type spec= ification.

[cols=3D"<,>,>"]
|=3D=3D=3D
|Field=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|Size=C2=A0 = =C2=A0 =C2=A0|Compressed

|Bitfield=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |1 byte=C2=A0 =C2=A0| 1 = byte
|Version=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|4 bytes=C2=A0 |0 \= | 4 bytes
|Previous block hash |32 bytes |0 \| 32 bytes
|Merkle root hash=C2=A0 =C2=A0 |32 bytes |32 bytes
|Time=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |4 bytes=C2=A0= |2 \| 4 bytes
|nBits=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|4 bytes=C2=A0= |0 \| 4 bytes
|nonce=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|4 bytes=C2=A0= |4 bytes
|*Total*=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|81 bytes |range: 3= 9 - 81 bytes
|=3D=3D=3D

This compression results in a maximum reduction from an 81 byte header to b= est-case 39 byte header. With 629,474 blocks in the current blockchain, a c= ontinuous header sync from genesis (requiring a single full 81 byte header = followed by only compressed `block_header2`) has been tested to have its re= quired bandwidth reduced from 50.98MB down to 25.86MB, a saving of 49%.

=3D=3D=3D=3D Bitfield

To make parsing of header messages easier and further increase header compr= ession, a single byte bitfield was suggested by gmaxwell footnote:[https://lists.linuxfoundat= ion.org/pipermail/bitcoin-dev/2017-December/015397.html]. We propose th= e following amended bitfield meanings (bits re-ordered to match `headers2` = field order):

[cols=3D"<,<"]
|=3D=3D=3D
|Bit |Meaning + field size to read

|0 +
1 +
2=C2=A0 =C2=A0 |version: same as the last *distinct* value 1st ... 7th (0 b= yte field) or a new 32bit distinct value (4 byte field).
|3=C2=A0 =C2=A0|prev_block_hash: is omitted (0 byte field) or included (32 = byte field)
|4=C2=A0 =C2=A0|timestamp: as small offset (2 byte field) or full (4 byte f= ield).
|5=C2=A0 =C2=A0|nbits: same as last header (0 byte field) or new (4 byte fi= eld).
|6=C2=A0 =C2=A0|possibly to signal "more headers follow" to make = the encoding self-delimiting.
|7=C2=A0 =C2=A0|currently undefined
|=3D=3D=3D

This bitfield adds 1 byte for every block in the chain, for a current total= increase of 629,474B.

=3D=3D=3D=3D Version

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 Bitfie= ld.

To block 629,474 there were 616,137 blocks whose version was in the previou= s 7 distinct versions, and only 13,338 blocks whose version was not, this i= ncludes any version bit manipulation done via overt ASIC boost.

[cols=3D">,>,>,>"]
|=3D=3D=3D
|Genesis to block |Current (B) |Compressed (B) |Saving (%)

|629,474=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |2,517,896=C2=A0 =C2=A0|53,352= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|98
|=3D=3D=3D

=3D=3D=3D=3D Previous block hash

The previous block hash will always be the
`SHA256(SHA256(<previous_header>))` so is redundant, presuming you ha= ve the previous header in the chain.

[cols=3D">,>,>,>"]
|=3D=3D=3D
|Genesis to block |Current (B) |Compressed (B) |Saving (%)

|629,474=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |20,143,168=C2=A0 |0=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |100
|=3D=3D=3D

=3D=3D=3D=3D Time

The timestamp (in seconds) is consensus bound, based both on the time in th= e previous
header: `MAX_FUTURE_BLOCK_TIME =3D 2 * 60 * 60 =3D 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' timestamp u= sing a 2 byte `signed short int`.

[cols=3D">,>,>,>"]
|=3D=3D=3D
|Genesis to block |Current (B) |Compressed (B) |Saving (%)

|629,474=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |2,517,896=C2=A0 =C2=A0|1,258,95= 2=C2=A0 =C2=A0 =C2=A0 |50
|=3D=3D=3D

=3D=3D=3D=3D nBits

nBits currently changes once every 2016 blocks. It could be entirely calcul= ated 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 e= rror: https://bitcointalk.org/ind= ex.php?topic=3D43692.msg521772#msg521772"].

To simplify 'light' client implementations which would otherwise re= quire consensus-valid calculation of the adjustments, we propose to transmi= t this according to the <<Bitfield>> specification above.

To block 629,474 there have been 298 nBits adjustments (vs an expected 311 = -- there was none before block 32,256).

[cols=3D">,>,>,>"]
|=3D=3D=3D
|Genesis to block |Current (B) |Compressed (B) |Saving (%)

|629,474=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |2,517,896=C2=A0 =C2=A0|1,196=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |99.6
|=3D=3D=3D

=3D=3D=3D=3D txn_count

txn_count is included to make parsing of these messages compatible with par= sing of `block` messages footnote:[https://bitcoin.stackexchange.com/questi= ons/2104/why-is-the-block-header-txn-count-field-always-zero]. Therefor= e this field and its associated byte can be removed for transmission of com= pact headers.

[cols=3D">,>,>,>"]
|=3D=3D=3D
|Genesis to block |Current (B) |Compressed (B) |Saving (%)

|629,474=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |629,474=C2=A0 =C2=A0 =C2=A0|0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |100
|=3D=3D=3D

=3D=3D=3D Service Bit

A new service bit would be required so that the nodes can advertise their a= bility to supply compact headers.

=3D=3D=3D P2P Messages

Three new messages would be used by nodes that enable compact block header = support, two query messages: `getheaders2` and `sendheaders2` and one respo= nse: `headers2`.

=3D=3D=3D=3D `getheaders2` -- Requesting compact headers

The new p2p message required to request compact block headers would require= the same fields as the current `getheaders` message:

[cols=3D">,<,<,<"]
|=3D=3D=3D
|Field Size |Description=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |Data type |Comm= ents

|4=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |version=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 |uint32_t=C2=A0 |the protocol version
|1+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|hash count=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0|var_int=C2=A0 =C2=A0|number of block locator hash entries |32+=C2=A0 =C2=A0 =C2=A0 =C2=A0 |block locator hashes |char[32]=C2=A0 |bloc= k locator object; newest back to genesis block (dense to start, but then sp= arse)
|32=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|hash_stop=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 |char[32]=C2=A0 |hash of the last desired block header; set t= o zero to get as many blocks as possible (2000)
|=3D=3D=3D

=3D=3D=3D=3D `sendheaders2` -- Request compact header announcements

Since https://github.com/= bitcoin/bips/blob/master/bip-0130.mediawiki[BIP-130], nodes have been a= ble to request to receive new headers directly in `headers` messages, rathe= r than via an `inv` of the new block hash and subsequent `getheader` reques= t and `headers` response (followed by a final `getdata` to get the tip bloc= k itself, if desired). This is requested by transmitting an empty `sendhead= ers` message after the version handshake is complete.]

Upon receipt of this message, the node is permitted, but not required, to p= reemptively announce new headers with the `headers2` message (instead of `i= nv`). Preemptive header announcement is supported by the protocol version = =E2=89=A5 70012 | Bitcoin Core version =E2=89=A5 0.12.0.

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= .

=3D=3D=3D=3D `headers2` -- Receiving compact headers

A `headers2` message is returned in response to `getheaders2` or at new hea= der announcement following a `sendheaders2` request. It contains both `leng= th` and `headers` fields. The `headers` field contains a variable length ve= ctor of `block_header2`:

|=3D=3D=3D
|Field Size |Description |Data type=C2=A0 =C2=A0 =C2=A0 =C2=A0|Comments

|1+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|length=C2=A0 =C2=A0 =C2=A0 |var_int= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|Length of `headers`
|39-81x?=C2=A0 =C2=A0 |headers=C2=A0 =C2=A0 =C2=A0|block_header2[] |Compres= sed block headers in <<block_header2 data type>> format
|=3D=3D=3D

=3D=3D=3D Implementation

* The first header in the first `block_header2[]` vector to a newly-connect= ed client MUST contain the full nBits`, `timestamp`, `version` and `prev_bl= ock_hash` fields, along with a correctly populated `bitfield` byte.
* Subsequent headers in a contiguous vector SHOULD follow the compressed &l= t;<block_header2 data type>> format.
* Subsequent compressed headers supplied to an already-connected client (re= questing compressed headers), SHOULD follow the compressed <<block_he= ader2 data type>> format.





_______________________________________________
bitcoin-dev mailing list
= bitcoin-dev@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mail= man/listinfo/bitcoin-dev


--
Richard Myers
Decentralized Applications Engineer, goTenna
gotenna.com
@gotenna
--000000000000084c8105a614106f--