summaryrefslogtreecommitdiff
path: root/a6/314a49e88cba812eb0db351e90e23deca9e002
blob: d52e54c296a5e1e05f8a98532c960669eb4a0629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
Return-Path: <johnathan@corganlabs.com>
Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org
	[172.17.192.35])
	by mail.linuxfoundation.org (Postfix) with ESMTPS id 2DFFB483
	for <bitcoin-dev@lists.linuxfoundation.org>;
	Sun,  8 May 2016 00:40:51 +0000 (UTC)
X-Greylist: whitelisted by SQLgrey-1.7.6
Received: from mail-lf0-f41.google.com (mail-lf0-f41.google.com
	[209.85.215.41])
	by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2C30113D
	for <bitcoin-dev@lists.linuxfoundation.org>;
	Sun,  8 May 2016 00:40:47 +0000 (UTC)
Received: by mail-lf0-f41.google.com with SMTP id m64so166815058lfd.1
	for <bitcoin-dev@lists.linuxfoundation.org>;
	Sat, 07 May 2016 17:40:46 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=corganlabs-com.20150623.gappssmtp.com; s=20150623;
	h=mime-version:in-reply-to:references:from:date:message-id:subject:to
	:cc; bh=om7pIvK1fDyecoJaEBJe271Rz7d+JhLmstHUDEFH3sI=;
	b=ON+S4v/iAFb/mDVPW8uPK9k+q9fvJBMxNk8tgVF0wN0gn4lM8bCUeBFL7ha2bqNdqp
	1p6IqX0cEeTH6HtUgwWYnS6eaQMhQ8g1GL3T2OOoH1siq0UzS+bmbyYxp6ZjB966gPNw
	kSrQfteTi1V8nf9toL1fGH7V/lxjuUCgkqJViCQhaDlzc9RZDyHGvt6ooKNrinVvW9vP
	O0Dc5mvV9aCAV3ne6MGkXagRgxjO1AWU55nPTEERfMbZ2CWGPz1eQAJDi1XnoRhx0D9m
	4UGVdYBL4CLSnvtD4SF4NDy1TyujiRTJSncgJIq/eoqo764LQnlq7A5g7/rdOypZg/Yg
	zQWw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20130820;
	h=x-gm-message-state:mime-version:in-reply-to:references:from:date
	:message-id:subject:to:cc;
	bh=om7pIvK1fDyecoJaEBJe271Rz7d+JhLmstHUDEFH3sI=;
	b=f7Yhn/XmjFPlLh3VzXqXoVfyZLSrTXUdRK2neZvzALiskqwT+MTOWGO3PhL5QHQEAc
	bW7/OVih0fYiRA43oGzAR6ZbQjOcTHxLZe82e8zStr5qwleeWHJwjS62XsG0z8ecRefu
	zOYBxXCASGVbgYQ8FEeOpQobQZ1hHIzrzkt11Ah4xdGjRmtIgMy0C4QWUSAEqh/c69MX
	DxhsUD4nV2Umz/GdadnqxMp2p9rLvP008xpC8PaNYsieCu8675Y+ujIVjCxiCXOXVbxm
	EMZjYlPUULpP+ZlJ/HxfidqYIUySy7up2jcQirzG2NE+uWSXPye22ULwP430La2Ep0im
	w+zQ==
X-Gm-Message-State: AOPr4FUx7yVCb3lYP5vLtPT5xS1wyAgtryJ0yeXA+oqtJorx6zXFb4xKJxiKIxmax3aXEonirkpbPL+cXqK2LQ==
X-Received: by 10.25.18.102 with SMTP id h99mr12421218lfi.127.1462668045173;
	Sat, 07 May 2016 17:40:45 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.114.91.80 with HTTP; Sat, 7 May 2016 17:40:25 -0700 (PDT)
In-Reply-To: <5727D102.1020807@mattcorallo.com>
References: <5727D102.1020807@mattcorallo.com>
From: Johnathan Corgan <johnathan@corganlabs.com>
Date: Sat, 7 May 2016 17:40:25 -0700
Message-ID: <CALOxbZv5GL5br=Z5idR-ACVzkBxS6JP_KgSr3JBuYVLgsej3eA@mail.gmail.com>
To: Matt Corallo <lf-lists@mattcorallo.com>
Content-Type: multipart/alternative; boundary=001a113fb2ec41dfe9053249f1aa
X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on
	smtp1.linux-foundation.org
X-Mailman-Approved-At: Sun, 08 May 2016 00:42:18 +0000
Cc: Bitcoin Dev <bitcoin-dev@lists.linuxfoundation.org>,
	Luke Dashjr <luke_bipeditor@dashjr.org>
Subject: Re: [bitcoin-dev] Compact Block Relay BIP
X-BeenThere: bitcoin-dev@lists.linuxfoundation.org
X-Mailman-Version: 2.1.12
Precedence: list
List-Id: Bitcoin Development Discussion <bitcoin-dev.lists.linuxfoundation.org>
List-Unsubscribe: <https://lists.linuxfoundation.org/mailman/options/bitcoin-dev>,
	<mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=unsubscribe>
List-Archive: <http://lists.linuxfoundation.org/pipermail/bitcoin-dev/>
List-Post: <mailto:bitcoin-dev@lists.linuxfoundation.org>
List-Help: <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=help>
List-Subscribe: <https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev>,
	<mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=subscribe>
X-List-Received-Date: Sun, 08 May 2016 00:40:51 -0000

--001a113fb2ec41dfe9053249f1aa
Content-Type: text/plain; charset=UTF-8

There was some confusion over the following email which was posted to the list
which appears to have been cancelled before a decision could be reached.

Please note the email seems inflammatory in the "acknowledgement" section and
really should have been rewritten to contain specific details of the objection
and corrections expected.

To be clear posts to the mailing list are either approved, or rejected for not
meeting the posting standards. This allows the author to make a quick correction
and resubmit. All rejections are cc'd to
https://lists.ozlabs.org/pipermail/bitcoin-dev-moderation/
for transparency. Sometimes moderators get delayed - this week has been a busy
with lots of distractions one for everyone :)

I'm copying the entire message below:

---------- Forwarded message ----------
From: Tom <tomz@freedommail.ch>
To: bitcoin-dev@lists.linuxfoundation.org, Matt Corallo
<lf-lists@mattcorallo.com>
Cc:
Date: Fri, 06 May 2016 13:31:15 +0100
Subject: Re: [bitcoin-dev] Compact Block Relay BIP
On Monday 02 May 2016 22:13:22 Matt Corallo via bitcoin-dev wrote:

Thanks for putting in the time to make a spec!

It looks good already, but I do think some more improvements can be made.


> ===Intended Protocol Flow===
I'm not a fan of the solution that a CNode should keep state and talk to
its remote nodes differently while announcing new blocks.
Its too complicated and ultimately counter-productive.

The problem is that an individual node needs to predict network behaviour in
advance. With the downside that if it guesses wrong that both nodes end up
paying for the wrong guess.
This is not a good way to design a p2p layer.



I would suggest that a new block is announced to all nodes equally and then
individual nodes can respond with a request of either a 'compact' or a
normal block.
This is much more in line with the current design as well.

Detection if remote nodes support compact blocks, for the purpose of
requesting a compact-block, can be done either via a network-bit or just a
protocol version. Or something else entirely, if you have better
suggestions.



> Variable-length integers: bytes are a MSB base-128 encoding of the
> number.
> The high bit in each byte signifies whether another digit follows.
> [snip bitwise spec]

I suggest just referring to UTF-8 which describes this just fine.
it is good practice to refer to existing specs when possible and not copy
the details.

> ====Short transaction IDs====
> 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

I don't think this is needed. Just use the first 8 bytes.
The reason to do xor-ing doesn't hold up and extra complexity is unneeded.
Especially since you mention some lines down;

> The short transaction ID calculation is designed to take absolutely
> minimal processing time during block compaction to avoid introducing
> serious DoS vulnerabilities


==Acknowledgements==

I think you need to acknowledge some more people, or just remove this
paragraph.

Cheers


---------- Forwarded message ----------
From: bitcoin-dev-request@lists.linuxfoundation.org
To:
Cc:
Date: Fri, 06 May 2016 12:31:23 +0000
Subject: confirm 37d25406a07ab77823fba5f9b450438c410ccd75
If you reply to this message, keeping the Subject: header intact,
Mailman will discard the held message.  Do this if the message is
spam.  If you reply to this message and include an Approved: header
with the list password in it, the message will be approved for posting
to the list.  The Approved: header can also appear in the first line
of the body of the reply.


On Mon, May 2, 2016 at 3:13 PM, Matt Corallo via bitcoin-dev <
bitcoin-dev@lists.linuxfoundation.org> wrote:

> Hi all,
>
> The following is a BIP-formatted design spec for compact block relay
> designed to limit on wire bytes during block relay. You can find the
> latest version of this document at
> https://github.com/TheBlueMatt/bips/blob/master/bip-TODO.mediawiki.
>
> There are several TODO items left on the document as indicated.
> Additionally, the implementation linked at the bottom of the document
> has a few remaining TODO items as well:
>
>  * Only request compact-block-announcement from one or two peers at a
> time, as the spec requires.
>  * Request new blocks using MSG_CMPCT_BLOCK where appropriate.
>  * Fill prefilledtxn with more than just the coinbase, as noted by the
> spec, up to 10K in transactions.
>
> Luke (CC'd): Can you assign a BIP number?
>
> Thanks,
> Matt
>
> <pre>
>   BIP: TODO
>   Title: Compact block relay
>   Author: Matt Corallo <bip@bluematt.me>
>   Status: Draft
>   Type: Standards Track
>   Created: 2016-04-27
> </pre>
>
> ==Abstract==
>
> Compact blocks on the wire as a way to save bandwidth for nodes on the
> P2P network.
>
> The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
> "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
> document are to be interpreted as described in RFC 2119.
>
> ==Motivation==
>
> Historically, the Bitcoin P2P protocol has not been very bandwidth
> efficient for block relay. Every transaction in a block is included when
> relayed, even though a large number of the transactions in a given block
> are already available to nodes before the block is relayed. This causes
> moderate inbound bandwidth spikes for nodes when receiving blocks, but
> can cause very significant outbound bandwidth spikes for some nodes
> which receive a block before their peers. When such spikes occur, buffer
> bloat can make consumer-grade internet connections temporarily unusable,
> and can delay the relay of blocks to remote peers who may choose to wait
> instead of redundantly requesting the same block from other, less
> congested, peers.
>
> Thus, decreasing the bandwidth used during block relay is very useful
> for many individuals running nodes.
>
> 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.
>
> ==Specification==
>
> ===Intended Protocol Flow===
> TODO: Diagrams
>
> The protocol is intended to be used in two ways, depending on the peers
> and bandwidth available, as discussed [[#Implementation_Details|later]].
> The "high-bandwidth" mode, which nodes may only enable for a few of
> their peers, is enabled by setting the first boolean to 1 in a
> "sendcmpct" message. In this mode, peers send new block announcements
> with the short transaction IDs already, possibly even before fully
> validating the block. In some cases no further round-trip is needed, and
> the receiver can reconstruct the block and process it as usual
> immediately. When some transactions were not available from local
> sources (ie mempool), a getblocktxn/blocktxn roundtrip is neccessary,
> bringing the best-case latency to the same 1.5*RTT minimum time that
> nodes take today, though with significantly less bandwidth usage.
>
> The "low-bandwidth" mode is enabled by setting the first boolean to 0 in
> a "sendcmpct" message. In this mode, peers send new block announcements
> with the usual inv/headers announcements (as per BIP130, and after fully
> validating the block). The receiving peer may then request the block
> using a MSG_CMPCT_BLOCK getdata reqeuest, which will receive a response
> of the header and short transaction IDs. In some cases no further
> round-trip is needed, and the receiver can reconstruct the block and
> process it as usual, taking the same 1.5*RTT minimum time that nodes
> take today, though with significantly less bandwidth usage. When some
> transactions were not available from local sources (ie mempool), a
> getblocktxn/blocktxn roundtrip is neccessary, bringing the best-case
> latency to 2.5*RTT, again with significantly less bandwidth usage than
> today. Because TCP often exhibits worse transfer latency for larger data
> sizes (as a multiple of RTT), total latency is expected to be reduced
> even when full the 2.5*RTT transfer mechanism is used.
>
> ===New data structures===
> Several new data structures are added to the P2P network to relay
> compact blocks: PrefilledTransaction, HeaderAndShortIDs,
> BlockTransactionsRequest, and BlockTransactions. Additionally, we
> introduce a new variable-length integer encoding for use in these data
> structures.
>
> For the purposes of this section, 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.
>
> ====New VarInt====
> TODO: I just copied this out of the src...Something that is
> wiki-formatted and more descriptive should be used here isntead.
>
> 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.
> Thus, the byte sequence a[] with length len, where all but the last byte
> has bit 128 set, encodes the number:
>
> (a[len-1] & 0x7F) + sum(i=1..len-1, 128^i*((a[len-i-1] & 0x7F)+1))
>
> Properties:
> * Very small (0-127: 1 byte, 128-16511: 2 bytes, 16512-2113663: 3 bytes)
> * Every integer has exactly one encoding
> * Encoding does not depend on size of original integer type
> * No redundancy: every (infinite) byte sequence corresponds to a list
>   of encoded integers.
>
> 0:         [0x00]  256:        [0x81 0x00]
> 1:         [0x01]  16383:      [0xFE 0x7F]
> 127:       [0x7F]  16384:      [0xFF 0x00]
> 128:  [0x80 0x00]  16511: [0x80 0xFF 0x7F]
> 255:  [0x80 0x7F]  65535: [0x82 0xFD 0x7F]
> 2^32:           [0x8E 0xFE 0xFE 0xFF 0x00]
>
> Several uses of New VarInts below are "differentially encoded". For
> these, instead of using raw indexes, the number encoded is the
> difference between the current index and the previous index, minus one.
> For example, a first index of 0 implies a real index of 0, a second
> index of 0 thereafter refers to a real index of 1, etc.
>
> ====PrefilledTransaction====
> A PrefilledTransaction structure is used in HeaderAndShortIDs to provide
> a list of a few transactions explicitly.
>
> {|
> |Field Name||Type||Size||Encoding||Purpose
> |-
> |index||New VarInt||1-3 bytes||[[#New_VarInt|New VarInt]],
> differentially encoded since the last PrefilledTransaction in a
> list||The index into the block at which this transaction is
> |-
> |tx||Transaction||variable||As encoded in "tx" messages||The transaction
> which is in the block at index index.
> |}
>
> ====HeaderAndShortIDs====
> 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.
>
> {|
> |Field Name||Type||Size||Encoding||Purpose
> |-
> |header||Block header||80 bytes||First 80 bytes of the block as defined
> by the encoding used by "block" messages||The header of the block being
> provided
> |-
> |nonce||uint64_t||8 bytes||Little Endian||A nonce for use in short
> transaction ID calculations
> |-
> |shortids_length||CompactSize||1, 3, 5, or 9 bytes||As used elsewhere to
> encode array lengths||The number of short transaction IDs in shortids
> |-
> |shortids||List of uint64_ts||8*shortids_length bytes||Little
> Endian||The short transaction IDs calculated from the transactions which
> were not provided explicitly in prefilledtxn
> |-
> |prefilledtxn_length||CompactSize||1, 3, 5, or 9 bytes||As used
> elsewhere to encode array lengths||The number of prefilled transactions
> in prefilledtxn
> |-
> |prefilledtxn||List of PrefilledTransactions||variable
> size*prefilledtxn_length||As defined by PrefilledTransaction definition,
> above||Used to provide the coinbase transaction and a select few which
> we expect a peer may be missing
> |}
>
> ====BlockTransactionsRequest====
> A BlockTransactionsRequest structure is used to list transaction indexes
> in a block being requested.
>
> {|
> |Field Name||Type||Size||Encoding||Purpose
> |-
> |blockhash||Binary blob||32 bytes||The output from a double-SHA256 of
> the block header, as used elsewhere||The blockhash of the block which
> the transactions being requested are in
> |-
> |indexes_length||New VarInt||1-3 bytes||As defined in [[#New_VarInt|New
> VarInt]]||The number of transactions being requested
> |-
> |indexes||List of New VarInts||1-3 bytes*indexes_length||As defined in
> [[#New_VarInt|New VarInt]], differentially encoded||The indexes of the
> transactions being requested in the block
> |}
>
> ====BlockTransactions====
> A BlockTransactions structure is used to provide some of the
> transactions in a block, as requested.
>
> {|
> |Field Name||Type||Size||Encoding||Purpose
> |-
> |blockhash||Binary blob||32 bytes||The output from a double-SHA256 of
> the block header, as used elsewhere||The blockhash of the block which
> the transactions being provided are in
> |-
> |transactions_length||New VarInt||1-3 bytes||As defined in
> [[#New_VarInt|New VarInt]]||The number of transactions provided
> |-
> |transactions||List of Transactions||variable||As encoded in "tx"
> messages||The transactions provided
> |}
>
> ====Short transaction IDs====
> 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
>
> ===New messages===
> A new inv type (MSG_CMPCT_BLOCK == 4) and several new protocol messages
> are added: sendcmpct, cmpctblock, getblocktxn, and blocktxn.
>
> ====sendcmpct====
> # The sendcmpct message is defined as a message containing a 1-byte
> integer followed by a 8-byte integer where pchCommand == "sendcmpct".
> # The first integer SHALL be interpreted as a boolean (and MUST have a
> value of either 1 or 0)
> # The second integer SHALL be interpreted as a little-endian version
> number. Nodes sending a sendcmpct message MUST currently set this value
> to 1.
> # Upon receipt of a "sendcmpct" message with the first and second
> integers set to 1, the node SHOULD announce new blocks by sending a
> cmpctblock message.
> # Upon receipt of a "sendcmpct" message with the first integer set to 0,
> the node SHOULD NOT announce new blocks by sending a cmpctblock message,
> but SHOULD announce new blocks by sending invs or headers, as defined by
> BIP130.
> # Upon receipt of a "sendcmpct" message with the second integer set to
> something other than 1, nodes SHOULD 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)
> # Nodes SHOULD check for a protocol version of >= 70014 before sending
> sendcmpct messages.
> # Nodes MUST NOT send a request for a MSG_CMPCT_BLOCK object to a peer
> before having received a sendcmpct message from that peer.
>
> ====MSG_CMPCT_BLOCK====
> # getdata messages may now contain requests for MSG_CMPCT_BLOCK objects.
> # Upon receipt of a getdata containing a request for a MSG_CMPCT_BLOCK
> object with the hash of a block which was recently announced and after
> having sent the requesting peer a sendcmpct message, nodes MUST respond
> with a cmpctblock message containing appropriate data representing the
> block being requested.
> # MSG_CMPCT_BLOCK inv objects MUST NOT appear anywhere except for in
> getdata messages.
>
> ====cmpctblock====
> # The cmpctblock message is defined as as a message containing a
> serialized HeaderAndShortIDs message and pchCommand == "cmpctblock".
> # Upon receipt of a cmpctblock message after sending a sendcmpct
> message, nodes SHOULD calculate the short transaction ID for each
> unconfirmed transaction they have available (ie in their mempool) and
> compare each to each short transaction ID in the cmpctblock message.
> # After finding already-available transactions, nodes which do not have
> all transactions available to reconstruct the full block SHOULD request
> the missing transactions using a getblocktxn message.
> # A node MUST NOT send a cmpctblock message unless they are able to
> respond to a getblocktxn message which requests every transaction in the
> block.
> # A node MUST NOT send a cmpctblock message without having validated
> that the header properly commits to each transaction in the block, and
> properly builds on top of the existing chain with a valid proof-of-work.
> A node MAY send a cmpctblock before validating that each transaction in
> the block validly spends existing UTXO set entries.
>
> ====getblocktxn====
> # The getblocktxn message is defined as as a message containing a
> serialized BlockTransactionsRequest message and pchCommand ==
> "getblocktxn".
> # Upon receipt of a properly-formatted getblocktxnmessage, nodes which
> recently provided the sender of such a message a cmpctblock for the
> block hash identified in this message MUST respond with an appropriate
> blocktxn message. Such a blocktxn message MUST contain exactly and only
> each transaction which is present in the appropriate block at the index
> specified in the getblocktxn indexes list, in the order requested.
>
> ====blocktxn====
> # The blocktxn message is defined as as a message containing a
> serialized BlockTransactions message and pchCommand == "blocktxn".
> # Upon receipt of a properly-formatted requested blocktxn message, nodes
> SHOULD attempt to reconstruct the full block by:
> ## Taking the prefilledtxn transactions from the original cmpctblock and
> placing them in the marked positions.
> ## 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.
> # 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.
>
> ===Implementation Notes===
> # For nodes which have sufficient inbound bandwidth, sending a sendcmpct
> message with the first integer set to 1 to up to three peers is
> RECOMMENDED. If possible, it is RECOMMENDED that those peers be selected
> based on their past performance in providing blocks quickly. This will
> allow them to receive some blocks in only 0.5*RTT between them and the
> sending peer. It will also reduce their block transfer latency in other
> cases due to the smaller amount of data transmitted. Nodes MUST NOT send
> such sendcmpct messages to all peers, as it encourages wasting outbound
> bandwidth across the network.
>
> # All nodes SHOULD send a sendcmpct message to all appropriate peers.
> This will reduce their outbound bandwidth usage by allowing their peers
> to request compact blocks instead of full blocks.
>
> # Nodes with limited inbound bandwidth SHOULD request blocks using
> MSG_CMPCT_BLOCK/getblocktxn requests, when possible. While this
> increases worst-case message round-trips, it is expected to reduce
> overall transfer latency as TCP is more likely to exhibit poor
> throughput on low-bandwidth nodes.
>
> # Nodes sending cmpctblock messages SHOULD make an attempt to not place
> too many transactions into prefilledtxn (ie should limit prefilledtxn to
> only around 10KB of transactions). When in doubt, nodes SHOULD only
> include the coinbase transaction in prefilledtxn.
>
> # Nodes MAY pick one nonce per block they wish to send, and only build a
> cmpctblock message once for all peers which they wish to send a given
> block to. Nodes SHOULD NOT use the same nonce across multiple different
> blocks.
>
> # Nodes MAY impose additional requirements on when they announce new
> blocks by sending cmpctblock messages. For example, nodes with limited
> outbound bandwidth MAY choose to announce new blocks using inv/header
> messages (as per BIP130) to conserve outbound bandwidth.
>
> # 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. Thus, nodes MUST
> NOT request blocks using MSG_CMPCT_BLOCK getdatas unless it is in
> response to an inv/headers block announcement (as per BIP130), and MUST
> NOT request blocks using MSG_CMPCT_BLOCK getdatas in response to headers
> messages which were, themselves, responses to getheaders requests.
>
> # 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.
>
> ==Justification==
>
> ====Protocol design====
> There have been many proposals to save wire bytes when relaying blocks.
> Many of them have a two-fold goal of reducing block relay time and thus
> rely on the use of significant processing power in order to avoid
> introducing additional worst-case RTTs. Because this work is not focused
> primarily on reducing block relay time, its design is much simpler (ie
> does not rely on set reconciliation protocols). Still, in testing at the
> time of writing, nodes are able to relay blocks without the extra
> getblocktxn/blocktxn RTT around 90% of the time. With a smart
> compact-block-announcement policy, it is thus expected that this work
> might allow blocks to be relayed between nodes in 0.5*RTT instead of
> 1.5*RTT at least 75% of the time.
>
> ====Use of New VarInts====
> Bitcoin has long had a variable-length integer implementation (referred
> to as CompactSize in this document), making a second a strange protocol
> quirk. However, in this protocol most of our variable-length integers
> are between 0 and 2000. For both encodings, small numbers (<100) are
> encoded as 1-byte. For numbers over 250, the CompactSize encoding begins
> to use 3 bytes instead of 1, whereas the New VarInt encoding uses 2.
> Because the primary motivation for this work is to save bytes during
> block relay, the extra byte of saving per transaction-difference is
> considered worth the extra design complexity.
>
> ====Short transaction ID calculation====
> The short transaction ID calculation is designed to take absolutely
> minimal processing time during block compaction to avoid introducing
> serious DoS vulnerabilities such as those introduced by the
> bloom-filtering in BIP 37. As such, it is possible for a node to
> construct one compact-block representation of a block for relay to
> multiple peers. Additionally, only one cryptographic hash (2 SHA rounds)
> is used when calculating the short transaction IDs for an entire block.
>
> The XOR-and-add method is used for calculating short transaction IDs
> primarily because it is fast and is reasonably able to limit the ability
> of an attacker who does not know the block hash or nonce to cause
> collisions in short transaction IDs. If an attacker were able to cause
> such collisions, filling mempools (and, thus, blocks) with them would
> cause poor network propagation of new (or non-attacker, in the case of a
> miner) blocks.
>
> The 8-byte nonce in short transaction ID calculation is used to
> introduce additional entropy on a per-node level. While the use of 8
> bytes is sufficient for an attacker to maliciously cause short
> transaction ID collisions in their own block relay, this would have less
> of an effect than if such an attacker were relaying headers/invs and not
> responding to requests for the full block.
>
> ==Backward compatibility==
>
> Older clients remain fully compatible and interoperable after this change.
>
> ==Implementation==
>
> https://github.com/TheBlueMatt/bitcoin/tree/udp
>
> ==Acknowledgements==
>
> Thanks to Gregory Maxwell for the initial suggestion as well as a lot of
> back-and-forth design and significant testing.
>
> ==Copyright==
>
> This document is placed in the public domain.
>
> _______________________________________________
> bitcoin-dev mailing list
> bitcoin-dev@lists.linuxfoundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev
>



-- 
Johnathan Corgan
Corgan Labs - SDR Training and Development Services
http://corganlabs.com

--001a113fb2ec41dfe9053249f1aa
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-size:small"><pr=
e style=3D"color:rgb(0,0,0);word-wrap:break-word;white-space:pre-wrap">Ther=
e was some confusion over the following email which was posted to the list
which appears to have been cancelled before a decision could be reached.

Please note the email seems inflammatory in the &quot;acknowledgement&quot;=
 section and
really should have been rewritten to contain specific details of the object=
ion
and corrections expected.

To be clear posts to the mailing list are either approved, or rejected for =
not
meeting the posting standards. This allows the author to make a quick corre=
ction
and resubmit. All rejections are cc&#39;d to <a href=3D"https://lists.ozlab=
s.org/pipermail/bitcoin-dev-moderation/">https://lists.ozlabs.org/pipermail=
/bitcoin-dev-moderation/</a>
for transparency. Sometimes moderators get delayed - this week has been a b=
usy
with lots of distractions one for everyone :)

I&#39;m copying the entire message below:

---------- Forwarded message ----------
From: Tom &lt;<a href=3D"mailto:tomz@freedommail.ch">tomz@freedommail.ch</a=
>&gt;
To: <a href=3D"mailto:bitcoin-dev@lists.linuxfoundation.org">bitcoin-dev@li=
sts.linuxfoundation.org</a>, Matt Corallo &lt;<a href=3D"mailto:lf-lists@ma=
ttcorallo.com">lf-lists@mattcorallo.com</a>&gt;
Cc:=20
Date: Fri, 06 May 2016 13:31:15 +0100
Subject: Re: [bitcoin-dev] Compact Block Relay BIP
On Monday 02 May 2016 22:13:22 Matt Corallo via bitcoin-dev wrote:

Thanks for putting in the time to make a spec!

It looks good already, but I do think some more improvements can be made.


&gt; =3D=3D=3DIntended Protocol Flow=3D=3D=3D
I&#39;m not a fan of the solution that a CNode should keep state and talk t=
o
its remote nodes differently while announcing new blocks.
Its too complicated and ultimately counter-productive.

The problem is that an individual node needs to predict network behaviour i=
n
advance. With the downside that if it guesses wrong that both nodes end up
paying for the wrong guess.
This is not a good way to design a p2p layer.



I would suggest that a new block is announced to all nodes equally and then
individual nodes can respond with a request of either a &#39;compact&#39; o=
r a
normal block.
This is much more in line with the current design as well.

Detection if remote nodes support compact blocks, for the purpose of
requesting a compact-block, can be done either via a network-bit or just a
protocol version. Or something else entirely, if you have better
suggestions.



&gt; Variable-length integers: bytes are a MSB base-128 encoding of the
&gt; number.
&gt; The high bit in each byte signifies whether another digit follows.
&gt; [snip bitwise spec]

I suggest just referring to UTF-8 which describes this just fine.
it is good practice to refer to existing specs when possible and not copy
the details.

&gt; =3D=3D=3D=3DShort transaction IDs=3D=3D=3D=3D
&gt; Short transaction IDs are used to represent a transaction without
&gt; sending a full 256-bit hash. They are calculated by:
&gt; # single-SHA256 hashing the block header with the nonce appended (in
&gt; little-endian)
&gt; # XORing each 8-byte chunk of the double-SHA256 transaction hash with
&gt; each corresponding 8-byte chunk of the hash from the previous step
&gt; # Adding each of the XORed 8-byte chunks together (in little-endian)
&gt; iteratively to find the short transaction ID

I don&#39;t think this is needed. Just use the first 8 bytes.
The reason to do xor-ing doesn&#39;t hold up and extra complexity is unneed=
ed.
Especially since you mention some lines down;

&gt; The short transaction ID calculation is designed to take absolutely
&gt; minimal processing time during block compaction to avoid introducing
&gt; serious DoS vulnerabilities


=3D=3DAcknowledgements=3D=3D

I think you need to acknowledge some more people, or just remove this
paragraph.

Cheers


---------- Forwarded message ----------
From: <a href=3D"mailto:bitcoin-dev-request@lists.linuxfoundation.org">bitc=
oin-dev-request@lists.linuxfoundation.org</a>
To:=20
Cc:=20
Date: Fri, 06 May 2016 12:31:23 +0000
Subject: confirm 37d25406a07ab77823fba5f9b450438c410ccd75
If you reply to this message, keeping the Subject: header intact,
Mailman will discard the held message.  Do this if the message is
spam.  If you reply to this message and include an Approved: header
with the list password in it, the message will be approved for posting
to the list.  The Approved: header can also appear in the first line
of the body of the reply.</pre></div><div class=3D"gmail_extra"><br><div cl=
ass=3D"gmail_quote">On Mon, May 2, 2016 at 3:13 PM, Matt Corallo via bitcoi=
n-dev <span dir=3D"ltr">&lt;<a href=3D"mailto:bitcoin-dev@lists.linuxfounda=
tion.org" target=3D"_blank">bitcoin-dev@lists.linuxfoundation.org</a>&gt;</=
span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8e=
x;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
The following is a BIP-formatted design spec for compact block relay<br>
designed to limit on wire bytes during block relay. You can find the<br>
latest version of this document at<br>
<a href=3D"https://github.com/TheBlueMatt/bips/blob/master/bip-TODO.mediawi=
ki" rel=3D"noreferrer" target=3D"_blank">https://github.com/TheBlueMatt/bip=
s/blob/master/bip-TODO.mediawiki</a>.<br>
<br>
There are several TODO items left on the document as indicated.<br>
Additionally, the implementation linked at the bottom of the document<br>
has a few remaining TODO items as well:<br>
<br>
=C2=A0* Only request compact-block-announcement from one or two peers at a<=
br>
time, as the spec requires.<br>
=C2=A0* Request new blocks using MSG_CMPCT_BLOCK where appropriate.<br>
=C2=A0* Fill prefilledtxn with more than just the coinbase, as noted by the=
<br>
spec, up to 10K in transactions.<br>
<br>
Luke (CC&#39;d): Can you assign a BIP number?<br>
<br>
Thanks,<br>
Matt<br>
<br>
&lt;pre&gt;<br>
=C2=A0 BIP: TODO<br>
=C2=A0 Title: Compact block relay<br>
=C2=A0 Author: Matt Corallo &lt;<a href=3D"mailto:bip@bluematt.me">bip@blue=
matt.me</a>&gt;<br>
=C2=A0 Status: Draft<br>
=C2=A0 Type: Standards Track<br>
=C2=A0 Created: 2016-04-27<br>
&lt;/pre&gt;<br>
<br>
=3D=3DAbstract=3D=3D<br>
<br>
Compact blocks on the wire as a way to save bandwidth for nodes on the<br>
P2P network.<br>
<br>
The key words &quot;MUST&quot;, &quot;MUST NOT&quot;, &quot;REQUIRED&quot;,=
 &quot;SHALL&quot;, &quot;SHALL NOT&quot;,<br>
&quot;SHOULD&quot;, &quot;SHOULD NOT&quot;, &quot;RECOMMENDED&quot;, &quot;=
MAY&quot;, and &quot;OPTIONAL&quot; in this<br>
document are to be interpreted as described in RFC 2119.<br>
<br>
=3D=3DMotivation=3D=3D<br>
<br>
Historically, the Bitcoin P2P protocol has not been very bandwidth<br>
efficient for block relay. Every transaction in a block is included when<br=
>
relayed, even though a large number of the transactions in a given block<br=
>
are already available to nodes before the block is relayed. This causes<br>
moderate inbound bandwidth spikes for nodes when receiving blocks, but<br>
can cause very significant outbound bandwidth spikes for some nodes<br>
which receive a block before their peers. When such spikes occur, buffer<br=
>
bloat can make consumer-grade internet connections temporarily unusable,<br=
>
and can delay the relay of blocks to remote peers who may choose to wait<br=
>
instead of redundantly requesting the same block from other, less<br>
congested, peers.<br>
<br>
Thus, decreasing the bandwidth used during block relay is very useful<br>
for many individuals running nodes.<br>
<br>
While the goal of this work is explicitly not to reduce block transfer<br>
latency, it does, as a side effect reduce block transfer latencies in<br>
some rather significant ways. Additionally, this work forms a foundation<br=
>
for future work explicitly targeting low-latency block transfer.<br>
<br>
=3D=3DSpecification=3D=3D<br>
<br>
=3D=3D=3DIntended Protocol Flow=3D=3D=3D<br>
TODO: Diagrams<br>
<br>
The protocol is intended to be used in two ways, depending on the peers<br>
and bandwidth available, as discussed [[#Implementation_Details|later]].<br=
>
The &quot;high-bandwidth&quot; mode, which nodes may only enable for a few =
of<br>
their peers, is enabled by setting the first boolean to 1 in a<br>
&quot;sendcmpct&quot; message. In this mode, peers send new block announcem=
ents<br>
with the short transaction IDs already, possibly even before fully<br>
validating the block. In some cases no further round-trip is needed, and<br=
>
the receiver can reconstruct the block and process it as usual<br>
immediately. When some transactions were not available from local<br>
sources (ie mempool), a getblocktxn/blocktxn roundtrip is neccessary,<br>
bringing the best-case latency to the same 1.5*RTT minimum time that<br>
nodes take today, though with significantly less bandwidth usage.<br>
<br>
The &quot;low-bandwidth&quot; mode is enabled by setting the first boolean =
to 0 in<br>
a &quot;sendcmpct&quot; message. In this mode, peers send new block announc=
ements<br>
with the usual inv/headers announcements (as per BIP130, and after fully<br=
>
validating the block). The receiving peer may then request the block<br>
using a MSG_CMPCT_BLOCK getdata reqeuest, which will receive a response<br>
of the header and short transaction IDs. In some cases no further<br>
round-trip is needed, and the receiver can reconstruct the block and<br>
process it as usual, taking the same 1.5*RTT minimum time that nodes<br>
take today, though with significantly less bandwidth usage. When some<br>
transactions were not available from local sources (ie mempool), a<br>
getblocktxn/blocktxn roundtrip is neccessary, bringing the best-case<br>
latency to 2.5*RTT, again with significantly less bandwidth usage than<br>
today. Because TCP often exhibits worse transfer latency for larger data<br=
>
sizes (as a multiple of RTT), total latency is expected to be reduced<br>
even when full the 2.5*RTT transfer mechanism is used.<br>
<br>
=3D=3D=3DNew data structures=3D=3D=3D<br>
Several new data structures are added to the P2P network to relay<br>
compact blocks: PrefilledTransaction, HeaderAndShortIDs,<br>
BlockTransactionsRequest, and BlockTransactions. Additionally, we<br>
introduce a new variable-length integer encoding for use in these data<br>
structures.<br>
<br>
For the purposes of this section, CompactSize refers to the<br>
variable-length integer encoding used across the existing P2P protocol<br>
to encode array lengths, among other things, in 1, 3, 5 or 9 bytes.<br>
<br>
=3D=3D=3D=3DNew VarInt=3D=3D=3D=3D<br>
TODO: I just copied this out of the src...Something that is<br>
wiki-formatted and more descriptive should be used here isntead.<br>
<br>
Variable-length integers: bytes are a MSB base-128 encoding of the number.<=
br>
The high bit in each byte signifies whether another digit follows. To make<=
br>
sure the encoding is one-to-one, one is subtracted from all but the last<br=
>
digit.<br>
Thus, the byte sequence a[] with length len, where all but the last byte<br=
>
has bit 128 set, encodes the number:<br>
<br>
(a[len-1] &amp; 0x7F) + sum(i=3D1..len-1, 128^i*((a[len-i-1] &amp; 0x7F)+1)=
)<br>
<br>
Properties:<br>
* Very small (0-127: 1 byte, 128-16511: 2 bytes, 16512-2113663: 3 bytes)<br=
>
* Every integer has exactly one encoding<br>
* Encoding does not depend on size of original integer type<br>
* No redundancy: every (infinite) byte sequence corresponds to a list<br>
=C2=A0 of encoded integers.<br>
<br>
0:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[0x00]=C2=A0 256:=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 [0x81 0x00]<br>
1:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[0x01]=C2=A0 16383:=C2=A0 =C2=A0 =C2=A0=
 [0xFE 0x7F]<br>
127:=C2=A0 =C2=A0 =C2=A0 =C2=A0[0x7F]=C2=A0 16384:=C2=A0 =C2=A0 =C2=A0 [0xF=
F 0x00]<br>
128:=C2=A0 [0x80 0x00]=C2=A0 16511: [0x80 0xFF 0x7F]<br>
255:=C2=A0 [0x80 0x7F]=C2=A0 65535: [0x82 0xFD 0x7F]<br>
2^32:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[0x8E 0xFE 0xFE 0xFF 0x00]<br=
>
<br>
Several uses of New VarInts below are &quot;differentially encoded&quot;. F=
or<br>
these, instead of using raw indexes, the number encoded is the<br>
difference between the current index and the previous index, minus one.<br>
For example, a first index of 0 implies a real index of 0, a second<br>
index of 0 thereafter refers to a real index of 1, etc.<br>
<br>
=3D=3D=3D=3DPrefilledTransaction=3D=3D=3D=3D<br>
A PrefilledTransaction structure is used in HeaderAndShortIDs to provide<br=
>
a list of a few transactions explicitly.<br>
<br>
{|<br>
|Field Name||Type||Size||Encoding||Purpose<br>
|-<br>
|index||New VarInt||1-3 bytes||[[#New_VarInt|New VarInt]],<br>
differentially encoded since the last PrefilledTransaction in a<br>
list||The index into the block at which this transaction is<br>
|-<br>
|tx||Transaction||variable||As encoded in &quot;tx&quot; messages||The tran=
saction<br>
which is in the block at index index.<br>
|}<br>
<br>
=3D=3D=3D=3DHeaderAndShortIDs=3D=3D=3D=3D<br>
A HeaderAndShortIDs structure is used to relay a block header, the short<br=
>
transactions IDs used for matching already-available transactions, and a<br=
>
select few transactions which we expect a peer may be missing.<br>
<br>
{|<br>
|Field Name||Type||Size||Encoding||Purpose<br>
|-<br>
|header||Block header||80 bytes||First 80 bytes of the block as defined<br>
by the encoding used by &quot;block&quot; messages||The header of the block=
 being<br>
provided<br>
|-<br>
|nonce||uint64_t||8 bytes||Little Endian||A nonce for use in short<br>
transaction ID calculations<br>
|-<br>
|shortids_length||CompactSize||1, 3, 5, or 9 bytes||As used elsewhere to<br=
>
encode array lengths||The number of short transaction IDs in shortids<br>
|-<br>
|shortids||List of uint64_ts||8*shortids_length bytes||Little<br>
Endian||The short transaction IDs calculated from the transactions which<br=
>
were not provided explicitly in prefilledtxn<br>
|-<br>
|prefilledtxn_length||CompactSize||1, 3, 5, or 9 bytes||As used<br>
elsewhere to encode array lengths||The number of prefilled transactions<br>
in prefilledtxn<br>
|-<br>
|prefilledtxn||List of PrefilledTransactions||variable<br>
size*prefilledtxn_length||As defined by PrefilledTransaction definition,<br=
>
above||Used to provide the coinbase transaction and a select few which<br>
we expect a peer may be missing<br>
|}<br>
<br>
=3D=3D=3D=3DBlockTransactionsRequest=3D=3D=3D=3D<br>
A BlockTransactionsRequest structure is used to list transaction indexes<br=
>
in a block being requested.<br>
<br>
{|<br>
|Field Name||Type||Size||Encoding||Purpose<br>
|-<br>
|blockhash||Binary blob||32 bytes||The output from a double-SHA256 of<br>
the block header, as used elsewhere||The blockhash of the block which<br>
the transactions being requested are in<br>
|-<br>
|indexes_length||New VarInt||1-3 bytes||As defined in [[#New_VarInt|New<br>
VarInt]]||The number of transactions being requested<br>
|-<br>
|indexes||List of New VarInts||1-3 bytes*indexes_length||As defined in<br>
[[#New_VarInt|New VarInt]], differentially encoded||The indexes of the<br>
transactions being requested in the block<br>
|}<br>
<br>
=3D=3D=3D=3DBlockTransactions=3D=3D=3D=3D<br>
A BlockTransactions structure is used to provide some of the<br>
transactions in a block, as requested.<br>
<br>
{|<br>
|Field Name||Type||Size||Encoding||Purpose<br>
|-<br>
|blockhash||Binary blob||32 bytes||The output from a double-SHA256 of<br>
the block header, as used elsewhere||The blockhash of the block which<br>
the transactions being provided are in<br>
|-<br>
|transactions_length||New VarInt||1-3 bytes||As defined in<br>
[[#New_VarInt|New VarInt]]||The number of transactions provided<br>
|-<br>
|transactions||List of Transactions||variable||As encoded in &quot;tx&quot;=
<br>
messages||The transactions provided<br>
|}<br>
<br>
=3D=3D=3D=3DShort transaction IDs=3D=3D=3D=3D<br>
Short transaction IDs are used to represent a transaction without<br>
sending a full 256-bit hash. They are calculated by:<br>
# single-SHA256 hashing the block header with the nonce appended (in<br>
little-endian)<br>
# XORing each 8-byte chunk of the double-SHA256 transaction hash with<br>
each corresponding 8-byte chunk of the hash from the previous step<br>
# Adding each of the XORed 8-byte chunks together (in little-endian)<br>
iteratively to find the short transaction ID<br>
<br>
=3D=3D=3DNew messages=3D=3D=3D<br>
A new inv type (MSG_CMPCT_BLOCK =3D=3D 4) and several new protocol messages=
<br>
are added: sendcmpct, cmpctblock, getblocktxn, and blocktxn.<br>
<br>
=3D=3D=3D=3Dsendcmpct=3D=3D=3D=3D<br>
# The sendcmpct message is defined as a message containing a 1-byte<br>
integer followed by a 8-byte integer where pchCommand =3D=3D &quot;sendcmpc=
t&quot;.<br>
# The first integer SHALL be interpreted as a boolean (and MUST have a<br>
value of either 1 or 0)<br>
# The second integer SHALL be interpreted as a little-endian version<br>
number. Nodes sending a sendcmpct message MUST currently set this value<br>
to 1.<br>
# Upon receipt of a &quot;sendcmpct&quot; message with the first and second=
<br>
integers set to 1, the node SHOULD announce new blocks by sending a<br>
cmpctblock message.<br>
# Upon receipt of a &quot;sendcmpct&quot; message with the first integer se=
t to 0,<br>
the node SHOULD NOT announce new blocks by sending a cmpctblock message,<br=
>
but SHOULD announce new blocks by sending invs or headers, as defined by<br=
>
BIP130.<br>
# Upon receipt of a &quot;sendcmpct&quot; message with the second integer s=
et to<br>
something other than 1, nodes SHOULD treat the peer as if they had not<br>
received the message (as it indicates the peer will provide an<br>
unexpected encoding in cmpctblock, and/or other, messages)<br>
# Nodes SHOULD check for a protocol version of &gt;=3D 70014 before sending=
<br>
sendcmpct messages.<br>
# Nodes MUST NOT send a request for a MSG_CMPCT_BLOCK object to a peer<br>
before having received a sendcmpct message from that peer.<br>
<br>
=3D=3D=3D=3DMSG_CMPCT_BLOCK=3D=3D=3D=3D<br>
# getdata messages may now contain requests for MSG_CMPCT_BLOCK objects.<br=
>
# Upon receipt of a getdata containing a request for a MSG_CMPCT_BLOCK<br>
object with the hash of a block which was recently announced and after<br>
having sent the requesting peer a sendcmpct message, nodes MUST respond<br>
with a cmpctblock message containing appropriate data representing the<br>
block being requested.<br>
# MSG_CMPCT_BLOCK inv objects MUST NOT appear anywhere except for in<br>
getdata messages.<br>
<br>
=3D=3D=3D=3Dcmpctblock=3D=3D=3D=3D<br>
# The cmpctblock message is defined as as a message containing a<br>
serialized HeaderAndShortIDs message and pchCommand =3D=3D &quot;cmpctblock=
&quot;.<br>
# Upon receipt of a cmpctblock message after sending a sendcmpct<br>
message, nodes SHOULD calculate the short transaction ID for each<br>
unconfirmed transaction they have available (ie in their mempool) and<br>
compare each to each short transaction ID in the cmpctblock message.<br>
# After finding already-available transactions, nodes which do not have<br>
all transactions available to reconstruct the full block SHOULD request<br>
the missing transactions using a getblocktxn message.<br>
# A node MUST NOT send a cmpctblock message unless they are able to<br>
respond to a getblocktxn message which requests every transaction in the<br=
>
block.<br>
# A node MUST NOT send a cmpctblock message without having validated<br>
that the header properly commits to each transaction in the block, and<br>
properly builds on top of the existing chain with a valid proof-of-work.<br=
>
A node MAY send a cmpctblock before validating that each transaction in<br>
the block validly spends existing UTXO set entries.<br>
<br>
=3D=3D=3D=3Dgetblocktxn=3D=3D=3D=3D<br>
# The getblocktxn message is defined as as a message containing a<br>
serialized BlockTransactionsRequest message and pchCommand =3D=3D &quot;get=
blocktxn&quot;.<br>
# Upon receipt of a properly-formatted getblocktxnmessage, nodes which<br>
recently provided the sender of such a message a cmpctblock for the<br>
block hash identified in this message MUST respond with an appropriate<br>
blocktxn message. Such a blocktxn message MUST contain exactly and only<br>
each transaction which is present in the appropriate block at the index<br>
specified in the getblocktxn indexes list, in the order requested.<br>
<br>
=3D=3D=3D=3Dblocktxn=3D=3D=3D=3D<br>
# The blocktxn message is defined as as a message containing a<br>
serialized BlockTransactions message and pchCommand =3D=3D &quot;blocktxn&q=
uot;.<br>
# Upon receipt of a properly-formatted requested blocktxn message, nodes<br=
>
SHOULD attempt to reconstruct the full block by:<br>
## Taking the prefilledtxn transactions from the original cmpctblock and<br=
>
placing them in the marked positions.<br>
## For each short transaction ID from the original cmpctblock, in order,<br=
>
find the corresponding transaction either from the blocktxn message or<br>
from other sources and place it in the first available position in the<br>
block.<br>
# Once the block has been reconstructed, it shall be processed as<br>
normal, keeping in mind that short transaction IDs are expected to<br>
occasionally collide, and that nodes MUST NOT be penalized for such<br>
collisions, wherever they appear.<br>
<br>
=3D=3D=3DImplementation Notes=3D=3D=3D<br>
# For nodes which have sufficient inbound bandwidth, sending a sendcmpct<br=
>
message with the first integer set to 1 to up to three peers is<br>
RECOMMENDED. If possible, it is RECOMMENDED that those peers be selected<br=
>
based on their past performance in providing blocks quickly. This will<br>
allow them to receive some blocks in only 0.5*RTT between them and the<br>
sending peer. It will also reduce their block transfer latency in other<br>
cases due to the smaller amount of data transmitted. Nodes MUST NOT send<br=
>
such sendcmpct messages to all peers, as it encourages wasting outbound<br>
bandwidth across the network.<br>
<br>
# All nodes SHOULD send a sendcmpct message to all appropriate peers.<br>
This will reduce their outbound bandwidth usage by allowing their peers<br>
to request compact blocks instead of full blocks.<br>
<br>
# Nodes with limited inbound bandwidth SHOULD request blocks using<br>
MSG_CMPCT_BLOCK/getblocktxn requests, when possible. While this<br>
increases worst-case message round-trips, it is expected to reduce<br>
overall transfer latency as TCP is more likely to exhibit poor<br>
throughput on low-bandwidth nodes.<br>
<br>
# Nodes sending cmpctblock messages SHOULD make an attempt to not place<br>
too many transactions into prefilledtxn (ie should limit prefilledtxn to<br=
>
only around 10KB of transactions). When in doubt, nodes SHOULD only<br>
include the coinbase transaction in prefilledtxn.<br>
<br>
# Nodes MAY pick one nonce per block they wish to send, and only build a<br=
>
cmpctblock message once for all peers which they wish to send a given<br>
block to. Nodes SHOULD NOT use the same nonce across multiple different<br>
blocks.<br>
<br>
# Nodes MAY impose additional requirements on when they announce new<br>
blocks by sending cmpctblock messages. For example, nodes with limited<br>
outbound bandwidth MAY choose to announce new blocks using inv/header<br>
messages (as per BIP130) to conserve outbound bandwidth.<br>
<br>
# Note that the MSG_CMPCT_BLOCK section does not require that nodes<br>
respond to MSG_CMPCT_BLOCK getdata requests for blocks which they did<br>
not recently announce. This allows nodes to calculate cmpctblock<br>
messages at announce-time instead of at request-time. Thus, nodes MUST<br>
NOT request blocks using MSG_CMPCT_BLOCK getdatas unless it is in<br>
response to an inv/headers block announcement (as per BIP130), and MUST<br>
NOT request blocks using MSG_CMPCT_BLOCK getdatas in response to headers<br=
>
messages which were, themselves, responses to getheaders requests.<br>
<br>
# While the current version sends transactions with the same encodings<br>
as is used in tx messages and elsewhere in the protocol, the version<br>
field in sendcmpct is intended to allow this to change in the future.<br>
For this reason, it is recommended that the code used to decode<br>
PrefilledTransaction and BlockTransactions messages be prepared to take<br>
a different transaction encoding, if and when the version field in<br>
sendcmpct changes in a future BIP.<br>
<br>
=3D=3DJustification=3D=3D<br>
<br>
=3D=3D=3D=3DProtocol design=3D=3D=3D=3D<br>
There have been many proposals to save wire bytes when relaying blocks.<br>
Many of them have a two-fold goal of reducing block relay time and thus<br>
rely on the use of significant processing power in order to avoid<br>
introducing additional worst-case RTTs. Because this work is not focused<br=
>
primarily on reducing block relay time, its design is much simpler (ie<br>
does not rely on set reconciliation protocols). Still, in testing at the<br=
>
time of writing, nodes are able to relay blocks without the extra<br>
getblocktxn/blocktxn RTT around 90% of the time. With a smart<br>
compact-block-announcement policy, it is thus expected that this work<br>
might allow blocks to be relayed between nodes in 0.5*RTT instead of<br>
1.5*RTT at least 75% of the time.<br>
<br>
=3D=3D=3D=3DUse of New VarInts=3D=3D=3D=3D<br>
Bitcoin has long had a variable-length integer implementation (referred<br>
to as CompactSize in this document), making a second a strange protocol<br>
quirk. However, in this protocol most of our variable-length integers<br>
are between 0 and 2000. For both encodings, small numbers (&lt;100) are<br>
encoded as 1-byte. For numbers over 250, the CompactSize encoding begins<br=
>
to use 3 bytes instead of 1, whereas the New VarInt encoding uses 2.<br>
Because the primary motivation for this work is to save bytes during<br>
block relay, the extra byte of saving per transaction-difference is<br>
considered worth the extra design complexity.<br>
<br>
=3D=3D=3D=3DShort transaction ID calculation=3D=3D=3D=3D<br>
The short transaction ID calculation is designed to take absolutely<br>
minimal processing time during block compaction to avoid introducing<br>
serious DoS vulnerabilities such as those introduced by the<br>
bloom-filtering in BIP 37. As such, it is possible for a node to<br>
construct one compact-block representation of a block for relay to<br>
multiple peers. Additionally, only one cryptographic hash (2 SHA rounds)<br=
>
is used when calculating the short transaction IDs for an entire block.<br>
<br>
The XOR-and-add method is used for calculating short transaction IDs<br>
primarily because it is fast and is reasonably able to limit the ability<br=
>
of an attacker who does not know the block hash or nonce to cause<br>
collisions in short transaction IDs. If an attacker were able to cause<br>
such collisions, filling mempools (and, thus, blocks) with them would<br>
cause poor network propagation of new (or non-attacker, in the case of a<br=
>
miner) blocks.<br>
<br>
The 8-byte nonce in short transaction ID calculation is used to<br>
introduce additional entropy on a per-node level. While the use of 8<br>
bytes is sufficient for an attacker to maliciously cause short<br>
transaction ID collisions in their own block relay, this would have less<br=
>
of an effect than if such an attacker were relaying headers/invs and not<br=
>
responding to requests for the full block.<br>
<br>
=3D=3DBackward compatibility=3D=3D<br>
<br>
Older clients remain fully compatible and interoperable after this change.<=
br>
<br>
=3D=3DImplementation=3D=3D<br>
<br>
<a href=3D"https://github.com/TheBlueMatt/bitcoin/tree/udp" rel=3D"noreferr=
er" target=3D"_blank">https://github.com/TheBlueMatt/bitcoin/tree/udp</a><b=
r>
<br>
=3D=3DAcknowledgements=3D=3D<br>
<br>
Thanks to Gregory Maxwell for the initial suggestion as well as a lot of<br=
>
back-and-forth design and significant testing.<br>
<br>
=3D=3DCopyright=3D=3D<br>
<br>
This document is placed in the public domain.<br>
<br>
_______________________________________________<br>
bitcoin-dev mailing list<br>
<a href=3D"mailto:bitcoin-dev@lists.linuxfoundation.org">bitcoin-dev@lists.=
linuxfoundation.org</a><br>
<a href=3D"https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev" =
rel=3D"noreferrer" target=3D"_blank">https://lists.linuxfoundation.org/mail=
man/listinfo/bitcoin-dev</a><br>
</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div class=
=3D"gmail_signature"><div dir=3D"ltr"><div><div dir=3D"ltr"><div dir=3D"ltr=
"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div>Johnathan Corgan<=
br>Corgan Labs - SDR Training and Development Services</div><div><a href=3D=
"http://corganlabs.com" style=3D"font-size:12.8px" target=3D"_blank">http:/=
/corganlabs.com</a><br></div></div></div></div></div></div></div></div></di=
v>
</div></div>

--001a113fb2ec41dfe9053249f1aa--