@lodestar/beacon-node 1.47.0-dev.16cb8ec36c → 1.47.0-dev.1c8babbe6e

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 (175) hide show
  1. package/lib/api/impl/beacon/blocks/index.js +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  3. package/lib/api/impl/beacon/pool/index.d.ts.map +1 -1
  4. package/lib/api/impl/beacon/pool/index.js +8 -1
  5. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  6. package/lib/api/impl/beacon/state/utils.d.ts +2 -1
  7. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  8. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  9. package/lib/api/impl/events/index.d.ts.map +1 -1
  10. package/lib/api/impl/events/index.js +2 -0
  11. package/lib/api/impl/events/index.js.map +1 -1
  12. package/lib/api/rest/base.d.ts.map +1 -1
  13. package/lib/api/rest/base.js +7 -0
  14. package/lib/api/rest/base.js.map +1 -1
  15. package/lib/chain/blocks/importExecutionPayload.d.ts +3 -2
  16. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  17. package/lib/chain/blocks/importExecutionPayload.js +11 -9
  18. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  19. package/lib/chain/blocks/index.d.ts.map +1 -1
  20. package/lib/chain/blocks/index.js +14 -6
  21. package/lib/chain/blocks/index.js.map +1 -1
  22. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
  23. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +22 -12
  24. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
  25. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.d.ts +2 -2
  26. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.d.ts.map +1 -1
  27. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.js +2 -2
  28. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.js.map +1 -1
  29. package/lib/chain/bls/index.d.ts +1 -1
  30. package/lib/chain/bls/index.d.ts.map +1 -1
  31. package/lib/chain/bls/interface.d.ts +5 -5
  32. package/lib/chain/bls/interface.d.ts.map +1 -1
  33. package/lib/chain/bls/multithread/index.d.ts +5 -11
  34. package/lib/chain/bls/multithread/index.d.ts.map +1 -1
  35. package/lib/chain/bls/multithread/index.js +116 -101
  36. package/lib/chain/bls/multithread/index.js.map +1 -1
  37. package/lib/chain/bls/multithread/jobItem.d.ts +5 -19
  38. package/lib/chain/bls/multithread/jobItem.d.ts.map +1 -1
  39. package/lib/chain/bls/multithread/jobItem.js +10 -65
  40. package/lib/chain/bls/multithread/jobItem.js.map +1 -1
  41. package/lib/chain/bls/multithread/types.d.ts +29 -8
  42. package/lib/chain/bls/multithread/types.d.ts.map +1 -1
  43. package/lib/chain/bls/multithread/types.js +12 -0
  44. package/lib/chain/bls/multithread/types.js.map +1 -1
  45. package/lib/chain/bls/multithread/utils.d.ts +4 -0
  46. package/lib/chain/bls/multithread/utils.d.ts.map +1 -1
  47. package/lib/chain/bls/multithread/utils.js +10 -0
  48. package/lib/chain/bls/multithread/utils.js.map +1 -1
  49. package/lib/chain/bls/multithread/worker.js +49 -23
  50. package/lib/chain/bls/multithread/worker.js.map +1 -1
  51. package/lib/chain/bls/singleThread.d.ts +4 -10
  52. package/lib/chain/bls/singleThread.d.ts.map +1 -1
  53. package/lib/chain/bls/singleThread.js +8 -45
  54. package/lib/chain/bls/singleThread.js.map +1 -1
  55. package/lib/chain/bls/utils.d.ts +4 -4
  56. package/lib/chain/bls/utils.d.ts.map +1 -1
  57. package/lib/chain/bls/utils.js +18 -19
  58. package/lib/chain/bls/utils.js.map +1 -1
  59. package/lib/chain/chain.d.ts +2 -1
  60. package/lib/chain/chain.d.ts.map +1 -1
  61. package/lib/chain/chain.js +5 -3
  62. package/lib/chain/chain.js.map +1 -1
  63. package/lib/chain/errors/blockError.d.ts +1 -0
  64. package/lib/chain/errors/blockError.d.ts.map +1 -1
  65. package/lib/chain/errors/blockError.js +6 -1
  66. package/lib/chain/errors/blockError.js.map +1 -1
  67. package/lib/chain/interface.d.ts +2 -1
  68. package/lib/chain/interface.d.ts.map +1 -1
  69. package/lib/chain/interface.js.map +1 -1
  70. package/lib/chain/opPools/aggregatedAttestationPool.js +1 -1
  71. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  72. package/lib/chain/opPools/attestationPool.d.ts +1 -1
  73. package/lib/chain/opPools/attestationPool.d.ts.map +1 -1
  74. package/lib/chain/opPools/attestationPool.js +1 -1
  75. package/lib/chain/opPools/attestationPool.js.map +1 -1
  76. package/lib/chain/opPools/payloadAttestationPool.js +1 -1
  77. package/lib/chain/opPools/payloadAttestationPool.js.map +1 -1
  78. package/lib/chain/opPools/syncCommitteeMessagePool.js +1 -1
  79. package/lib/chain/opPools/syncCommitteeMessagePool.js.map +1 -1
  80. package/lib/chain/opPools/syncContributionAndProofPool.js +1 -1
  81. package/lib/chain/opPools/syncContributionAndProofPool.js.map +1 -1
  82. package/lib/chain/opPools/utils.d.ts +1 -1
  83. package/lib/chain/opPools/utils.d.ts.map +1 -1
  84. package/lib/chain/opPools/utils.js +1 -1
  85. package/lib/chain/opPools/utils.js.map +1 -1
  86. package/lib/chain/validation/attestation.d.ts.map +1 -1
  87. package/lib/chain/validation/attestation.js +1 -4
  88. package/lib/chain/validation/attestation.js.map +1 -1
  89. package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
  90. package/lib/chain/validation/attesterSlashing.js +1 -1
  91. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  92. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  93. package/lib/chain/validation/executionPayloadBid.js +1 -2
  94. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  95. package/lib/chain/validation/executionPayloadEnvelope.js +1 -1
  96. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
  97. package/lib/chain/validation/payloadAttestationMessage.js +2 -9
  98. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  99. package/lib/chain/validation/proposerPreferences.js +2 -2
  100. package/lib/chain/validation/proposerPreferences.js.map +1 -1
  101. package/lib/chain/validation/proposerSlashing.js +1 -1
  102. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  103. package/lib/metrics/metrics/lodestar.d.ts +38 -18
  104. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  105. package/lib/metrics/metrics/lodestar.js +80 -50
  106. package/lib/metrics/metrics/lodestar.js.map +1 -1
  107. package/lib/network/gossip/topic.d.ts +13 -0
  108. package/lib/network/gossip/topic.d.ts.map +1 -1
  109. package/lib/network/gossip/topic.js +37 -0
  110. package/lib/network/gossip/topic.js.map +1 -1
  111. package/lib/network/network.d.ts.map +1 -1
  112. package/lib/network/network.js +22 -43
  113. package/lib/network/network.js.map +1 -1
  114. package/lib/network/util.d.ts +0 -1
  115. package/lib/network/util.d.ts.map +1 -1
  116. package/lib/network/util.js +0 -4
  117. package/lib/network/util.js.map +1 -1
  118. package/lib/node/nodejs.d.ts +2 -1
  119. package/lib/node/nodejs.d.ts.map +1 -1
  120. package/lib/node/nodejs.js.map +1 -1
  121. package/lib/sync/range/batch.d.ts +23 -5
  122. package/lib/sync/range/batch.d.ts.map +1 -1
  123. package/lib/sync/range/batch.js +61 -22
  124. package/lib/sync/range/batch.js.map +1 -1
  125. package/lib/sync/range/chain.d.ts +2 -1
  126. package/lib/sync/range/chain.d.ts.map +1 -1
  127. package/lib/sync/range/chain.js +23 -10
  128. package/lib/sync/range/chain.js.map +1 -1
  129. package/package.json +18 -18
  130. package/src/api/impl/beacon/blocks/index.ts +1 -1
  131. package/src/api/impl/beacon/pool/index.ts +7 -1
  132. package/src/api/impl/beacon/state/utils.ts +2 -1
  133. package/src/api/impl/events/index.ts +3 -1
  134. package/src/api/rest/base.ts +7 -0
  135. package/src/chain/blocks/importExecutionPayload.ts +12 -11
  136. package/src/chain/blocks/index.ts +18 -6
  137. package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +25 -16
  138. package/src/chain/blocks/verifyExecutionPayloadEnvelope.ts +1 -9
  139. package/src/chain/bls/index.ts +1 -1
  140. package/src/chain/bls/interface.ts +7 -3
  141. package/src/chain/bls/multithread/index.ts +148 -120
  142. package/src/chain/bls/multithread/jobItem.ts +12 -82
  143. package/src/chain/bls/multithread/types.ts +33 -8
  144. package/src/chain/bls/multithread/utils.ts +11 -0
  145. package/src/chain/bls/multithread/worker.ts +85 -27
  146. package/src/chain/bls/singleThread.ts +11 -55
  147. package/src/chain/bls/utils.ts +23 -24
  148. package/src/chain/chain.ts +6 -4
  149. package/src/chain/errors/blockError.ts +8 -2
  150. package/src/chain/interface.ts +2 -1
  151. package/src/chain/opPools/aggregatedAttestationPool.ts +1 -1
  152. package/src/chain/opPools/attestationPool.ts +1 -1
  153. package/src/chain/opPools/payloadAttestationPool.ts +1 -1
  154. package/src/chain/opPools/syncCommitteeMessagePool.ts +1 -1
  155. package/src/chain/opPools/syncContributionAndProofPool.ts +1 -1
  156. package/src/chain/opPools/utils.ts +1 -1
  157. package/src/chain/validation/attestation.ts +1 -7
  158. package/src/chain/validation/attesterSlashing.ts +1 -8
  159. package/src/chain/validation/executionPayloadBid.ts +1 -2
  160. package/src/chain/validation/executionPayloadEnvelope.ts +0 -1
  161. package/src/chain/validation/payloadAttestationMessage.ts +3 -11
  162. package/src/chain/validation/proposerPreferences.ts +3 -3
  163. package/src/chain/validation/proposerSlashing.ts +1 -1
  164. package/src/metrics/metrics/lodestar.ts +85 -51
  165. package/src/network/gossip/topic.ts +38 -0
  166. package/src/network/network.ts +27 -55
  167. package/src/network/util.ts +0 -5
  168. package/src/node/nodejs.ts +2 -1
  169. package/src/sync/range/batch.ts +83 -28
  170. package/src/sync/range/chain.ts +26 -11
  171. package/lib/chain/bls/maybeBatch.d.ts +0 -12
  172. package/lib/chain/bls/maybeBatch.d.ts.map +0 -1
  173. package/lib/chain/bls/maybeBatch.js +0 -35
  174. package/lib/chain/bls/maybeBatch.js.map +0 -1
  175. package/src/chain/bls/maybeBatch.ts +0 -45
@@ -39,6 +39,7 @@ export enum BatchStatus {
39
39
  AwaitingValidation = "AwaitingValidation",
40
40
  }
41
41
 
42
+ /** Identity of one download attempt*/
42
43
  export type Attempt = {
43
44
  /** The peer that made the attempt */
44
45
  peers: PeerIdStr[];
@@ -46,6 +47,16 @@ export type Attempt = {
46
47
  hash: RootHex;
47
48
  };
48
49
 
50
+ /**
51
+ * A failed attempt that has been classified for blame.
52
+ */
53
+ export type FailedAttempt = Attempt & {
54
+ /**
55
+ * True when the failure is evidence the peers served bad data, so they may be downscored..
56
+ */
57
+ peerAttributable: boolean;
58
+ };
59
+
49
60
  type TrackedRequest = {
50
61
  /** only happen for the 1st batch in checkpoint sync */
51
62
  parentPayload: boolean;
@@ -108,10 +119,12 @@ export type BatchMetadata = {
108
119
  // Retry counters
109
120
  downloadAttempts: number;
110
121
  processingAttempts: number;
122
+ executionErrorAttempts: number;
111
123
 
112
124
  // Cumulative peer attribution for failed attempts (only present when non-empty)
113
125
  failedDownloadPeers?: string;
114
126
  failedProcessingPeers?: string;
127
+ executionErrorPeers?: string;
115
128
  };
116
129
 
117
130
  function formatRangeReq(req: {startSlot: Slot; count: number}): string {
@@ -152,10 +165,10 @@ export class Batch {
152
165
  state: BatchState = {status: BatchStatus.AwaitingDownload, blocks: [], payloadEnvelopes: null};
153
166
  /** Peers that provided good data, with column coverage for by_range requests */
154
167
  private readonly successfulDownloads = new Map<PeerIdStr, TrackedRequest>();
155
- /** The `Attempts` that have been made and failed to send us this batch. */
156
- readonly failedProcessingAttempts: Attempt[] = [];
157
- /** The `Attempts` that have been made and failed because of execution malfunction. */
158
- readonly executionErrorAttempts: Attempt[] = [];
168
+ /** The attempts that have been made and failed to send us this batch. */
169
+ readonly failedProcessingAttempts: FailedAttempt[] = [];
170
+ /** The attempts that have been made and failed because of execution malfunction. */
171
+ readonly executionErrorAttempts: FailedAttempt[] = [];
159
172
  /** The number of download retries this batch has undergone due to a failed request. */
160
173
  private readonly failedDownloadAttempts: PeerIdStr[] = [];
161
174
  private readonly config: ChainForkConfig;
@@ -419,10 +432,18 @@ export class Batch {
419
432
  }
420
433
 
421
434
  /**
422
- * Gives a list of peers from which this batch has had a failed download or processing attempt.
435
+ * Gives a list of peers from which this batch has had a failed download attempt, or a
436
+ * peer-attributable failed processing/execution attempt.
423
437
  */
424
438
  getFailedPeers(): PeerIdStr[] {
425
- return [...this.failedDownloadAttempts, ...this.failedProcessingAttempts.flatMap((a) => a.peers)];
439
+ return [...this.failedDownloadAttempts, ...this.getPeerAttributableAttempts().flatMap((a) => a.peers)];
440
+ }
441
+
442
+ /**
443
+ * Attempts whose failure is peer-attributable, across both the processing and execution error
444
+ */
445
+ getPeerAttributableAttempts(): FailedAttempt[] {
446
+ return [...this.failedProcessingAttempts, ...this.executionErrorAttempts].filter((a) => a.peerAttributable);
426
447
  }
427
448
 
428
449
  /**
@@ -457,6 +478,7 @@ export class Batch {
457
478
  getMetadata(): BatchMetadata {
458
479
  const {blocksRequest, blobsRequest, columnsRequest, envelopesRequest} = this.requests;
459
480
  const failedProcessingPeerList = this.failedProcessingAttempts.flatMap((a) => a.peers);
481
+ const executionErrorPeerList = this.executionErrorAttempts.flatMap((a) => a.peers);
460
482
  return {
461
483
  startEpoch: this.startEpoch,
462
484
  startSlot: this.startSlot,
@@ -468,12 +490,16 @@ export class Batch {
468
490
  ...(envelopesRequest && {envelopesReq: formatRangeReq(envelopesRequest)}),
469
491
  downloadAttempts: this.failedDownloadAttempts.length,
470
492
  processingAttempts: this.failedProcessingAttempts.length,
493
+ executionErrorAttempts: this.executionErrorAttempts.length,
471
494
  ...(this.failedDownloadAttempts.length > 0 && {
472
495
  failedDownloadPeers: this.failedDownloadAttempts.join(","),
473
496
  }),
474
497
  ...(failedProcessingPeerList.length > 0 && {
475
498
  failedProcessingPeers: failedProcessingPeerList.join(","),
476
499
  }),
500
+ ...(executionErrorPeerList.length > 0 && {
501
+ executionErrorPeers: executionErrorPeerList.join(","),
502
+ }),
477
503
  };
478
504
  }
479
505
 
@@ -703,11 +729,7 @@ export class Batch {
703
729
  throw new BatchError(this.wrongStatusErrorType(BatchStatus.Processing));
704
730
  }
705
731
 
706
- if (isExecutionEngineError(err)) {
707
- this.onExecutionEngineError(this.state.attempt);
708
- } else {
709
- this.onProcessingError(this.state.attempt);
710
- }
732
+ this.routeProcessingFailure(err, this.state.attempt);
711
733
  }
712
734
 
713
735
  /**
@@ -718,10 +740,17 @@ export class Batch {
718
740
  throw new BatchError(this.wrongStatusErrorType(BatchStatus.AwaitingValidation));
719
741
  }
720
742
 
721
- if (isExecutionEngineError(err)) {
722
- this.onExecutionEngineError(this.state.attempt);
743
+ this.routeProcessingFailure(err, this.state.attempt);
744
+ }
745
+
746
+ private routeProcessingFailure(err: Error, attempt: Attempt): void {
747
+ const code = err instanceof BlockError || err instanceof PayloadError ? err.type.code : null;
748
+ const failedAttempt: FailedAttempt = {...attempt, peerAttributable: isPeerAttributableFailure(code)};
749
+
750
+ if (isExecutionEngineFailure(code)) {
751
+ this.onExecutionEngineError(failedAttempt);
723
752
  } else {
724
- this.onProcessingError(this.state.attempt);
753
+ this.onProcessingError(failedAttempt);
725
754
  }
726
755
  }
727
756
 
@@ -735,7 +764,7 @@ export class Batch {
735
764
  return this.state.attempt;
736
765
  }
737
766
 
738
- private onExecutionEngineError(attempt: Attempt): void {
767
+ private onExecutionEngineError(attempt: FailedAttempt): void {
739
768
  this.executionErrorAttempts.push(attempt);
740
769
  if (this.executionErrorAttempts.length > MAX_BATCH_PROCESSING_ATTEMPTS) {
741
770
  throw new BatchError(this.errorType({code: BatchErrorCode.MAX_EXECUTION_ENGINE_ERROR_ATTEMPTS}));
@@ -746,7 +775,7 @@ export class Batch {
746
775
  this.state = {status: BatchStatus.AwaitingDownload, blocks: [], payloadEnvelopes: null};
747
776
  }
748
777
 
749
- private onProcessingError(attempt: Attempt): void {
778
+ private onProcessingError(attempt: FailedAttempt): void {
750
779
  this.failedProcessingAttempts.push(attempt);
751
780
  if (this.failedProcessingAttempts.length > MAX_BATCH_PROCESSING_ATTEMPTS) {
752
781
  throw new BatchError(this.errorType({code: BatchErrorCode.MAX_PROCESSING_ATTEMPTS}));
@@ -789,18 +818,44 @@ type BatchErrorMetadata = {
789
818
 
790
819
  export class BatchError extends LodestarError<BatchErrorType & BatchErrorMetadata> {}
791
820
 
792
- function isExecutionEngineError(err: Error): boolean {
793
- if (!(err instanceof BlockError)) {
794
- return false;
795
- }
796
-
797
- if (err.type.code === BlockErrorCode.EXECUTION_ENGINE_ERROR) {
798
- return true;
799
- }
800
-
821
+ /**
822
+ * Whether a processing failure is an execution-engine failure. Pre-gloas, all EL errors stay in
823
+ * BlockErrorCode, post-gloas, they stay in PayloadErrorCode.
824
+ */
825
+ function isExecutionEngineFailure(code: BlockErrorCode | PayloadErrorCode | null): boolean {
801
826
  return (
802
- err.type.code === BlockErrorCode.BEACON_CHAIN_ERROR &&
803
- err.type.error instanceof PayloadError &&
804
- err.type.error.type.code === PayloadErrorCode.EXECUTION_ENGINE_ERROR
827
+ code === BlockErrorCode.EXECUTION_ENGINE_INVALID ||
828
+ code === BlockErrorCode.EXECUTION_ENGINE_ERROR ||
829
+ code === PayloadErrorCode.EXECUTION_ENGINE_INVALID ||
830
+ code === PayloadErrorCode.EXECUTION_ENGINE_ERROR
805
831
  );
806
832
  }
833
+
834
+ /**
835
+ * Based on an error code, return if peer is attributable for FailedAttempt.
836
+ */
837
+ function isPeerAttributableFailure(code: BlockErrorCode | PayloadErrorCode | null): boolean {
838
+ switch (code) {
839
+ // EL returned a definitive INVALID verdict on the payload
840
+ case BlockErrorCode.EXECUTION_ENGINE_INVALID:
841
+ case PayloadErrorCode.EXECUTION_ENGINE_INVALID:
842
+ // a block or envelope signature is invalid
843
+ case BlockErrorCode.INVALID_SIGNATURE:
844
+ case PayloadErrorCode.INVALID_SIGNATURE:
845
+ // the block's state transition produced an invalid state root, or failed per_slot/per_block processing
846
+ case BlockErrorCode.INVALID_STATE_ROOT:
847
+ case BlockErrorCode.PER_BLOCK_PROCESSING_ERROR:
848
+ // the segment this peer served is internally inconsistent (in-segment link breaks, see PR #9684)
849
+ case BlockErrorCode.NON_LINEAR_SLOTS:
850
+ case BlockErrorCode.NON_LINEAR_PARENT_ROOTS:
851
+ case BlockErrorCode.NON_LINEAR_PAYLOAD_ROOTS:
852
+ // the envelope references a mismatched block root, or fails field verification
853
+ case BlockErrorCode.ENVELOPE_BLOCK_ROOT_MISMATCH:
854
+ case PayloadErrorCode.ENVELOPE_VERIFICATION_ERROR:
855
+ // the peer served a block we have explicitly blacklisted
856
+ case BlockErrorCode.BLACKLISTED_BLOCK:
857
+ return true;
858
+ default:
859
+ return false;
860
+ }
861
+ }
@@ -358,9 +358,10 @@ export class SyncChain {
358
358
  // If a batch exceeds it's retry limit, maybe downscore peers.
359
359
  // shouldDownscoreOnBatchError() functions enforces that all BatchErrorCode values are covered
360
360
  if (e instanceof BatchError) {
361
- const shouldReportPeer = shouldReportPeerOnBatchError(e.type.code);
361
+ const shouldReportPeer = shouldReportPeerOnBatchError(e.type.code, this.batches.get(e.type.startEpoch));
362
362
  if (shouldReportPeer) {
363
- for (const peer of this.peerset.keys()) {
363
+ // Only the peers actually at fault are reported, never the whole peerset.
364
+ for (const peer of shouldReportPeer.peers) {
364
365
  this.reportPeer(peer, shouldReportPeer.action, shouldReportPeer.reason);
365
366
  }
366
367
  }
@@ -768,8 +769,11 @@ export class SyncChain {
768
769
 
769
770
  // The last batch attempt is right, all others are wrong. Penalize other peers
770
771
  const attemptOk = batch.validationSuccess();
771
- for (const attempt of batch.failedProcessingAttempts) {
772
+ for (const attempt of batch.getPeerAttributableAttempts()) {
772
773
  if (attempt.hash !== attemptOk.hash) {
774
+ // attempt.peers contains block/column/envelope peers.
775
+ // And if there is one bad envelope we will downscore block and column peers to
776
+ // TODO: resolve this
773
777
  for (const badAttemptPeer of attempt.peers) {
774
778
  if (attemptOk.peers.find((goodPeer) => goodPeer === badAttemptPeer)) {
775
779
  // The same peer corrected its previous attempt
@@ -830,21 +834,32 @@ export class SyncChain {
830
834
  * If peer should not be downscored, returns null.
831
835
  */
832
836
  export function shouldReportPeerOnBatchError(
833
- code: BatchErrorCode
834
- ): {action: PeerAction.LowToleranceError; reason: string} | null {
837
+ code: BatchErrorCode,
838
+ batch: Batch | undefined
839
+ ): {action: PeerAction.LowToleranceError; reason: string; peers: PeerIdStr[]} | null {
835
840
  switch (code) {
836
- // A batch could not be processed after max retry limit. It's likely that all peers
837
- // in this chain are sending invalid batches repeatedly so are either malicious or faulty.
838
- // We drop the chain and report all peers.
839
- // There are some edge cases with forks that could cause this situation, but it's unlikely.
841
+ // A batch could not be processed after max retry limit. Report
842
+ // only the peers that served a peer-attributable failed attempt.
840
843
  case BatchErrorCode.MAX_PROCESSING_ATTEMPTS:
841
- return {action: PeerAction.LowToleranceError, reason: "SyncChainMaxProcessingAttempts"};
844
+ case BatchErrorCode.MAX_EXECUTION_ENGINE_ERROR_ATTEMPTS: {
845
+ // penalize both the processing-error and execution-error peers
846
+ const attributablePeers = [
847
+ ...new Set(batch?.getPeerAttributableAttempts().flatMap((attempt) => attempt.peers) ?? []),
848
+ ];
849
+ if (attributablePeers.length === 0) {
850
+ return null;
851
+ }
852
+ const reason =
853
+ code === BatchErrorCode.MAX_PROCESSING_ATTEMPTS
854
+ ? "SyncChainMaxProcessingAttempts"
855
+ : "SyncChainMaxExecutionEngineErrorAttempts";
856
+ return {action: PeerAction.LowToleranceError, reason, peers: attributablePeers};
857
+ }
842
858
 
843
859
  // TODO: Should peers be reported for MAX_DOWNLOAD_ATTEMPTS?
844
860
  case BatchErrorCode.MAX_DOWNLOAD_ATTEMPTS:
845
861
  case BatchErrorCode.INVALID_COUNT:
846
862
  case BatchErrorCode.WRONG_STATUS:
847
- case BatchErrorCode.MAX_EXECUTION_ENGINE_ERROR_ATTEMPTS:
848
863
  return null;
849
864
  }
850
865
  }
@@ -1,12 +0,0 @@
1
- import { PublicKey } from "@chainsafe/blst";
2
- export type SignatureSetDeserialized = {
3
- publicKey: PublicKey;
4
- message: Uint8Array;
5
- signature: Uint8Array;
6
- };
7
- /**
8
- * Verify signatures sets with batch verification or regular core verify depending on the set count.
9
- * Abstracted in a separate file to be consumed by the threaded pool and the main thread implementation.
10
- */
11
- export declare function verifySignatureSetsMaybeBatch(sets: SignatureSetDeserialized[]): boolean;
12
- //# sourceMappingURL=maybeBatch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"maybeBatch.d.ts","sourceRoot":"","sources":["../../../src/chain/bls/maybeBatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAuD,MAAM,iBAAiB,CAAC;AAIhG,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,EAAE,UAAU,CAAC;IACpB,SAAS,EAAE,UAAU,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,wBAAwB,EAAE,GAAG,OAAO,CA8BvF"}
@@ -1,35 +0,0 @@
1
- import { Signature, verify, verifyMultipleAggregateSignatures } from "@chainsafe/blst";
2
- const MIN_SET_COUNT_TO_BATCH = 2;
3
- /**
4
- * Verify signatures sets with batch verification or regular core verify depending on the set count.
5
- * Abstracted in a separate file to be consumed by the threaded pool and the main thread implementation.
6
- */
7
- export function verifySignatureSetsMaybeBatch(sets) {
8
- try {
9
- if (sets.length >= MIN_SET_COUNT_TO_BATCH) {
10
- return verifyMultipleAggregateSignatures(sets.map((s) => ({
11
- pk: s.publicKey,
12
- msg: s.message,
13
- // true = validate signature
14
- sig: Signature.fromBytes(s.signature, true),
15
- })));
16
- }
17
- // .every on an empty array returns true
18
- if (sets.length === 0) {
19
- throw Error("Empty signature set");
20
- }
21
- // If too few signature sets verify them without batching
22
- return sets.every((set) => {
23
- // true = validate signature
24
- const sig = Signature.fromBytes(set.signature, true);
25
- return verify(set.message, set.publicKey, sig);
26
- });
27
- }
28
- catch (_) {
29
- // A signature could be malformed, in that case fromBytes throws error
30
- // blst-ts `verifyMultipleSignatures` is also a fallible operation if mul_n_aggregate fails
31
- // see https://github.com/ChainSafe/blst-ts/blob/b1ba6333f664b08e5c50b2b0d18c4f079203962b/src/lib.ts#L291
32
- return false;
33
- }
34
- }
35
- //# sourceMappingURL=maybeBatch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"maybeBatch.js","sourceRoot":"","sources":["../../../src/chain/bls/maybeBatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,EAAE,iCAAiC,EAAC,MAAM,iBAAiB,CAAC;AAEhG,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAQjC;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAAC,IAAgC;IAC5E,IAAI,CAAC;QACH,IAAI,IAAI,CAAC,MAAM,IAAI,sBAAsB,EAAE,CAAC;YAC1C,OAAO,iCAAiC,CACtC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACf,EAAE,EAAE,CAAC,CAAC,SAAS;gBACf,GAAG,EAAE,CAAC,CAAC,OAAO;gBACd,4BAA4B;gBAC5B,GAAG,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC;aAC5C,CAAC,CAAC,CACJ,CAAC;QACJ,CAAC;QAED,wCAAwC;QACxC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACrC,CAAC;QAED,yDAAyD;QACzD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACxB,4BAA4B;YAC5B,MAAM,GAAG,GAAG,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YACrD,OAAO,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,sEAAsE;QACtE,2FAA2F;QAC3F,yGAAyG;QACzG,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -1,45 +0,0 @@
1
- import {PublicKey, Signature, verify, verifyMultipleAggregateSignatures} from "@chainsafe/blst";
2
-
3
- const MIN_SET_COUNT_TO_BATCH = 2;
4
-
5
- export type SignatureSetDeserialized = {
6
- publicKey: PublicKey;
7
- message: Uint8Array;
8
- signature: Uint8Array;
9
- };
10
-
11
- /**
12
- * Verify signatures sets with batch verification or regular core verify depending on the set count.
13
- * Abstracted in a separate file to be consumed by the threaded pool and the main thread implementation.
14
- */
15
- export function verifySignatureSetsMaybeBatch(sets: SignatureSetDeserialized[]): boolean {
16
- try {
17
- if (sets.length >= MIN_SET_COUNT_TO_BATCH) {
18
- return verifyMultipleAggregateSignatures(
19
- sets.map((s) => ({
20
- pk: s.publicKey,
21
- msg: s.message,
22
- // true = validate signature
23
- sig: Signature.fromBytes(s.signature, true),
24
- }))
25
- );
26
- }
27
-
28
- // .every on an empty array returns true
29
- if (sets.length === 0) {
30
- throw Error("Empty signature set");
31
- }
32
-
33
- // If too few signature sets verify them without batching
34
- return sets.every((set) => {
35
- // true = validate signature
36
- const sig = Signature.fromBytes(set.signature, true);
37
- return verify(set.message, set.publicKey, sig);
38
- });
39
- } catch (_) {
40
- // A signature could be malformed, in that case fromBytes throws error
41
- // blst-ts `verifyMultipleSignatures` is also a fallible operation if mul_n_aggregate fails
42
- // see https://github.com/ChainSafe/blst-ts/blob/b1ba6333f664b08e5c50b2b0d18c4f079203962b/src/lib.ts#L291
43
- return false;
44
- }
45
- }