@lodestar/beacon-node 1.52.0-dev.025dabac49 → 1.52.0-dev.18d4ea7338

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 (32) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +45 -34
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/validator/index.d.ts.map +1 -1
  5. package/lib/api/impl/validator/index.js +4 -3
  6. package/lib/api/impl/validator/index.js.map +1 -1
  7. package/lib/chain/chain.d.ts.map +1 -1
  8. package/lib/chain/chain.js +12 -6
  9. package/lib/chain/chain.js.map +1 -1
  10. package/lib/network/network.d.ts +1 -0
  11. package/lib/network/network.d.ts.map +1 -1
  12. package/lib/network/network.js +20 -11
  13. package/lib/network/network.js.map +1 -1
  14. package/lib/network/processor/gossipValidatorFn.d.ts.map +1 -1
  15. package/lib/network/processor/gossipValidatorFn.js +4 -1
  16. package/lib/network/processor/gossipValidatorFn.js.map +1 -1
  17. package/lib/network/reqresp/utils/collect.d.ts +4 -4
  18. package/lib/network/reqresp/utils/collect.d.ts.map +1 -1
  19. package/lib/network/reqresp/utils/collect.js +9 -8
  20. package/lib/network/reqresp/utils/collect.js.map +1 -1
  21. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts +1 -1
  22. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts.map +1 -1
  23. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js +2 -2
  24. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js.map +1 -1
  25. package/package.json +16 -16
  26. package/src/api/impl/beacon/blocks/index.ts +54 -42
  27. package/src/api/impl/validator/index.ts +4 -2
  28. package/src/chain/chain.ts +12 -6
  29. package/src/network/network.ts +33 -11
  30. package/src/network/processor/gossipValidatorFn.ts +4 -0
  31. package/src/network/reqresp/utils/collect.ts +16 -8
  32. package/src/network/reqresp/utils/collectSequentialBlocksInRange.ts +3 -2
@@ -12,11 +12,12 @@ import {ResponseTypeGetter} from "../types.js";
12
12
  */
13
13
  export async function collectExactOneTyped<T>(
14
14
  source: AsyncIterable<ResponseIncoming>,
15
- typeFn: ResponseTypeGetter<T>
15
+ typeFn: ResponseTypeGetter<T>,
16
+ onInvalidResponse?: (chunk: ResponseIncoming) => void
16
17
  ): Promise<T> {
17
18
  for await (const chunk of source) {
18
19
  const type = typeFn(chunk.fork, chunk.protocolVersion);
19
- const response = sszDeserializeResponse(type, chunk.data);
20
+ const response = sszDeserializeResponse(type, chunk, onInvalidResponse);
20
21
  return response;
21
22
  }
22
23
  throw new RequestError({code: RequestErrorCode.EMPTY_RESPONSE});
@@ -33,13 +34,14 @@ export async function collectMaxResponseTyped<T>(
33
34
  source: AsyncIterable<ResponseIncoming>,
34
35
  maxResponses: number,
35
36
  typeFn: ResponseTypeGetter<T>,
36
- serializedCache?: SerializedCache
37
+ serializedCache?: SerializedCache,
38
+ onInvalidResponse?: (chunk: ResponseIncoming) => void
37
39
  ): Promise<T[]> {
38
40
  // else: zero or more responses
39
41
  const responses: T[] = [];
40
42
  for await (const chunk of source) {
41
43
  const type = typeFn(chunk.fork, chunk.protocolVersion);
42
- const response = sszDeserializeResponse(type, chunk.data);
44
+ const response = sszDeserializeResponse(type, chunk, onInvalidResponse);
43
45
  // optionally cache the serialized response if the cache is available
44
46
  serializedCache?.set(response as object, chunk.data);
45
47
  responses.push(response);
@@ -62,13 +64,14 @@ export async function collectMaxResponseTypedWithBytes<T>(
62
64
  source: AsyncIterable<ResponseIncoming>,
63
65
  maxResponses: number,
64
66
  typeFn: ResponseTypeGetter<T>,
65
- serializedCache?: SerializedCache
67
+ serializedCache?: SerializedCache,
68
+ onInvalidResponse?: (chunk: ResponseIncoming) => void
66
69
  ): Promise<T[]> {
67
70
  // else: zero or more responses
68
71
  const responses: T[] = [];
69
72
  for await (const chunk of source) {
70
73
  const type = typeFn(chunk.fork, chunk.protocolVersion);
71
- const data = sszDeserializeResponse(type, chunk.data);
74
+ const data = sszDeserializeResponse(type, chunk, onInvalidResponse);
72
75
  responses.push(data);
73
76
  // optionally cache the serialized response if the cache is available
74
77
  serializedCache?.set(data as object, chunk.data);
@@ -81,10 +84,15 @@ export async function collectMaxResponseTypedWithBytes<T>(
81
84
  }
82
85
 
83
86
  /** Light wrapper on type to wrap deserialize errors */
84
- export function sszDeserializeResponse<T>(type: Type<T>, bytes: Uint8Array): T {
87
+ export function sszDeserializeResponse<T>(
88
+ type: Type<T>,
89
+ chunk: ResponseIncoming,
90
+ onInvalidResponse?: (chunk: ResponseIncoming) => void
91
+ ): T {
85
92
  try {
86
- return type.deserialize(bytes);
93
+ return type.deserialize(chunk.data);
87
94
  } catch (e) {
95
+ onInvalidResponse?.(chunk);
88
96
  throw new RequestError({code: RequestErrorCode.INVALID_RESPONSE_SSZ, errorMessage: (e as Error).message});
89
97
  }
90
98
  }
@@ -12,13 +12,14 @@ import {sszDeserializeResponse} from "./collect.js";
12
12
  export async function collectSequentialBlocksInRange(
13
13
  blockStream: AsyncIterable<ResponseIncoming>,
14
14
  {count, startSlot}: Pick<phase0.BeaconBlocksByRangeRequest, "count" | "startSlot">,
15
- serializedCache?: SerializedCache
15
+ serializedCache?: SerializedCache,
16
+ onInvalidResponse?: (chunk: ResponseIncoming) => void
16
17
  ): Promise<SignedBeaconBlock[]> {
17
18
  const blocks: SignedBeaconBlock[] = [];
18
19
 
19
20
  for await (const chunk of blockStream) {
20
21
  const blockType = responseSszTypeByMethod[ReqRespMethod.BeaconBlocksByRange](chunk.fork, chunk.protocolVersion);
21
- const block = sszDeserializeResponse(blockType, chunk.data);
22
+ const block = sszDeserializeResponse(blockType, chunk, onInvalidResponse);
22
23
 
23
24
  const blockSlot = block.message.slot;
24
25