You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: bip-0152.mediawiki
+30-6Lines changed: 30 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ Thus, decreasing the bandwidth used during block relay is very useful for many i
21
21
22
22
While the goal of this work is explicitly not to reduce block transfer latency, it does, as a side effect reduce block transfer latencies in some rather significant ways. Additionally, this work forms a foundation for future work explicitly targeting low-latency block transfer.
23
23
24
-
==Specification==
24
+
==Specification for version 1==
25
25
26
26
===Intended Protocol Flow===
27
27
<img src=bip-0152/protocol-flow.png></img>
@@ -45,7 +45,7 @@ A PrefilledTransaction structure is used in HeaderAndShortIDs to provide a list
45
45
|-
46
46
|index||CompactSize||1, 3 bytes||Compact Size, differentially encoded since the last PrefilledTransaction in a list||The index into the block at which this transaction is
47
47
|-
48
-
|tx||Transaction||variable||As encoded in "tx" messages||The transaction which is in the block at index index.
48
+
|tx||Transaction||variable||As encoded in "tx" messages sent in response to getdata MSG_TX||The transaction which is in the block at index index.
49
49
|}
50
50
51
51
====HeaderAndShortIDs====
@@ -90,7 +90,7 @@ A BlockTransactions structure is used to provide some of the transactions in a b
90
90
|-
91
91
|transactions_length||CompactSize||1 or 3 bytes||As used to encode array lengths elsewhere||||The number of transactions provided
92
92
|-
93
-
|transactions||List of Transactions||variable||As encoded in "tx" messages||The transactions provided
93
+
|transactions||List of Transactions||variable||As encoded in "tx" messages in response to getdata MSG_TX||The transactions provided
94
94
|}
95
95
96
96
====Short transaction IDs====
@@ -111,6 +111,7 @@ A new inv type (MSG_CMPCT_BLOCK == 4) and several new protocol messages are adde
111
111
# Upon receipt of a "sendcmpct" message with the second integer set to something other than 1, nodes MUST treat the peer as if they had not received the message (as it indicates the peer will provide an unexpected encoding in cmpctblock, and/or other, messages). This allows future versions to send duplicate sendcmpct messages with different versions as a part of a version handshake for future versions.
112
112
# Nodes SHOULD check for a protocol version of >= 70014 before sending sendcmpct messages.
113
113
# Nodes MUST NOT send a request for a MSG_CMPCT_BLOCK object to a peer before having received a sendcmpct message from that peer.
114
+
# Nodes MUST NOT request a MSG_CMPCT_BLOCK object before having sent a sendcmpct message to that peer, as the peer cannot know what version protocol to use in the response.
114
115
115
116
====MSG_CMPCT_BLOCK====
116
117
# getdata messages may now contain requests for MSG_CMPCT_BLOCK objects.
@@ -136,7 +137,17 @@ A new inv type (MSG_CMPCT_BLOCK == 4) and several new protocol messages are adde
136
137
## For each short transaction ID from the original cmpctblock, in order, find the corresponding transaction either from the blocktxn message or from other sources and place it in the first available position in the block.
137
138
# Once the block has been reconstructed, it shall be processed as normal, keeping in mind that short transaction IDs are expected to occasionally collide, and that nodes MUST NOT be penalized for such collisions, wherever they appear.
138
139
139
-
===Implementation Notes===
140
+
==Specification for version 2==
141
+
Compact blocks version 2 is almost identical to version 1, but supports segregated witness transactions (BIP 141 and BIP 144). The changes are:
142
+
143
+
# The version number inside sendcmpct is 2 instead of 1.
144
+
# Transactions inside cmpctblock messages (both those used as direct announcement and those in response to getdata) and in blocktxn should include witness data, using the same format as responses to getdata MSG_WITNESS_TX, specified in BIP144.
145
+
# Short transaction IDs sent to us in cmpctblock messages, and sent by us in getblocktxn messages, are computed using the same process as in version 1, but using the wtxid as defined in BIP 141 instead of the txid.
146
+
147
+
Nodes that support segwit MAY choose to support both version 1 and 2 compact blocks. To do so, two sendcmpct messages SHOULD be sent at startup: the first one for version 1 and a second one for version 2.
148
+
When receiving multiple sendcmpct messages, the last received one that is compatible with the receiver's software MUST be used.
149
+
150
+
==Implementation Notes==
140
151
# For nodes which have sufficient inbound bandwidth, sending a sendcmpct message with the first integer set to 1 to up to 3 peers is RECOMMENDED. If possible, it is RECOMMENDED that those peers be selected based on their past performance in providing blocks quickly (eg the three peers which provided the highest number of the recent N blocks the quickest), allowing nodes to receive blocks which come from those peers in only 0.5*RTT.
141
152
142
153
# Nodes MUST NOT send such sendcmpct messages to more than three peers, as it encourages wasting outbound bandwidth across the network.
@@ -153,7 +164,7 @@ A new inv type (MSG_CMPCT_BLOCK == 4) and several new protocol messages are adde
153
164
154
165
# Note that the MSG_CMPCT_BLOCK section does not require that nodes respond to MSG_CMPCT_BLOCK getdata requests for blocks which they did not recently announce. This allows nodes to calculate cmpctblock messages at announce-time instead of at request-time. Blocks which are requested with a MSG_CMPCT_BLOCK getdata, but which are not responded to with a cmpctblock message MUST be responded to with a block message, allowing nodes to request all blocks using MSG_CMPCT_BLOCK getdatas and rely on their peer to pick an appropriate response.
155
166
156
-
# While the current version sends transactions with the same encodings as is used in tx messages and elsewhere in the protocol, the version field in sendcmpct is intended to allow this to change in the future. For this reason, it is recommended that the code used to decode PrefilledTransaction and BlockTransactions messages be prepared to take a different transaction encoding, if and when the version field in sendcmpct changes in a future BIP.
167
+
# While the current version sends transactions with the same encodings as are used in tx messages and elsewhere in the protocol, the version field in sendcmpct is intended to allow this to change in the future. For this reason, it is recommended that the code used to decode PrefilledTransaction and BlockTransactions messages be prepared to take a different transaction encoding, if and when the version field in sendcmpct changes in a future BIP.
157
168
158
169
# Any undefined behavior in this spec may cause failure to transfer block to, peer disconnection by, or self-destruction by the receiving node. A node receiving non-minimally-encoded CompactSize encodings should make a best-effort to eat the sender's cat.
159
170
@@ -190,13 +201,26 @@ In case 1, we're good. In cases 2, 3, or 4, we request the full transaction beca
190
201
191
202
This means that ''B = 48'' bits short IDs suffice for blocks with up to ''t = 10000'' transactions, mempools up to ''m = 100000'' transactions, with failure to reconstruct at most one in ''F = 281474'' blocks. Since failure to reconstruct just means we fall back to normal inv/header based relay, it isn't necessary to avoid such failure completely. It just needs to be sufficiently rare they have a lower impact than random transmission failures (for example, network disconnection, node overloaded, ...).
192
203
204
+
====Separate version for segregated witness====
205
+
206
+
The changes to transaction and block relay in BIP 144 introduce separate MSG_FILTERED_ versions of messages in getdata,
207
+
allowing a receiver to choose individually where witness data is wanted.
208
+
209
+
This method is not useful for compact blocks because `cmpctblock` blocks can be sent unsolicitedly in high-bandwidth
210
+
mode, so we need to negotiate at least whether those should include witness data up front. There is little use for a
211
+
validating node that only sometimes processes witness data, so we may as well use that negotiation for everything and
212
+
turn it into a separate protocol version. We also need a means to distinguish different versions of the same transaction
213
+
with different witnesses for correct reconstruction, so this also forces us to use wtxids instead of txids for short IDs
214
+
everywhere in that case.
215
+
193
216
==Backward compatibility==
194
217
195
218
Older clients remain fully compatible and interoperable after this change.
196
219
197
220
==Implementation==
198
221
199
-
https://github.com/bitcoin/bitcoin/pull/8068
222
+
https://github.com/bitcoin/bitcoin/pull/8068 for version 1.
223
+
https://github.com/bitcoin/bitcoin/pull/8393 for version 2.
0 commit comments