@lodestar/beacon-node 1.52.0-dev.b59a889970 → 1.52.0-dev.b6f233b964

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 (219) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +4 -3
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/pool/index.js +1 -1
  5. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  6. package/lib/api/impl/validator/index.d.ts.map +1 -1
  7. package/lib/api/impl/validator/index.js +74 -44
  8. package/lib/api/impl/validator/index.js.map +1 -1
  9. package/lib/chain/archiveStore/utils/archiveBlocks.js +1 -1
  10. package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
  11. package/lib/chain/chain.d.ts +1 -1
  12. package/lib/chain/chain.d.ts.map +1 -1
  13. package/lib/chain/chain.js +18 -21
  14. package/lib/chain/chain.js.map +1 -1
  15. package/lib/chain/errors/executionPayloadBid.d.ts +6 -1
  16. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
  17. package/lib/chain/errors/executionPayloadBid.js +1 -0
  18. package/lib/chain/errors/executionPayloadBid.js.map +1 -1
  19. package/lib/chain/errors/executionPayloadEnvelope.d.ts +7 -0
  20. package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
  21. package/lib/chain/errors/executionPayloadEnvelope.js +1 -0
  22. package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
  23. package/lib/chain/prepareNextSlot.d.ts +45 -0
  24. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  25. package/lib/chain/prepareNextSlot.js +265 -69
  26. package/lib/chain/prepareNextSlot.js.map +1 -1
  27. package/lib/chain/produceBlock/produceBlockBody.d.ts +6 -2
  28. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  29. package/lib/chain/produceBlock/produceBlockBody.js +54 -64
  30. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  31. package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
  32. package/lib/chain/validation/attesterSlashing.js +4 -2
  33. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  34. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  35. package/lib/chain/validation/executionPayloadBid.js +17 -2
  36. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  37. package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
  38. package/lib/chain/validation/executionPayloadEnvelope.js +21 -5
  39. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
  40. package/lib/chain/validation/proposerSlashing.js +4 -2
  41. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  42. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -2
  43. package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
  44. package/lib/chain/validation/signatureSets/contributionAndProof.js +2 -2
  45. package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
  46. package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -2
  47. package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
  48. package/lib/chain/validation/signatureSets/syncCommittee.js +2 -2
  49. package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
  50. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +2 -2
  51. package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
  52. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js +2 -2
  53. package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
  54. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -2
  55. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
  56. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +2 -2
  57. package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
  58. package/lib/chain/validation/syncCommittee.d.ts +1 -1
  59. package/lib/chain/validation/syncCommittee.d.ts.map +1 -1
  60. package/lib/chain/validation/syncCommittee.js +5 -5
  61. package/lib/chain/validation/syncCommittee.js.map +1 -1
  62. package/lib/chain/validation/syncCommitteeContributionAndProof.js +3 -3
  63. package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
  64. package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
  65. package/lib/chain/validation/voluntaryExit.js +39 -6
  66. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  67. package/lib/execution/engine/blockHash.d.ts +12 -0
  68. package/lib/execution/engine/blockHash.d.ts.map +1 -0
  69. package/lib/execution/engine/blockHash.js +17 -0
  70. package/lib/execution/engine/blockHash.js.map +1 -0
  71. package/lib/execution/engine/http.d.ts +2 -2
  72. package/lib/execution/engine/http.d.ts.map +1 -1
  73. package/lib/execution/engine/http.js +13 -7
  74. package/lib/execution/engine/http.js.map +1 -1
  75. package/lib/execution/engine/interface.d.ts +16 -3
  76. package/lib/execution/engine/interface.d.ts.map +1 -1
  77. package/lib/execution/engine/interface.js +11 -0
  78. package/lib/execution/engine/interface.js.map +1 -1
  79. package/lib/execution/engine/jsonRpcHttpClient.d.ts +2 -0
  80. package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +1 -1
  81. package/lib/execution/engine/jsonRpcHttpClient.js +14 -6
  82. package/lib/execution/engine/jsonRpcHttpClient.js.map +1 -1
  83. package/lib/execution/engine/jsonRpcTransport.d.ts +2 -2
  84. package/lib/execution/engine/jsonRpcTransport.d.ts.map +1 -1
  85. package/lib/execution/engine/jsonRpcTransport.js +4 -4
  86. package/lib/execution/engine/jsonRpcTransport.js.map +1 -1
  87. package/lib/execution/engine/mock.d.ts.map +1 -1
  88. package/lib/execution/engine/mock.js +6 -6
  89. package/lib/execution/engine/mock.js.map +1 -1
  90. package/lib/execution/engine/payloadIdCache.d.ts +6 -1
  91. package/lib/execution/engine/payloadIdCache.d.ts.map +1 -1
  92. package/lib/execution/engine/payloadIdCache.js +7 -2
  93. package/lib/execution/engine/payloadIdCache.js.map +1 -1
  94. package/lib/execution/engine/restHttpClient.d.ts.map +1 -1
  95. package/lib/execution/engine/restHttpClient.js +9 -5
  96. package/lib/execution/engine/restHttpClient.js.map +1 -1
  97. package/lib/execution/engine/restTransport.d.ts +2 -2
  98. package/lib/execution/engine/restTransport.d.ts.map +1 -1
  99. package/lib/execution/engine/restTransport.js +4 -4
  100. package/lib/execution/engine/restTransport.js.map +1 -1
  101. package/lib/execution/engine/signal.d.ts +6 -0
  102. package/lib/execution/engine/signal.d.ts.map +1 -0
  103. package/lib/execution/engine/signal.js +24 -0
  104. package/lib/execution/engine/signal.js.map +1 -0
  105. package/lib/execution/engine/transport.d.ts +2 -2
  106. package/lib/execution/engine/transport.d.ts.map +1 -1
  107. package/lib/index.d.ts +1 -1
  108. package/lib/index.d.ts.map +1 -1
  109. package/lib/index.js +1 -1
  110. package/lib/index.js.map +1 -1
  111. package/lib/metrics/metrics/beacon.d.ts +5 -0
  112. package/lib/metrics/metrics/beacon.d.ts.map +1 -1
  113. package/lib/metrics/metrics/beacon.js +5 -0
  114. package/lib/metrics/metrics/beacon.js.map +1 -1
  115. package/lib/metrics/metrics/lodestar.d.ts +1 -0
  116. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  117. package/lib/metrics/metrics/lodestar.js +5 -0
  118. package/lib/metrics/metrics/lodestar.js.map +1 -1
  119. package/lib/network/core/events.d.ts +6 -2
  120. package/lib/network/core/events.d.ts.map +1 -1
  121. package/lib/network/core/events.js +9 -0
  122. package/lib/network/core/events.js.map +1 -1
  123. package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -1
  124. package/lib/network/core/networkCoreWorkerHandler.js +3 -2
  125. package/lib/network/core/networkCoreWorkerHandler.js.map +1 -1
  126. package/lib/network/peers/peerManager.d.ts.map +1 -1
  127. package/lib/network/peers/peerManager.js +10 -1
  128. package/lib/network/peers/peerManager.js.map +1 -1
  129. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +1 -1
  130. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  131. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +1 -1
  132. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
  133. package/lib/sync/range/batch.d.ts +4 -0
  134. package/lib/sync/range/batch.d.ts.map +1 -1
  135. package/lib/sync/range/batch.js +12 -0
  136. package/lib/sync/range/batch.js.map +1 -1
  137. package/lib/sync/range/chain.d.ts +17 -2
  138. package/lib/sync/range/chain.d.ts.map +1 -1
  139. package/lib/sync/range/chain.js +52 -19
  140. package/lib/sync/range/chain.js.map +1 -1
  141. package/lib/sync/range/range.d.ts.map +1 -1
  142. package/lib/sync/range/range.js +1 -0
  143. package/lib/sync/range/range.js.map +1 -1
  144. package/lib/sync/range/utils/batches.d.ts +20 -4
  145. package/lib/sync/range/utils/batches.d.ts.map +1 -1
  146. package/lib/sync/range/utils/batches.js +31 -13
  147. package/lib/sync/range/utils/batches.js.map +1 -1
  148. package/lib/sync/range/utils/peerBalancer.d.ts +1 -1
  149. package/lib/sync/range/utils/peerBalancer.d.ts.map +1 -1
  150. package/lib/sync/range/utils/peerBalancer.js +5 -2
  151. package/lib/sync/range/utils/peerBalancer.js.map +1 -1
  152. package/lib/sync/types.d.ts +2 -0
  153. package/lib/sync/types.d.ts.map +1 -1
  154. package/lib/sync/types.js.map +1 -1
  155. package/lib/sync/unknownBlock.d.ts.map +1 -1
  156. package/lib/sync/unknownBlock.js +60 -19
  157. package/lib/sync/unknownBlock.js.map +1 -1
  158. package/lib/sync/utils/downloadByRange.d.ts +8 -0
  159. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  160. package/lib/sync/utils/downloadByRange.js +43 -23
  161. package/lib/sync/utils/downloadByRange.js.map +1 -1
  162. package/lib/util/asyncIterableToEvents.d.ts +20 -3
  163. package/lib/util/asyncIterableToEvents.d.ts.map +1 -1
  164. package/lib/util/asyncIterableToEvents.js +76 -20
  165. package/lib/util/asyncIterableToEvents.js.map +1 -1
  166. package/lib/util/dataColumns.d.ts +1 -1
  167. package/lib/util/dataColumns.d.ts.map +1 -1
  168. package/lib/util/dataColumns.js +4 -1
  169. package/lib/util/dataColumns.js.map +1 -1
  170. package/package.json +17 -17
  171. package/src/api/impl/beacon/blocks/index.ts +4 -3
  172. package/src/api/impl/beacon/pool/index.ts +1 -1
  173. package/src/api/impl/validator/index.ts +107 -61
  174. package/src/chain/archiveStore/utils/archiveBlocks.ts +1 -1
  175. package/src/chain/chain.ts +17 -41
  176. package/src/chain/errors/executionPayloadBid.ts +6 -0
  177. package/src/chain/errors/executionPayloadEnvelope.ts +8 -0
  178. package/src/chain/prepareNextSlot.ts +347 -89
  179. package/src/chain/produceBlock/produceBlockBody.ts +69 -80
  180. package/src/chain/validation/attesterSlashing.ts +4 -2
  181. package/src/chain/validation/executionPayloadBid.ts +20 -2
  182. package/src/chain/validation/executionPayloadEnvelope.ts +28 -5
  183. package/src/chain/validation/proposerSlashing.ts +4 -2
  184. package/src/chain/validation/signatureSets/contributionAndProof.ts +4 -6
  185. package/src/chain/validation/signatureSets/syncCommittee.ts +2 -3
  186. package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +2 -3
  187. package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +2 -3
  188. package/src/chain/validation/syncCommittee.ts +3 -5
  189. package/src/chain/validation/syncCommitteeContributionAndProof.ts +3 -3
  190. package/src/chain/validation/voluntaryExit.ts +44 -6
  191. package/src/execution/engine/blockHash.ts +27 -0
  192. package/src/execution/engine/http.ts +18 -10
  193. package/src/execution/engine/interface.ts +18 -3
  194. package/src/execution/engine/jsonRpcHttpClient.ts +26 -14
  195. package/src/execution/engine/jsonRpcTransport.ts +8 -4
  196. package/src/execution/engine/mock.ts +13 -8
  197. package/src/execution/engine/payloadIdCache.ts +12 -4
  198. package/src/execution/engine/restHttpClient.ts +17 -11
  199. package/src/execution/engine/restTransport.ts +5 -4
  200. package/src/execution/engine/signal.ts +28 -0
  201. package/src/execution/engine/transport.ts +3 -2
  202. package/src/index.ts +6 -1
  203. package/src/metrics/metrics/beacon.ts +9 -0
  204. package/src/metrics/metrics/lodestar.ts +5 -0
  205. package/src/network/core/events.ts +12 -0
  206. package/src/network/core/networkCoreWorkerHandler.ts +6 -2
  207. package/src/network/peers/peerManager.ts +14 -1
  208. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +1 -1
  209. package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +1 -1
  210. package/src/sync/range/batch.ts +13 -0
  211. package/src/sync/range/chain.ts +64 -17
  212. package/src/sync/range/range.ts +1 -0
  213. package/src/sync/range/utils/batches.ts +38 -13
  214. package/src/sync/range/utils/peerBalancer.ts +4 -1
  215. package/src/sync/types.ts +2 -0
  216. package/src/sync/unknownBlock.ts +65 -21
  217. package/src/sync/utils/downloadByRange.ts +60 -26
  218. package/src/util/asyncIterableToEvents.ts +100 -21
  219. package/src/util/dataColumns.ts +4 -1
@@ -5,6 +5,7 @@ import {
5
5
  IteratorEvent,
6
6
  RequestCancelEvent,
7
7
  RequestEvent,
8
+ ResponsePullEvent,
8
9
  } from "../../util/asyncIterableToEvents.js";
9
10
  import {StrictEventEmitterSingleArg} from "../../util/strictEvents.js";
10
11
  import {EventDirection} from "../events.js";
@@ -14,18 +15,22 @@ export enum ReqRespBridgeEvent {
14
15
  outgoingRequest = "reqresp.outgoingRequest",
15
16
  outgoingRequestCancel = "reqresp.outgoingRequestCancel",
16
17
  outgoingResponse = "reqresp.outgoingResponse",
18
+ outgoingResponsePull = "reqresp.outgoingResponsePull",
17
19
  incomingRequest = "reqresp.incomingRequest",
18
20
  incomingRequestCancel = "reqresp.incomingRequestCancel",
19
21
  incomingResponse = "reqresp.incomingResponse",
22
+ incomingResponsePull = "reqresp.incomingResponsePull",
20
23
  }
21
24
 
22
25
  export type ReqRespBridgeEventData = {
23
26
  [ReqRespBridgeEvent.outgoingRequest]: RequestEvent<OutgoingRequestArgs>;
24
27
  [ReqRespBridgeEvent.outgoingRequestCancel]: RequestCancelEvent;
25
28
  [ReqRespBridgeEvent.outgoingResponse]: IteratorEvent<ResponseOutgoing>;
29
+ [ReqRespBridgeEvent.outgoingResponsePull]: ResponsePullEvent;
26
30
  [ReqRespBridgeEvent.incomingRequest]: RequestEvent<IncomingRequestArgs>;
27
31
  [ReqRespBridgeEvent.incomingRequestCancel]: RequestCancelEvent;
28
32
  [ReqRespBridgeEvent.incomingResponse]: IteratorEvent<ResponseIncoming>;
33
+ [ReqRespBridgeEvent.incomingResponsePull]: ResponsePullEvent;
29
34
  };
30
35
 
31
36
  type IReqRespBridgeEventBus = StrictEventEmitterSingleArg<ReqRespBridgeEventData>;
@@ -37,9 +42,12 @@ export const reqRespBridgeEventDirection: Record<ReqRespBridgeEvent, EventDirect
37
42
  [ReqRespBridgeEvent.outgoingRequest]: EventDirection.mainToWorker,
38
43
  [ReqRespBridgeEvent.outgoingRequestCancel]: EventDirection.mainToWorker,
39
44
  [ReqRespBridgeEvent.outgoingResponse]: EventDirection.mainToWorker,
45
+ // Credit flows from the consumer back to the producer, opposite the response it paces
46
+ [ReqRespBridgeEvent.outgoingResponsePull]: EventDirection.workerToMain,
40
47
  [ReqRespBridgeEvent.incomingRequest]: EventDirection.workerToMain,
41
48
  [ReqRespBridgeEvent.incomingRequestCancel]: EventDirection.workerToMain,
42
49
  [ReqRespBridgeEvent.incomingResponse]: EventDirection.workerToMain,
50
+ [ReqRespBridgeEvent.incomingResponsePull]: EventDirection.mainToWorker,
43
51
  };
44
52
 
45
53
  export function getReqRespBridgeReqEvents(
@@ -49,9 +57,11 @@ export function getReqRespBridgeReqEvents(
49
57
  emitRequest: (data) => events.emit(ReqRespBridgeEvent.outgoingRequest, data),
50
58
  emitRequestCancel: (data) => events.emit(ReqRespBridgeEvent.outgoingRequestCancel, data),
51
59
  emitResponse: (data) => events.emit(ReqRespBridgeEvent.incomingResponse, data),
60
+ emitResponsePull: (data) => events.emit(ReqRespBridgeEvent.incomingResponsePull, data),
52
61
  onRequest: (cb) => events.on(ReqRespBridgeEvent.outgoingRequest, cb),
53
62
  onRequestCancel: (cb) => events.on(ReqRespBridgeEvent.outgoingRequestCancel, cb),
54
63
  onResponse: (cb) => events.on(ReqRespBridgeEvent.incomingResponse, cb),
64
+ onResponsePull: (cb) => events.on(ReqRespBridgeEvent.incomingResponsePull, cb),
55
65
  };
56
66
  }
57
67
 
@@ -62,9 +72,11 @@ export function getReqRespBridgeRespEvents(
62
72
  emitRequest: (data) => events.emit(ReqRespBridgeEvent.incomingRequest, data),
63
73
  emitRequestCancel: (data) => events.emit(ReqRespBridgeEvent.incomingRequestCancel, data),
64
74
  emitResponse: (data) => events.emit(ReqRespBridgeEvent.outgoingResponse, data),
75
+ emitResponsePull: (data) => events.emit(ReqRespBridgeEvent.outgoingResponsePull, data),
65
76
  onRequest: (cb) => events.on(ReqRespBridgeEvent.incomingRequest, cb),
66
77
  onRequestCancel: (cb) => events.on(ReqRespBridgeEvent.incomingRequestCancel, cb),
67
78
  onResponse: (cb) => events.on(ReqRespBridgeEvent.outgoingResponse, cb),
79
+ onResponsePull: (cb) => events.on(ReqRespBridgeEvent.outgoingResponsePull, cb),
68
80
  };
69
81
  }
70
82
 
@@ -74,8 +74,12 @@ export class WorkerNetworkCore implements INetworkCore {
74
74
  private readonly reqRespBridgeEventBus = new ReqRespBridgeEventBus();
75
75
 
76
76
  constructor(private readonly modules: WorkerNetworkCoreModules) {
77
- // Get called from main thread to issue a ReqResp request, and emits event to worker
78
- this.reqRespBridgeReqCaller = new AsyncIterableBridgeCaller(getReqRespBridgeReqEvents(this.reqRespBridgeEventBus));
77
+ // Get called from main thread to issue a ReqResp request, and emits event to worker. Unbounded: we
78
+ // buffer the whole response into an array anyway, so pacing the worker only risks a read buffer overflow
79
+ this.reqRespBridgeReqCaller = new AsyncIterableBridgeCaller(
80
+ getReqRespBridgeReqEvents(this.reqRespBridgeEventBus),
81
+ Infinity
82
+ );
79
83
  // Handles ReqResp response from worker and calls async generator in main thread
80
84
  this.reqRespBridgeRespHandler = new AsyncIterableBridgeHandler(
81
85
  getReqRespBridgeRespEvents(this.reqRespBridgeEventBus),
@@ -449,7 +449,8 @@ export class PeerManager {
449
449
  .catch((e) => this.logger.verbose("cannot tag peer", {peerId: peer.toString()}, e as Error));
450
450
  peerData.relevantStatus = RelevantPeerStatus.relevant;
451
451
  }
452
- if (getConnection(this.libp2p, peer.toString())) {
452
+ // A peer rejected on connect is not tracked and may still send a status before its goodbye completes
453
+ if (peerData && getConnection(this.libp2p, peer.toString())) {
453
454
  const nodeId = peerData?.nodeId ?? computeNodeId(peer);
454
455
  // TODO(fulu): Are we sure we've run Metadata before this?
455
456
  const custodyGroupCount = peerData?.metadata?.custodyGroupCount ?? this.config.CUSTODY_REQUIREMENT;
@@ -797,6 +798,18 @@ export class PeerManager {
797
798
  return false;
798
799
  }
799
800
 
801
+ // The heartbeat only disconnects peers that are already connected, a peer with a bad score
802
+ // could otherwise reconnect right after and stay connected until the next heartbeat
803
+ const scoreState = this.peerRpcScores.getScoreState(remotePeer);
804
+ if (scoreState !== ScoreState.Healthy && !this.gossipsub.isDirectPeer(remotePeerStr)) {
805
+ this.logger.debug("Peer with bad score connected, disconnecting", {peer: remotePeerPrettyStr, scoreState});
806
+ void this.goodbyeAndDisconnect(
807
+ remotePeer,
808
+ scoreState === ScoreState.Banned ? GoodByeReasonCode.BANNED : GoodByeReasonCode.SCORE_TOO_LOW
809
+ );
810
+ return false;
811
+ }
812
+
800
813
  if (!opts.overwriteExisting && this.connectedPeers.has(remotePeerStr)) {
801
814
  return false;
802
815
  }
@@ -216,7 +216,7 @@ export function validateDataColumnSidecarsByRangeRequest(
216
216
  throw new ResponseError(RespStatus.INVALID_REQUEST, "startSlot < genesis");
217
217
  }
218
218
 
219
- // Spec: [max(compute_blob_data_retention_start_epoch(current_epoch), FULU_FORK_EPOCH), current_epoch]
219
+ // Spec: [max(current_epoch - MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS, FULU_FORK_EPOCH), current_epoch]
220
220
  const minimumRequestEpoch = Math.max(getBlobDataRetentionStartEpoch(config, currentEpoch), config.FULU_FORK_EPOCH);
221
221
  if (computeEpochAtSlot(startSlot) < minimumRequestEpoch) {
222
222
  throw new ResponseError(RespStatus.RESOURCE_UNAVAILABLE, "startSlot is before the blob data retention window");
@@ -19,7 +19,7 @@ export async function* onDataColumnSidecarsByRoot(
19
19
  peerId: PeerId,
20
20
  peerClient: string
21
21
  ): AsyncIterable<ResponseOutgoing> {
22
- // SPEC: minimum_request_epoch = max(compute_blob_data_retention_start_epoch(current_epoch), FULU_FORK_EPOCH)
22
+ // SPEC: minimum_request_epoch = max(current_epoch - MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS, FULU_FORK_EPOCH)
23
23
  const currentEpoch = chain.clock.currentEpoch;
24
24
  const minimumRequestEpoch = Math.max(
25
25
  getBlobDataRetentionStartEpoch(chain.config, currentEpoch),
@@ -430,6 +430,19 @@ export class Batch {
430
430
  return [...this.failedProcessingAttempts, ...this.executionErrorAttempts].filter((a) => a.peerAttributable);
431
431
  }
432
432
 
433
+ /**
434
+ * How many failed processing/execution attempts each peer took part in, peer-attributable or not
435
+ */
436
+ getTriedPeerCounts(): Map<PeerIdStr, number> {
437
+ const counts = new Map<PeerIdStr, number>();
438
+ for (const attempt of [...this.failedProcessingAttempts, ...this.executionErrorAttempts]) {
439
+ for (const peer of attempt.peers) {
440
+ counts.set(peer, (counts.get(peer) ?? 0) + 1);
441
+ }
442
+ }
443
+ return counts;
444
+ }
445
+
433
446
  /**
434
447
  * True only if the peer has already returned a successful response for the current request.
435
448
  * A by_range success may update `this.requests` to parent_payload, and the same peer is then
@@ -1,5 +1,5 @@
1
1
  import {ChainForkConfig} from "@lodestar/config";
2
- import {Epoch, Root, Slot} from "@lodestar/types";
2
+ import {Epoch, Root, RootHex, Slot} from "@lodestar/types";
3
3
  import {ErrorAborted, LodestarError, Logger, prettyPrintIndices, toRootHex} from "@lodestar/utils";
4
4
  import {isBlockInputColumns} from "../../chain/blocks/blockInput/blockInput.js";
5
5
  import {BlockInputErrorCode} from "../../chain/blocks/blockInput/errors.js";
@@ -68,6 +68,8 @@ export type SyncChainFns = {
68
68
  onEnd: (err: Error | null, target: ChainTarget | null) => void;
69
69
  /** Deletes an array of BlockInputs from the BlockInputCache */
70
70
  pruneBlockInputs: (blockInputs: IBlockInput[]) => void;
71
+ /** Returns true if the block is known to fork choice */
72
+ hasBlock: (blockRoot: Root) => boolean;
71
73
  };
72
74
 
73
75
  /**
@@ -81,6 +83,15 @@ export type ChainTarget = {
81
83
 
82
84
  export class SyncChainStartError extends Error {}
83
85
 
86
+ export enum SyncChainErrorCode {
87
+ /** The terminal batch has 0 blocks but the target block is not known */
88
+ MISSING_TARGET_BLOCK = "SYNC_CHAIN_ERROR_MISSING_TARGET_BLOCK",
89
+ }
90
+
91
+ type SyncChainErrorType = {code: SyncChainErrorCode.MISSING_TARGET_BLOCK; targetSlot: Slot; targetRoot: RootHex};
92
+
93
+ export class SyncChainError extends LodestarError<SyncChainErrorType> {}
94
+
84
95
  export type SyncChainDebugState = {
85
96
  targetRoot: string | null;
86
97
  targetSlot: number | null;
@@ -136,6 +147,7 @@ export class SyncChain {
136
147
  private readonly reportPeer: SyncChainFns["reportPeer"];
137
148
  private readonly getConnectedPeerSyncMeta: SyncChainFns["getConnectedPeerSyncMeta"];
138
149
  private readonly pruneBlockInputs: SyncChainFns["pruneBlockInputs"];
150
+ private readonly hasBlock: SyncChainFns["hasBlock"];
139
151
 
140
152
  /** AsyncIterable that guarantees processChainSegment is run only at once at anytime */
141
153
  private readonly batchProcessor = new ItTrigger();
@@ -178,6 +190,7 @@ export class SyncChain {
178
190
  this.downloadByRange = fns.downloadByRange;
179
191
  this.reportPeer = fns.reportPeer;
180
192
  this.pruneBlockInputs = fns.pruneBlockInputs;
193
+ this.hasBlock = fns.hasBlock;
181
194
  this.getConnectedPeerSyncMeta = fns.getConnectedPeerSyncMeta;
182
195
  this.config = config;
183
196
  this.clock = clock;
@@ -335,6 +348,32 @@ export class SyncChain {
335
348
 
336
349
  // Returns true if SyncChain has processed all possible blocks with slot <= target.slot
337
350
  if (isSyncChainDone(toArr(this.batches), this.lastEpochWithProcessBlocks, this.target.slot)) {
351
+ // A 0-block terminal batch is only trusted once the target block is known, otherwise a peer returning no
352
+ // blocks for the last range ends the chain short of its target
353
+ const lastAwaitingValidation = toArr(this.batches).findLast(
354
+ (b) => b.state.status === BatchStatus.AwaitingValidation
355
+ );
356
+ if (
357
+ lastAwaitingValidation !== undefined &&
358
+ lastAwaitingValidation.getBlocks().length === 0 &&
359
+ !this.hasBlock(this.target.root)
360
+ ) {
361
+ this.logger.verbose("Terminal 0-block batch without target block", {
362
+ id: this.logId,
363
+ ...lastAwaitingValidation.getMetadata(),
364
+ });
365
+ // Not peer attributable: throws MAX_PROCESSING_ATTEMPTS after MAX_BATCH_PROCESSING_ATTEMPTS without
366
+ // reporting any peer
367
+ lastAwaitingValidation.validationError(
368
+ new SyncChainError({
369
+ code: SyncChainErrorCode.MISSING_TARGET_BLOCK,
370
+ targetSlot: this.target.slot,
371
+ targetRoot: toRootHex(this.target.root),
372
+ })
373
+ );
374
+ this.triggerBatchDownloader();
375
+ continue;
376
+ }
338
377
  break;
339
378
  }
340
379
 
@@ -509,9 +548,12 @@ export class SyncChain {
509
548
  // if last processed epoch is n, we don't want to request batches with epoch > n + MAX_LOOK_AHEAD_EPOCHS
510
549
  // we should have enough batches to process in the buffer: n + 1, ..., n + MAX_LOOK_AHEAD_EPOCHS
511
550
  // let's focus on redownloading these batches first because it may have to reach different peers to get enough sampled columns
551
+ // Note: Don't count batches in the AwaitingValidation state, 0-block batches never advance
552
+ // lastEpochWithProcessBlocks so more than MAX_LOOK_AHEAD_EPOCHS of them in a row would stall sync
553
+ const pendingBatches = batches.filter((batch) => batch.state.status !== BatchStatus.AwaitingValidation);
512
554
  if (
513
- batches.length > 0 &&
514
- Math.max(...batches.map((b) => b.startEpoch)) >= this.lastEpochWithProcessBlocks + MAX_LOOK_AHEAD_EPOCHS
555
+ pendingBatches.length > 0 &&
556
+ Math.max(...pendingBatches.map((b) => b.startEpoch)) >= this.lastEpochWithProcessBlocks + MAX_LOOK_AHEAD_EPOCHS
515
557
  ) {
516
558
  return null;
517
559
  }
@@ -576,6 +618,7 @@ export class SyncChain {
576
618
  }
577
619
  }
578
620
  switch (errCode) {
621
+ case DownloadByRangeErrorCode.DATA_WITHOUT_BLOCKS:
579
622
  case DownloadByRangeErrorCode.EXTRA_BLOCKS:
580
623
  case DownloadByRangeErrorCode.OUT_OF_ORDER_BLOCKS:
581
624
  case DownloadByRangeErrorCode.OUT_OF_RANGE_BLOCKS:
@@ -722,39 +765,43 @@ export class SyncChain {
722
765
  } else {
723
766
  this.logger.verbose("Batch process error", logCtx, res.err);
724
767
 
725
- const invalidatePreviousBatches = (): number => {
726
- let invalidatedCount = 0;
768
+ // advanceChain() drops every batch before the last batch with blocks, so the AwaitingValidation batches before
769
+ // `batch` are that batch followed by 0-block batches, see classifyProcessingFault(). With no batch with blocks
770
+ // yet, fall back to the first 0-block batch so a wrong 0-block answer at the start of the chain is retried
771
+ const awaitingValidationBefore = toArr(this.batches).filter(
772
+ (b) => b.startEpoch < batch.startEpoch && b.state.status === BatchStatus.AwaitingValidation
773
+ );
774
+ const parentBatch =
775
+ awaitingValidationBefore.findLast((b) => b.getBlocks().length > 0) ?? awaitingValidationBefore[0];
776
+ // The 0-block batches after `parentBatch` are invalidated with it: an AwaitingValidation batch must not follow a
777
+ // batch that is downloaded again, see validateBatchesStatus()
778
+ const invalidateFromParentBatch = (faultyParentBatch: Batch): void => {
727
779
  for (const pendingBatch of this.batches.values()) {
728
780
  if (
781
+ pendingBatch.startEpoch >= faultyParentBatch.startEpoch &&
729
782
  pendingBatch.startEpoch < batch.startEpoch &&
730
783
  pendingBatch.state.status === BatchStatus.AwaitingValidation
731
784
  ) {
732
785
  this.logger.verbose("Batch validation error", {id: this.logId, ...pendingBatch.getMetadata()});
733
786
  pendingBatch.validationError(res.err);
734
- invalidatedCount++;
735
787
  }
736
788
  }
737
- return invalidatedCount;
738
789
  };
739
790
 
740
- const prevBatch = this.batches.get(batch.startEpoch - EPOCHS_PER_BATCH);
741
- switch (classifyProcessingFault(res.err, batch, prevBatch)) {
791
+ const fault = classifyProcessingFault(res.err, batch, parentBatch);
792
+ switch (fault.kind) {
742
793
  case ProcessingFaultKind.CurrentBatch:
743
794
  batch.processingError(res.err);
744
795
  break;
745
796
 
746
- case ProcessingFaultKind.PreviousBatch:
747
- // If no previous batch was invalidated, it means the error is on this batch
748
- if (invalidatePreviousBatches() === 0) {
749
- batch.processingError(res.err);
750
- } else {
751
- batch.retainForReprocessing();
752
- }
797
+ case ProcessingFaultKind.ParentBatch:
798
+ invalidateFromParentBatch(fault.parentBatch);
799
+ batch.retainForReprocessing();
753
800
  break;
754
801
 
755
802
  case ProcessingFaultKind.Ambiguous:
756
803
  batch.processingError(res.err);
757
- invalidatePreviousBatches();
804
+ invalidateFromParentBatch(fault.parentBatch);
758
805
  break;
759
806
  }
760
807
  }
@@ -461,6 +461,7 @@ export class RangeSync extends (EventEmitter as {new (): RangeSyncEmitter}) {
461
461
  reportPeer: this.reportPeer,
462
462
  getConnectedPeerSyncMeta: this.getConnectedPeerSyncMeta,
463
463
  pruneBlockInputs: this.pruneBlockInputs,
464
+ hasBlock: (blockRoot) => this.chain.forkChoice.hasBlock(blockRoot),
464
465
  onEnd: this.onSyncChainEnd,
465
466
  },
466
467
  {
@@ -125,39 +125,64 @@ export function isSyncChainDone(batches: Batch[], lastEpochWithProcessBlocks: Ep
125
125
  export enum ProcessingFaultKind {
126
126
  /** This batch's own blocks are bad or incomplete, so redownload this batch. */
127
127
  CurrentBatch = "CurrentBatch",
128
- /** This batch is valid, but a previous batch did not deliver the parent. */
129
- PreviousBatch = "PreviousBatch",
130
- /** The fault could be in this batch or a previous batch, so hedge both ways. */
128
+ /** This batch is valid, but the parent batch did not deliver the parent. */
129
+ ParentBatch = "ParentBatch",
130
+ /** The fault could be in this batch or the parent batch, so hedge both ways. */
131
131
  Ambiguous = "Ambiguous",
132
132
  }
133
133
 
134
+ export type ProcessingFault =
135
+ | {kind: ProcessingFaultKind.CurrentBatch}
136
+ | {kind: ProcessingFaultKind.ParentBatch; parentBatch: Batch}
137
+ | {kind: ProcessingFaultKind.Ambiguous; parentBatch: Batch};
138
+
134
139
  /**
135
140
  * Classify a processChainSegment error for a batch so range sync only redownloads
136
141
  * the batch or batches that could actually be at fault.
137
142
  * Note that range sync is supposed to only handle linear chain, for forky condition we'll handle it via backward sync
138
143
  * in BlockInputSync or the upcoming/TODO beacon_blocks_by_head req/resp.
144
+ *
145
+ * `parentBatch` is the last batch with blocks before `batch`, it may be followed by 0-block batches. If no batch with
146
+ * blocks awaits validation, it is the first 0-block batch before `batch`.
147
+ * Epochs with 0 blocks usually happen on devnets, during periods of poor liveness when no proposer gets a block
148
+ * included for whole epochs. A wrong 0-block response only shows up as an unknown parent in `batch`, so with 0-block
149
+ * batches in between the fault is never pinned on `batch` alone: `parentBatch` and the 0-block batches after it are
150
+ * downloaded again.
139
151
  */
140
- export function classifyProcessingFault(err: Error, batch: Batch, prevBatch: Batch | undefined): ProcessingFaultKind {
152
+ export function classifyProcessingFault(err: Error, batch: Batch, parentBatch: Batch | undefined): ProcessingFault {
141
153
  if (!(err instanceof BlockError)) {
142
- return ProcessingFaultKind.CurrentBatch;
154
+ return {kind: ProcessingFaultKind.CurrentBatch};
143
155
  }
144
156
 
145
157
  const {code} = err.type;
146
158
  if (code !== BlockErrorCode.PARENT_BLOCK_UNKNOWN && code !== BlockErrorCode.PARENT_PAYLOAD_UNKNOWN) {
147
- return ProcessingFaultKind.CurrentBatch;
159
+ return {kind: ProcessingFaultKind.CurrentBatch};
160
+ }
161
+
162
+ if (parentBatch === undefined) {
163
+ return {kind: ProcessingFaultKind.CurrentBatch};
148
164
  }
149
165
 
150
166
  const firstErrorSlot = err.signedBlock.message.slot;
151
167
  if (firstErrorSlot === batch.startSlot) {
152
- // note that range sync is for linear chain, so this is clearly an issue of the previous batch
153
- return prevBatch === undefined ? ProcessingFaultKind.CurrentBatch : ProcessingFaultKind.PreviousBatch;
168
+ // note that range sync is for linear chain, so this is clearly an issue of the parent batch
169
+ return {kind: ProcessingFaultKind.ParentBatch, parentBatch};
154
170
  }
155
171
 
156
- const prevTailSlot = batch.startSlot - 1;
157
- const prevHasFullTail =
172
+ // `parentBatch` can be followed by 0-block batches, so its tail is the end of its own range
173
+ const parentTailSlot = parentBatch.startSlot + parentBatch.count - 1;
174
+ const parentHasFullTail =
158
175
  code === BlockErrorCode.PARENT_PAYLOAD_UNKNOWN
159
- ? (prevBatch?.getPayloadEnvelopes()?.get(prevTailSlot)?.hasPayloadEnvelope() ?? false)
160
- : (prevBatch?.getBlocks().some((b) => b.slot === prevTailSlot) ?? false);
176
+ ? (parentBatch.getPayloadEnvelopes()?.get(parentTailSlot)?.hasPayloadEnvelope() ?? false)
177
+ : parentBatch.getBlocks().some((b) => b.slot === parentTailSlot);
161
178
 
162
- return prevHasFullTail ? ProcessingFaultKind.CurrentBatch : ProcessingFaultKind.Ambiguous;
179
+ // With 0-block batches in between, it could be a wrong 0-block batch
180
+ const hasZeroBlockGap = parentTailSlot + 1 < batch.startSlot;
181
+
182
+ // Assumes the tail block / payload delivered by `parentBatch` is canonical. If it is orphaned, `parentBatch` is at
183
+ // fault: `batch` keeps failing until MAX_PROCESSING_ATTEMPTS and a new SyncChain is created.
184
+ if (parentHasFullTail && !hasZeroBlockGap) {
185
+ return {kind: ProcessingFaultKind.CurrentBatch};
186
+ }
187
+ return {kind: ProcessingFaultKind.Ambiguous, parentBatch};
163
188
  }
@@ -52,7 +52,7 @@ export class ChainPeersBalancer {
52
52
 
53
53
  /**
54
54
  * Return the most suitable peer to retry
55
- * Sort peers by (1) less active requests (2) most columns we need.
55
+ * Sort peers by (1) fewer failed attempts for this batch (2) less active requests (3) most columns we need.
56
56
  * Peers that failed this batch or already succeeded for the same request are excluded inside `filterPeers`.
57
57
  */
58
58
  bestPeerToRetryBatch(batch: Batch): PeerSyncMeta | undefined {
@@ -63,9 +63,12 @@ export class ChainPeersBalancer {
63
63
  // TODO(fulu): This is fulu specific and hinders our peer selection PreFulu
64
64
  const pendingDataColumns = columnsRequest?.columns ?? this.custodyConfig.sampledColumns;
65
65
  const eligiblePeers = this.filterPeers(batch, pendingDataColumns, false);
66
+ const triedPeerCounts = batch.getTriedPeerCounts();
66
67
 
67
68
  const sortedBestPeers = sortBy(
68
69
  eligiblePeers,
70
+ // prefer peers not tried for this batch yet
71
+ ({syncInfo}) => triedPeerCounts.get(syncInfo.peerId) ?? 0,
69
72
  ({syncInfo}) => this.activeRequestsByPeer.get(syncInfo.peerId) ?? 0, // prefer peers with least active req
70
73
  ({columns}) => -1 * columns // prefer peers with the most columns
71
74
  );
package/src/sync/types.ts CHANGED
@@ -172,6 +172,8 @@ export type PendingPayloadRootHex = {
172
172
  export type PendingPayloadEnvelope = {
173
173
  status: PendingPayloadInputStatus.waitingForBlock;
174
174
  envelope: SignedExecutionPayloadEnvelope;
175
+ /** Peer that served the envelope, undefined if it was already cached */
176
+ envelopePeerId?: string;
175
177
  timeAddedSec: number;
176
178
  peerIdStrings: Set<string>;
177
179
  };
@@ -1501,10 +1501,22 @@ export class BlockInputSync {
1501
1501
  return;
1502
1502
  }
1503
1503
  if (validationResult.err) {
1504
+ const err = validationResult.err;
1505
+ const {envelopePeerId} = pendingPayload;
1506
+ // Same penalties as for an envelope validated right after download in fetchPayloadInput
1507
+ if (
1508
+ envelopePeerId !== undefined &&
1509
+ err instanceof ExecutionPayloadEnvelopeError &&
1510
+ (pendingPayload.envelope.message.payload.slotNumber !== payloadInput.slot ||
1511
+ toRootHex(pendingPayload.envelope.message.payload.blockHash) !== payloadInput.getBlockHashHex())
1512
+ ) {
1513
+ this.network.reportPeer(envelopePeerId, PeerAction.LowToleranceError, err.type.code);
1514
+ }
1515
+
1504
1516
  this.logger.debug(
1505
1517
  "Pending payload envelope failed validation after block import, refetching by root",
1506
1518
  {slot: pendingPayload.envelope.message.payload.slotNumber, root: rootHex},
1507
- validationResult.err
1519
+ err
1508
1520
  );
1509
1521
 
1510
1522
  const pendingPayloadByRoot: PendingPayloadRootHex = {
@@ -1514,6 +1526,10 @@ export class BlockInputSync {
1514
1526
  timeAddedSec: pendingPayload.timeAddedSec,
1515
1527
  peerIdStrings: new Set(pendingPayload.peerIdStrings),
1516
1528
  };
1529
+ // Do not prefer the peer whose envelope just failed validation
1530
+ if (envelopePeerId !== undefined) {
1531
+ pendingPayloadByRoot.peerIdStrings.delete(envelopePeerId);
1532
+ }
1517
1533
  this.pendingPayloads.set(rootHex, pendingPayloadByRoot);
1518
1534
 
1519
1535
  if (this.network.getConnectedPeers().length > 0) {
@@ -1722,6 +1738,8 @@ export class BlockInputSync {
1722
1738
  ? cacheItem.payloadInput
1723
1739
  : await this.chain.seenPayloadEnvelopeInputCache.getOrReload(rootHex);
1724
1740
  let envelope = payloadInput?.hasPayloadEnvelope() ? payloadInput.getPayloadEnvelope() : undefined;
1741
+ // An envelope downloaded in an earlier attempt is validated with the peer of a later one
1742
+ let envelopePeerId: PeerIdStr | undefined;
1725
1743
 
1726
1744
  const fetchStartSec = Date.now() / 1000;
1727
1745
  if (typeof slot === "number") {
@@ -1769,6 +1787,7 @@ export class BlockInputSync {
1769
1787
  try {
1770
1788
  if (!envelope) {
1771
1789
  envelope = await this.fetchExecutionPayloadEnvelope(peerId, blockRoot, rootHex);
1790
+ envelopePeerId = peerId;
1772
1791
  cacheItem.peerIdStrings.add(peerId);
1773
1792
  const slotWasUnknown = typeof slot !== "number";
1774
1793
  slot = envelope.message.payload.slotNumber;
@@ -1792,6 +1811,7 @@ export class BlockInputSync {
1792
1811
  return {
1793
1812
  status: PendingPayloadInputStatus.waitingForBlock,
1794
1813
  envelope,
1814
+ envelopePeerId,
1795
1815
  timeAddedSec: cacheItem.timeAddedSec,
1796
1816
  peerIdStrings: cacheItem.peerIdStrings,
1797
1817
  };
@@ -1877,24 +1897,39 @@ export class BlockInputSync {
1877
1897
  excludedPeers.add(peerId);
1878
1898
  }
1879
1899
 
1900
+ // Honest peers serve the requested root and columns, and every path that stores payload columns verifies them
1901
+ if (e instanceof DownloadByRootError || e instanceof DataColumnSidecarValidationError) {
1902
+ this.network.reportPeer(peerId, PeerAction.LowToleranceError, e.type.code);
1903
+ }
1904
+
1880
1905
  if (e instanceof ExecutionPayloadEnvelopeError) {
1881
- switch (e.type.code) {
1882
- // Caused by local state, the downloaded envelope may still be valid
1883
- case ExecutionPayloadEnvelopeErrorCode.BLOCK_ROOT_UNKNOWN:
1884
- case ExecutionPayloadEnvelopeErrorCode.ENVELOPE_ALREADY_KNOWN:
1885
- case ExecutionPayloadEnvelopeErrorCode.PAYLOAD_ENVELOPE_INPUT_MISSING:
1886
- case ExecutionPayloadEnvelopeErrorCode.UNKNOWN_BLOCK_STATE:
1887
- break;
1888
- // Every copy fails once the block is finalized, only a wrong slot makes the served copy invalid
1889
- case ExecutionPayloadEnvelopeErrorCode.BELONG_TO_FINALIZED_BLOCK:
1890
- if (envelope?.message.payload.slotNumber !== payloadInput?.slot) {
1906
+ // Range sync stores an envelope after checking only its root, slot and block hash, so an honest peer may
1907
+ // serve one that fails the other checks. Compared directly since validation stops at the first failure.
1908
+ if (
1909
+ envelope !== undefined &&
1910
+ payloadInput &&
1911
+ (envelope.message.payload.slotNumber !== payloadInput.slot ||
1912
+ toRootHex(envelope.message.payload.blockHash) !== payloadInput.getBlockHashHex())
1913
+ ) {
1914
+ if (envelopePeerId !== undefined) {
1915
+ this.network.reportPeer(envelopePeerId, PeerAction.LowToleranceError, e.type.code);
1916
+ }
1917
+ envelope = payloadInput.hasPayloadEnvelope() ? payloadInput.getPayloadEnvelope() : undefined;
1918
+ } else {
1919
+ switch (e.type.code) {
1920
+ // Caused by local state, the downloaded envelope may still be valid
1921
+ case ExecutionPayloadEnvelopeErrorCode.BLOCK_ROOT_UNKNOWN:
1922
+ case ExecutionPayloadEnvelopeErrorCode.ENVELOPE_ALREADY_KNOWN:
1923
+ case ExecutionPayloadEnvelopeErrorCode.PAYLOAD_ENVELOPE_INPUT_MISSING:
1924
+ case ExecutionPayloadEnvelopeErrorCode.UNKNOWN_BLOCK_STATE:
1925
+ // Every copy fails once the block is finalized
1926
+ case ExecutionPayloadEnvelopeErrorCode.BELONG_TO_FINALIZED_BLOCK:
1927
+ break;
1928
+ // The served copy is invalid, take the envelope from payloadInput or another peer on the next attempt
1929
+ default:
1891
1930
  envelope = payloadInput?.hasPayloadEnvelope() ? payloadInput.getPayloadEnvelope() : undefined;
1892
- }
1893
- break;
1894
- // The served copy is invalid, take the envelope from payloadInput or another peer on the next attempt
1895
- default:
1896
- envelope = payloadInput?.hasPayloadEnvelope() ? payloadInput.getPayloadEnvelope() : undefined;
1897
- break;
1931
+ break;
1932
+ }
1898
1933
  }
1899
1934
  }
1900
1935
  } finally {
@@ -1931,7 +1966,12 @@ export class BlockInputSync {
1931
1966
 
1932
1967
  const receivedRootHex = toRootHex(envelope.message.beaconBlockRoot);
1933
1968
  if (receivedRootHex !== rootHex) {
1934
- throw new Error(`Execution payload envelope root mismatch requested=${rootHex} received=${receivedRootHex}`);
1969
+ throw new DownloadByRootError({
1970
+ code: DownloadByRootErrorCode.MISMATCH_BLOCK_ROOT,
1971
+ peer: prettyPrintPeerIdStr(peerIdStr),
1972
+ requestedBlockRoot: rootHex,
1973
+ receivedBlockRoot: receivedRootHex,
1974
+ });
1935
1975
  }
1936
1976
 
1937
1977
  return envelope;
@@ -1960,9 +2000,13 @@ export class BlockInputSync {
1960
2000
  const requestedColumnsSet = new Set(requestedColumns);
1961
2001
  const extraColumns = columnSidecars.filter((columnSidecar) => !requestedColumnsSet.has(columnSidecar.index));
1962
2002
  if (extraColumns.length > 0) {
1963
- throw new Error(
1964
- `Received unexpected payload data columns indices=${prettyPrintIndices(extraColumns.map((column) => column.index))}`
1965
- );
2003
+ throw new DownloadByRootError({
2004
+ code: DownloadByRootErrorCode.EXTRA_SIDECAR_RECEIVED,
2005
+ peer: prettyPrintPeerIdStr(peerIdStr),
2006
+ slot: payloadInput.slot,
2007
+ blockRoot: payloadInput.blockRootHex,
2008
+ invalidIndices: prettyPrintIndices(extraColumns.map((column) => column.index)),
2009
+ });
1966
2010
  }
1967
2011
 
1968
2012
  // PayloadEnvelopeInput already carries the block slot, root, and commitments, so reuse the