@lodestar/beacon-node 2.1.0-dev.a6c4b2f428 → 2.1.0-dev.b091dc24a3

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 (132) 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/beacon/pool/index.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/pool/index.js +8 -0
  6. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  7. package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
  8. package/lib/api/impl/beacon/state/index.js +3 -2
  9. package/lib/api/impl/beacon/state/index.js.map +1 -1
  10. package/lib/api/impl/beacon/state/utils.js +1 -1
  11. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  12. package/lib/api/impl/validator/index.js +1 -1
  13. package/lib/api/impl/validator/index.js.map +1 -1
  14. package/lib/chain/ColumnReconstructionTracker.d.ts +3 -0
  15. package/lib/chain/ColumnReconstructionTracker.d.ts.map +1 -1
  16. package/lib/chain/ColumnReconstructionTracker.js +3 -1
  17. package/lib/chain/ColumnReconstructionTracker.js.map +1 -1
  18. package/lib/chain/GetBlobsTracker.d.ts +3 -0
  19. package/lib/chain/GetBlobsTracker.d.ts.map +1 -1
  20. package/lib/chain/GetBlobsTracker.js +3 -1
  21. package/lib/chain/GetBlobsTracker.js.map +1 -1
  22. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +2 -1
  23. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
  24. package/lib/chain/chain.d.ts +2 -1
  25. package/lib/chain/chain.d.ts.map +1 -1
  26. package/lib/chain/chain.js +16 -5
  27. package/lib/chain/chain.js.map +1 -1
  28. package/lib/chain/errors/dataColumnSidecarError.d.ts +7 -0
  29. package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
  30. package/lib/chain/errors/dataColumnSidecarError.js +1 -0
  31. package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
  32. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  33. package/lib/chain/forkChoice/index.js +18 -10
  34. package/lib/chain/forkChoice/index.js.map +1 -1
  35. package/lib/chain/interface.d.ts +2 -1
  36. package/lib/chain/interface.d.ts.map +1 -1
  37. package/lib/chain/interface.js.map +1 -1
  38. package/lib/chain/seenCache/index.d.ts +1 -0
  39. package/lib/chain/seenCache/index.d.ts.map +1 -1
  40. package/lib/chain/seenCache/index.js +1 -0
  41. package/lib/chain/seenCache/index.js.map +1 -1
  42. package/lib/chain/seenCache/seenBlockProposers.d.ts +1 -0
  43. package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -1
  44. package/lib/chain/seenCache/seenBlockProposers.js +5 -1
  45. package/lib/chain/seenCache/seenBlockProposers.js.map +1 -1
  46. package/lib/chain/seenCache/seenDataColumnSidecars.d.ts +16 -0
  47. package/lib/chain/seenCache/seenDataColumnSidecars.d.ts.map +1 -0
  48. package/lib/chain/seenCache/seenDataColumnSidecars.js +56 -0
  49. package/lib/chain/seenCache/seenDataColumnSidecars.js.map +1 -0
  50. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +11 -2
  51. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
  52. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +28 -2
  53. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
  54. package/lib/chain/validation/attestation.d.ts.map +1 -1
  55. package/lib/chain/validation/attestation.js +4 -2
  56. package/lib/chain/validation/attestation.js.map +1 -1
  57. package/lib/chain/validation/block.d.ts.map +1 -1
  58. package/lib/chain/validation/block.js +12 -2
  59. package/lib/chain/validation/block.js.map +1 -1
  60. package/lib/chain/validation/dataColumnSidecar.js +1 -1
  61. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  62. package/lib/network/forks.d.ts +2 -2
  63. package/lib/network/forks.d.ts.map +1 -1
  64. package/lib/network/forks.js +3 -3
  65. package/lib/network/forks.js.map +1 -1
  66. package/lib/network/gossip/scoringParameters.js +19 -14
  67. package/lib/network/gossip/scoringParameters.js.map +1 -1
  68. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  69. package/lib/network/processor/gossipHandlers.js +75 -9
  70. package/lib/network/processor/gossipHandlers.js.map +1 -1
  71. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
  72. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +3 -1
  73. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  74. package/lib/sync/range/chain.d.ts.map +1 -1
  75. package/lib/sync/range/chain.js +1 -0
  76. package/lib/sync/range/chain.js.map +1 -1
  77. package/lib/sync/range/range.d.ts.map +1 -1
  78. package/lib/sync/range/range.js +5 -1
  79. package/lib/sync/range/range.js.map +1 -1
  80. package/lib/sync/unknownBlock.d.ts.map +1 -1
  81. package/lib/sync/unknownBlock.js +14 -1
  82. package/lib/sync/unknownBlock.js.map +1 -1
  83. package/lib/sync/utils/downloadByRange.d.ts +6 -0
  84. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  85. package/lib/sync/utils/downloadByRange.js +17 -8
  86. package/lib/sync/utils/downloadByRange.js.map +1 -1
  87. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  88. package/lib/sync/utils/downloadByRoot.js +1 -1
  89. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  90. package/lib/sync/utils/pendingBlocksTree.d.ts.map +1 -1
  91. package/lib/sync/utils/pendingBlocksTree.js +6 -1
  92. package/lib/sync/utils/pendingBlocksTree.js.map +1 -1
  93. package/lib/util/dataColumns.d.ts +2 -1
  94. package/lib/util/dataColumns.d.ts.map +1 -1
  95. package/lib/util/dataColumns.js +7 -2
  96. package/lib/util/dataColumns.js.map +1 -1
  97. package/lib/util/execution.d.ts +2 -1
  98. package/lib/util/execution.d.ts.map +1 -1
  99. package/lib/util/execution.js +7 -2
  100. package/lib/util/execution.js.map +1 -1
  101. package/package.json +16 -19
  102. package/src/api/impl/beacon/blocks/index.ts +1 -5
  103. package/src/api/impl/beacon/pool/index.ts +11 -0
  104. package/src/api/impl/beacon/state/index.ts +3 -7
  105. package/src/api/impl/beacon/state/utils.ts +1 -1
  106. package/src/api/impl/validator/index.ts +1 -1
  107. package/src/chain/ColumnReconstructionTracker.ts +5 -1
  108. package/src/chain/GetBlobsTracker.ts +5 -0
  109. package/src/chain/blocks/payloadEnvelopeInput/types.ts +8 -1
  110. package/src/chain/chain.ts +21 -4
  111. package/src/chain/errors/dataColumnSidecarError.ts +8 -0
  112. package/src/chain/forkChoice/index.ts +18 -10
  113. package/src/chain/interface.ts +2 -0
  114. package/src/chain/seenCache/index.ts +1 -0
  115. package/src/chain/seenCache/seenBlockProposers.ts +11 -1
  116. package/src/chain/seenCache/seenDataColumnSidecars.ts +64 -0
  117. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +28 -2
  118. package/src/chain/validation/attestation.ts +4 -2
  119. package/src/chain/validation/block.ts +11 -2
  120. package/src/chain/validation/dataColumnSidecar.ts +1 -1
  121. package/src/network/forks.ts +7 -3
  122. package/src/network/gossip/scoringParameters.ts +23 -14
  123. package/src/network/processor/gossipHandlers.ts +134 -17
  124. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +4 -1
  125. package/src/sync/range/chain.ts +1 -0
  126. package/src/sync/range/range.ts +7 -1
  127. package/src/sync/unknownBlock.ts +20 -1
  128. package/src/sync/utils/downloadByRange.ts +30 -7
  129. package/src/sync/utils/downloadByRoot.ts +12 -9
  130. package/src/sync/utils/pendingBlocksTree.ts +6 -1
  131. package/src/util/dataColumns.ts +13 -1
  132. package/src/util/execution.ts +16 -1
@@ -542,11 +542,7 @@ export function getBeaconBlockApi(
542
542
  })
543
543
  );
544
544
  return {
545
- data: result.filter(
546
- (item) =>
547
- // skip if no slot filter
548
- !(slot !== undefined && slot !== 0) || item.header.message.slot === slot
549
- ),
545
+ data: result.filter((item) => slot === undefined || item.header.message.slot === slot),
550
546
  meta: {executionOptimistic, finalized},
551
547
  };
552
548
  }
@@ -200,12 +200,23 @@ export function getBeaconPoolApi({
200
200
  const verifiedDomains = await validateApiAttesterSlashing(chain, attesterSlashing);
201
201
  const fork = chain.config.getForkName(Number(attesterSlashing.attestation1.data.slot));
202
202
  chain.opPool.insertAttesterSlashing(fork, attesterSlashing, verifiedDomains);
203
+ try {
204
+ chain.forkChoice.onAttesterSlashing(attesterSlashing);
205
+ } catch (e) {
206
+ logger.warn(
207
+ "Error processing AttesterSlashing from api",
208
+ {slot: attesterSlashing.attestation1.data.slot},
209
+ e as Error
210
+ );
211
+ }
212
+ chain.emitter.emit(routes.events.EventType.attesterSlashing, attesterSlashing);
203
213
  await network.publishAttesterSlashing(attesterSlashing);
204
214
  },
205
215
 
206
216
  async submitPoolProposerSlashings({proposerSlashing}) {
207
217
  const verifiedDomain = await validateApiProposerSlashing(chain, proposerSlashing);
208
218
  chain.opPool.insertProposerSlashing(proposerSlashing, verifiedDomain);
219
+ chain.emitter.emit(routes.events.EventType.proposerSlashing, proposerSlashing);
209
220
  await network.publishProposerSlashing(proposerSlashing);
210
221
  },
211
222
 
@@ -114,16 +114,12 @@ export function getBeaconStateApi({
114
114
  if (resp.valid) {
115
115
  const validatorIndex = resp.validatorIndex;
116
116
  const validator = state.getValidator(validatorIndex);
117
- const status = getValidatorStatus(validator, currentEpoch);
117
+ const balance = state.getBalance(validatorIndex);
118
+ const status = getValidatorStatus(validator, balance, currentEpoch);
118
119
  if (statuses.length && !statuses.includes(status) && !statuses.includes(mapToGeneralStatus(status))) {
119
120
  continue;
120
121
  }
121
- const validatorResponse = toValidatorResponse(
122
- validatorIndex,
123
- validator,
124
- state.getBalance(validatorIndex),
125
- currentEpoch
126
- );
122
+ const validatorResponse = toValidatorResponse(validatorIndex, validator, balance, currentEpoch);
127
123
  validatorResponses.push(validatorResponse);
128
124
  }
129
125
  }
@@ -109,7 +109,7 @@ export function toValidatorResponse(
109
109
  ): routes.beacon.ValidatorResponse {
110
110
  return {
111
111
  index,
112
- status: getValidatorStatus(validator, currentEpoch),
112
+ status: getValidatorStatus(validator, balance, currentEpoch),
113
113
  balance,
114
114
  validator,
115
115
  };
@@ -2174,7 +2174,7 @@ export function getValidatorApi(
2174
2174
  if (validatorIndex === null || validatorIndex >= headState.validatorCount) return false;
2175
2175
 
2176
2176
  const validator = headState.getValidator(validatorIndex);
2177
- const status = getValidatorStatus(validator, currentEpoch);
2177
+ const status = getValidatorStatus(validator, headState.getBalance(validatorIndex), currentEpoch);
2178
2178
  return (
2179
2179
  status === "active_exiting" ||
2180
2180
  status === "active_ongoing" ||
@@ -8,6 +8,7 @@ import {JobItemQueue} from "../util/queue/index.js";
8
8
  import {BlockInputColumns} from "./blocks/blockInput/index.js";
9
9
  import {PayloadEnvelopeInput} from "./blocks/payloadEnvelopeInput/index.js";
10
10
  import {ChainEventEmitter} from "./emitter.js";
11
+ import {SeenDataColumnSidecars} from "./seenCache/seenDataColumnSidecars.js";
11
12
 
12
13
  /**
13
14
  * Minimum time to wait before attempting reconstruction
@@ -31,6 +32,7 @@ export type ColumnReconstructionInput = BlockInputColumns | PayloadEnvelopeInput
31
32
  export type ColumnReconstructionTrackerInit = {
32
33
  logger: Logger;
33
34
  emitter: ChainEventEmitter;
35
+ seenDataColumnSidecars: SeenDataColumnSidecars;
34
36
  metrics: Metrics | null;
35
37
  config: ChainForkConfig;
36
38
  signal: AbortSignal;
@@ -44,6 +46,7 @@ export type ColumnReconstructionTrackerInit = {
44
46
  export class ColumnReconstructionTracker {
45
47
  logger: Logger;
46
48
  emitter: ChainEventEmitter;
49
+ seenDataColumnSidecars: SeenDataColumnSidecars;
47
50
  metrics: Metrics | null;
48
51
  config: ChainForkConfig;
49
52
 
@@ -54,6 +57,7 @@ export class ColumnReconstructionTracker {
54
57
  constructor(init: ColumnReconstructionTrackerInit) {
55
58
  this.logger = init.logger;
56
59
  this.emitter = init.emitter;
60
+ this.seenDataColumnSidecars = init.seenDataColumnSidecars;
57
61
  this.metrics = init.metrics;
58
62
  this.config = init.config;
59
63
  this.signal = init.signal;
@@ -104,7 +108,7 @@ export class ColumnReconstructionTracker {
104
108
  const logCtx = {slot: input.slot, root: input.blockRootHex};
105
109
  this.logger.debug("Attempting data column sidecar reconstruction", logCtx);
106
110
  try {
107
- const result = await recoverDataColumnSidecars(input, this.emitter, this.metrics);
111
+ const result = await recoverDataColumnSidecars(input, this.emitter, this.seenDataColumnSidecars, this.metrics);
108
112
  this.metrics?.recoverDataColumnSidecars.reconstructionResult.inc({result});
109
113
  this.logger.debug("Data column sidecar reconstruction complete", {...logCtx, result});
110
114
  } catch (e) {
@@ -8,6 +8,7 @@ import {DataColumnEngineResult, getDataColumnSidecarsFromExecution} from "../uti
8
8
  import {IBlockInput, isBlockInputColumns} from "./blocks/blockInput/index.js";
9
9
  import {PayloadEnvelopeInput} from "./blocks/payloadEnvelopeInput/index.js";
10
10
  import {ChainEventEmitter} from "./emitter.js";
11
+ import {SeenDataColumnSidecars} from "./seenCache/seenDataColumnSidecars.js";
11
12
 
12
13
  /** A `null` answer only changes if the EL receives the transactions later, so retries are few and spaced out */
13
14
  export const MAX_GET_BLOBS_ATTEMPTS = 3;
@@ -18,6 +19,7 @@ export type GetBlobsTrackerInit = {
18
19
  logger: Logger;
19
20
  executionEngine: Pick<IExecutionEngine, "getBlobs">;
20
21
  emitter: ChainEventEmitter;
22
+ seenDataColumnSidecars: SeenDataColumnSidecars;
21
23
  metrics: Metrics | null;
22
24
  config: ChainForkConfig;
23
25
  };
@@ -29,6 +31,7 @@ export class GetBlobsTracker {
29
31
  logger: Logger;
30
32
  executionEngine: Pick<IExecutionEngine, "getBlobs">;
31
33
  emitter: ChainEventEmitter;
34
+ seenDataColumnSidecars: SeenDataColumnSidecars;
32
35
  metrics: Metrics | null;
33
36
  config: ChainForkConfig;
34
37
  activeReconstructions = new Set<string>();
@@ -42,6 +45,7 @@ export class GetBlobsTracker {
42
45
  this.logger = init.logger;
43
46
  this.executionEngine = init.executionEngine;
44
47
  this.emitter = init.emitter;
48
+ this.seenDataColumnSidecars = init.seenDataColumnSidecars;
45
49
  this.metrics = init.metrics;
46
50
  this.config = init.config;
47
51
  }
@@ -101,6 +105,7 @@ export class GetBlobsTracker {
101
105
  this.config,
102
106
  this.executionEngine,
103
107
  this.emitter,
108
+ this.seenDataColumnSidecars,
104
109
  input,
105
110
  this.metrics,
106
111
  this.blobsAndProofsBuffers[freeIndex].buffers
@@ -22,9 +22,16 @@ export enum PayloadEnvelopeInputSource {
22
22
  * - finalized: below the finalized slot
23
23
  * - prune: explicit prune by root
24
24
  * - cap: insertion-order backstop cap (MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE)
25
+ * - capUnvalidated: cap eviction of an entry whose block is not validated and imported yet, evicted before the rest
25
26
  * - invalid: the cached envelope failed import with a definitive invalid verdict
26
27
  */
27
- export type PayloadEnvelopeInputPruneReason = "belowParent" | "finalized" | "remove" | "cap" | "invalid";
28
+ export type PayloadEnvelopeInputPruneReason =
29
+ | "belowParent"
30
+ | "finalized"
31
+ | "remove"
32
+ | "cap"
33
+ | "capUnvalidated"
34
+ | "invalid";
28
35
 
29
36
  export type SourceMeta = {
30
37
  source: PayloadEnvelopeInputSource;
@@ -127,6 +127,7 @@ import {
127
127
  SeenAttesters,
128
128
  SeenBlockProposers,
129
129
  SeenContributionAndProof,
130
+ SeenDataColumnSidecars,
130
131
  SeenExecutionPayloadBids,
131
132
  SeenPayloadAttesters,
132
133
  SeenPayloadEnvelopeInput,
@@ -224,6 +225,7 @@ export class BeaconChain implements IBeaconChain {
224
225
  readonly seenAggregatedAttestations: SeenAggregatedAttestations;
225
226
  readonly seenExecutionPayloadBids = new SeenExecutionPayloadBids();
226
227
  readonly seenBlockProposers = new SeenBlockProposers();
228
+ readonly seenDataColumnSidecars = new SeenDataColumnSidecars();
227
229
  /** Proposer indexes with an in-flight proposer slashing production */
228
230
  private readonly producingProposerSlashing = new Set<ValidatorIndex>();
229
231
  readonly seenSyncCommitteeMessages = new SeenSyncCommitteeMessages();
@@ -501,12 +503,14 @@ export class BeaconChain implements IBeaconChain {
501
503
  });
502
504
 
503
505
  const anchorBlockSlot = anchorState.latestBlockHeader.slot;
504
- if (isStatePostGloas(anchorState) && anchorBlockSlot > 0) {
506
+ const anchorBlockFork = config.getForkName(anchorBlockSlot);
507
+ // A pre-Gloas anchor in a state upgraded to Gloas carried its own payload, no envelope follows it
508
+ if (isStatePostGloas(anchorState) && anchorBlockSlot > 0 && isForkPostGloas(anchorBlockFork)) {
505
509
  const anchorBid = anchorState.latestExecutionPayloadBid;
506
510
  this.seenPayloadEnvelopeInputCache.addFromBid({
507
511
  blockRootHex: toRootHex(checkpoint.root),
508
512
  slot: anchorBlockSlot,
509
- forkName: anchorState.forkName,
513
+ forkName: anchorBlockFork,
510
514
  proposerIndex: anchorState.latestBlockHeader.proposerIndex,
511
515
  bid: anchorBid,
512
516
  sampledColumns: this.custodyConfig.sampledColumns,
@@ -525,12 +529,14 @@ export class BeaconChain implements IBeaconChain {
525
529
  logger,
526
530
  executionEngine: this.executionEngine,
527
531
  emitter,
532
+ seenDataColumnSidecars: this.seenDataColumnSidecars,
528
533
  metrics,
529
534
  config,
530
535
  });
531
536
  this.columnReconstructionTracker = new ColumnReconstructionTracker({
532
537
  logger,
533
538
  emitter,
539
+ seenDataColumnSidecars: this.seenDataColumnSidecars,
534
540
  metrics,
535
541
  config,
536
542
  signal,
@@ -2037,9 +2043,18 @@ export class BeaconChain implements IBeaconChain {
2037
2043
 
2038
2044
  const finalizedSlot = computeStartSlotAtEpoch(cp.epoch);
2039
2045
  this.seenBlockProposers.prune(finalizedSlot);
2046
+ this.seenDataColumnSidecars.prune(finalizedSlot);
2040
2047
 
2041
2048
  // Update validator custody to account for effective balance changes
2042
- await this.updateValidatorsCustodyRequirement(cp);
2049
+ try {
2050
+ await this.updateValidatorsCustodyRequirement(cp);
2051
+ } catch (e) {
2052
+ this.logger.warn(
2053
+ "Error updating validators custody requirement",
2054
+ {epoch: cp.epoch, root: cp.rootHex},
2055
+ e as Error
2056
+ );
2057
+ }
2043
2058
 
2044
2059
  // TODO: Improve using regen here
2045
2060
  const {blockRoot, stateRoot, slot} = this.forkChoice.getHead();
@@ -2145,7 +2160,9 @@ export class BeaconChain implements IBeaconChain {
2145
2160
  if (stateOrBytes instanceof Uint8Array) {
2146
2161
  effectiveBalances = getEffectiveBalancesFromStateBytes(this.config, stateOrBytes, validatorIndices);
2147
2162
  } else {
2148
- effectiveBalances = validatorIndices.map((index) => stateOrBytes.getValidator(index).effectiveBalance ?? 0);
2163
+ effectiveBalances = validatorIndices.map((index) =>
2164
+ index < stateOrBytes.validatorCount ? stateOrBytes.getValidator(index).effectiveBalance : 0
2165
+ );
2149
2166
  }
2150
2167
  }
2151
2168
 
@@ -35,6 +35,7 @@ export enum DataColumnSidecarErrorCode {
35
35
 
36
36
  // following errors are adapted from the block errors
37
37
  ALREADY_KNOWN = "DATA_COLUMN_SIDECAR_ERROR_ALREADY_KNOWN",
38
+ REPEAT_PROPOSAL = "DATA_COLUMN_SIDECAR_ERROR_REPEAT_PROPOSAL",
38
39
  FUTURE_SLOT = "DATA_COLUMN_SIDECAR_ERROR_FUTURE_SLOT",
39
40
  WOULD_REVERT_FINALIZED_SLOT = "DATA_COLUMN_SIDECAR_ERROR_WOULD_REVERT_FINALIZED_SLOT",
40
41
  PARENT_UNKNOWN = "DATA_COLUMN_SIDECAR_ERROR_PARENT_UNKNOWN",
@@ -79,6 +80,13 @@ export type DataColumnSidecarErrorType =
79
80
  limit: number;
80
81
  }
81
82
  | {code: DataColumnSidecarErrorCode.ALREADY_KNOWN; columnIndex: number; slot: Slot}
83
+ | {
84
+ code: DataColumnSidecarErrorCode.REPEAT_PROPOSAL;
85
+ slot: Slot;
86
+ proposerIndex: number;
87
+ columnIndex: number;
88
+ root: RootHex;
89
+ }
82
90
  | {code: DataColumnSidecarErrorCode.FUTURE_SLOT; blockSlot: Slot; currentSlot: Slot}
83
91
  | {code: DataColumnSidecarErrorCode.WOULD_REVERT_FINALIZED_SLOT; blockSlot: Slot; finalizedSlot: Slot}
84
92
  | {
@@ -13,7 +13,7 @@ import {
13
13
  ProtoBlock,
14
14
  ForkChoiceOpts as RawForkChoiceOpts,
15
15
  } from "@lodestar/fork-choice";
16
- import {ForkSeq, SLOTS_PER_HISTORICAL_ROOT, ZERO_HASH_HEX} from "@lodestar/params";
16
+ import {ForkSeq, SLOTS_PER_HISTORICAL_ROOT, ZERO_HASH_HEX, isForkPostGloas} from "@lodestar/params";
17
17
  import {
18
18
  DataAvailabilityStatus,
19
19
  IBeaconStateView,
@@ -135,7 +135,7 @@ export function initializeForkChoiceFromFinalizedState(
135
135
  // production code use ForkChoice constructor directly
136
136
  const forkchoiceConstructor = opts.forkchoiceConstructor ?? ForkChoice;
137
137
 
138
- const isForkPostGloas = computeEpochAtSlot(state.slot) >= config.GLOAS_FORK_EPOCH;
138
+ const isPostGloasAnchor = isStatePostGloas(state) && isForkPostGloas(config.getForkName(blockHeader.slot));
139
139
 
140
140
  return new forkchoiceConstructor(
141
141
  config,
@@ -184,15 +184,20 @@ export function initializeForkChoiceFromFinalizedState(
184
184
  // TODO GLOAS: executionPayloadNumber/GasLimit are not tracked in BeaconState post-gloas
185
185
  // (EIP-7732 removed latestExecutionPayloadHeader). Using 0 as unavailable fallback —
186
186
  // see initializeForkChoiceFromUnfinalizedState for the same caveat on validation.
187
+ // A pre-Gloas anchor's gas limit is kept in the state's bid by the upgrade.
187
188
  executionPayloadNumber: isStatePostGloas(state) ? 0 : state.payloadBlockNumber,
188
- executionPayloadGasLimit: isStatePostGloas(state) ? 0 : state.latestExecutionPayloadHeader.gasLimit,
189
+ executionPayloadGasLimit: isPostGloasAnchor
190
+ ? 0
191
+ : isStatePostGloas(state)
192
+ ? Number(state.latestExecutionPayloadBid.gasLimit)
193
+ : state.latestExecutionPayloadHeader.gasLimit,
189
194
  executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
190
195
  }
191
196
  : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
192
197
 
193
198
  dataAvailabilityStatus: DataAvailabilityStatus.PreData,
194
- payloadStatus: isForkPostGloas ? PayloadStatus.PENDING : PayloadStatus.FULL,
195
- parentBlockHash: isStatePostGloas(state) ? toRootHex(state.latestBlockHash) : null,
199
+ payloadStatus: isPostGloasAnchor ? PayloadStatus.PENDING : PayloadStatus.FULL,
200
+ parentBlockHash: isPostGloasAnchor ? toRootHex(state.latestBlockHash) : null,
196
201
  },
197
202
  currentSlot
198
203
  ),
@@ -431,7 +436,7 @@ export function initializeForkChoiceFromUnfinalizedState(
431
436
  // this is not the justified state, but there is no other ways to get justified balances
432
437
  const justifiedBalances = unfinalizedState.getEffectiveBalanceIncrementsZeroInactive();
433
438
 
434
- const isForkPostGloas = computeEpochAtSlot(unfinalizedState.slot) >= config.GLOAS_FORK_EPOCH;
439
+ const isPostGloasAnchor = isStatePostGloas(unfinalizedState) && isForkPostGloas(config.getForkName(blockHeader.slot));
435
440
 
436
441
  const store = new ForkChoiceStore(
437
442
  currentSlot,
@@ -484,17 +489,20 @@ export function initializeForkChoiceFromUnfinalizedState(
484
489
  // PENDING/EMPTY convention), so gossip bids that reference the head's *own* payload
485
490
  // hash won't match this variant anyway and will IGNORE until `onExecutionPayload`
486
491
  // upgrades the head to FULL with real values.
492
+ // A pre-Gloas anchor's gas limit is kept in the state's bid by the upgrade.
487
493
  executionPayloadNumber: isStatePostGloas(unfinalizedState) ? 0 : unfinalizedState.payloadBlockNumber,
488
- executionPayloadGasLimit: isStatePostGloas(unfinalizedState)
494
+ executionPayloadGasLimit: isPostGloasAnchor
489
495
  ? 0
490
- : unfinalizedState.latestExecutionPayloadHeader.gasLimit,
496
+ : isStatePostGloas(unfinalizedState)
497
+ ? Number(unfinalizedState.latestExecutionPayloadBid.gasLimit)
498
+ : unfinalizedState.latestExecutionPayloadHeader.gasLimit,
491
499
  executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
492
500
  }
493
501
  : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
494
502
 
495
503
  dataAvailabilityStatus: DataAvailabilityStatus.PreData,
496
- payloadStatus: isForkPostGloas ? PayloadStatus.PENDING : PayloadStatus.FULL,
497
- parentBlockHash: isStatePostGloas(unfinalizedState) ? toRootHex(unfinalizedState.latestBlockHash) : null,
504
+ payloadStatus: isPostGloasAnchor ? PayloadStatus.PENDING : PayloadStatus.FULL,
505
+ parentBlockHash: isPostGloasAnchor ? toRootHex(unfinalizedState.latestBlockHash) : null,
498
506
  };
499
507
 
500
508
  const parentSlot = blockHeader.slot - 1;
@@ -68,6 +68,7 @@ import {
68
68
  SeenAttesters,
69
69
  SeenBlockProposers,
70
70
  SeenContributionAndProof,
71
+ SeenDataColumnSidecars,
71
72
  SeenExecutionPayloadBids,
72
73
  SeenPayloadAttesters,
73
74
  SeenSyncCommitteeMessages,
@@ -147,6 +148,7 @@ export interface IBeaconChain {
147
148
  readonly seenAggregatedAttestations: SeenAggregatedAttestations;
148
149
  readonly seenExecutionPayloadBids: SeenExecutionPayloadBids;
149
150
  readonly seenBlockProposers: SeenBlockProposers;
151
+ readonly seenDataColumnSidecars: SeenDataColumnSidecars;
150
152
  readonly seenSyncCommitteeMessages: SeenSyncCommitteeMessages;
151
153
  readonly seenContributionAndProof: SeenContributionAndProof;
152
154
  readonly seenAttestationDatas: SeenAttestationDatas;
@@ -2,6 +2,7 @@ export {SeenAggregators, SeenAttesters, SeenPayloadAttesters} from "./seenAttest
2
2
  export {SeenBlockProposers} from "./seenBlockProposers.js";
3
3
  export {SeenSyncCommitteeMessages} from "./seenCommittee.js";
4
4
  export {SeenContributionAndProof} from "./seenCommitteeContribution.js";
5
+ export {SeenDataColumnSidecars} from "./seenDataColumnSidecars.js";
5
6
  export {SeenExecutionPayloadBids} from "./seenExecutionPayloadBids.js";
6
7
  export {SeenBlockInput} from "./seenGossipBlockInput.js";
7
8
  export {PayloadEnvelopeInput, SeenPayloadEnvelopeInput} from "./seenPayloadEnvelopeInput.js";
@@ -1,6 +1,6 @@
1
1
  import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
2
2
  import {Epoch, RootHex, Slot, ValidatorIndex, phase0} from "@lodestar/types";
3
- import {MapDef} from "@lodestar/utils";
3
+ import {MapDef, byteArrayEquals} from "@lodestar/utils";
4
4
 
5
5
  /** Two distinct block roots signed by the same proposer for the same slot are sufficient to establish an equivocation */
6
6
  const MIN_EQUIVOCATION_BLOCK_ROOTS_PER_PROPOSAL = 2;
@@ -44,6 +44,16 @@ export class SeenBlockProposers {
44
44
  return this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.has(blockRoot) === true;
45
45
  }
46
46
 
47
+ hasBlockSignature(
48
+ blockSlot: Slot,
49
+ proposerIndex: ValidatorIndex,
50
+ blockRoot: RootHex,
51
+ signature: Uint8Array
52
+ ): boolean {
53
+ const signedBlockHeader = this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.get(blockRoot);
54
+ return signedBlockHeader !== undefined && byteArrayEquals(signedBlockHeader.signature, signature);
55
+ }
56
+
47
57
  isEquivocating(blockSlot: Slot, proposerIndex: ValidatorIndex): boolean {
48
58
  return (
49
59
  (this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.size ?? 0) >=
@@ -0,0 +1,64 @@
1
+ import {ColumnIndex, RootHex, Slot, ValidatorIndex} from "@lodestar/types";
2
+ import {MapDef} from "@lodestar/utils";
3
+
4
+ /**
5
+ * Tracks the column indices of valid gossip data column sidecars per slot, proposer and block root,
6
+ * to ignore sidecars of a repeated proposal. Pruned on finalization.
7
+ */
8
+ export class SeenDataColumnSidecars {
9
+ private readonly columnIndicesBySlot = new MapDef<Slot, MapDef<ValidatorIndex, MapDef<RootHex, Set<ColumnIndex>>>>(
10
+ () => new MapDef(() => new MapDef(() => new Set()))
11
+ );
12
+ private readonly evidenceChecksBySlot = new MapDef<Slot, Set<ValidatorIndex>>(() => new Set());
13
+ private finalizedSlot: Slot = 0;
14
+
15
+ isRepeatProposal(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: ColumnIndex, blockRoot: RootHex): boolean {
16
+ const columnIndicesByRoot = this.columnIndicesBySlot.get(slot)?.get(proposerIndex);
17
+ if (columnIndicesByRoot === undefined) {
18
+ return false;
19
+ }
20
+ for (const [root, columnIndices] of columnIndicesByRoot) {
21
+ if (root !== blockRoot && columnIndices.has(columnIndex)) {
22
+ return true;
23
+ }
24
+ }
25
+ return false;
26
+ }
27
+
28
+ isKnown(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: ColumnIndex, blockRoot: RootHex): boolean {
29
+ return this.columnIndicesBySlot.get(slot)?.get(proposerIndex)?.get(blockRoot)?.has(columnIndex) === true;
30
+ }
31
+
32
+ add(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: ColumnIndex, blockRoot: RootHex): void {
33
+ if (slot < this.finalizedSlot || this.isRepeatProposal(slot, proposerIndex, columnIndex, blockRoot)) {
34
+ return;
35
+ }
36
+ this.columnIndicesBySlot.getOrDefault(slot).getOrDefault(proposerIndex).getOrDefault(blockRoot).add(columnIndex);
37
+ }
38
+
39
+ markEvidenceCheck(slot: Slot, proposerIndex: ValidatorIndex): boolean {
40
+ if (slot < this.finalizedSlot) {
41
+ return false;
42
+ }
43
+ const proposers = this.evidenceChecksBySlot.getOrDefault(slot);
44
+ if (proposers.has(proposerIndex)) {
45
+ return false;
46
+ }
47
+ proposers.add(proposerIndex);
48
+ return true;
49
+ }
50
+
51
+ prune(finalizedSlot: Slot): void {
52
+ this.finalizedSlot = finalizedSlot;
53
+ for (const slot of this.columnIndicesBySlot.keys()) {
54
+ if (slot < finalizedSlot) {
55
+ this.columnIndicesBySlot.delete(slot);
56
+ }
57
+ }
58
+ for (const slot of this.evidenceChecksBySlot.keys()) {
59
+ if (slot < finalizedSlot) {
60
+ this.evidenceChecksBySlot.delete(slot);
61
+ }
62
+ }
63
+ }
64
+ }
@@ -64,6 +64,7 @@ export class SeenPayloadEnvelopeInput {
64
64
  private readonly metrics: Metrics | null;
65
65
  private readonly logger?: Logger;
66
66
  private payloadInputs = new Map<RootHex, PayloadEnvelopeInput>();
67
+ private readonly unvalidatedRoots = new Set<RootHex>();
67
68
  // Dedup concurrent DB reloads of the same root so callers share one reconstructed object.
68
69
  private readonly reloading = new Map<RootHex, Promise<PayloadEnvelopeInput | undefined>>();
69
70
 
@@ -127,9 +128,17 @@ export class SeenPayloadEnvelopeInput {
127
128
  });
128
129
  };
129
130
 
130
- add(props: Omit<CreateFromBlockProps, "daOutOfRange">): PayloadEnvelopeInput {
131
+ /**
132
+ * Set `unvalidated` for a block of which only the proposer signature is verified, e.g. one retained for unknown
133
+ * parent sync. Such entries are evicted first when the cache is over its max size, until the block passes gossip
134
+ * validation or is imported. Adding an existing entry without `unvalidated` promotes it without replacing it.
135
+ */
136
+ add(props: Omit<CreateFromBlockProps, "daOutOfRange">, opts?: {unvalidated?: boolean}): PayloadEnvelopeInput {
131
137
  const existing = this.payloadInputs.get(props.blockRootHex);
132
138
  if (existing !== undefined) {
139
+ if (!opts?.unvalidated) {
140
+ this.unvalidatedRoots.delete(props.blockRootHex);
141
+ }
133
142
  this.logger?.verbose("SeenPayloadEnvelopeInput.add reused existing entry", {
134
143
  slot: existing.slot,
135
144
  root: props.blockRootHex,
@@ -139,6 +148,9 @@ export class SeenPayloadEnvelopeInput {
139
148
  const daOutOfRange = isDaOutOfRange(this.config, props.forkName, props.block.message.slot, this.clock.currentEpoch);
140
149
  const input = PayloadEnvelopeInput.createFromBlock({...props, daOutOfRange});
141
150
  this.payloadInputs.set(props.blockRootHex, input);
151
+ if (opts?.unvalidated) {
152
+ this.unvalidatedRoots.add(props.blockRootHex);
153
+ }
142
154
  this.metrics?.seenCache.payloadEnvelopeInput.created.inc({source: props.source});
143
155
  this.logger?.verbose("SeenPayloadEnvelopeInput.add created new entry", {
144
156
  slot: input.slot,
@@ -300,12 +312,25 @@ export class SeenPayloadEnvelopeInput {
300
312
 
301
313
  /**
302
314
  * Bound this cache to have at most MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE items.
303
- * Evicts by insertion order so a just-reloaded old-slot entry is not evicted right after.
315
+ * Evicts entries of unvalidated blocks that are not imported yet first, then the rest by insertion order so a
316
+ * just-reloaded old-slot entry is not evicted right after.
304
317
  * On unstable network, we may need to query an evicted item, UnknownBlockInput will recover
305
318
  * it from db via getOrReload() api. Runs after every single insert, so it evicts ~1 per call.
306
319
  */
307
320
  private pruneToMaxSize(): void {
308
321
  let evicted = 0;
322
+ for (const blockRootHex of this.unvalidatedRoots) {
323
+ if (this.payloadInputs.size <= MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE) {
324
+ break;
325
+ }
326
+ const input = this.payloadInputs.get(blockRootHex);
327
+ if (input === undefined || this.forkChoice.hasBlockHex(blockRootHex)) {
328
+ this.unvalidatedRoots.delete(blockRootHex);
329
+ continue;
330
+ }
331
+ this.evictPayloadInput(input, "capUnvalidated");
332
+ evicted++;
333
+ }
309
334
  for (const input of this.payloadInputs.values()) {
310
335
  if (this.payloadInputs.size <= MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE) {
311
336
  break;
@@ -331,5 +356,6 @@ export class SeenPayloadEnvelopeInput {
331
356
  });
332
357
  this.serializedCache.delete(payloadInput.getSerializedCacheKeys());
333
358
  this.payloadInputs.delete(payloadInput.blockRootHex);
359
+ this.unvalidatedRoots.delete(payloadInput.blockRootHex);
334
360
  }
335
361
  }
@@ -261,10 +261,12 @@ async function validateAttestationNoSignatureCheck(
261
261
  const attSlot = attestationOrBytes.attSlot;
262
262
  attDataKey = getSeenAttDataKeyFromGossipAttestation(attestationOrBytes);
263
263
  const committeeIndexForLookup = isForkPostElectra(fork)
264
- ? (getCommitteeIndexFromAttestationOrBytes(fork, attestationOrBytes) ?? 0)
264
+ ? getCommitteeIndexFromAttestationOrBytes(fork, attestationOrBytes)
265
265
  : PRE_ELECTRA_SINGLE_ATTESTATION_COMMITTEE_INDEX;
266
266
  const cachedAttData =
267
- attDataKey !== null ? chain.seenAttestationDatas.get(attSlot, committeeIndexForLookup, attDataKey) : null;
267
+ attDataKey !== null && committeeIndexForLookup !== null
268
+ ? chain.seenAttestationDatas.get(attSlot, committeeIndexForLookup, attDataKey)
269
+ : null;
268
270
  if (cachedAttData === null) {
269
271
  const attestation = sszDeserializeSingleAttestation(fork, attestationOrBytes.serializedData);
270
272
  // only deserialize on the first AttestationData that's not cached
@@ -76,8 +76,17 @@ export async function validateGossipBlock(
76
76
  const proposerIndex = block.proposerIndex;
77
77
  if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
78
78
  if (chain.seenBlockProposers.isRepeatProposal(blockSlot, proposerIndex, blockRoot)) {
79
- const hasBlockRoot = chain.seenBlockProposers.hasBlockRoot(blockSlot, proposerIndex, blockRoot);
80
- if (!hasBlockRoot && !chain.seenBlockProposers.isEquivocating(blockSlot, proposerIndex)) {
79
+ if (chain.seenBlockProposers.hasBlockRoot(blockSlot, proposerIndex, blockRoot)) {
80
+ // The root is known with a verified signature, e.g. from the header of a data column sidecar, and a valid
81
+ // BLS signature of the same message by the same proposer is unique
82
+ if (!chain.seenBlockProposers.hasBlockSignature(blockSlot, proposerIndex, blockRoot, signedBlock.signature)) {
83
+ throw new BlockGossipError(GossipAction.REJECT, {
84
+ code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID,
85
+ slot: blockSlot,
86
+ root: blockRoot,
87
+ });
88
+ }
89
+ } else if (!chain.seenBlockProposers.isEquivocating(blockSlot, proposerIndex)) {
81
90
  await verifyBlockProposerSignature(chain, signedBlock, blockRoot, {verifyOnMainThread: false});
82
91
  chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot, signedBlockHeader);
83
92
  }
@@ -225,7 +225,7 @@ export async function validateGossipFuluDataColumnSidecar(
225
225
 
226
226
  // 12) [IGNORE] The sidecar is the first sidecar for the tuple (block_header.slot, block_header.proposer_index,
227
227
  // sidecar.index) with valid header signature, sidecar inclusion proof, and kzg proof
228
- // -- Handled in seenGossipBlockInput
228
+ // -- Handled in gossip handler with seenDataColumnSidecars
229
229
  }
230
230
 
231
231
  // SPEC FUNCTION
@@ -29,10 +29,14 @@ import {Epoch} from "@lodestar/types";
29
29
  export const FORK_EPOCH_LOOKAHEAD = 2;
30
30
 
31
31
  /**
32
- * Return the list of `ForkBoundary`s meant to be active at `epoch`
32
+ * Return the fork boundaries active at any epoch in the inclusive range.
33
33
  * @see FORK_EPOCH_LOOKAHEAD for details on when fork boundaries are considered 'active'
34
34
  */
35
- export function getActiveForkBoundaries(config: ChainForkConfig, epoch: Epoch): ForkBoundary[] {
35
+ export function getActiveForkBoundaries(
36
+ config: ChainForkConfig,
37
+ fromEpoch: Epoch,
38
+ toEpoch = fromEpoch
39
+ ): ForkBoundary[] {
36
40
  const activeBoundaries: ForkBoundary[] = [];
37
41
  const {forkBoundariesAscendingEpochOrder} = config;
38
42
 
@@ -48,7 +52,7 @@ export function getActiveForkBoundaries(config: ChainForkConfig, epoch: Epoch):
48
52
  continue;
49
53
  }
50
54
 
51
- if (epoch >= currentEpoch - FORK_EPOCH_LOOKAHEAD && epoch <= nextEpoch + FORK_EPOCH_LOOKAHEAD) {
55
+ if (toEpoch >= currentEpoch - FORK_EPOCH_LOOKAHEAD && fromEpoch <= nextEpoch + FORK_EPOCH_LOOKAHEAD) {
52
56
  activeBoundaries.push(currentForkBoundary);
53
57
  }
54
58
  }