@lodestar/beacon-node 1.44.0-dev.2defe36dd3 → 1.44.0-dev.41c6b9d097

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 (82) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +13 -5
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/config/constants.d.ts +1 -0
  5. package/lib/api/impl/config/constants.d.ts.map +1 -1
  6. package/lib/api/impl/config/constants.js +2 -1
  7. package/lib/api/impl/config/constants.js.map +1 -1
  8. package/lib/api/impl/debug/index.d.ts.map +1 -1
  9. package/lib/api/impl/debug/index.js +69 -12
  10. package/lib/api/impl/debug/index.js.map +1 -1
  11. package/lib/api/impl/validator/index.d.ts.map +1 -1
  12. package/lib/api/impl/validator/index.js +17 -3
  13. package/lib/api/impl/validator/index.js.map +1 -1
  14. package/lib/chain/archiveStore/archiveStore.d.ts +0 -1
  15. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  16. package/lib/chain/archiveStore/archiveStore.js +0 -4
  17. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  18. package/lib/chain/produceBlock/produceBlockBody.js +2 -2
  19. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  20. package/lib/chain/regen/interface.d.ts +0 -1
  21. package/lib/chain/regen/interface.d.ts.map +1 -1
  22. package/lib/chain/regen/queued.d.ts +0 -1
  23. package/lib/chain/regen/queued.d.ts.map +1 -1
  24. package/lib/chain/regen/queued.js +0 -4
  25. package/lib/chain/regen/queued.js.map +1 -1
  26. package/lib/chain/stateCache/fifoBlockStateCache.d.ts +0 -5
  27. package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -1
  28. package/lib/chain/stateCache/fifoBlockStateCache.js +0 -5
  29. package/lib/chain/stateCache/fifoBlockStateCache.js.map +1 -1
  30. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +1 -4
  31. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  32. package/lib/chain/stateCache/persistentCheckpointsCache.js +5 -2
  33. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  34. package/lib/chain/stateCache/types.d.ts +0 -2
  35. package/lib/chain/stateCache/types.d.ts.map +1 -1
  36. package/lib/chain/stateCache/types.js.map +1 -1
  37. package/lib/network/gossip/topic.d.ts +749 -2
  38. package/lib/network/gossip/topic.d.ts.map +1 -1
  39. package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
  40. package/lib/network/reqresp/handlers/beaconBlocksByRange.js +9 -5
  41. package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
  42. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
  43. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +13 -3
  44. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  45. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +1 -1
  46. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
  47. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.d.ts +2 -1
  48. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.d.ts.map +1 -1
  49. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js +16 -6
  50. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js.map +1 -1
  51. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.d.ts +2 -1
  52. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.d.ts.map +1 -1
  53. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js +15 -1
  54. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js.map +1 -1
  55. package/lib/network/reqresp/handlers/index.js +4 -4
  56. package/lib/network/reqresp/handlers/index.js.map +1 -1
  57. package/lib/network/reqresp/utils/dataColumnResponseValidation.d.ts.map +1 -1
  58. package/lib/network/reqresp/utils/dataColumnResponseValidation.js +22 -3
  59. package/lib/network/reqresp/utils/dataColumnResponseValidation.js.map +1 -1
  60. package/lib/util/dataColumns.d.ts.map +1 -1
  61. package/lib/util/dataColumns.js +16 -11
  62. package/lib/util/dataColumns.js.map +1 -1
  63. package/package.json +14 -16
  64. package/src/api/impl/beacon/blocks/index.ts +13 -5
  65. package/src/api/impl/config/constants.ts +2 -0
  66. package/src/api/impl/debug/index.ts +73 -12
  67. package/src/api/impl/validator/index.ts +19 -8
  68. package/src/chain/archiveStore/archiveStore.ts +0 -5
  69. package/src/chain/produceBlock/produceBlockBody.ts +2 -2
  70. package/src/chain/regen/interface.ts +0 -1
  71. package/src/chain/regen/queued.ts +0 -5
  72. package/src/chain/stateCache/fifoBlockStateCache.ts +0 -6
  73. package/src/chain/stateCache/persistentCheckpointsCache.ts +6 -2
  74. package/src/chain/stateCache/types.ts +0 -2
  75. package/src/network/reqresp/handlers/beaconBlocksByRange.ts +12 -5
  76. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +17 -3
  77. package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +1 -1
  78. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRange.ts +22 -6
  79. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRoot.ts +20 -1
  80. package/src/network/reqresp/handlers/index.ts +4 -4
  81. package/src/network/reqresp/utils/dataColumnResponseValidation.ts +21 -3
  82. package/src/util/dataColumns.ts +17 -12
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ChainSafe/lodestar/issues"
13
13
  },
14
- "version": "1.44.0-dev.2defe36dd3",
14
+ "version": "1.44.0-dev.41c6b9d097",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -116,7 +116,6 @@
116
116
  "@chainsafe/libp2p-quic": "^2.0.1",
117
117
  "@chainsafe/persistent-merkle-tree": "^1.2.5",
118
118
  "@chainsafe/prometheus-gc-stats": "^1.0.0",
119
- "@chainsafe/pubkey-index-map": "^3.0.0",
120
119
  "@chainsafe/snappy-wasm": "^0.5.0",
121
120
  "@chainsafe/ssz": "^1.4.0",
122
121
  "@chainsafe/threads": "^1.11.3",
@@ -135,17 +134,17 @@
135
134
  "@libp2p/peer-id": "^6.0.4",
136
135
  "@libp2p/prometheus-metrics": "^5.0.14",
137
136
  "@libp2p/tcp": "^11.0.13",
138
- "@lodestar/api": "^1.44.0-dev.2defe36dd3",
139
- "@lodestar/config": "^1.44.0-dev.2defe36dd3",
140
- "@lodestar/db": "^1.44.0-dev.2defe36dd3",
141
- "@lodestar/fork-choice": "^1.44.0-dev.2defe36dd3",
142
- "@lodestar/logger": "^1.44.0-dev.2defe36dd3",
143
- "@lodestar/params": "^1.44.0-dev.2defe36dd3",
144
- "@lodestar/reqresp": "^1.44.0-dev.2defe36dd3",
145
- "@lodestar/state-transition": "^1.44.0-dev.2defe36dd3",
146
- "@lodestar/types": "^1.44.0-dev.2defe36dd3",
147
- "@lodestar/utils": "^1.44.0-dev.2defe36dd3",
148
- "@lodestar/validator": "^1.44.0-dev.2defe36dd3",
137
+ "@lodestar/api": "^1.44.0-dev.41c6b9d097",
138
+ "@lodestar/config": "^1.44.0-dev.41c6b9d097",
139
+ "@lodestar/db": "^1.44.0-dev.41c6b9d097",
140
+ "@lodestar/fork-choice": "^1.44.0-dev.41c6b9d097",
141
+ "@lodestar/logger": "^1.44.0-dev.41c6b9d097",
142
+ "@lodestar/params": "^1.44.0-dev.41c6b9d097",
143
+ "@lodestar/reqresp": "^1.44.0-dev.41c6b9d097",
144
+ "@lodestar/state-transition": "^1.44.0-dev.41c6b9d097",
145
+ "@lodestar/types": "^1.44.0-dev.41c6b9d097",
146
+ "@lodestar/utils": "^1.44.0-dev.41c6b9d097",
147
+ "@lodestar/validator": "^1.44.0-dev.41c6b9d097",
149
148
  "@multiformats/multiaddr": "^13.0.1",
150
149
  "datastore-core": "^11.0.2",
151
150
  "datastore-fs": "^11.0.2",
@@ -168,13 +167,12 @@
168
167
  "@libp2p/interface-internal": "^3.0.13",
169
168
  "@libp2p/logger": "^6.2.2",
170
169
  "@libp2p/utils": "^7.0.13",
171
- "@lodestar/spec-test-util": "^1.44.0-dev.2defe36dd3",
170
+ "@lodestar/spec-test-util": "^1.44.0-dev.41c6b9d097",
172
171
  "@types/js-yaml": "^4.0.5",
173
172
  "@types/qs": "^6.9.7",
174
173
  "@types/tmp": "^0.2.3",
175
174
  "dotenv": "^16.4.5",
176
175
  "js-yaml": "^4.1.0",
177
- "rewiremock": "^3.14.5",
178
176
  "rimraf": "^4.4.1",
179
177
  "snappy": "^7.2.2",
180
178
  "snappyjs": "^0.7.0",
@@ -186,5 +184,5 @@
186
184
  "beacon",
187
185
  "blockchain"
188
186
  ],
189
- "gitHead": "14e0154c3e2b6c61607a1840c888b70493dbfae9"
187
+ "gitHead": "bd2d4c7382cfd09e91f3b780f8f2c3bc72d7ee2c"
190
188
  }
@@ -205,11 +205,19 @@ export function getBeaconBlockApi({
205
205
  try {
206
206
  await validateGossipBlock(config, chain, signedBlock, fork);
207
207
  } catch (error) {
208
- if (error instanceof BlockGossipError && error.type.code === BlockErrorCode.ALREADY_KNOWN) {
209
- chain.logger.debug("Ignoring known block during publishing", valLogMeta);
210
- // Blocks might already be published by another node as part of a fallback setup or DVT cluster
211
- // and can reach our node by gossip before the api. The error can be ignored and should not result in a 500 response.
212
- return;
208
+ if (error instanceof BlockGossipError) {
209
+ switch (error.type.code) {
210
+ case BlockErrorCode.ALREADY_KNOWN:
211
+ // Block has already been seen, e.g. via gossip racing the publish API. Benign.
212
+ chain.logger.debug("Ignoring already-known block during publishing", valLogMeta);
213
+ return;
214
+ case BlockErrorCode.REPEAT_PROPOSAL:
215
+ // The proposer already produced a block for this slot. For a solo setup this is a
216
+ // notable signal (duplicate-proposal attempt). For fallback / DVT setups it is
217
+ // expected on every block where another node published first.
218
+ chain.logger.warn("Ignoring repeat-proposal block during publishing", valLogMeta);
219
+ return;
220
+ }
213
221
  }
214
222
 
215
223
  chain.logger.error("Gossip validations failed while publishing the block", valLogMeta, error as Error);
@@ -53,6 +53,7 @@ import {
53
53
  VERSIONED_HASH_VERSION_KZG,
54
54
  WEIGHT_DENOMINATOR,
55
55
  WITHDRAWAL_REQUEST_TYPE,
56
+ ZERO_HASH_HEX,
56
57
  } from "@lodestar/params";
57
58
 
58
59
  /**
@@ -69,6 +70,7 @@ export const specConstants = {
69
70
  DEPOSIT_CONTRACT_TREE_DEPTH,
70
71
  JUSTIFICATION_BITS_LENGTH,
71
72
  ENDIANNESS: "little",
73
+ EMPTY_BLOCK_HASH: ZERO_HASH_HEX,
72
74
  // ## Withdrawal prefixes
73
75
  BLS_WITHDRAWAL_PREFIX: toHexByte(BLS_WITHDRAWAL_PREFIX),
74
76
  ETH1_ADDRESS_WITHDRAWAL_PREFIX: toHexByte(ETH1_ADDRESS_WITHDRAWAL_PREFIX),
@@ -1,7 +1,8 @@
1
1
  import {routes} from "@lodestar/api";
2
2
  import {ApplicationMethods} from "@lodestar/api/server";
3
- import {ExecutionStatus} from "@lodestar/fork-choice";
3
+ import {ExecutionStatus, PayloadStatus} from "@lodestar/fork-choice";
4
4
  import {ForkPostDeneb, ZERO_HASH_HEX, isForkPostDeneb, isForkPostFulu} from "@lodestar/params";
5
+ import {computeTimeAtSlot} from "@lodestar/state-transition";
5
6
  import {BeaconState, DataColumnSidecar, DataColumnSidecars, type SignedBeaconBlock, sszTypesFor} from "@lodestar/types";
6
7
  import {toRootHex} from "@lodestar/utils";
7
8
  import {getBlobKzgCommitments} from "../../../util/dataColumns.js";
@@ -12,6 +13,29 @@ import {getStateResponseWithRegen} from "../beacon/state/utils.js";
12
13
  import {ApiModules} from "../types.js";
13
14
  import {assertUniqueItems} from "../utils.js";
14
15
 
16
+ function toForkChoiceValidity(status: ExecutionStatus): "valid" | "invalid" | "optimistic" {
17
+ switch (status) {
18
+ case ExecutionStatus.Valid:
19
+ return "valid";
20
+ case ExecutionStatus.Invalid:
21
+ return "invalid";
22
+ case ExecutionStatus.Syncing:
23
+ case ExecutionStatus.PreMerge:
24
+ return "optimistic";
25
+ }
26
+ }
27
+
28
+ function toPayloadStatusName(status: PayloadStatus): "pending" | "empty" | "full" {
29
+ switch (status) {
30
+ case PayloadStatus.PENDING:
31
+ return "pending";
32
+ case PayloadStatus.EMPTY:
33
+ return "empty";
34
+ case PayloadStatus.FULL:
35
+ return "full";
36
+ }
37
+ }
38
+
15
39
  export function getDebugApi({
16
40
  chain,
17
41
  config,
@@ -40,23 +64,60 @@ export function getDebugApi({
40
64
  justifiedEpoch: node.justifiedEpoch,
41
65
  finalizedEpoch: node.finalizedEpoch,
42
66
  weight: node.weight,
43
- validity: (() => {
44
- switch (node.executionStatus) {
45
- case ExecutionStatus.Valid:
46
- return "valid";
47
- case ExecutionStatus.Invalid:
48
- return "invalid";
49
- case ExecutionStatus.Syncing:
50
- case ExecutionStatus.PreMerge:
51
- return "optimistic";
52
- }
53
- })(),
67
+ validity: toForkChoiceValidity(node.executionStatus),
54
68
  executionBlockHash: node.executionPayloadBlockHash ?? ZERO_HASH_HEX,
55
69
  })),
56
70
  },
57
71
  };
58
72
  },
59
73
 
74
+ async getDebugForkChoiceV2() {
75
+ const {forkChoice} = chain;
76
+ return {
77
+ data: {
78
+ justifiedCheckpoint: forkChoice.getJustifiedCheckpoint(),
79
+ finalizedCheckpoint: forkChoice.getFinalizedCheckpoint(),
80
+ forkChoiceNodes: forkChoice.getAllNodes().map((node) => {
81
+ // Payload-specific fields apply only to a revealed Gloas payload = the FULL variant of a
82
+ // Gloas block
83
+ const ptc = node.payloadStatus === PayloadStatus.FULL ? forkChoice.getPTCVoteCounts(node.blockRoot) : null;
84
+ return {
85
+ payloadStatus: toPayloadStatusName(node.payloadStatus),
86
+ slot: node.slot,
87
+ blockRoot: node.blockRoot,
88
+ parentRoot: node.parentRoot,
89
+ weight: node.weight,
90
+ validity: toForkChoiceValidity(node.executionStatus),
91
+ executionBlockHash: node.executionPayloadBlockHash ?? ZERO_HASH_HEX,
92
+ extraData: {
93
+ executionOptimistic: isOptimisticBlock(node),
94
+ timestamp: computeTimeAtSlot(config, node.slot, chain.genesisTime),
95
+ target: node.targetRoot,
96
+ justifiedEpoch: node.justifiedEpoch,
97
+ finalizedEpoch: node.finalizedEpoch,
98
+ unrealizedJustifiedEpoch: node.unrealizedJustifiedEpoch,
99
+ unrealizedFinalizedEpoch: node.unrealizedFinalizedEpoch,
100
+ payloadAttesterCount: ptc?.attesterCount ?? null,
101
+ payloadAvailabilityYesCount: ptc?.payloadPresentCount ?? null,
102
+ payloadDataAvailabilityYesCount: ptc?.dataAvailableCount ?? null,
103
+ gasLimit:
104
+ node.payloadStatus === PayloadStatus.FULL && "executionPayloadGasLimit" in node
105
+ ? node.executionPayloadGasLimit
106
+ : null,
107
+ },
108
+ };
109
+ }),
110
+ extraData: {
111
+ unrealizedJustifiedCheckpoint: forkChoice.getUnrealizedJustifiedCheckpoint(),
112
+ unrealizedFinalizedCheckpoint: forkChoice.getUnrealizedFinalizedCheckpoint(),
113
+ proposerBoostRoot: forkChoice.getProposerBoostRoot(),
114
+ previousProposerBoostRoot: forkChoice.getPreviousProposerBoostRoot(),
115
+ headRoot: forkChoice.getHeadRoot(),
116
+ },
117
+ },
118
+ };
119
+ },
120
+
60
121
  async getProtoArrayNodes() {
61
122
  const nodes = chain.forkChoice.getAllNodes().map((node) => ({
62
123
  // if node has executionPayloadNumber, it will overwrite the below default
@@ -927,11 +927,9 @@ export function getValidatorApi(
927
927
  // TODO GLOAS: respect builderSelection (MaxProfit, BuilderAlways, ExecutionAlways, etc.) to let
928
928
  // the user control bid source preferences and value comparison. Also add external builder api
929
929
  // support when it is implemented.
930
- const builderBid = chain.executionPayloadBidPool.getBestBid(
931
- slot,
932
- parentBlock.executionPayloadBlockHash,
933
- parentBlockRootHex
934
- );
930
+ const isBuildingOnFull = chain.forkChoice.shouldBuildOnFull(parentBlock, slot);
931
+ const bidParentBlockHash = isBuildingOnFull ? parentBlock.executionPayloadBlockHash : parentBlock.parentBlockHash;
932
+ const builderBid = chain.executionPayloadBidPool.getBestBid(slot, bidParentBlockHash, parentBlockRootHex);
935
933
 
936
934
  const logCtx = {
937
935
  slot,
@@ -1123,11 +1121,24 @@ export function getValidatorApi(
1123
1121
  // into the slot. Use the envelope's own arrival time (getPayloadEnvelopeSource), not
1124
1122
  // the input's creation time.
1125
1123
  const payloadDueSec = config.getPayloadDueMs() / 1000;
1126
- const payloadPresent =
1127
- payloadInput?.hasPayloadEnvelope() === true &&
1128
- chain.clock.secFromSlot(slot, payloadInput.getPayloadEnvelopeSource().seenTimestampSec) < payloadDueSec;
1124
+ const payloadSeenSec =
1125
+ payloadInput?.hasPayloadEnvelope() === true
1126
+ ? chain.clock.secFromSlot(slot, payloadInput.getPayloadEnvelopeSource().seenTimestampSec)
1127
+ : null;
1128
+ const payloadPresent = payloadSeenSec !== null && payloadSeenSec < payloadDueSec;
1129
1129
  const blobDataAvailable = payloadInput?.hasAllData() === true;
1130
1130
 
1131
+ logger.debug("Produced payload attestation data", {
1132
+ slot,
1133
+ blockRoot: block.blockRoot,
1134
+ blockSlot: block.slot,
1135
+ payloadPresent,
1136
+ blobDataAvailable,
1137
+ hasPayloadInput: payloadInput !== undefined,
1138
+ payloadSeenSec,
1139
+ payloadDueSec,
1140
+ });
1141
+
1131
1142
  return {
1132
1143
  data: {
1133
1144
  beaconBlockRoot: fromHex(block.blockRoot),
@@ -30,7 +30,6 @@ export enum ArchiveStoreTask {
30
30
  PruneHistory = "prune_history",
31
31
  OnFinalizedCheckpoint = "on_finalized_checkpoint",
32
32
  MaybeArchiveState = "maybe_archive_state",
33
- RegenPruneOnFinalized = "regen_prune_on_finalized",
34
33
  ForkchoicePrune = "forkchoice_prune",
35
34
  UpdateBackfillRange = "update_backfill_range",
36
35
  }
@@ -229,10 +228,6 @@ export class ArchiveStore {
229
228
  await this.statesArchiverStrategy.maybeArchiveState(finalized, this.metrics);
230
229
  timer?.({source: ArchiveStoreTask.MaybeArchiveState});
231
230
 
232
- timer = this.metrics?.processFinalizedCheckpoint.durationByTask.startTimer();
233
- this.chain.regen.pruneOnFinalized(finalizedEpoch);
234
- timer?.({source: ArchiveStoreTask.RegenPruneOnFinalized});
235
-
236
231
  // tasks rely on extended fork choice
237
232
  timer = this.metrics?.processFinalizedCheckpoint.durationByTask.startTimer();
238
233
  const prunedBlocks = this.chain.forkChoice.prune(finalized.rootHex);
@@ -276,8 +276,8 @@ export async function produceBlockBody<T extends BlockType>(
276
276
  // Apply parent payload once here as it's reused by EL prep and voluntary exit filtering below
277
277
  let stateAfterParentPayload: IBeaconStateViewBellatrix = currentState;
278
278
  // Spec: should_build_on_full(store, head). `parentBlock` is the proposer's head
279
- // (set by chain.getProposerHead(slot)). Returns false when the PTC majority
280
- // signalled the blob data is not available, forcing a build on EMPTY (reorg).
279
+ // (set by chain.getProposerHead(slot)). Returns false when the PTC majority signalled
280
+ // the blob data is not available or the payload was not timely, forcing a build on EMPTY (reorg).
281
281
  const isBuildingOnFull = this.forkChoice.shouldBuildOnFull(parentBlock, blockSlot);
282
282
  if (isBuildingOnFull) {
283
283
  parentBlockHash = currentState.latestExecutionPayloadBid.blockHash;
@@ -47,7 +47,6 @@ export interface IStateRegenerator extends IStateRegeneratorInternal {
47
47
  getCheckpointStateSync(cp: CheckpointHex): IBeaconStateView | null;
48
48
  getClosestHeadState(head: ProtoBlock): IBeaconStateView | null;
49
49
  pruneOnCheckpoint(finalizedEpoch: Epoch, justifiedEpoch: Epoch, headStateRoot: RootHex): void;
50
- pruneOnFinalized(finalizedEpoch: Epoch): void;
51
50
  processState(blockRootHex: RootHex, postState: IBeaconStateView): void;
52
51
  addCheckpointState(cp: phase0.Checkpoint, item: IBeaconStateView): void;
53
52
  updateHeadState(newHead: ProtoBlock, maybeHeadState: IBeaconStateView): void;
@@ -143,11 +143,6 @@ export class QueuedStateRegenerator implements IStateRegenerator {
143
143
  this.blockStateCache.prune(headStateRoot);
144
144
  }
145
145
 
146
- pruneOnFinalized(finalizedEpoch: number): void {
147
- this.checkpointStateCache.pruneFinalized(finalizedEpoch);
148
- this.blockStateCache.deleteAllBeforeEpoch(finalizedEpoch);
149
- }
150
-
151
146
  processState(blockRootHex: RootHex, postState: IBeaconStateView): void {
152
147
  this.blockStateCache.add(postState);
153
148
  this.checkpointStateCache.processState(blockRootHex, postState).catch((e) => {
@@ -167,12 +167,6 @@ export class FIFOBlockStateCache implements BlockStateCache {
167
167
  }
168
168
  }
169
169
 
170
- /**
171
- * No need for this implementation
172
- * This is only to conform to the old api
173
- */
174
- deleteAllBeforeEpoch(): void {}
175
-
176
170
  /**
177
171
  * ONLY FOR DEBUGGING PURPOSES. For lodestar debug API.
178
172
  */
@@ -414,11 +414,12 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
414
414
 
415
415
  /**
416
416
  * Prune all checkpoint states before the provided finalized epoch.
417
+ * Driven sequentially from processState() so it never interleaves with persist.
417
418
  */
418
- pruneFinalized(finalizedEpoch: Epoch): void {
419
+ private async pruneFinalized(finalizedEpoch: Epoch): Promise<void> {
419
420
  for (const epoch of this.epochIndex.keys()) {
420
421
  if (epoch < finalizedEpoch) {
421
- this.deleteAllEpochItems(epoch).catch((e) =>
422
+ await this.deleteAllEpochItems(epoch).catch((e) =>
422
423
  this.logger.debug("Error delete all epoch items", {epoch, finalizedEpoch}, e as Error)
423
424
  );
424
425
  }
@@ -476,6 +477,9 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
476
477
  * As of Mar 2024, it takes <=350ms to persist a holesky state on fast server
477
478
  */
478
479
  async processState(blockRootHex: RootHex, state: IBeaconStateView): Promise<number> {
480
+ // prune finalized in the same flow so a finalized cp state is pruned, never persisted
481
+ await this.pruneFinalized(state.finalizedCheckpoint.epoch);
482
+
479
483
  let persistCount = 0;
480
484
  // it's important to sort the epochs in ascending order, in case of big reorg we always want to keep the most recent checkpoint states
481
485
  const sortedEpochs = Array.from(this.epochIndex.keys()).sort((a, b) => a - b);
@@ -30,7 +30,6 @@ export interface BlockStateCache {
30
30
  clear(): void;
31
31
  size: number;
32
32
  prune(headStateRootHex: RootHex): void;
33
- deleteAllBeforeEpoch(finalizedEpoch: Epoch): void;
34
33
  dumpSummary(): routes.lodestar.StateCacheItem[];
35
34
  /** Expose beacon states stored in cache. Use with caution */
36
35
  getStates(): IterableIterator<IBeaconStateView>;
@@ -67,7 +66,6 @@ export interface CheckpointStateCache {
67
66
  getOrReloadLatest(rootHex: RootHex, maxEpoch: Epoch): Promise<IBeaconStateView | null>;
68
67
  updatePreComputedCheckpoint(rootHex: RootHex, epoch: Epoch): number | null;
69
68
  prune(finalizedEpoch: Epoch, justifiedEpoch: Epoch): void;
70
- pruneFinalized(finalizedEpoch: Epoch): void;
71
69
  processState(blockRootHex: RootHex, state: IBeaconStateView): Promise<number>;
72
70
  clear(): void;
73
71
  dumpSummary(): routes.lodestar.StateCacheItem[];
@@ -1,6 +1,6 @@
1
1
  import {PeerId} from "@libp2p/interface";
2
2
  import {BeaconConfig} from "@lodestar/config";
3
- import {GENESIS_SLOT, isForkPostDeneb, isForkPostFulu} from "@lodestar/params";
3
+ import {GENESIS_SLOT, isForkPostDeneb} from "@lodestar/params";
4
4
  import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp";
5
5
  import {computeEpochAtSlot} from "@lodestar/state-transition";
6
6
  import {deneb, phase0} from "@lodestar/types";
@@ -29,13 +29,20 @@ export async function* onBeaconBlocksByRange(
29
29
  // starts above it to avoid duplicate yields. See archiveBlocks.ts for the migration logic.
30
30
  const archiveMaxSlot = finalizedSlot;
31
31
 
32
- const forkName = chain.config.getForkName(startSlot);
33
- if (isForkPostFulu(forkName) && startSlot < chain.earliestAvailableSlot) {
34
- chain.logger.verbose("Peer did not respect earliestAvailableSlot for BeaconBlocksByRange", {
32
+ // endSlot is exclusive, so highest served slot is endSlot - 1.
33
+ // Throw only when the entire requested range is below earliestAvailableSlot.
34
+ if (endSlot - 1 < chain.earliestAvailableSlot) {
35
+ chain.logger.verbose("Peer requested range before earliestAvailableSlot for BeaconBlocksByRange", {
35
36
  peer: prettyPrintPeerId(peerId),
36
37
  client: peerClient,
38
+ startSlot,
39
+ count,
40
+ earliestAvailableSlot: chain.earliestAvailableSlot,
37
41
  });
38
- return;
42
+ throw new ResponseError(
43
+ RespStatus.RESOURCE_UNAVAILABLE,
44
+ `Requested range is before earliestAvailableSlot startSlot=${startSlot} count=${count} earliestAvailableSlot=${chain.earliestAvailableSlot}`
45
+ );
39
46
  }
40
47
 
41
48
  // Finalized range of blocks
@@ -1,5 +1,6 @@
1
1
  import {PeerId} from "@libp2p/interface";
2
2
  import {ChainConfig} from "@lodestar/config";
3
+ import {PayloadStatus} from "@lodestar/fork-choice";
3
4
  import {ForkSeq, GENESIS_SLOT} from "@lodestar/params";
4
5
  import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp";
5
6
  import {computeEpochAtSlot} from "@lodestar/state-transition";
@@ -33,12 +34,20 @@ export async function* onDataColumnSidecarsByRange(
33
34
  return;
34
35
  }
35
36
 
36
- if (startSlot < chain.earliestAvailableSlot) {
37
- chain.logger.verbose("Peer did not respect earliestAvailableSlot for DataColumnSidecarsByRange", {
37
+ // endSlot is exclusive, so highest served slot is endSlot - 1.
38
+ // Throw only when the entire requested range is below earliestAvailableSlot.
39
+ if (endSlot - 1 < chain.earliestAvailableSlot) {
40
+ chain.logger.verbose("Peer requested range before earliestAvailableSlot for DataColumnSidecarsByRange", {
38
41
  peer: prettyPrintPeerId(peerId),
39
42
  client: peerClient,
43
+ startSlot,
44
+ count,
45
+ earliestAvailableSlot: chain.earliestAvailableSlot,
40
46
  });
41
- return;
47
+ throw new ResponseError(
48
+ RespStatus.RESOURCE_UNAVAILABLE,
49
+ `Requested range is before earliestAvailableSlot startSlot=${startSlot} count=${count} earliestAvailableSlot=${chain.earliestAvailableSlot}`
50
+ );
42
51
  }
43
52
 
44
53
  const finalized = db.dataColumnSidecarArchive;
@@ -104,6 +113,11 @@ export async function* onDataColumnSidecarsByRange(
104
113
 
105
114
  // Must include only columns in the range requested
106
115
  if (block.slot > archiveMaxSlot && block.slot >= startSlot && block.slot < endSlot) {
116
+ // Post-gloas, columns exist only for FULL blocks (pre-gloas blocks are always FULL)
117
+ if (block.payloadStatus !== PayloadStatus.FULL) {
118
+ continue;
119
+ }
120
+
107
121
  // Note: Here the forkChoice head may change due to a re-org, so the headChain reflects the canonical chain
108
122
  // at the time of the start of the request. Spec is clear the chain of columns must be consistent, but on
109
123
  // re-org there's no need to abort the request
@@ -30,7 +30,7 @@ export async function* onDataColumnSidecarsByRoot(
30
30
  const {blockRoot, columns: requestedColumns} = dataColumnsByRootIdentifier;
31
31
  const availableColumns = validateRequestedDataColumns(chain, requestedColumns);
32
32
  if (availableColumns.length === 0) {
33
- return;
33
+ continue;
34
34
  }
35
35
 
36
36
  const blockRootHex = toRootHex(blockRoot);
@@ -1,3 +1,4 @@
1
+ import {PeerId} from "@libp2p/interface";
1
2
  import {ChainConfig} from "@lodestar/config";
2
3
  import {PayloadStatus} from "@lodestar/fork-choice";
3
4
  import {GENESIS_SLOT} from "@lodestar/params";
@@ -6,23 +7,38 @@ import {computeEpochAtSlot} from "@lodestar/state-transition";
6
7
  import {gloas} from "@lodestar/types";
7
8
  import {IBeaconChain} from "../../../chain/index.js";
8
9
  import {IBeaconDb} from "../../../db/index.js";
10
+ import {prettyPrintPeerId} from "../../util.js";
9
11
 
10
12
  export async function* onExecutionPayloadEnvelopesByRange(
11
13
  request: gloas.ExecutionPayloadEnvelopesByRangeRequest,
12
14
  chain: IBeaconChain,
13
- db: IBeaconDb
15
+ db: IBeaconDb,
16
+ peerId: PeerId,
17
+ peerClient: string
14
18
  ): AsyncIterable<ResponseOutgoing> {
15
19
  const {startSlot, count} = validateExecutionPayloadEnvelopesByRangeRequest(chain.config, request);
16
20
  const endSlot = startSlot + count;
17
21
 
18
- if (startSlot < chain.earliestAvailableSlot) {
19
- return;
22
+ // endSlot is exclusive, so highest served slot is endSlot - 1.
23
+ // Throw only when the entire requested range is below earliestAvailableSlot.
24
+ if (endSlot - 1 < chain.earliestAvailableSlot) {
25
+ chain.logger.verbose("Peer requested range before earliestAvailableSlot for ExecutionPayloadEnvelopesByRange", {
26
+ peer: prettyPrintPeerId(peerId),
27
+ client: peerClient,
28
+ startSlot,
29
+ count,
30
+ earliestAvailableSlot: chain.earliestAvailableSlot,
31
+ });
32
+ throw new ResponseError(
33
+ RespStatus.RESOURCE_UNAVAILABLE,
34
+ `Requested range is before earliestAvailableSlot startSlot=${startSlot} count=${count} earliestAvailableSlot=${chain.earliestAvailableSlot}`
35
+ );
20
36
  }
21
37
 
22
38
  const finalized = db.executionPayloadEnvelopeArchive;
23
- const finalizedSlot = chain.forkChoice.getFinalizedCheckpointSlot();
24
- // The current finalized block's envelope is still in the hot db; archive migration happens
25
- // in the next finalization run (see migrateExecutionPayloadEnvelopesFromHotToColdDb).
39
+ // Use the finalized block's actual slot as the checkpoint epoch-boundary slot may be skipped
40
+ const finalizedSlot = chain.forkChoice.getFinalizedBlock().slot;
41
+ // The finalized block's envelope stays in the hot db until the next finalization run
26
42
  const archiveMaxSlot = finalizedSlot - 1;
27
43
 
28
44
  // Finalized range of envelopes
@@ -1,14 +1,18 @@
1
+ import {PeerId} from "@libp2p/interface";
1
2
  import {ResponseOutgoing} from "@lodestar/reqresp";
2
3
  import {computeEpochAtSlot} from "@lodestar/state-transition";
3
4
  import {toRootHex} from "@lodestar/utils";
4
5
  import {IBeaconChain} from "../../../chain/index.js";
5
6
  import {IBeaconDb} from "../../../db/index.js";
6
7
  import {ExecutionPayloadEnvelopesByRootRequest} from "../../../util/types.js";
8
+ import {prettyPrintPeerId} from "../../util.js";
7
9
 
8
10
  export async function* onExecutionPayloadEnvelopesByRoot(
9
11
  requestBody: ExecutionPayloadEnvelopesByRootRequest,
10
12
  chain: IBeaconChain,
11
- db: IBeaconDb
13
+ db: IBeaconDb,
14
+ peerId: PeerId,
15
+ peerClient: string
12
16
  ): AsyncIterable<ResponseOutgoing> {
13
17
  // The gloas req/resp spec uses MIN_EPOCHS_FOR_BLOCK_REQUESTS to define the minimum range peers MUST serve.
14
18
  // Archival nodes may still serve older retained payloads to allow genesis sync.
@@ -20,6 +24,14 @@ export async function* onExecutionPayloadEnvelopesByRoot(
20
24
  const slot = block ? block.slot : await db.blockArchive.getSlotByRoot(root);
21
25
 
22
26
  if (slot === null) {
27
+ chain.logger.debug(
28
+ "Cannot serve ExecutionPayloadEnvelopesByRoot: block root not in fork choice or block archive",
29
+ {
30
+ root: rootHex,
31
+ peer: prettyPrintPeerId(peerId),
32
+ client: peerClient,
33
+ }
34
+ );
23
35
  continue;
24
36
  }
25
37
 
@@ -29,6 +41,13 @@ export async function* onExecutionPayloadEnvelopesByRoot(
29
41
  data: envelopeBytes,
30
42
  boundary: chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(slot)),
31
43
  };
44
+ } else {
45
+ chain.logger.debug("Cannot serve ExecutionPayloadEnvelopesByRoot: envelope not found", {
46
+ slot,
47
+ root: rootHex,
48
+ peer: prettyPrintPeerId(peerId),
49
+ client: peerClient,
50
+ });
32
51
  }
33
52
  }
34
53
  }
@@ -70,13 +70,13 @@ export function getReqRespHandlers({db, chain}: {db: IBeaconDb; chain: IBeaconCh
70
70
  return onDataColumnSidecarsByRoot(body, chain, db, peerId, peerClient);
71
71
  },
72
72
 
73
- [ReqRespMethod.ExecutionPayloadEnvelopesByRoot]: (req) => {
73
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRoot]: (req, peerId, peerClient) => {
74
74
  const body = ExecutionPayloadEnvelopesByRootRequestType(chain.config).deserialize(req.data);
75
- return onExecutionPayloadEnvelopesByRoot(body, chain, db);
75
+ return onExecutionPayloadEnvelopesByRoot(body, chain, db, peerId, peerClient);
76
76
  },
77
- [ReqRespMethod.ExecutionPayloadEnvelopesByRange]: (req) => {
77
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRange]: (req, peerId, peerClient) => {
78
78
  const body = ssz.gloas.ExecutionPayloadEnvelopesByRangeRequest.deserialize(req.data);
79
- return onExecutionPayloadEnvelopesByRange(body, chain, db);
79
+ return onExecutionPayloadEnvelopesByRange(body, chain, db, peerId, peerClient);
80
80
  },
81
81
 
82
82
  [ReqRespMethod.LightClientBootstrap]: (req) => {
@@ -1,4 +1,5 @@
1
1
  import {LogData} from "@lodestar/logger";
2
+ import {ForkSeq} from "@lodestar/params";
2
3
  import {RespStatus, ResponseError} from "@lodestar/reqresp";
3
4
  import {ColumnIndex, Slot} from "@lodestar/types";
4
5
  import {prettyBytes, prettyPrintIndices, toRootHex} from "@lodestar/utils";
@@ -38,6 +39,13 @@ export async function handleColumnSidecarUnavailability({
38
39
 
39
40
  chain.logger.debug("dataColumnSidecar requested unavailable", logData);
40
41
 
42
+ // Post-gloas, columns exist only for FULL blocks; a finalized block is FULL if its envelope was
43
+ // archived. Bid blobsCount is unreliable here since an EMPTY block's bid may still commit to blobs
44
+ if (blockRoot === undefined && chain.config.getForkSeq(slot) >= ForkSeq.gloas) {
45
+ const envelopeBytes = await db.executionPayloadEnvelopeArchive.getBinary(slot);
46
+ if (!envelopeBytes) return;
47
+ }
48
+
41
49
  const blockBytes = blockRoot ? await db.block.getBinary(blockRoot) : await db.blockArchive.getBinary(slot);
42
50
  if (!blockBytes) {
43
51
  chain.logger.verbose(
@@ -71,9 +79,19 @@ export function validateRequestedDataColumns(chain: IBeaconChain, requestedColum
71
79
  throw new ResponseError(RespStatus.INVALID_REQUEST, "dataColumnSidecar requested without column indices");
72
80
  }
73
81
 
74
- const custodyColumns = chain.custodyConfig.custodyColumns;
75
- const availableColumns = requestedColumns.filter((c) => custodyColumns.includes(c));
76
- const missingColumns = requestedColumns.filter((c) => !custodyColumns.includes(c));
82
+ const {custodyColumns, custodyColumnsIndex} = chain.custodyConfig;
83
+ const availableColumns: ColumnIndex[] = [];
84
+ const missingColumns: ColumnIndex[] = [];
85
+ for (const c of requestedColumns) {
86
+ // `c` is peer-controlled and SSZ-deserialized as `uint64`, so it may exceed
87
+ // `NUMBER_OF_COLUMNS - 1`; `Uint8Array` returns `undefined` for OOB reads,
88
+ // and `undefined !== 0` would silently classify OOB indices as custodied.
89
+ if ((custodyColumnsIndex[c] ?? 0) !== 0) {
90
+ availableColumns.push(c);
91
+ } else {
92
+ missingColumns.push(c);
93
+ }
94
+ }
77
95
 
78
96
  if (missingColumns.length > 0) {
79
97
  chain.logger.verbose("Requested dataColumnSidecar for non-custody columns", {