@lodestar/beacon-node 1.52.0-dev.269cf1aa5b → 1.52.0-dev.3238de719b

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 (188) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +46 -26
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/pool/index.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/pool/index.js +3 -1
  6. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  7. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  8. package/lib/api/impl/beacon/state/utils.js +2 -1
  9. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  10. package/lib/api/impl/debug/index.d.ts.map +1 -1
  11. package/lib/api/impl/debug/index.js +6 -2
  12. package/lib/api/impl/debug/index.js.map +1 -1
  13. package/lib/api/impl/validator/index.d.ts.map +1 -1
  14. package/lib/api/impl/validator/index.js +13 -4
  15. package/lib/api/impl/validator/index.js.map +1 -1
  16. package/lib/chain/ColumnReconstructionTracker.d.ts +4 -0
  17. package/lib/chain/ColumnReconstructionTracker.d.ts.map +1 -1
  18. package/lib/chain/ColumnReconstructionTracker.js +4 -0
  19. package/lib/chain/ColumnReconstructionTracker.js.map +1 -1
  20. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
  21. package/lib/chain/archiveStore/historicalState/getHistoricalState.js +7 -0
  22. package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
  23. package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
  24. package/lib/chain/archiveStore/utils/pruneHistory.js +8 -4
  25. package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
  26. package/lib/chain/blocks/importExecutionPayload.d.ts +1 -1
  27. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  28. package/lib/chain/blocks/importExecutionPayload.js +9 -3
  29. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  30. package/lib/chain/blocks/index.d.ts.map +1 -1
  31. package/lib/chain/blocks/index.js +3 -17
  32. package/lib/chain/blocks/index.js.map +1 -1
  33. package/lib/chain/chain.d.ts +6 -5
  34. package/lib/chain/chain.d.ts.map +1 -1
  35. package/lib/chain/chain.js +62 -20
  36. package/lib/chain/chain.js.map +1 -1
  37. package/lib/chain/errors/attestationError.d.ts +15 -1
  38. package/lib/chain/errors/attestationError.d.ts.map +1 -1
  39. package/lib/chain/errors/attestationError.js +8 -0
  40. package/lib/chain/errors/attestationError.js.map +1 -1
  41. package/lib/chain/errors/executionPayloadBid.d.ts +3 -2
  42. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
  43. package/lib/chain/errors/executionPayloadBid.js +1 -1
  44. package/lib/chain/errors/executionPayloadBid.js.map +1 -1
  45. package/lib/chain/errors/executionPayloadEnvelope.d.ts +48 -0
  46. package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
  47. package/lib/chain/errors/executionPayloadEnvelope.js +7 -0
  48. package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
  49. package/lib/chain/interface.d.ts +1 -1
  50. package/lib/chain/interface.d.ts.map +1 -1
  51. package/lib/chain/lightClient/index.d.ts +13 -6
  52. package/lib/chain/lightClient/index.d.ts.map +1 -1
  53. package/lib/chain/lightClient/index.js +95 -115
  54. package/lib/chain/lightClient/index.js.map +1 -1
  55. package/lib/chain/opPools/opPool.js +6 -6
  56. package/lib/chain/opPools/opPool.js.map +1 -1
  57. package/lib/chain/seenCache/seenAttesters.d.ts +1 -0
  58. package/lib/chain/seenCache/seenAttesters.d.ts.map +1 -1
  59. package/lib/chain/seenCache/seenAttesters.js +1 -1
  60. package/lib/chain/seenCache/seenAttesters.js.map +1 -1
  61. package/lib/chain/seenCache/seenBlockAttesters.d.ts +8 -2
  62. package/lib/chain/seenCache/seenBlockAttesters.d.ts.map +1 -1
  63. package/lib/chain/seenCache/seenBlockAttesters.js +43 -6
  64. package/lib/chain/seenCache/seenBlockAttesters.js.map +1 -1
  65. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts +13 -4
  66. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts.map +1 -1
  67. package/lib/chain/seenCache/seenExecutionPayloadBids.js +13 -12
  68. package/lib/chain/seenCache/seenExecutionPayloadBids.js.map +1 -1
  69. package/lib/chain/validation/aggregateAndProof.d.ts.map +1 -1
  70. package/lib/chain/validation/aggregateAndProof.js +24 -7
  71. package/lib/chain/validation/aggregateAndProof.js.map +1 -1
  72. package/lib/chain/validation/attestation.d.ts.map +1 -1
  73. package/lib/chain/validation/attestation.js +32 -16
  74. package/lib/chain/validation/attestation.js.map +1 -1
  75. package/lib/chain/validation/block.d.ts.map +1 -1
  76. package/lib/chain/validation/block.js +9 -1
  77. package/lib/chain/validation/block.js.map +1 -1
  78. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  79. package/lib/chain/validation/executionPayloadBid.js +30 -40
  80. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  81. package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
  82. package/lib/chain/validation/executionPayloadEnvelope.js +79 -4
  83. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
  84. package/lib/chain/validation/payloadAttestationMessage.js +9 -0
  85. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  86. package/lib/chain/validatorMonitor.js +43 -43
  87. package/lib/chain/validatorMonitor.js.map +1 -1
  88. package/lib/network/gossip/gossipsub.js +2 -2
  89. package/lib/network/gossip/gossipsub.js.map +1 -1
  90. package/lib/network/gossip/topic.d.ts +1 -7
  91. package/lib/network/gossip/topic.d.ts.map +1 -1
  92. package/lib/network/gossip/topic.js +0 -13
  93. package/lib/network/gossip/topic.js.map +1 -1
  94. package/lib/network/network.d.ts +1 -0
  95. package/lib/network/network.d.ts.map +1 -1
  96. package/lib/network/network.js +20 -11
  97. package/lib/network/network.js.map +1 -1
  98. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  99. package/lib/network/processor/gossipHandlers.js +19 -6
  100. package/lib/network/processor/gossipHandlers.js.map +1 -1
  101. package/lib/network/processor/gossipValidatorFn.d.ts.map +1 -1
  102. package/lib/network/processor/gossipValidatorFn.js +4 -1
  103. package/lib/network/processor/gossipValidatorFn.js.map +1 -1
  104. package/lib/network/processor/index.d.ts.map +1 -1
  105. package/lib/network/processor/index.js +4 -2
  106. package/lib/network/processor/index.js.map +1 -1
  107. package/lib/network/reqresp/utils/collect.d.ts +4 -4
  108. package/lib/network/reqresp/utils/collect.d.ts.map +1 -1
  109. package/lib/network/reqresp/utils/collect.js +9 -8
  110. package/lib/network/reqresp/utils/collect.js.map +1 -1
  111. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts +1 -1
  112. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts.map +1 -1
  113. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js +2 -2
  114. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js.map +1 -1
  115. package/lib/sync/range/batch.d.ts +6 -0
  116. package/lib/sync/range/batch.d.ts.map +1 -1
  117. package/lib/sync/range/batch.js +17 -0
  118. package/lib/sync/range/batch.js.map +1 -1
  119. package/lib/sync/range/chain.d.ts.map +1 -1
  120. package/lib/sync/range/chain.js +8 -1
  121. package/lib/sync/range/chain.js.map +1 -1
  122. package/lib/sync/range/range.d.ts.map +1 -1
  123. package/lib/sync/range/range.js +43 -3
  124. package/lib/sync/range/range.js.map +1 -1
  125. package/lib/sync/types.d.ts +12 -1
  126. package/lib/sync/types.d.ts.map +1 -1
  127. package/lib/sync/types.js +2 -0
  128. package/lib/sync/types.js.map +1 -1
  129. package/lib/sync/unknownBlock.d.ts +28 -1
  130. package/lib/sync/unknownBlock.d.ts.map +1 -1
  131. package/lib/sync/unknownBlock.js +256 -24
  132. package/lib/sync/unknownBlock.js.map +1 -1
  133. package/lib/sync/utils/downloadByRange.d.ts +14 -1
  134. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  135. package/lib/sync/utils/downloadByRange.js +12 -2
  136. package/lib/sync/utils/downloadByRange.js.map +1 -1
  137. package/lib/sync/utils/downloadByRoot.d.ts +24 -2
  138. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  139. package/lib/sync/utils/downloadByRoot.js +43 -1
  140. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  141. package/lib/util/eventLoop.d.ts +3 -3
  142. package/lib/util/eventLoop.d.ts.map +1 -1
  143. package/lib/util/eventLoop.js +3 -3
  144. package/lib/util/eventLoop.js.map +1 -1
  145. package/package.json +18 -18
  146. package/src/api/impl/beacon/blocks/index.ts +52 -28
  147. package/src/api/impl/beacon/pool/index.ts +9 -7
  148. package/src/api/impl/beacon/state/utils.ts +2 -1
  149. package/src/api/impl/debug/index.ts +6 -2
  150. package/src/api/impl/validator/index.ts +15 -5
  151. package/src/chain/ColumnReconstructionTracker.ts +5 -0
  152. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +9 -0
  153. package/src/chain/archiveStore/utils/pruneHistory.ts +9 -4
  154. package/src/chain/blocks/importExecutionPayload.ts +9 -2
  155. package/src/chain/blocks/index.ts +3 -31
  156. package/src/chain/chain.ts +95 -37
  157. package/src/chain/errors/attestationError.ts +11 -1
  158. package/src/chain/errors/executionPayloadBid.ts +3 -2
  159. package/src/chain/errors/executionPayloadEnvelope.ts +50 -0
  160. package/src/chain/interface.ts +1 -1
  161. package/src/chain/lightClient/index.ts +108 -142
  162. package/src/chain/opPools/opPool.ts +6 -6
  163. package/src/chain/seenCache/seenAttesters.ts +1 -1
  164. package/src/chain/seenCache/seenBlockAttesters.ts +48 -6
  165. package/src/chain/seenCache/seenExecutionPayloadBids.ts +35 -15
  166. package/src/chain/validation/aggregateAndProof.ts +24 -9
  167. package/src/chain/validation/attestation.ts +31 -20
  168. package/src/chain/validation/block.ts +9 -1
  169. package/src/chain/validation/executionPayloadBid.ts +40 -42
  170. package/src/chain/validation/executionPayloadEnvelope.ts +87 -3
  171. package/src/chain/validation/payloadAttestationMessage.ts +10 -0
  172. package/src/chain/validatorMonitor.ts +43 -43
  173. package/src/network/gossip/gossipsub.ts +2 -2
  174. package/src/network/gossip/topic.ts +1 -14
  175. package/src/network/network.ts +33 -11
  176. package/src/network/processor/gossipHandlers.ts +25 -13
  177. package/src/network/processor/gossipValidatorFn.ts +4 -0
  178. package/src/network/processor/index.ts +7 -2
  179. package/src/network/reqresp/utils/collect.ts +16 -8
  180. package/src/network/reqresp/utils/collectSequentialBlocksInRange.ts +3 -2
  181. package/src/sync/range/batch.ts +20 -0
  182. package/src/sync/range/chain.ts +8 -0
  183. package/src/sync/range/range.ts +56 -3
  184. package/src/sync/types.ts +11 -0
  185. package/src/sync/unknownBlock.ts +295 -24
  186. package/src/sync/utils/downloadByRange.ts +29 -3
  187. package/src/sync/utils/downloadByRoot.ts +68 -2
  188. package/src/util/eventLoop.ts +3 -3
@@ -596,7 +596,8 @@ export class Network implements INetwork {
596
596
  request
597
597
  ),
598
598
  request,
599
- this.chain.serializedCache
599
+ this.chain.serializedCache,
600
+ () => this.reportInvalidResponse(peerId)
600
601
  );
601
602
  }
602
603
 
@@ -611,7 +612,8 @@ export class Network implements INetwork {
611
612
  ),
612
613
  request.length,
613
614
  responseSszTypeByMethod[ReqRespMethod.BeaconBlocksByRoot],
614
- this.chain.serializedCache
615
+ this.chain.serializedCache,
616
+ () => this.reportInvalidResponse(peerId)
615
617
  );
616
618
  }
617
619
 
@@ -623,28 +625,32 @@ export class Network implements INetwork {
623
625
  this.sendReqRespRequest(peerId, ReqRespMethod.BeaconBlocksByHead, [Version.V1], request),
624
626
  Math.min(request.count, this.config.MAX_REQUEST_BLOCKS_DENEB),
625
627
  responseSszTypeByMethod[ReqRespMethod.BeaconBlocksByHead],
626
- this.chain.serializedCache
628
+ this.chain.serializedCache,
629
+ () => this.reportInvalidResponse(peerId)
627
630
  );
628
631
  }
629
632
 
630
633
  async sendLightClientBootstrap(peerId: PeerIdStr, request: Root): Promise<LightClientBootstrap> {
631
634
  return collectExactOneTyped(
632
635
  this.sendReqRespRequest(peerId, ReqRespMethod.LightClientBootstrap, [Version.V1], request),
633
- responseSszTypeByMethod[ReqRespMethod.LightClientBootstrap]
636
+ responseSszTypeByMethod[ReqRespMethod.LightClientBootstrap],
637
+ () => this.reportInvalidResponse(peerId)
634
638
  );
635
639
  }
636
640
 
637
641
  async sendLightClientOptimisticUpdate(peerId: PeerIdStr): Promise<LightClientOptimisticUpdate> {
638
642
  return collectExactOneTyped(
639
643
  this.sendReqRespRequest(peerId, ReqRespMethod.LightClientOptimisticUpdate, [Version.V1], null),
640
- responseSszTypeByMethod[ReqRespMethod.LightClientOptimisticUpdate]
644
+ responseSszTypeByMethod[ReqRespMethod.LightClientOptimisticUpdate],
645
+ () => this.reportInvalidResponse(peerId)
641
646
  );
642
647
  }
643
648
 
644
649
  async sendLightClientFinalityUpdate(peerId: PeerIdStr): Promise<LightClientFinalityUpdate> {
645
650
  return collectExactOneTyped(
646
651
  this.sendReqRespRequest(peerId, ReqRespMethod.LightClientFinalityUpdate, [Version.V1], null),
647
- responseSszTypeByMethod[ReqRespMethod.LightClientFinalityUpdate]
652
+ responseSszTypeByMethod[ReqRespMethod.LightClientFinalityUpdate],
653
+ () => this.reportInvalidResponse(peerId)
648
654
  );
649
655
  }
650
656
 
@@ -655,7 +661,9 @@ export class Network implements INetwork {
655
661
  return collectMaxResponseTyped(
656
662
  this.sendReqRespRequest(peerId, ReqRespMethod.LightClientUpdatesByRange, [Version.V1], request),
657
663
  request.count,
658
- responseSszTypeByMethod[ReqRespMethod.LightClientUpdatesByRange]
664
+ responseSszTypeByMethod[ReqRespMethod.LightClientUpdatesByRange],
665
+ undefined,
666
+ () => this.reportInvalidResponse(peerId)
659
667
  );
660
668
  }
661
669
 
@@ -666,7 +674,9 @@ export class Network implements INetwork {
666
674
  return collectMaxResponseTyped(
667
675
  this.sendReqRespRequest(peerId, ReqRespMethod.DataColumnSidecarsByRange, [Version.V1], request),
668
676
  request.count * request.columns.length,
669
- responseSszTypeByMethod[ReqRespMethod.DataColumnSidecarsByRange]
677
+ responseSszTypeByMethod[ReqRespMethod.DataColumnSidecarsByRange],
678
+ undefined,
679
+ () => this.reportInvalidResponse(peerId)
670
680
  );
671
681
  }
672
682
 
@@ -678,7 +688,8 @@ export class Network implements INetwork {
678
688
  this.sendReqRespRequest(peerId, ReqRespMethod.DataColumnSidecarsByRoot, [Version.V1], request),
679
689
  request.reduce((total, {columns}) => total + columns.length, 0),
680
690
  responseSszTypeByMethod[ReqRespMethod.DataColumnSidecarsByRoot],
681
- this.chain.serializedCache
691
+ this.chain.serializedCache,
692
+ () => this.reportInvalidResponse(peerId)
682
693
  );
683
694
  }
684
695
 
@@ -689,7 +700,9 @@ export class Network implements INetwork {
689
700
  return collectMaxResponseTyped(
690
701
  this.sendReqRespRequest(peerId, ReqRespMethod.ExecutionPayloadEnvelopesByRange, [Version.V1], request),
691
702
  request.count,
692
- responseSszTypeByMethod[ReqRespMethod.ExecutionPayloadEnvelopesByRange]
703
+ responseSszTypeByMethod[ReqRespMethod.ExecutionPayloadEnvelopesByRange],
704
+ undefined,
705
+ () => this.reportInvalidResponse(peerId)
693
706
  );
694
707
  }
695
708
 
@@ -701,10 +714,19 @@ export class Network implements INetwork {
701
714
  this.sendReqRespRequest(peerId, ReqRespMethod.ExecutionPayloadEnvelopesByRoot, [Version.V1], request),
702
715
  request.length,
703
716
  responseSszTypeByMethod[ReqRespMethod.ExecutionPayloadEnvelopesByRoot],
704
- this.chain.serializedCache
717
+ this.chain.serializedCache,
718
+ () => this.reportInvalidResponse(peerId)
705
719
  );
706
720
  }
707
721
 
722
+ private async reportInvalidResponse(peerId: PeerIdStr): Promise<void> {
723
+ try {
724
+ await this.core.reportPeer(peerId, PeerAction.LowToleranceError, "InvalidResponseSsz");
725
+ } catch (error) {
726
+ this.logger.debug("Failed to report invalid response", {peerId}, error as Error);
727
+ }
728
+ }
729
+
708
730
  private sendReqRespRequest<Req>(
709
731
  peerId: PeerIdStr,
710
732
  method: ReqRespMethod,
@@ -89,7 +89,7 @@ import {validateGossipProposerPreferences} from "../../chain/validation/proposer
89
89
  import {OpSource} from "../../chain/validatorMonitor.js";
90
90
  import {Metrics} from "../../metrics/index.js";
91
91
  import {getBlobKzgCommitments, getDataColumnSidecarSlot} from "../../util/dataColumns.js";
92
- import {callImmediate, callInNextEventLoop} from "../../util/eventLoop.js";
92
+ import {callAfterIO, callInNextEventLoop} from "../../util/eventLoop.js";
93
93
  import {INetworkCore} from "../core/index.js";
94
94
  import {NetworkEventBus} from "../events.js";
95
95
  import {
@@ -269,6 +269,16 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
269
269
  // The block is retained for unknown parent sync without full validation. Authenticate it first, this
270
270
  // does not need the parent state
271
271
  const proposerIndex = signedBlock.message.proposerIndex;
272
+ // An active proposer missing from the cache comes from a branch that finalized validators this node never
273
+ // processed, range sync recovers that branch from peer status
274
+ if (proposerIndex >= chain.pubkeyCache.size) {
275
+ throw new BlockGossipError(GossipAction.REJECT, {
276
+ code: BlockErrorCode.UNKNOWN_PROPOSER,
277
+ slot,
278
+ root: blockRootHex,
279
+ proposerIndex,
280
+ });
281
+ }
272
282
  await verifyBlockProposerSignature(chain, signedBlock, blockRootHex);
273
283
  chain.seenBlockProposers.observeBlockRoot(
274
284
  slot,
@@ -676,7 +686,7 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
676
686
  try {
677
687
  const blockInput = await validateBeaconBlock(signedBlock, topic.boundary.fork, peerIdStr, seenTimestampSec);
678
688
  // Runs after the validation result is reported, except with `network.useWorker: false`
679
- callImmediate(() => {
689
+ callAfterIO(() => {
680
690
  try {
681
691
  chain.serializedCache.set(signedBlock, serializedData);
682
692
  handleValidBeaconBlock(blockInput, peerIdStr, seenTimestampSec);
@@ -1301,13 +1311,16 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
1301
1311
  }
1302
1312
  }
1303
1313
 
1304
- chain.forkChoice.notifyPtcMessages(
1305
- toRootHex(payloadAttestationMessage.data.beaconBlockRoot),
1306
- payloadAttestationMessage.data.slot,
1307
- validationResult.validatorCommitteeIndices,
1308
- payloadAttestationMessage.data.payloadPresent,
1309
- payloadAttestationMessage.data.blobDataAvailable
1310
- );
1314
+ // Gossip accepts adjacent slots within the clock disparity but fork choice only counts the current slot
1315
+ if (payloadAttestationMessage.data.slot === chain.clock.currentSlot) {
1316
+ chain.forkChoice.notifyPtcMessages(
1317
+ toRootHex(payloadAttestationMessage.data.beaconBlockRoot),
1318
+ payloadAttestationMessage.data.slot,
1319
+ validationResult.validatorCommitteeIndices,
1320
+ payloadAttestationMessage.data.payloadPresent,
1321
+ payloadAttestationMessage.data.blobDataAvailable
1322
+ );
1323
+ }
1311
1324
 
1312
1325
  chain.emitter.emit(routes.events.EventType.payloadAttestationMessage, {
1313
1326
  version: config.getForkName(payloadAttestationMessage.data.slot),
@@ -1422,12 +1435,11 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
1422
1435
  try {
1423
1436
  metrics?.inclusionListsValid.inc({source: InclusionListSource.gossip});
1424
1437
  metrics?.inclusionListsValidSize.inc(totalBytes);
1425
- // Timely only if received within its own slot before the deadline, so a list for the next slot that
1426
- // passed validation under clock disparity is untimely. Late lists are still stored, marked untimely
1438
+ // A list received before its slot is timely, the spec delays it until the slot starts. Only gossip
1439
+ // validation bounds how early a list can be. Late lists are still stored, marked untimely
1427
1440
  const secFromSlot = chain.clock.secFromSlot(slot, seenTimestampSec);
1428
1441
  metrics?.inclusionListArrivalTime.observe(secFromSlot);
1429
- const isTimely =
1430
- secFromSlot >= 0 && secFromSlot * 1000 < config.getInclusionListDueMs(config.getForkName(slot));
1442
+ const isTimely = secFromSlot * 1000 < config.getInclusionListDueMs(config.getForkName(slot));
1431
1443
 
1432
1444
  const insertOutcome = chain.inclusionListStore.process(signedInclusionList, committeeIndices, isTimely);
1433
1445
  metrics?.inclusionListStore.insertOutcome.inc({insertOutcome});
@@ -12,6 +12,7 @@ import {
12
12
  ExecutionPayloadEnvelopeErrorCode,
13
13
  GossipAction,
14
14
  GossipActionError,
15
+ GossipErrorCode,
15
16
  InclusionListErrorCode,
16
17
  PayloadAttestationErrorCode,
17
18
  ProposerPreferencesErrorCode,
@@ -116,6 +117,9 @@ const gossipRejectPeerAction: Record<GossipType, RejectPeerActionRule> = {
116
117
  };
117
118
 
118
119
  export function rejectPeerAction(type: GossipType, code: string): PeerAction {
120
+ if (code === GossipErrorCode.INVALID_SERIALIZED_BYTES_ERROR_CODE) {
121
+ return PeerAction.LowToleranceError;
122
+ }
119
123
  const rule = gossipRejectPeerAction[type];
120
124
  return rule.byCode?.[code] ?? rule.default;
121
125
  }
@@ -1,7 +1,7 @@
1
1
  import {TopicValidatorResult} from "@libp2p/gossipsub";
2
2
  import {routes} from "@lodestar/api";
3
3
  import {ForkSeq, NUMBER_OF_COLUMNS, isForkPostGloas} from "@lodestar/params";
4
- import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
4
+ import {computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition";
5
5
  import {RootHex, Slot, SlotRootHex} from "@lodestar/types";
6
6
  import {Logger, MapDef, mapValues, sleep} from "@lodestar/utils";
7
7
  import {BlockInputSource} from "../../chain/blocks/blockInput/types.js";
@@ -947,8 +947,13 @@ export class NetworkProcessor {
947
947
  this.bufferedRootsBySlot.delete(slot);
948
948
  }
949
949
 
950
+ // A slot's search budget lives as long as gossip accepts messages for it, a pruned budget would start over
951
+ const minSearchedSlot = Math.min(
952
+ clockSlot - DEFAULT_EARLIEST_PERMISSIBLE_SLOT_DISTANCE,
953
+ computeStartSlotAtEpoch(computeEpochAtSlot(clockSlot) - 1)
954
+ );
950
955
  for (const slot of this.searchedRootsBySlot.keys()) {
951
- if (slot <= minSlot) this.searchedRootsBySlot.delete(slot);
956
+ if (slot < minSearchedSlot) this.searchedRootsBySlot.delete(slot);
952
957
  }
953
958
 
954
959
  for (const [peer, slot] of this.fatalPeers) {
@@ -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
 
@@ -633,6 +633,26 @@ export class Batch {
633
633
  };
634
634
  }
635
635
 
636
+ /**
637
+ * Downloading -> AwaitingDownload
638
+ *
639
+ * The batch may hold an evicted invalid block, drop every downloaded block and request the whole batch again
640
+ */
641
+ downloadingInvalidBlock(peer: PeerIdStr): void {
642
+ if (this.state.status !== BatchStatus.Downloading) {
643
+ throw new BatchError(this.wrongStatusErrorType(BatchStatus.Downloading));
644
+ }
645
+
646
+ this.failedDownloadAttempts.push(peer);
647
+ if (this.failedDownloadAttempts.length > MAX_BATCH_DOWNLOAD_ATTEMPTS) {
648
+ throw new BatchError(this.errorType({code: BatchErrorCode.MAX_DOWNLOAD_ATTEMPTS}));
649
+ }
650
+
651
+ this.successfulDownloads.clear();
652
+ this.state = {status: BatchStatus.AwaitingDownload, blocks: [], payloadEnvelopes: null};
653
+ this.resetRequests();
654
+ }
655
+
636
656
  /**
637
657
  * Downloading -> AwaitingDownload (without counting as a failed attempt).
638
658
  * Used when the peer rate-limited us — the request was never actually served.
@@ -602,6 +602,14 @@ export class SyncChain {
602
602
  this.scheduleRateLimitBackoffRetry();
603
603
  batch.downloadingRateLimited();
604
604
  this.triggerBatchDownloader();
605
+ } else if (
606
+ res.err instanceof DownloadByRangeError &&
607
+ res.err.type.code === DownloadByRangeErrorCode.INVALID_CACHED_BLOCK
608
+ ) {
609
+ if (res.err.type.blockPeer !== undefined) {
610
+ this.reportPeer(res.err.type.blockPeer, PeerAction.LowToleranceError, res.err.message);
611
+ }
612
+ batch.downloadingInvalidBlock(res.err.type.blockPeer ?? peer.peerId); // Throws after MAX_DOWNLOAD_ATTEMPTS
605
613
  } else {
606
614
  batch.downloadingError(peer.peerId); // Throws after MAX_DOWNLOAD_ATTEMPTS
607
615
  }
@@ -3,13 +3,20 @@ import {StrictEventEmitter} from "strict-event-emitter-types";
3
3
  import {BeaconConfig} from "@lodestar/config";
4
4
  import {IBeaconStateViewGloas, computeStartSlotAtEpoch, isStatePostGloas} from "@lodestar/state-transition";
5
5
  import {Epoch, Status, fulu, ssz} from "@lodestar/types";
6
- import {Logger, byteArrayEquals, prettyPrintIndices, toRootHex} from "@lodestar/utils";
6
+ import {Logger, byteArrayEquals, prettyPrintIndices, toHex, toRootHex} from "@lodestar/utils";
7
7
  import {IBlockInput} from "../../chain/blocks/blockInput/types.js";
8
8
  import {PayloadError, PayloadErrorCode} from "../../chain/blocks/importExecutionPayload.js";
9
9
  import {AttestationImportOpt, ImportBlockOpts} from "../../chain/blocks/index.js";
10
10
  import {assertLinearChainSegment} from "../../chain/blocks/utils/chainSegment.js";
11
- import {BlockError} from "../../chain/errors/index.js";
11
+ import {
12
+ BlockError,
13
+ BlockErrorCode,
14
+ BlockGossipError,
15
+ DataColumnSidecarErrorCode,
16
+ DataColumnSidecarValidationError,
17
+ } from "../../chain/errors/index.js";
12
18
  import {IBeaconChain} from "../../chain/index.js";
19
+ import {verifyBlockProposerSignature} from "../../chain/validation/block.js";
13
20
  import {Metrics} from "../../metrics/index.js";
14
21
  import {INetwork} from "../../network/index.js";
15
22
  import {PeerIdStr} from "../../util/peerId.js";
@@ -291,7 +298,7 @@ export class RangeSync extends (EventEmitter as {new (): RangeSyncEmitter}) {
291
298
  ...requests,
292
299
  });
293
300
  const {responses, payloadEnvelopes: downloadedPayloadEnvelopes} = result;
294
- const {blocks, payloadEnvelopes} = cacheByRangeResponses({
301
+ const {blocks, payloadEnvelopes, signatureMismatch} = cacheByRangeResponses({
295
302
  cache: this.chain.seenBlockInputCache,
296
303
  seenPayloadEnvelopeInputCache: this.chain.seenPayloadEnvelopeInputCache,
297
304
  peerIdStr: peer.peerId,
@@ -304,6 +311,52 @@ export class RangeSync extends (EventEmitter as {new (): RangeSyncEmitter}) {
304
311
  seenTimestampSec: Date.now() / 1000,
305
312
  });
306
313
 
314
+ if (signatureMismatch !== null) {
315
+ const {blockInput, columnSidecar} = signatureMismatch;
316
+ const block = blockInput.getBlock();
317
+ let isValidBlockSignature: boolean | null = true;
318
+ try {
319
+ await verifyBlockProposerSignature(this.chain, block, blockInput.blockRootHex);
320
+ } catch (e) {
321
+ isValidBlockSignature =
322
+ e instanceof BlockGossipError && e.type.code === BlockErrorCode.PROPOSAL_SIGNATURE_INVALID ? false : null;
323
+ }
324
+
325
+ if (isValidBlockSignature) {
326
+ throw new DataColumnSidecarValidationError(
327
+ {
328
+ code: DataColumnSidecarErrorCode.INCORRECT_BLOCK,
329
+ slot: blockInput.slot,
330
+ columnIndex: columnSidecar.index,
331
+ expected: toHex(block.signature),
332
+ actual: toHex(columnSidecar.signedBlockHeader.signature),
333
+ },
334
+ "DataColumnSidecar header signature doesn't match block signature"
335
+ );
336
+ }
337
+
338
+ // Later downloads reuse a cached block, evict it and the other unverified blocks of a peer
339
+ // proven to serve invalid signatures
340
+ const blockPeer = isValidBlockSignature === false ? blockInput.getBlockSource().peerIdStr : undefined;
341
+ const cache = this.chain.seenBlockInputCache;
342
+ for (const b of blocks) {
343
+ const isSuspect = b === blockInput || (blockPeer !== undefined && b.getBlockSource().peerIdStr === blockPeer);
344
+ if (
345
+ isSuspect &&
346
+ cache.get(b.blockRootHex) === b &&
347
+ !cache.isVerifiedProposerSignature(b.slot, b.blockRootHex, b.getBlock().signature)
348
+ ) {
349
+ cache.remove(b.blockRootHex);
350
+ }
351
+ }
352
+ throw new DownloadByRangeError({
353
+ code: DownloadByRangeErrorCode.INVALID_CACHED_BLOCK,
354
+ slot: blockInput.slot,
355
+ blockRoot: blockInput.blockRootHex,
356
+ blockPeer,
357
+ });
358
+ }
359
+
307
360
  const segmentBlocks = blocks.filter((b) => b.hasBlock()).sort((a, b) => a.slot - b.slot);
308
361
  const envelopeSlots = payloadEnvelopes
309
362
  ? Array.from(payloadEnvelopes.entries())
package/src/sync/types.ts CHANGED
@@ -107,6 +107,8 @@ export enum DroppedItemReason {
107
107
  invalidSignature = "invalid_signature",
108
108
  /** an unexpected / unhandled error code led to removal */
109
109
  unknown = "unknown",
110
+ /** a block waiting on its parent was evicted because the peer that gossiped it exceeded its byte budget */
111
+ peerBudget = "peer_budget",
110
112
  }
111
113
 
112
114
  export enum PendingPayloadInputStatus {
@@ -123,6 +125,12 @@ export type PendingBlockInput = {
123
125
  timeAddedSec: number;
124
126
  timeSyncedSec?: number;
125
127
  peerIdStrings: Set<string>;
128
+ /** Peer that gossiped a block retained for unknown parent sync */
129
+ retainedBy?: string;
130
+ retainedBytes?: number;
131
+ failedDownloads?: number;
132
+ /** A failed download is not retried before this time */
133
+ retryAtMs?: number;
126
134
  };
127
135
 
128
136
  export type PendingRootHex = {
@@ -131,6 +139,9 @@ export type PendingRootHex = {
131
139
  timeAddedSec: number;
132
140
  timeSyncedSec?: number;
133
141
  peerIdStrings: Set<string>;
142
+ failedDownloads?: number;
143
+ /** A failed download is not retried before this time */
144
+ retryAtMs?: number;
134
145
  };
135
146
 
136
147
  export type BlockInputSyncCacheItem = PendingBlockInput | PendingRootHex;