@lodestar/reqresp 1.41.0-dev.ef310100c0 → 1.41.0-dev.f2caa915ab

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +1 -1
  2. package/lib/ReqResp.d.ts +3 -3
  3. package/lib/ReqResp.js +4 -4
  4. package/lib/ReqResp.js.map +1 -1
  5. package/lib/encoders/requestDecode.d.ts +2 -3
  6. package/lib/encoders/requestDecode.d.ts.map +1 -1
  7. package/lib/encoders/requestDecode.js +28 -11
  8. package/lib/encoders/requestDecode.js.map +1 -1
  9. package/lib/encoders/requestEncode.d.ts +1 -1
  10. package/lib/encoders/requestEncode.d.ts.map +1 -1
  11. package/lib/encoders/requestEncode.js +1 -1
  12. package/lib/encoders/requestEncode.js.map +1 -1
  13. package/lib/encoders/responseDecode.d.ts +10 -10
  14. package/lib/encoders/responseDecode.d.ts.map +1 -1
  15. package/lib/encoders/responseDecode.js +63 -60
  16. package/lib/encoders/responseDecode.js.map +1 -1
  17. package/lib/encoders/responseEncode.d.ts +2 -4
  18. package/lib/encoders/responseEncode.d.ts.map +1 -1
  19. package/lib/encoders/responseEncode.js +13 -22
  20. package/lib/encoders/responseEncode.js.map +1 -1
  21. package/lib/encodingStrategies/index.d.ts +4 -3
  22. package/lib/encodingStrategies/index.d.ts.map +1 -1
  23. package/lib/encodingStrategies/index.js +4 -4
  24. package/lib/encodingStrategies/index.js.map +1 -1
  25. package/lib/encodingStrategies/sszSnappy/decode.d.ts +5 -4
  26. package/lib/encodingStrategies/sszSnappy/decode.d.ts.map +1 -1
  27. package/lib/encodingStrategies/sszSnappy/decode.js +83 -52
  28. package/lib/encodingStrategies/sszSnappy/decode.js.map +1 -1
  29. package/lib/encodingStrategies/sszSnappy/encode.d.ts +2 -2
  30. package/lib/encodingStrategies/sszSnappy/encode.d.ts.map +1 -1
  31. package/lib/encodingStrategies/sszSnappy/encode.js +1 -1
  32. package/lib/encodingStrategies/sszSnappy/encode.js.map +1 -1
  33. package/lib/encodingStrategies/sszSnappy/errors.d.ts +0 -8
  34. package/lib/encodingStrategies/sszSnappy/errors.d.ts.map +1 -1
  35. package/lib/encodingStrategies/sszSnappy/errors.js +0 -2
  36. package/lib/encodingStrategies/sszSnappy/errors.js.map +1 -1
  37. package/lib/encodingStrategies/sszSnappy/index.d.ts +0 -1
  38. package/lib/encodingStrategies/sszSnappy/index.d.ts.map +1 -1
  39. package/lib/encodingStrategies/sszSnappy/index.js +0 -1
  40. package/lib/encodingStrategies/sszSnappy/index.js.map +1 -1
  41. package/lib/metrics.d.ts +1 -7
  42. package/lib/metrics.d.ts.map +1 -1
  43. package/lib/metrics.js +1 -17
  44. package/lib/metrics.js.map +1 -1
  45. package/lib/request/errors.d.ts +1 -7
  46. package/lib/request/errors.d.ts.map +1 -1
  47. package/lib/request/errors.js +1 -5
  48. package/lib/request/errors.js.map +1 -1
  49. package/lib/request/index.d.ts +0 -3
  50. package/lib/request/index.d.ts.map +1 -1
  51. package/lib/request/index.js +58 -70
  52. package/lib/request/index.js.map +1 -1
  53. package/lib/response/index.d.ts +1 -1
  54. package/lib/response/index.d.ts.map +1 -1
  55. package/lib/response/index.js +46 -50
  56. package/lib/response/index.js.map +1 -1
  57. package/lib/types.d.ts +1 -2
  58. package/lib/types.d.ts.map +1 -1
  59. package/lib/types.js +1 -2
  60. package/lib/types.js.map +1 -1
  61. package/lib/utils/collectMaxResponse.d.ts.map +1 -1
  62. package/lib/utils/collectMaxResponse.js +1 -2
  63. package/lib/utils/collectMaxResponse.js.map +1 -1
  64. package/lib/utils/errorMessage.d.ts +3 -3
  65. package/lib/utils/errorMessage.d.ts.map +1 -1
  66. package/lib/utils/errorMessage.js +14 -13
  67. package/lib/utils/errorMessage.js.map +1 -1
  68. package/lib/utils/index.d.ts +1 -3
  69. package/lib/utils/index.d.ts.map +1 -1
  70. package/lib/utils/index.js +1 -3
  71. package/lib/utils/index.js.map +1 -1
  72. package/lib/utils/protocolId.d.ts +2 -2
  73. package/lib/utils/protocolId.js +2 -2
  74. package/lib/utils/snappyCompress.d.ts +1 -1
  75. package/lib/utils/snappyCompress.d.ts.map +1 -1
  76. package/lib/utils/snappyCompress.js +1 -1
  77. package/lib/utils/snappyCompress.js.map +1 -1
  78. package/lib/utils/snappyIndex.d.ts +1 -1
  79. package/lib/utils/snappyIndex.d.ts.map +1 -1
  80. package/lib/utils/snappyIndex.js +1 -1
  81. package/lib/utils/snappyIndex.js.map +1 -1
  82. package/lib/utils/snappyUncompress.d.ts +7 -11
  83. package/lib/utils/snappyUncompress.d.ts.map +1 -1
  84. package/lib/utils/snappyUncompress.js +68 -68
  85. package/lib/utils/snappyUncompress.js.map +1 -1
  86. package/lib/utils/stream.d.ts +6 -0
  87. package/lib/utils/stream.d.ts.map +1 -0
  88. package/lib/utils/stream.js +21 -0
  89. package/lib/utils/stream.js.map +1 -0
  90. package/package.json +14 -16
  91. package/src/ReqResp.ts +4 -4
  92. package/src/encoders/requestDecode.ts +32 -16
  93. package/src/encoders/requestEncode.ts +1 -1
  94. package/src/encoders/responseDecode.ts +68 -72
  95. package/src/encoders/responseEncode.ts +17 -29
  96. package/src/encodingStrategies/index.ts +8 -6
  97. package/src/encodingStrategies/sszSnappy/decode.ts +111 -53
  98. package/src/encodingStrategies/sszSnappy/encode.ts +2 -2
  99. package/src/encodingStrategies/sszSnappy/errors.ts +0 -4
  100. package/src/encodingStrategies/sszSnappy/index.ts +0 -1
  101. package/src/metrics.ts +1 -17
  102. package/src/request/errors.ts +1 -6
  103. package/src/request/index.ts +74 -86
  104. package/src/response/index.ts +55 -61
  105. package/src/types.ts +1 -3
  106. package/src/utils/collectMaxResponse.ts +1 -2
  107. package/src/utils/errorMessage.ts +14 -13
  108. package/src/utils/index.ts +1 -3
  109. package/src/utils/protocolId.ts +2 -2
  110. package/src/utils/snappyCompress.ts +1 -1
  111. package/src/utils/snappyIndex.ts +1 -1
  112. package/src/utils/snappyUncompress.ts +73 -75
  113. package/src/utils/stream.ts +34 -0
  114. package/lib/utils/abortableSource.d.ts +0 -12
  115. package/lib/utils/abortableSource.d.ts.map +0 -1
  116. package/lib/utils/abortableSource.js +0 -69
  117. package/lib/utils/abortableSource.js.map +0 -1
  118. package/lib/utils/bufferedSource.d.ts +0 -16
  119. package/lib/utils/bufferedSource.d.ts.map +0 -1
  120. package/lib/utils/bufferedSource.js +0 -40
  121. package/lib/utils/bufferedSource.js.map +0 -1
  122. package/lib/utils/onChunk.d.ts +0 -6
  123. package/lib/utils/onChunk.d.ts.map +0 -1
  124. package/lib/utils/onChunk.js +0 -13
  125. package/lib/utils/onChunk.js.map +0 -1
  126. package/lib/utils/snappy.d.ts +0 -3
  127. package/lib/utils/snappy.d.ts.map +0 -1
  128. package/lib/utils/snappy.js +0 -3
  129. package/lib/utils/snappy.js.map +0 -1
  130. package/src/utils/abortableSource.ts +0 -80
  131. package/src/utils/bufferedSource.ts +0 -46
  132. package/src/utils/onChunk.ts +0 -12
  133. package/src/utils/snappy.ts +0 -2
@@ -1,10 +1,10 @@
1
1
  import { Encoding, ProtocolAttributes } from "../types.js";
2
2
  /**
3
- * https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#protocol-identification
3
+ * https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#protocol-identification
4
4
  */
5
5
  export declare function formatProtocolID(protocolPrefix: string, method: string, version: number, encoding: Encoding): string;
6
6
  /**
7
- * https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#protocol-identification
7
+ * https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#protocol-identification
8
8
  */
9
9
  export declare function parseProtocolID(protocolId: string): ProtocolAttributes;
10
10
  //# sourceMappingURL=protocolId.d.ts.map
@@ -1,12 +1,12 @@
1
1
  import { Encoding } from "../types.js";
2
2
  /**
3
- * https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#protocol-identification
3
+ * https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#protocol-identification
4
4
  */
5
5
  export function formatProtocolID(protocolPrefix, method, version, encoding) {
6
6
  return `${protocolPrefix}/${method}/${version}/${encoding}`;
7
7
  }
8
8
  /**
9
- * https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#protocol-identification
9
+ * https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#protocol-identification
10
10
  */
11
11
  export function parseProtocolID(protocolId) {
12
12
  const result = protocolId.split("/");
@@ -1,2 +1,2 @@
1
- export declare function encodeSnappy(bytes: Buffer): AsyncGenerator<Buffer>;
1
+ export declare function encodeSnappy(bytes: Buffer): Generator<Buffer>;
2
2
  //# sourceMappingURL=snappyCompress.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"snappyCompress.d.ts","sourceRoot":"","sources":["../../src/utils/snappyCompress.ts"],"names":[],"mappings":"AAKA,wBAAuB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,CAmBzE"}
1
+ {"version":3,"file":"snappyCompress.d.ts","sourceRoot":"","sources":["../../src/utils/snappyCompress.ts"],"names":[],"mappings":"AAKA,wBAAiB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAmB9D"}
@@ -2,7 +2,7 @@
2
2
  import { compressSync } from "snappy";
3
3
  import { ChunkType, IDENTIFIER_FRAME, UNCOMPRESSED_CHUNK_SIZE, crc } from "./snappyCommon.js";
4
4
  // The logic in this file is largely copied (in simplified form) from https://github.com/ChainSafe/node-snappy-stream/
5
- export async function* encodeSnappy(bytes) {
5
+ export function* encodeSnappy(bytes) {
6
6
  yield IDENTIFIER_FRAME;
7
7
  for (let i = 0; i < bytes.length; i += UNCOMPRESSED_CHUNK_SIZE) {
8
8
  const chunk = bytes.subarray(i, i + UNCOMPRESSED_CHUNK_SIZE);
@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AI,CAAC,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;gBAClE,GAAG,CAAC,KAAK,CAAC;gBACV,KAAK;aACN,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -1,4 +1,4 @@
1
1
  export * from "./snappyCommon.js";
2
2
  export { encodeSnappy } from "./snappyCompress.js";
3
- export { SnappyFramesUncompress } from "./snappyUncompress.js";
3
+ export * from "./snappyUncompress.js";
4
4
  //# sourceMappingURL=snappyIndex.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"snappyIndex.d.ts","sourceRoot":"","sources":["../../src/utils/snappyIndex.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAC,sBAAsB,EAAC,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"snappyIndex.d.ts","sourceRoot":"","sources":["../../src/utils/snappyIndex.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,cAAc,uBAAuB,CAAC"}
@@ -1,4 +1,4 @@
1
1
  export * from "./snappyCommon.js";
2
2
  export { encodeSnappy } from "./snappyCompress.js";
3
- export { SnappyFramesUncompress } from "./snappyUncompress.js";
3
+ export * from "./snappyUncompress.js";
4
4
  //# sourceMappingURL=snappyIndex.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"snappyIndex.js","sourceRoot":"","sources":["../../src/utils/snappyIndex.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAC,sBAAsB,EAAC,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"snappyIndex.js","sourceRoot":"","sources":["../../src/utils/snappyIndex.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,cAAc,uBAAuB,CAAC"}
@@ -1,13 +1,9 @@
1
1
  import { Uint8ArrayList } from "uint8arraylist";
2
- export declare class SnappyFramesUncompress {
3
- private buffer;
4
- private state;
5
- /**
6
- * Accepts chunk of data containing some part of snappy frames stream
7
- * @param chunk
8
- * @return Buffer if there is one or more whole frames, null if it's partial
9
- */
10
- uncompress(chunk: Uint8ArrayList): Uint8ArrayList | null;
11
- reset(): void;
12
- }
2
+ import { ChunkType } from "./snappyCommon.js";
3
+ export declare function parseSnappyFrameHeader(header: Uint8Array): {
4
+ type: ChunkType;
5
+ frameSize: number;
6
+ };
7
+ export declare function decodeSnappyFrameData(type: ChunkType, frame: Uint8Array): Uint8Array | null;
8
+ export declare function decodeSnappyFrames(data: Uint8Array): Uint8ArrayList;
13
9
  //# sourceMappingURL=snappyUncompress.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"snappyUncompress.d.ts","sourceRoot":"","sources":["../../src/utils/snappyUncompress.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAG9C,qBAAa,sBAAsB;IACjC,OAAO,CAAC,MAAM,CAAwB;IAEtC,OAAO,CAAC,KAAK,CAEX;IAEF;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,cAAc,GAAG,cAAc,GAAG,IAAI;IAgExD,KAAK,IAAI,IAAI;CAMd"}
1
+ {"version":3,"file":"snappyUncompress.d.ts","sourceRoot":"","sources":["../../src/utils/snappyUncompress.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAC,SAAS,EAA2C,MAAM,mBAAmB,CAAC;AAEtF,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU,GAAG;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAC,CAQ/F;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI,CAwC3F;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,CAoCnE"}
@@ -1,81 +1,81 @@
1
1
  import { uncompress } from "snappyjs";
2
2
  import { Uint8ArrayList } from "uint8arraylist";
3
3
  import { ChunkType, IDENTIFIER, UNCOMPRESSED_CHUNK_SIZE, crc } from "./snappyCommon.js";
4
- export class SnappyFramesUncompress {
5
- buffer = new Uint8ArrayList();
6
- state = {
7
- foundIdentifier: false,
8
- };
9
- /**
10
- * Accepts chunk of data containing some part of snappy frames stream
11
- * @param chunk
12
- * @return Buffer if there is one or more whole frames, null if it's partial
13
- */
14
- uncompress(chunk) {
15
- this.buffer.append(chunk);
16
- const result = new Uint8ArrayList();
17
- while (this.buffer.length > 0) {
18
- if (this.buffer.length < 4)
19
- break;
20
- const type = getChunkType(this.buffer.get(0));
21
- if (!this.state.foundIdentifier && type !== ChunkType.IDENTIFIER) {
22
- throw "malformed input: must begin with an identifier";
4
+ export function parseSnappyFrameHeader(header) {
5
+ if (header.length !== 4) {
6
+ throw new Error("malformed input: incomplete frame header");
7
+ }
8
+ const type = getChunkType(header[0]);
9
+ const frameSize = header[1] + (header[2] << 8) + (header[3] << 16);
10
+ return { type, frameSize };
11
+ }
12
+ export function decodeSnappyFrameData(type, frame) {
13
+ switch (type) {
14
+ case ChunkType.IDENTIFIER: {
15
+ if (!Buffer.prototype.equals.call(frame, IDENTIFIER)) {
16
+ throw new Error("malformed input: bad identifier");
23
17
  }
24
- const frameSize = getFrameSize(this.buffer, 1);
25
- if (this.buffer.length - 4 < frameSize) {
26
- break;
18
+ return null;
19
+ }
20
+ case ChunkType.PADDING:
21
+ case ChunkType.SKIPPABLE:
22
+ return null;
23
+ case ChunkType.COMPRESSED: {
24
+ if (frame.length < 4) {
25
+ throw new Error("malformed input: too short");
27
26
  }
28
- const frame = this.buffer.subarray(4, 4 + frameSize);
29
- this.buffer.consume(4 + frameSize);
30
- switch (type) {
31
- case ChunkType.IDENTIFIER: {
32
- if (!Buffer.prototype.equals.call(frame, IDENTIFIER)) {
33
- throw "malformed input: bad identifier";
34
- }
35
- this.state.foundIdentifier = true;
36
- continue;
37
- }
38
- case ChunkType.PADDING:
39
- case ChunkType.SKIPPABLE:
40
- continue;
41
- case ChunkType.COMPRESSED: {
42
- const checksum = frame.subarray(0, 4);
43
- const data = frame.subarray(4);
44
- const uncompressed = uncompress(data, UNCOMPRESSED_CHUNK_SIZE);
45
- if (crc(uncompressed).compare(checksum) !== 0) {
46
- throw "malformed input: bad checksum";
47
- }
48
- result.append(uncompressed);
49
- break;
50
- }
51
- case ChunkType.UNCOMPRESSED: {
52
- const checksum = frame.subarray(0, 4);
53
- const uncompressed = frame.subarray(4);
54
- if (uncompressed.length > UNCOMPRESSED_CHUNK_SIZE) {
55
- throw "malformed input: too large";
56
- }
57
- if (crc(uncompressed).compare(checksum) !== 0) {
58
- throw "malformed input: bad checksum";
59
- }
60
- result.append(uncompressed);
61
- break;
62
- }
27
+ const checksum = frame.subarray(0, 4);
28
+ const data = frame.subarray(4);
29
+ const uncompressed = uncompress(data, UNCOMPRESSED_CHUNK_SIZE);
30
+ if (crc(uncompressed).compare(checksum) !== 0) {
31
+ throw new Error("malformed input: bad checksum");
63
32
  }
33
+ return uncompressed;
64
34
  }
65
- if (result.length === 0) {
66
- return null;
35
+ case ChunkType.UNCOMPRESSED: {
36
+ if (frame.length < 4) {
37
+ throw new Error("malformed input: too short");
38
+ }
39
+ const checksum = frame.subarray(0, 4);
40
+ const uncompressed = frame.subarray(4);
41
+ if (uncompressed.length > UNCOMPRESSED_CHUNK_SIZE) {
42
+ throw new Error("malformed input: too large");
43
+ }
44
+ if (crc(uncompressed).compare(checksum) !== 0) {
45
+ throw new Error("malformed input: bad checksum");
46
+ }
47
+ return uncompressed;
67
48
  }
68
- return result;
69
- }
70
- reset() {
71
- this.buffer = new Uint8ArrayList();
72
- this.state = {
73
- foundIdentifier: false,
74
- };
75
49
  }
76
50
  }
77
- function getFrameSize(buffer, offset) {
78
- return buffer.get(offset) + (buffer.get(offset + 1) << 8) + (buffer.get(offset + 2) << 16);
51
+ export function decodeSnappyFrames(data) {
52
+ const out = new Uint8ArrayList();
53
+ let foundIdentifier = false;
54
+ let offset = 0;
55
+ while (offset < data.length) {
56
+ const remaining = data.length - offset;
57
+ if (remaining < 4) {
58
+ throw new Error("malformed input: incomplete frame header");
59
+ }
60
+ const { type, frameSize } = parseSnappyFrameHeader(data.subarray(offset, offset + 4));
61
+ if (!foundIdentifier && type !== ChunkType.IDENTIFIER) {
62
+ throw new Error("malformed input: must begin with an identifier");
63
+ }
64
+ offset += 4;
65
+ if (data.length - offset < frameSize) {
66
+ throw new Error("malformed input: incomplete frame");
67
+ }
68
+ const frame = data.subarray(offset, offset + frameSize);
69
+ offset += frameSize;
70
+ if (type === ChunkType.IDENTIFIER) {
71
+ foundIdentifier = true;
72
+ }
73
+ const uncompressed = decodeSnappyFrameData(type, frame);
74
+ if (uncompressed !== null) {
75
+ out.append(uncompressed);
76
+ }
77
+ }
78
+ return out;
79
79
  }
80
80
  function getChunkType(value) {
81
81
  switch (value) {
@@ -1 +1 @@
1
- {"version":3,"file":"snappyUncompress.js","sourceRoot":"","sources":["../../src/utils/snappyUncompress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACpC,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,uBAAuB,EAAE,GAAG,EAAC,MAAM,mBAAmB,CAAC;AAEtF,MAAM,OAAO,sBAAsB;IACzB,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;IAE9B,KAAK,GAAoB;QAC/B,eAAe,EAAE,KAAK;KACvB,CAAC;IAEF;;;;OAIG;IACH,UAAU,CAAC,KAAqB;QAC9B,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AAC,+BAA+B,CAAC,CAAC;IACrD,CAAC;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { Stream } from "@libp2p/interface";
2
+ import { ByteStream } from "@libp2p/utils";
3
+ import { Uint8ArrayList } from "uint8arraylist";
4
+ export declare function sendChunks(stream: Stream, source: Iterable<Uint8Array | Uint8ArrayList> | AsyncIterable<Uint8Array | Uint8ArrayList>, signal?: AbortSignal): Promise<void>;
5
+ export declare function drainByteStream(bytes: ByteStream<Stream>): Uint8Array | undefined;
6
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAG9C,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,QAAQ,CAAC,UAAU,GAAG,cAAc,CAAC,GAAG,aAAa,CAAC,UAAU,GAAG,cAAc,CAAC,EAC1F,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU,GAAG,SAAS,CAYjF"}
@@ -0,0 +1,21 @@
1
+ import { ErrorAborted } from "@lodestar/utils";
2
+ export async function sendChunks(stream, source, signal) {
3
+ for await (const chunk of source) {
4
+ if (signal?.aborted) {
5
+ throw new ErrorAborted("sendChunks");
6
+ }
7
+ if (!stream.send(chunk)) {
8
+ await stream.onDrain({ signal });
9
+ }
10
+ }
11
+ }
12
+ export function drainByteStream(bytes) {
13
+ const readBuffer = bytes.readBuffer;
14
+ if (readBuffer && readBuffer.byteLength > 0) {
15
+ const drained = readBuffer.subarray();
16
+ readBuffer.consume(readBuffer.byteLength);
17
+ return drained;
18
+ }
19
+ return undefined;
20
+ }
21
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAE7C,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAAc,EACd,MAA0F,EAC1F,MAAoB;IAEpB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACjC,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,YAAY,CAAC,YAAY,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,MAAM,CAAC,OAAO,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAyB;IACvD,MAAM,UAAU,GACd,KAGD,CAAC,UAAU,CAAC;IACb,IAAI,UAAU,IAAI,UAAU,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;QAC5C,MAAM,OAAO,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;QACtC,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC1C,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ChainSafe/lodestar/issues"
13
13
  },
14
- "version": "1.41.0-dev.ef310100c0",
14
+ "version": "1.41.0-dev.f2caa915ab",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -45,12 +45,11 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@chainsafe/fast-crc32c": "^4.2.0",
48
- "@libp2p/interface": "^2.7.0",
49
- "@lodestar/config": "^1.41.0-dev.ef310100c0",
50
- "@lodestar/params": "^1.41.0-dev.ef310100c0",
51
- "@lodestar/utils": "^1.41.0-dev.ef310100c0",
52
- "it-all": "^3.0.4",
53
- "it-pipe": "^3.0.1",
48
+ "@libp2p/interface": "^3.1.0",
49
+ "@libp2p/utils": "^7.0.11",
50
+ "@lodestar/config": "^1.41.0-dev.f2caa915ab",
51
+ "@lodestar/params": "^1.41.0-dev.f2caa915ab",
52
+ "@lodestar/utils": "^1.41.0-dev.f2caa915ab",
54
53
  "snappy": "^7.2.2",
55
54
  "snappyjs": "^0.7.0",
56
55
  "uint8-varint": "^2.0.2",
@@ -58,16 +57,15 @@
58
57
  },
59
58
  "devDependencies": {
60
59
  "@chainsafe/ssz": "^1.2.2",
61
- "@libp2p/crypto": "^5.1.7",
62
- "@libp2p/logger": "^5.1.21",
63
- "@libp2p/peer-id": "^5.1.8",
64
- "@lodestar/logger": "^1.41.0-dev.ef310100c0",
65
- "@lodestar/types": "^1.41.0-dev.ef310100c0",
66
- "it-stream-types": "^2.0.2",
67
- "libp2p": "2.9.0"
60
+ "@libp2p/crypto": "^5.1.13",
61
+ "@libp2p/logger": "^6.2.2",
62
+ "@libp2p/peer-id": "^6.0.4",
63
+ "@lodestar/logger": "^1.41.0-dev.f2caa915ab",
64
+ "@lodestar/types": "^1.41.0-dev.f2caa915ab",
65
+ "libp2p": "3.1.3"
68
66
  },
69
67
  "peerDependencies": {
70
- "libp2p": "~2.9.0"
68
+ "libp2p": "^3.1.3"
71
69
  },
72
70
  "keywords": [
73
71
  "ethereum",
@@ -77,5 +75,5 @@
77
75
  "reqresp",
78
76
  "blockchain"
79
77
  ],
80
- "gitHead": "8ad55796d153df8c5a2de477cd5b990590851a20"
78
+ "gitHead": "68d33fac21da9c1aa57fe7c24f9721b14ed96761"
81
79
  }
package/src/ReqResp.ts CHANGED
@@ -37,8 +37,8 @@ export interface ReqRespOpts extends SendRequestOpts, ReqRespRateLimiterOpts {
37
37
  /**
38
38
  * Implementation of Ethereum Consensus p2p Req/Resp domain.
39
39
  * For the spec that this code is based on, see:
40
- * https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#the-reqresp-domain
41
- * https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/p2p-interface.md#the-reqresp-domain
40
+ * https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#the-reqresp-domain
41
+ * https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/altair/light-client/p2p-interface.md#the-reqresp-domain
42
42
  */
43
43
  export class ReqResp {
44
44
  // protected to be usable by extending class
@@ -221,7 +221,7 @@ export class ReqResp {
221
221
  }
222
222
 
223
223
  private getRequestHandler(protocol: MixedProtocol, protocolID: string) {
224
- return async ({connection, stream}: {connection: Connection; stream: Stream}) => {
224
+ return async (stream: Stream, connection: Connection) => {
225
225
  if (this.dialOnlyProtocols.get(protocolID)) {
226
226
  throw new Error(`Received request on dial only protocol '${protocolID}'`);
227
227
  }
@@ -281,7 +281,7 @@ export class ReqResp {
281
281
  * ```
282
282
  * /ProtocolPrefix/MessageName/SchemaVersion/Encoding
283
283
  * ```
284
- * https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#protocol-identification
284
+ * https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#protocol-identification
285
285
  */
286
286
  protected formatProtocolID(protocol: Pick<MixedProtocol, "method" | "version" | "encoding">): string {
287
287
  return formatProtocolID(this.protocolPrefix, protocol.method, protocol.version, protocol.encoding);
@@ -1,8 +1,8 @@
1
- import type {Sink} from "it-stream-types";
2
- import {Uint8ArrayList} from "uint8arraylist";
1
+ import type {Stream} from "@libp2p/interface";
2
+ import {byteStream} from "@libp2p/utils";
3
3
  import {readEncodedPayload} from "../encodingStrategies/index.js";
4
4
  import {MixedProtocol} from "../types.js";
5
- import {BufferedSource} from "../utils/index.js";
5
+ import {drainByteStream} from "../utils/stream.ts";
6
6
 
7
7
  const EMPTY_DATA = new Uint8Array();
8
8
 
@@ -12,18 +12,34 @@ const EMPTY_DATA = new Uint8Array();
12
12
  * request ::= <encoding-dependent-header> | <encoded-payload>
13
13
  * ```
14
14
  */
15
- export function requestDecode(
16
- protocol: MixedProtocol
17
- ): Sink<AsyncIterable<Uint8Array | Uint8ArrayList>, Promise<Uint8Array>> {
18
- return async function requestDecodeSink(source) {
19
- const type = protocol.requestSizes;
20
- if (type === null) {
21
- // method has no body
22
- return EMPTY_DATA;
23
- }
15
+ export async function requestDecode(
16
+ protocol: MixedProtocol,
17
+ stream: Stream,
18
+ signal?: AbortSignal
19
+ ): Promise<Uint8Array> {
20
+ const type = protocol.requestSizes;
21
+ if (type === null) {
22
+ // method has no body
23
+ return EMPTY_DATA;
24
+ }
24
25
 
25
- // Request has a single payload, so return immediately
26
- const bufferedSource = new BufferedSource(source as AsyncGenerator<Uint8ArrayList>);
27
- return readEncodedPayload(bufferedSource, protocol.encoding, type);
28
- };
26
+ // Request has a single payload, so return immediately
27
+ const bytes = byteStream(stream);
28
+ let requestReadDone = false;
29
+ try {
30
+ const requestBody = await readEncodedPayload(bytes, protocol.encoding, type, signal);
31
+ requestReadDone = true;
32
+ return requestBody;
33
+ } finally {
34
+ try {
35
+ if (!requestReadDone) {
36
+ // Do not push partial bytes back into the stream on decode failure/abort.
37
+ // This stream is consumed by req/resp only once.
38
+ drainByteStream(bytes);
39
+ }
40
+ bytes.unwrap();
41
+ } catch {
42
+ // Ignore unwrap errors - stream may already be closed
43
+ }
44
+ }
29
45
  }
@@ -9,7 +9,7 @@ import {MixedProtocol} from "../types.js";
9
9
  * Requests may contain no payload (e.g. /eth2/beacon_chain/req/metadata/1/)
10
10
  * if so, it would yield no byte chunks
11
11
  */
12
- export async function* requestEncode(protocol: MixedProtocol, requestBody: Uint8Array): AsyncGenerator<Buffer> {
12
+ export function* requestEncode(protocol: MixedProtocol, requestBody: Uint8Array): Generator<Buffer> {
13
13
  const type = protocol.requestSizes;
14
14
 
15
15
  if (type && requestBody !== null) {