@lodestar/beacon-node 2.1.0-dev.6f6f023ffd → 2.1.0-dev.76e8ca15f1

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 (114) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +1 -3
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/errors.d.ts +7 -0
  5. package/lib/api/impl/errors.d.ts.map +1 -1
  6. package/lib/api/impl/errors.js +9 -0
  7. package/lib/api/impl/errors.js.map +1 -1
  8. package/lib/api/rest/base.d.ts.map +1 -1
  9. package/lib/api/rest/base.js +5 -2
  10. package/lib/api/rest/base.js.map +1 -1
  11. package/lib/chain/ColumnReconstructionTracker.d.ts +3 -0
  12. package/lib/chain/ColumnReconstructionTracker.d.ts.map +1 -1
  13. package/lib/chain/ColumnReconstructionTracker.js +3 -1
  14. package/lib/chain/ColumnReconstructionTracker.js.map +1 -1
  15. package/lib/chain/GetBlobsTracker.d.ts +3 -0
  16. package/lib/chain/GetBlobsTracker.d.ts.map +1 -1
  17. package/lib/chain/GetBlobsTracker.js +3 -1
  18. package/lib/chain/GetBlobsTracker.js.map +1 -1
  19. package/lib/chain/chain.d.ts +2 -1
  20. package/lib/chain/chain.d.ts.map +1 -1
  21. package/lib/chain/chain.js +5 -1
  22. package/lib/chain/chain.js.map +1 -1
  23. package/lib/chain/errors/dataColumnSidecarError.d.ts +7 -0
  24. package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
  25. package/lib/chain/errors/dataColumnSidecarError.js +1 -0
  26. package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
  27. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  28. package/lib/chain/forkChoice/index.js +1 -2
  29. package/lib/chain/forkChoice/index.js.map +1 -1
  30. package/lib/chain/interface.d.ts +2 -1
  31. package/lib/chain/interface.d.ts.map +1 -1
  32. package/lib/chain/interface.js.map +1 -1
  33. package/lib/chain/options.d.ts.map +1 -1
  34. package/lib/chain/options.js +0 -2
  35. package/lib/chain/options.js.map +1 -1
  36. package/lib/chain/seenCache/index.d.ts +1 -0
  37. package/lib/chain/seenCache/index.d.ts.map +1 -1
  38. package/lib/chain/seenCache/index.js +1 -0
  39. package/lib/chain/seenCache/index.js.map +1 -1
  40. package/lib/chain/seenCache/seenBlockProposers.d.ts +3 -0
  41. package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -1
  42. package/lib/chain/seenCache/seenBlockProposers.js +6 -2
  43. package/lib/chain/seenCache/seenBlockProposers.js.map +1 -1
  44. package/lib/chain/seenCache/seenDataColumnSidecars.d.ts +17 -0
  45. package/lib/chain/seenCache/seenDataColumnSidecars.d.ts.map +1 -0
  46. package/lib/chain/seenCache/seenDataColumnSidecars.js +61 -0
  47. package/lib/chain/seenCache/seenDataColumnSidecars.js.map +1 -0
  48. package/lib/chain/validation/block.d.ts.map +1 -1
  49. package/lib/chain/validation/block.js +12 -2
  50. package/lib/chain/validation/block.js.map +1 -1
  51. package/lib/chain/validation/dataColumnSidecar.js +1 -1
  52. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  53. package/lib/chain/validation/voluntaryExit.js +2 -2
  54. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  55. package/lib/index.d.ts +1 -0
  56. package/lib/index.d.ts.map +1 -1
  57. package/lib/index.js +1 -0
  58. package/lib/index.js.map +1 -1
  59. package/lib/network/core/networkCore.d.ts +1 -3
  60. package/lib/network/core/networkCore.d.ts.map +1 -1
  61. package/lib/network/core/networkCore.js +1 -3
  62. package/lib/network/core/networkCore.js.map +1 -1
  63. package/lib/network/network.d.ts +1 -6
  64. package/lib/network/network.d.ts.map +1 -1
  65. package/lib/network/network.js +16 -40
  66. package/lib/network/network.js.map +1 -1
  67. package/lib/network/options.d.ts +0 -1
  68. package/lib/network/options.d.ts.map +1 -1
  69. package/lib/network/options.js +0 -1
  70. package/lib/network/options.js.map +1 -1
  71. package/lib/network/peers/discover.d.ts +1 -0
  72. package/lib/network/peers/discover.d.ts.map +1 -1
  73. package/lib/network/peers/discover.js +44 -48
  74. package/lib/network/peers/discover.js.map +1 -1
  75. package/lib/network/peers/score/store.d.ts.map +1 -1
  76. package/lib/network/peers/score/store.js +1 -2
  77. package/lib/network/peers/score/store.js.map +1 -1
  78. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  79. package/lib/network/processor/gossipHandlers.js +61 -3
  80. package/lib/network/processor/gossipHandlers.js.map +1 -1
  81. package/lib/util/dataColumns.d.ts +2 -1
  82. package/lib/util/dataColumns.d.ts.map +1 -1
  83. package/lib/util/dataColumns.js +7 -2
  84. package/lib/util/dataColumns.js.map +1 -1
  85. package/lib/util/execution.d.ts +2 -1
  86. package/lib/util/execution.d.ts.map +1 -1
  87. package/lib/util/execution.js +7 -2
  88. package/lib/util/execution.js.map +1 -1
  89. package/package.json +18 -18
  90. package/src/api/impl/beacon/blocks/index.ts +1 -5
  91. package/src/api/impl/errors.ts +10 -0
  92. package/src/api/rest/base.ts +4 -2
  93. package/src/chain/ColumnReconstructionTracker.ts +5 -1
  94. package/src/chain/GetBlobsTracker.ts +5 -0
  95. package/src/chain/chain.ts +5 -0
  96. package/src/chain/errors/dataColumnSidecarError.ts +8 -0
  97. package/src/chain/forkChoice/index.ts +1 -3
  98. package/src/chain/interface.ts +2 -0
  99. package/src/chain/options.ts +0 -2
  100. package/src/chain/seenCache/index.ts +1 -0
  101. package/src/chain/seenCache/seenBlockProposers.ts +12 -2
  102. package/src/chain/seenCache/seenDataColumnSidecars.ts +69 -0
  103. package/src/chain/validation/block.ts +11 -2
  104. package/src/chain/validation/dataColumnSidecar.ts +1 -1
  105. package/src/chain/validation/voluntaryExit.ts +2 -2
  106. package/src/index.ts +1 -0
  107. package/src/network/core/networkCore.ts +1 -3
  108. package/src/network/network.ts +20 -44
  109. package/src/network/options.ts +0 -2
  110. package/src/network/peers/discover.ts +42 -52
  111. package/src/network/peers/score/store.ts +1 -2
  112. package/src/network/processor/gossipHandlers.ts +107 -3
  113. package/src/util/dataColumns.ts +13 -1
  114. package/src/util/execution.ts +16 -1
@@ -36,7 +36,7 @@ import {ChainEvent, IBeaconChain} from "../chain/index.js";
36
36
  import {computeSubnetForDataColumnSidecar} from "../chain/validation/dataColumnSidecar.js";
37
37
  import {GoodByeReasonCode} from "../constants/index.js";
38
38
  import {IBeaconDb} from "../db/interface.js";
39
- import {Metrics, RegistryMetricCreator} from "../metrics/index.js";
39
+ import {Metrics} from "../metrics/index.js";
40
40
  import {IClock} from "../util/clock.js";
41
41
  import {CustodyConfig} from "../util/dataColumns.js";
42
42
  import {PeerIdStr, peerIdToString} from "../util/peerId.js";
@@ -46,7 +46,7 @@ import {
46
46
  DataColumnSidecarsByRootRequest,
47
47
  ExecutionPayloadEnvelopesByRootRequest,
48
48
  } from "../util/types.js";
49
- import {INetworkCore, NetworkCore, WorkerNetworkCore} from "./core/index.js";
49
+ import {INetworkCore, WorkerNetworkCore} from "./core/index.js";
50
50
  import {INetworkEventBus, NetworkEvent, NetworkEventBus, NetworkEventData} from "./events.js";
51
51
  import {getActiveForkBoundaries} from "./forks.js";
52
52
  import {GossipHandlers, GossipTopicMap, GossipType, GossipTypeMap} from "./gossip/index.js";
@@ -100,12 +100,7 @@ export type NetworkInitModules = {
100
100
  };
101
101
 
102
102
  /**
103
- * Must support running both on worker and on main thread.
104
- *
105
- * Exists a front class that's what consumers interact with.
106
- * This class will multiplex between:
107
- * - libp2p in worker
108
- * - libp2p in main thread
103
+ * Front class that consumers interact with. libp2p runs in a worker thread.
109
104
  */
110
105
  export class Network implements INetwork {
111
106
  readonly peerId: PeerId;
@@ -173,42 +168,23 @@ export class Network implements INetwork {
173
168
  const initialStatus = chain.getStatus();
174
169
  const initialCustodyGroupCount = chain.custodyConfig.targetCustodyGroupCount;
175
170
 
176
- if (opts.useWorker) {
177
- logger.info("running libp2p instance in worker thread");
178
- }
179
-
180
- const core = opts.useWorker
181
- ? await WorkerNetworkCore.init({
182
- opts: {
183
- ...opts,
184
- peerStoreDir,
185
- metricsEnabled: Boolean(metrics),
186
- activeValidatorCount,
187
- genesisTime: chain.genesisTime,
188
- initialStatus,
189
- initialCustodyGroupCount,
190
- },
191
- config,
192
- privateKey,
193
- logger,
194
- events,
195
- metrics,
196
- getReqRespHandler,
197
- })
198
- : await NetworkCore.init({
199
- opts,
200
- config,
201
- privateKey,
202
- peerStoreDir,
203
- logger,
204
- clock: chain.clock,
205
- events,
206
- getReqRespHandler,
207
- metricsRegistry: metrics ? new RegistryMetricCreator() : null,
208
- initialStatus,
209
- initialCustodyGroupCount,
210
- activeValidatorCount,
211
- });
171
+ const core = await WorkerNetworkCore.init({
172
+ opts: {
173
+ ...opts,
174
+ peerStoreDir,
175
+ metricsEnabled: Boolean(metrics),
176
+ activeValidatorCount,
177
+ genesisTime: chain.genesisTime,
178
+ initialStatus,
179
+ initialCustodyGroupCount,
180
+ },
181
+ config,
182
+ privateKey,
183
+ logger,
184
+ events,
185
+ metrics,
186
+ getReqRespHandler,
187
+ });
212
188
 
213
189
  const networkProcessor = new NetworkProcessor(
214
190
  {chain, db, config, logger, metrics, events, gossipHandlers, core, aggregatorTracker},
@@ -28,7 +28,6 @@ export interface NetworkOptions
28
28
  /** Include the version in libp2p Identify. Private mode takes precedence. */
29
29
  advertiseVersion?: boolean;
30
30
  private?: boolean;
31
- useWorker?: boolean;
32
31
  maxYoungGenerationSizeMb?: number;
33
32
  disableLightClientServer?: boolean;
34
33
  /**
@@ -67,7 +66,6 @@ export const defaultNetworkOptions: NetworkOptions = {
67
66
  /** disabled by default */
68
67
  discv5: null,
69
68
  rateLimitMultiplier: 1,
70
- useWorker: true,
71
69
  // set after testing before 1.19.0, see https://github.com/ChainSafe/lodestar/issues/6596
72
70
  disableFloodPublish: true,
73
71
  // default set via research in https://github.com/ChainSafe/lodestar/issues/2115
@@ -4,7 +4,7 @@ import {ENR} from "@chainsafe/enr";
4
4
  import {BeaconConfig} from "@lodestar/config";
5
5
  import {LoggerNode} from "@lodestar/logger/node";
6
6
  import {ATTESTATION_SUBNET_COUNT, ForkSeq, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params";
7
- import {CustodyIndex, SubnetID} from "@lodestar/types";
7
+ import {SubnetID} from "@lodestar/types";
8
8
  import {bytesToInt, pruneSetToMax, sleep, toHex} from "@lodestar/utils";
9
9
  import {IClock} from "../../util/clock.js";
10
10
  import {getCustodyGroups} from "../../util/dataColumns.js";
@@ -252,32 +252,22 @@ export class PeerDiscovery {
252
252
  }
253
253
  cachedENRsReverse.reverse();
254
254
 
255
- this.peersToConnect += peersToConnect;
255
+ this.peersToConnect = peersToConnect;
256
256
 
257
257
  // starting from PeerDAS, we need to prioritize column subnet peers first in order to have stable subnet sampling
258
- const groupsToDiscover = new Set<CustodyIndex>();
259
- let groupPeersToDiscover = 0;
260
-
261
- const forkSeq = this.config.getForkSeq(this.clock.currentSlot);
262
- if (forkSeq >= ForkSeq.fulu) {
263
- group: for (const [group, maxPeersToConnect] of custodyGroupRequests) {
264
- let cachedENRsInGroup = 0;
265
- for (const cachedENR of cachedENRsReverse) {
266
- if (cachedENR.custodyGroups?.includes(group)) {
267
- cachedENRsToDial.set(cachedENR.peerId.toString(), cachedENR);
268
-
269
- if (++cachedENRsInGroup >= maxPeersToConnect) {
270
- continue group;
271
- }
272
- }
273
-
274
- const groupPeersToConnect = Math.max(maxPeersToConnect - cachedENRsInGroup, 0);
275
- this.custodyGroupQueries.set(group, groupPeersToConnect);
276
- groupsToDiscover.add(group);
277
- groupPeersToDiscover += groupPeersToConnect;
258
+ this.custodyGroupQueries.clear();
259
+ if (this.config.getForkSeq(this.clock.currentSlot) >= ForkSeq.fulu) {
260
+ for (const [group, count] of custodyGroupRequests) {
261
+ if (count > 0) this.custodyGroupQueries.set(group, count);
262
+ }
263
+ for (const cachedENR of cachedENRsReverse) {
264
+ if (this.custodyGroupQueries.size === 0) break;
265
+ if (this.consumeCustodyGroupRequests(cachedENR)) {
266
+ cachedENRsToDial.set(cachedENR.peerId.toString(), cachedENR);
278
267
  }
279
268
  }
280
269
  }
270
+ const groupPeersToDiscover = Array.from(this.custodyGroupQueries.values()).reduce((sum, count) => sum + count, 0);
281
271
 
282
272
  subnet: for (const subnetRequest of subnetRequests) {
283
273
  // Get cached ENRs from the discovery service that are in the requested `subnetId`, but not connected yet
@@ -312,7 +302,7 @@ export class PeerDiscovery {
312
302
  }
313
303
 
314
304
  // If subnetRequests won't connect enough peers for peersToConnect, add more
315
- if (cachedENRsToDial.size < peersToConnect) {
305
+ if (groupPeersToDiscover === 0 && cachedENRsToDial.size < peersToConnect) {
316
306
  for (const cachedENR of cachedENRsReverse) {
317
307
  cachedENRsToDial.set(cachedENR.peerId.toString(), cachedENR);
318
308
  if (cachedENRsToDial.size >= peersToConnect) {
@@ -330,7 +320,8 @@ export class PeerDiscovery {
330
320
  }
331
321
 
332
322
  // Run a discv5 subnet query to try to discover new peers
333
- const shouldRunFindRandomNodeQuery = subnetsToDiscoverPeers.length > 0 || cachedENRsToDial.size < peersToConnect;
323
+ const shouldRunFindRandomNodeQuery =
324
+ groupPeersToDiscover > 0 || subnetsToDiscoverPeers.length > 0 || cachedENRsToDial.size < peersToConnect;
334
325
  if (shouldRunFindRandomNodeQuery) {
335
326
  void this.runFindRandomNodeQuery();
336
327
  }
@@ -339,7 +330,7 @@ export class PeerDiscovery {
339
330
  peersToConnect,
340
331
  peersAvailableToDial: cachedENRsToDial.size,
341
332
  subnetsToDiscover: subnetsToDiscoverPeers.length,
342
- groupsToDiscover: Array.from(groupsToDiscover).join(","),
333
+ groupsToDiscover: Array.from(this.custodyGroupQueries.keys()).join(","),
343
334
  groupPeersToDiscover,
344
335
  shouldRunFindRandomNodeQuery,
345
336
  });
@@ -411,7 +402,14 @@ export class PeerDiscovery {
411
402
  if (this.randomNodeQuery.code === QueryStatusCode.Active) {
412
403
  this.randomNodeQuery.count++;
413
404
  }
414
- const peerId = enr.peerId;
405
+ let peerId: PeerId;
406
+ try {
407
+ peerId = enr.peerId;
408
+ } catch (e) {
409
+ this.logger.debug("Discovered ENR with invalid public key", {nodeId: enr.nodeId}, e as Error);
410
+ this.metrics?.discovery.discoveredStatus.inc({status: DiscoveredPeerStatus.error});
411
+ return;
412
+ }
415
413
  // At least one transport is known to be present, checked inside the worker
416
414
  const multiaddrTCP = enr.getLocationMultiaddr(ENRKey.tcp);
417
415
  const multiaddrQUIC = enr.getLocationMultiaddr(ENRKey.quic);
@@ -530,32 +528,24 @@ export class PeerDiscovery {
530
528
  }
531
529
  }
532
530
 
533
- private shouldDialPeer(peer: CachedENR): boolean {
534
- const forkSeq = this.config.getForkSeq(this.clock.currentSlot);
535
- if (forkSeq >= ForkSeq.fulu && peer.custodyGroups !== null) {
536
- // pre-fulu `this.custodyGroupQueries` is empty
537
- // starting from fulu, we need to make sure we have stable subnet sampling peers first
538
- // given SAMPLES_PER_SLOT = 8 and 100 peers, we have 800 custody columns from peers
539
- // with NUMBER_OF_CUSTODY_GROUPS = 128, we have 800 / 128 = 6.25 peers per column in average
540
- // it would not be hard to find TARGET_SUBNET_PEERS(6) peers per sampling columns columns and TARGET_GROUP_PEERS_PER_SUBNET(4) peers per non-sampling columns
541
- // after some first heartbeats, we should have no more column requested, then go with conditions of prior forks
542
- let hasMatchingGroup = false;
543
- let custodyGroupRequestCount = 0;
544
- for (const [group, peersToConnect] of this.custodyGroupQueries.entries()) {
545
- if (peersToConnect <= 0) {
546
- this.custodyGroupQueries.delete(group);
547
- } else if (peer.custodyGroups.includes(group)) {
548
- this.custodyGroupQueries.set(group, Math.max(0, peersToConnect - 1));
549
- hasMatchingGroup = true;
550
- custodyGroupRequestCount += peersToConnect;
551
- }
552
- }
531
+ private consumeCustodyGroupRequests(peer: CachedENR): boolean {
532
+ let matched = false;
533
+ for (const group of peer.custodyGroups ?? []) {
534
+ const remaining = this.custodyGroupQueries.get(group);
535
+ if (remaining === undefined) continue;
553
536
 
554
- // if subnet sampling peers are not stable and this peer is not in the requested columns, ignore it
555
- if (custodyGroupRequestCount > 0 && !hasMatchingGroup) {
556
- this.metrics?.discovery.notDialReason.inc({reason: NotDialReason.not_contain_requested_sampling_groups});
557
- return false;
558
- }
537
+ if (remaining === 1) this.custodyGroupQueries.delete(group);
538
+ else this.custodyGroupQueries.set(group, remaining - 1);
539
+ matched = true;
540
+ }
541
+ return matched;
542
+ }
543
+
544
+ private shouldDialPeer(peer: CachedENR): boolean {
545
+ const needsCustodyPeers = this.custodyGroupQueries.size > 0;
546
+ if (needsCustodyPeers && !this.consumeCustodyGroupRequests(peer)) {
547
+ this.metrics?.discovery.notDialReason.inc({reason: NotDialReason.not_contain_requested_sampling_groups});
548
+ return false;
559
549
  }
560
550
 
561
551
  // logics up to Deneb fork
@@ -580,7 +570,7 @@ export class PeerDiscovery {
580
570
  // ideally we may want to leave this cheap condition at the top of the function
581
571
  // however we want to also update peersToConnect in this.subnetRequests
582
572
  // the this.subnetRequests[type] gradually has 0 subnet so this function should be cheap enough
583
- if (this.peersToConnect > 0) {
573
+ if (needsCustodyPeers || this.peersToConnect > 0) {
584
574
  return true;
585
575
  }
586
576
 
@@ -85,8 +85,7 @@ export class PeerRpcScoreStore implements IPeerRpcScoreStore {
85
85
  for (const [peerIdStr, peerScore] of this.scores) {
86
86
  const newScore = peerScore.update();
87
87
 
88
- // Prune scores below threshold
89
- if (Math.abs(newScore) < SCORE_THRESHOLD) {
88
+ if (Math.abs(newScore) < SCORE_THRESHOLD && !peerScore.isCoolingDown()) {
90
89
  this.scores.delete(peerIdStr);
91
90
  }
92
91
  }
@@ -12,7 +12,11 @@ import {
12
12
  isForkPostElectra,
13
13
  isForkPostGloas,
14
14
  } from "@lodestar/params";
15
- import {computeTimeAtSlot, signedBlockToSignedHeader} from "@lodestar/state-transition";
15
+ import {
16
+ computeTimeAtSlot,
17
+ getBlockHeaderProposerSignatureSetByHeaderSlot,
18
+ signedBlockToSignedHeader,
19
+ } from "@lodestar/state-transition";
16
20
  import {
17
21
  Root,
18
22
  RootHex,
@@ -25,6 +29,7 @@ import {
25
29
  gloas,
26
30
  isGloasBeaconBlock,
27
31
  isGloasDataColumnSidecar,
32
+ phase0,
28
33
  ssz,
29
34
  sszTypesFor,
30
35
  } from "@lodestar/types";
@@ -380,6 +385,28 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
380
385
  }
381
386
  }
382
387
 
388
+ // The block input may have been pruned before the block was imported
389
+ if (
390
+ chain.seenDataColumnSidecars.isKnown(
391
+ slot,
392
+ dataColumnBlockHeader.proposerIndex,
393
+ dataColumnSidecar.index,
394
+ blockRootHex
395
+ )
396
+ ) {
397
+ metrics?.peerDas.dataColumnSidecarProcessingSkip.inc();
398
+ throw new DataColumnSidecarGossipError(GossipAction.IGNORE, {
399
+ code: DataColumnSidecarErrorCode.ALREADY_KNOWN,
400
+ columnIndex: dataColumnSidecar.index,
401
+ slot,
402
+ });
403
+ }
404
+
405
+ if (isRepeatColumnProposal(chain, dataColumnSidecar, blockRootHex)) {
406
+ await observeRepeatColumnProposal(chain, dataColumnSidecar, blockRootHex);
407
+ throw repeatColumnProposalError(dataColumnSidecar, blockRootHex);
408
+ }
409
+
383
410
  const verificationTimer = metrics?.peerDas.dataColumnSidecarGossipVerificationTime.startTimer();
384
411
 
385
412
  const delaySec = chain.clock.secFromSlot(slot, seenTimestampSec);
@@ -388,6 +415,17 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
388
415
 
389
416
  try {
390
417
  await validateGossipFuluDataColumnSidecar(chain, dataColumnSidecar, gossipSubnet, metrics);
418
+ observeColumnBlockHeader(chain, dataColumnSidecar.signedBlockHeader, blockRootHex);
419
+ // Another block root may have been seen for the same tuple while validating
420
+ if (isRepeatColumnProposal(chain, dataColumnSidecar, blockRootHex)) {
421
+ throw repeatColumnProposalError(dataColumnSidecar, blockRootHex);
422
+ }
423
+ chain.seenDataColumnSidecars.add(
424
+ slot,
425
+ dataColumnBlockHeader.proposerIndex,
426
+ dataColumnSidecar.index,
427
+ blockRootHex
428
+ );
391
429
  const blockInput = chain.seenBlockInputCache.getByColumn({
392
430
  blockRootHex,
393
431
  columnSidecar: dataColumnSidecar,
@@ -697,7 +735,7 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
697
735
  const signedBlock = sszDeserialize(topic, serializedData);
698
736
  try {
699
737
  const blockInput = await validateBeaconBlock(signedBlock, topic.boundary.fork, peerIdStr, seenTimestampSec);
700
- // Runs after the validation result is reported, except with `network.useWorker: false`
738
+ // Runs after the validation result is reported
701
739
  callAfterIO(() => {
702
740
  try {
703
741
  chain.serializedCache.set(signedBlock, serializedData);
@@ -719,7 +757,12 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
719
757
  e.type.code === BlockErrorCode.REPEAT_PROPOSAL &&
720
758
  // Only a signature-verified sibling recorded in the seen cache is imported. The cache holds at most two
721
759
  // roots per proposer and slot, which bounds full imports over gossip to one alternate
722
- chain.seenBlockProposers.hasBlockRoot(signedBlock.message.slot, e.type.proposerIndex, e.type.root) &&
760
+ chain.seenBlockProposers.hasBlockSignature(
761
+ signedBlock.message.slot,
762
+ e.type.proposerIndex,
763
+ e.type.root,
764
+ signedBlock.signature
765
+ ) &&
723
766
  // A sibling with an unknown parent cannot be imported, sync fetches it if its branch becomes relevant
724
767
  chain.forkChoice.getBlockHexDefaultStatus(toRootHex(signedBlock.message.parentRoot)) !== null &&
725
768
  (!isGloasBeaconBlock(signedBlock.message) ||
@@ -1663,3 +1706,64 @@ function getCutoffTimeMs(
1663
1706
  0
1664
1707
  );
1665
1708
  }
1709
+
1710
+ /**
1711
+ * [IGNORE] The sidecar is the first sidecar for the tuple (block_header.slot, block_header.proposer_index, sidecar.index)
1712
+ * with valid header signature, sidecar inclusion proof, and kzg proof
1713
+ */
1714
+ function isRepeatColumnProposal(
1715
+ chain: IBeaconChain,
1716
+ dataColumnSidecar: fulu.DataColumnSidecar,
1717
+ blockRootHex: RootHex
1718
+ ): boolean {
1719
+ const {slot, proposerIndex} = dataColumnSidecar.signedBlockHeader.message;
1720
+ return chain.seenDataColumnSidecars.isRepeatProposal(slot, proposerIndex, dataColumnSidecar.index, blockRootHex);
1721
+ }
1722
+
1723
+ function repeatColumnProposalError(
1724
+ dataColumnSidecar: fulu.DataColumnSidecar,
1725
+ blockRootHex: RootHex
1726
+ ): DataColumnSidecarGossipError {
1727
+ const {slot, proposerIndex} = dataColumnSidecar.signedBlockHeader.message;
1728
+ return new DataColumnSidecarGossipError(GossipAction.IGNORE, {
1729
+ code: DataColumnSidecarErrorCode.REPEAT_PROPOSAL,
1730
+ slot,
1731
+ proposerIndex,
1732
+ columnIndex: dataColumnSidecar.index,
1733
+ root: blockRootHex,
1734
+ });
1735
+ }
1736
+
1737
+ function observeColumnBlockHeader(
1738
+ chain: IBeaconChain,
1739
+ signedBlockHeader: phase0.SignedBeaconBlockHeader,
1740
+ blockRootHex: RootHex
1741
+ ): void {
1742
+ const {slot, proposerIndex} = signedBlockHeader.message;
1743
+ chain.seenBlockProposers.observeBlockRoot(slot, proposerIndex, blockRootHex, signedBlockHeader);
1744
+ if (chain.seenBlockProposers.isEquivocating(slot, proposerIndex)) {
1745
+ chain.processProposerEquivocation(slot, proposerIndex);
1746
+ }
1747
+ }
1748
+
1749
+ async function observeRepeatColumnProposal(
1750
+ chain: IBeaconChain,
1751
+ dataColumnSidecar: fulu.DataColumnSidecar,
1752
+ blockRootHex: RootHex
1753
+ ): Promise<void> {
1754
+ const {signedBlockHeader} = dataColumnSidecar;
1755
+ const {slot, proposerIndex} = signedBlockHeader.message;
1756
+ // Only needed as slashing evidence, so verify at most one conflicting header per slot and proposer
1757
+ if (
1758
+ chain.seenBlockProposers.hasBlockRoot(slot, proposerIndex, blockRootHex) ||
1759
+ chain.seenBlockProposers.isEquivocating(slot, proposerIndex) ||
1760
+ !chain.seenDataColumnSidecars.markEvidenceCheck(slot, proposerIndex)
1761
+ ) {
1762
+ return;
1763
+ }
1764
+
1765
+ const signatureSet = getBlockHeaderProposerSignatureSetByHeaderSlot(chain.config, signedBlockHeader);
1766
+ if (await chain.bls.verifySignatureSets([signatureSet])) {
1767
+ observeColumnBlockHeader(chain, signedBlockHeader, blockRootHex);
1768
+ }
1769
+ }
@@ -33,6 +33,7 @@ import {BlockInputColumns} from "../chain/blocks/blockInput/blockInput.js";
33
33
  import {BlockInputSource} from "../chain/blocks/blockInput/types.js";
34
34
  import {PayloadEnvelopeInput, PayloadEnvelopeInputSource} from "../chain/blocks/payloadEnvelopeInput/index.js";
35
35
  import {ChainEvent, ChainEventEmitter} from "../chain/emitter.js";
36
+ import {SeenDataColumnSidecars} from "../chain/seenCache/seenDataColumnSidecars.js";
36
37
  import {Metrics} from "../metrics/metrics.js";
37
38
  import {NodeId} from "../network/subnets/index.js";
38
39
  import {dataColumnMatrixRecovery} from "./blobs.js";
@@ -434,6 +435,7 @@ export function getGloasDataColumnSidecars(
434
435
  export async function recoverDataColumnSidecars(
435
436
  input: BlockInputColumns | PayloadEnvelopeInput,
436
437
  emitter: ChainEventEmitter,
438
+ seenDataColumnSidecars: SeenDataColumnSidecars,
437
439
  metrics: Metrics | null
438
440
  ): Promise<DataColumnReconstructionCode> {
439
441
  const existingColumns = input.getAllColumns();
@@ -486,6 +488,7 @@ export async function recoverDataColumnSidecars(
486
488
  const sidecarsToPublish: DataColumnSidecar[] = [];
487
489
  for (const columnSidecar of fullSidecars) {
488
490
  if (!input.hasColumn(columnSidecar.index)) {
491
+ let isRepeatProposal = false;
489
492
  if (input instanceof PayloadEnvelopeInput) {
490
493
  if (!isGloasDataColumnSidecar(columnSidecar)) {
491
494
  throw new Error(`Expected gloas DataColumnSidecar for block ${input.blockRootHex}`);
@@ -505,9 +508,18 @@ export async function recoverDataColumnSidecars(
505
508
  seenTimestampSec: Date.now() / 1000,
506
509
  source: BlockInputSource.recovery,
507
510
  });
511
+ // Reconstructed columns count as received via gossip for the repeat proposal check
512
+ const {slot, proposerIndex} = columnSidecar.signedBlockHeader.message;
513
+ isRepeatProposal = seenDataColumnSidecars.isRepeatProposal(
514
+ slot,
515
+ proposerIndex,
516
+ columnSidecar.index,
517
+ input.blockRootHex
518
+ );
519
+ seenDataColumnSidecars.add(slot, proposerIndex, columnSidecar.index, input.blockRootHex);
508
520
  }
509
521
  sidecarsReconstructed.push(columnSidecar);
510
- if (missingSampledColumns.has(columnSidecar.index)) {
522
+ if (missingSampledColumns.has(columnSidecar.index) && !isRepeatProposal) {
511
523
  sidecarsToPublish.push(columnSidecar);
512
524
  }
513
525
  }
@@ -11,6 +11,7 @@ import {
11
11
  EnvelopeReconstructionError,
12
12
  EnvelopeReconstructionErrorCode,
13
13
  } from "../chain/errors/envelopeReconstructionError.js";
14
+ import {SeenDataColumnSidecars} from "../chain/seenCache/seenDataColumnSidecars.js";
14
15
  import {IBeaconDb} from "../db/index.js";
15
16
  import {ArchivedEnvelope, decodeArchivedEnvelope} from "../db/repositories/index.js";
16
17
  import {IExecutionEngine} from "../execution/index.js";
@@ -48,6 +49,7 @@ export async function getDataColumnSidecarsFromExecution(
48
49
  config: ChainForkConfig,
49
50
  executionEngine: Pick<IExecutionEngine, "getBlobs">,
50
51
  emitter: ChainEventEmitter,
52
+ seenDataColumnSidecars: SeenDataColumnSidecars,
51
53
  input: IBlockInput | PayloadEnvelopeInput,
52
54
  metrics: Metrics | null,
53
55
  blobAndProofBuffers?: Uint8Array[]
@@ -112,8 +114,18 @@ export async function getDataColumnSidecarsFromExecution(
112
114
  const previouslyMissingColumns = input.getMissingSampledColumnMeta().missing;
113
115
  const sampledColumns = previouslyMissingColumns.map((columnIndex) => dataColumnSidecars[columnIndex]);
114
116
 
117
+ const columnsToPublish = sampledColumns.filter(
118
+ (columnSidecar) =>
119
+ isGloasDataColumnSidecar(columnSidecar) ||
120
+ !seenDataColumnSidecars.isRepeatProposal(
121
+ columnSidecar.signedBlockHeader.message.slot,
122
+ columnSidecar.signedBlockHeader.message.proposerIndex,
123
+ columnSidecar.index,
124
+ input.blockRootHex
125
+ )
126
+ );
115
127
  // for columns we have already seen, publishDataColumnSidecar() catches PublishError.Duplicate and marks alreadyPublished=true
116
- emitter.emit(ChainEvent.publishDataColumns, sampledColumns);
128
+ emitter.emit(ChainEvent.publishDataColumns, columnsToPublish);
117
129
  // TODO: Can we record dataColumns.sentPeersPerSubnet metric here somehow
118
130
 
119
131
  // add all sampled columns to the input, even if we didn't sample them
@@ -145,6 +157,9 @@ export async function getDataColumnSidecarsFromExecution(
145
157
  source: BlockInputSource.engine,
146
158
  seenTimestampSec,
147
159
  });
160
+ // Columns from the execution layer count as received via gossip for the repeat proposal check
161
+ const {slot, proposerIndex} = columnSidecar.signedBlockHeader.message;
162
+ seenDataColumnSidecars.add(slot, proposerIndex, columnSidecar.index, input.blockRootHex);
148
163
  }
149
164
 
150
165
  if (emitter.listenerCount(routes.events.EventType.dataColumnSidecar)) {