@lodestar/beacon-node 1.50.0-dev.040a952dd7 → 1.50.0-dev.0edec865c8

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/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/index.js +13 -0
  3. package/lib/api/impl/beacon/index.js.map +1 -1
  4. package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/state/index.js +23 -3
  6. package/lib/api/impl/beacon/state/index.js.map +1 -1
  7. package/lib/api/impl/debug/index.d.ts.map +1 -1
  8. package/lib/api/impl/debug/index.js +26 -18
  9. package/lib/api/impl/debug/index.js.map +1 -1
  10. package/lib/api/impl/validator/index.d.ts +1 -0
  11. package/lib/api/impl/validator/index.d.ts.map +1 -1
  12. package/lib/api/impl/validator/index.js +23 -1
  13. package/lib/api/impl/validator/index.js.map +1 -1
  14. package/lib/chain/archiveStore/archiveStore.d.ts +5 -0
  15. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  16. package/lib/chain/archiveStore/archiveStore.js +13 -23
  17. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  18. package/lib/chain/archiveStore/utils/pruneHistory.d.ts +1 -1
  19. package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
  20. package/lib/chain/archiveStore/utils/pruneHistory.js +2 -1
  21. package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
  22. package/lib/chain/chain.d.ts +4 -1
  23. package/lib/chain/chain.d.ts.map +1 -1
  24. package/lib/chain/chain.js +20 -3
  25. package/lib/chain/chain.js.map +1 -1
  26. package/lib/chain/emitter.d.ts +7 -1
  27. package/lib/chain/emitter.d.ts.map +1 -1
  28. package/lib/chain/emitter.js +5 -0
  29. package/lib/chain/emitter.js.map +1 -1
  30. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  31. package/lib/chain/forkChoice/index.js +2 -0
  32. package/lib/chain/forkChoice/index.js.map +1 -1
  33. package/lib/chain/interface.d.ts +1 -0
  34. package/lib/chain/interface.d.ts.map +1 -1
  35. package/lib/chain/opPools/proposerPreferencesPool.d.ts +4 -4
  36. package/lib/chain/opPools/proposerPreferencesPool.d.ts.map +1 -1
  37. package/lib/chain/opPools/proposerPreferencesPool.js +14 -11
  38. package/lib/chain/opPools/proposerPreferencesPool.js.map +1 -1
  39. package/lib/chain/options.d.ts +1 -0
  40. package/lib/chain/options.d.ts.map +1 -1
  41. package/lib/db/beacon.d.ts +2 -0
  42. package/lib/db/beacon.d.ts.map +1 -1
  43. package/lib/db/beacon.js +3 -0
  44. package/lib/db/beacon.js.map +1 -1
  45. package/lib/db/buckets.d.ts +2 -1
  46. package/lib/db/buckets.d.ts.map +1 -1
  47. package/lib/db/buckets.js +1 -0
  48. package/lib/db/buckets.js.map +1 -1
  49. package/lib/db/interface.d.ts +2 -0
  50. package/lib/db/interface.d.ts.map +1 -1
  51. package/lib/db/repositories/blockArchiveIndex.d.ts +2 -2
  52. package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
  53. package/lib/db/repositories/earliestAvailableSlot.d.ts +11 -0
  54. package/lib/db/repositories/earliestAvailableSlot.d.ts.map +1 -0
  55. package/lib/db/repositories/earliestAvailableSlot.js +19 -0
  56. package/lib/db/repositories/earliestAvailableSlot.js.map +1 -0
  57. package/lib/node/nodejs.d.ts +3 -1
  58. package/lib/node/nodejs.d.ts.map +1 -1
  59. package/lib/node/nodejs.js +2 -1
  60. package/lib/node/nodejs.js.map +1 -1
  61. package/lib/sync/range/chain.d.ts.map +1 -1
  62. package/lib/sync/range/chain.js +5 -1
  63. package/lib/sync/range/chain.js.map +1 -1
  64. package/package.json +17 -17
  65. package/src/api/impl/beacon/index.ts +15 -0
  66. package/src/api/impl/beacon/state/index.ts +31 -3
  67. package/src/api/impl/debug/index.ts +28 -19
  68. package/src/api/impl/validator/index.ts +24 -2
  69. package/src/chain/archiveStore/archiveStore.ts +18 -24
  70. package/src/chain/archiveStore/utils/pruneHistory.ts +4 -1
  71. package/src/chain/chain.ts +32 -2
  72. package/src/chain/emitter.ts +7 -1
  73. package/src/chain/forkChoice/index.ts +2 -0
  74. package/src/chain/interface.ts +1 -0
  75. package/src/chain/opPools/proposerPreferencesPool.ts +14 -10
  76. package/src/chain/options.ts +1 -1
  77. package/src/db/beacon.ts +3 -0
  78. package/src/db/buckets.ts +1 -0
  79. package/src/db/interface.ts +2 -0
  80. package/src/db/repositories/earliestAvailableSlot.ts +19 -0
  81. package/src/node/nodejs.ts +4 -0
  82. package/src/sync/range/chain.ts +6 -1
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.50.0-dev.040a952dd7",
14
+ "version": "1.50.0-dev.0edec865c8",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -104,12 +104,12 @@
104
104
  "@chainsafe/discv5": "^12.0.2",
105
105
  "@chainsafe/enr": "^6.0.2",
106
106
  "@chainsafe/libp2p-noise": "^17.0.0",
107
- "@chainsafe/libp2p-quic": "^2.1.4",
107
+ "@chainsafe/libp2p-quic": "^2.1.5",
108
108
  "@chainsafe/lodestar-z": "catalog:",
109
109
  "@chainsafe/persistent-merkle-tree": "^1.3.1",
110
110
  "@chainsafe/prometheus-gc-stats": "^1.0.0",
111
111
  "@chainsafe/snappy-wasm": "^0.5.2",
112
- "@chainsafe/ssz": "^1.8.0",
112
+ "@chainsafe/ssz": "^1.8.1",
113
113
  "@chainsafe/threads": "^1.11.3",
114
114
  "@crate-crypto/node-eth-kzg": "0.9.1",
115
115
  "@fastify/bearer-auth": "^10.0.1",
@@ -127,17 +127,17 @@
127
127
  "@libp2p/prometheus-metrics": "^5.0.28",
128
128
  "@libp2p/tcp": "^11.0.27",
129
129
  "@libp2p/utils": "^7.4.0",
130
- "@lodestar/api": "^1.50.0-dev.040a952dd7",
131
- "@lodestar/config": "^1.50.0-dev.040a952dd7",
132
- "@lodestar/db": "^1.50.0-dev.040a952dd7",
133
- "@lodestar/fork-choice": "^1.50.0-dev.040a952dd7",
134
- "@lodestar/logger": "^1.50.0-dev.040a952dd7",
135
- "@lodestar/params": "^1.50.0-dev.040a952dd7",
136
- "@lodestar/reqresp": "^1.50.0-dev.040a952dd7",
137
- "@lodestar/state-transition": "^1.50.0-dev.040a952dd7",
138
- "@lodestar/types": "^1.50.0-dev.040a952dd7",
139
- "@lodestar/utils": "^1.50.0-dev.040a952dd7",
140
- "@lodestar/validator": "^1.50.0-dev.040a952dd7",
130
+ "@lodestar/api": "^1.50.0-dev.0edec865c8",
131
+ "@lodestar/config": "^1.50.0-dev.0edec865c8",
132
+ "@lodestar/db": "^1.50.0-dev.0edec865c8",
133
+ "@lodestar/fork-choice": "^1.50.0-dev.0edec865c8",
134
+ "@lodestar/logger": "^1.50.0-dev.0edec865c8",
135
+ "@lodestar/params": "^1.50.0-dev.0edec865c8",
136
+ "@lodestar/reqresp": "^1.50.0-dev.0edec865c8",
137
+ "@lodestar/state-transition": "^1.50.0-dev.0edec865c8",
138
+ "@lodestar/types": "^1.50.0-dev.0edec865c8",
139
+ "@lodestar/utils": "^1.50.0-dev.0edec865c8",
140
+ "@lodestar/validator": "^1.50.0-dev.0edec865c8",
141
141
  "@multiformats/multiaddr": "^13.0.1",
142
142
  "datastore-core": "^12.0.1",
143
143
  "datastore-level": "^13.0.1",
@@ -158,8 +158,8 @@
158
158
  "devDependencies": {
159
159
  "@libp2p/interface-internal": "^3.1.12",
160
160
  "@libp2p/logger": "^6.2.13",
161
- "@lodestar/spec-test-util": "^1.50.0-dev.040a952dd7",
162
- "@lodestar/test-utils": "^1.50.0-dev.040a952dd7",
161
+ "@lodestar/spec-test-util": "^1.50.0-dev.0edec865c8",
162
+ "@lodestar/test-utils": "^1.50.0-dev.0edec865c8",
163
163
  "@types/js-yaml": "^4.0.5",
164
164
  "@types/qs": "^6.9.7",
165
165
  "@types/tmp": "^0.2.3",
@@ -174,5 +174,5 @@
174
174
  "beacon",
175
175
  "blockchain"
176
176
  ],
177
- "gitHead": "156629b17ad44c8a312b54015fd953e94b4874e6"
177
+ "gitHead": "1259f71df5e7291cc1623e493fd89d3e2cd0908d"
178
178
  }
@@ -1,5 +1,9 @@
1
1
  import {routes} from "@lodestar/api";
2
2
  import {ApplicationMethods} from "@lodestar/api/server";
3
+ import {isForkPostGloas} from "@lodestar/params";
4
+ import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
5
+ import {toRootHex} from "@lodestar/utils";
6
+ import {ApiError} from "../errors.js";
3
7
  import {ApiModules} from "../types.js";
4
8
  import {getBeaconBlockApi} from "./blocks/index.js";
5
9
  import {getBeaconPoolApi} from "./pool/index.js";
@@ -31,5 +35,16 @@ export function getBeaconApi(
31
35
  },
32
36
  };
33
37
  },
38
+
39
+ async getProposerPreferences({slot, dependentRoot}) {
40
+ // Preferences are broadcast up to one epoch ahead of their proposal slot, the first ones before Gloas is active
41
+ const fork = config.getForkName(slot ?? computeStartSlotAtEpoch(chain.clock.currentEpoch + 1));
42
+ if (!isForkPostGloas(fork)) {
43
+ throw new ApiError(400, `Proposer preferences are not supported before Gloas fork=${fork}`);
44
+ }
45
+
46
+ const preferences = chain.proposerPreferencesPool.getAll(slot, dependentRoot && toRootHex(dependentRoot));
47
+ return {data: preferences, meta: {version: fork}};
48
+ },
34
49
  };
35
50
  }
@@ -1,6 +1,11 @@
1
1
  import {routes} from "@lodestar/api";
2
2
  import {ApplicationMethods} from "@lodestar/api/server";
3
- import {EPOCHS_PER_HISTORICAL_VECTOR, SLOTS_PER_EPOCH, SYNC_COMMITTEE_SUBNET_SIZE} from "@lodestar/params";
3
+ import {
4
+ EPOCHS_PER_HISTORICAL_VECTOR,
5
+ MIN_SEED_LOOKAHEAD,
6
+ SLOTS_PER_EPOCH,
7
+ SYNC_COMMITTEE_SUBNET_SIZE,
8
+ } from "@lodestar/params";
4
9
  import {
5
10
  IBeaconStateView,
6
11
  computeEpochAtSlot,
@@ -11,7 +16,7 @@ import {
11
16
  isStatePostFulu,
12
17
  isStatePostGloas,
13
18
  } from "@lodestar/state-transition";
14
- import {ValidatorIndex, getBuilderStatus, getValidatorStatus, ssz} from "@lodestar/types";
19
+ import {ValidatorIndex, getBuilderStatus, getValidatorStatus, mapToGeneralStatus, ssz} from "@lodestar/types";
15
20
  import {ApiError} from "../../errors.js";
16
21
  import {ApiModules} from "../../types.js";
17
22
  import {assertUniqueItems} from "../../utils.js";
@@ -100,7 +105,8 @@ export function getBeaconStateApi({
100
105
  if (resp.valid) {
101
106
  const validatorIndex = resp.validatorIndex;
102
107
  const validator = state.getValidator(validatorIndex);
103
- if (statuses.length && !statuses.includes(getValidatorStatus(validator, currentEpoch))) {
108
+ const status = getValidatorStatus(validator, currentEpoch);
109
+ if (statuses.length && !statuses.includes(status) && !statuses.includes(mapToGeneralStatus(status))) {
104
110
  continue;
105
111
  }
106
112
  const validatorResponse = toValidatorResponse(
@@ -374,6 +380,28 @@ export function getBeaconStateApi({
374
380
  };
375
381
  },
376
382
 
383
+ async getStatePtc({stateId, slot}) {
384
+ const {state, executionOptimistic, finalized} = await getState(stateId);
385
+ if (!isStatePostGloas(state)) {
386
+ throw new ApiError(400, `Cannot retrieve PTC for pre-gloas state fork=${state.forkName}`);
387
+ }
388
+
389
+ const usedSlot = slot ?? state.slot;
390
+ const epoch = computeEpochAtSlot(usedSlot);
391
+ const stateEpoch = computeEpochAtSlot(state.slot);
392
+ if (epoch < config.GLOAS_FORK_EPOCH) {
393
+ throw new ApiError(400, `Cannot retrieve PTC for pre-gloas slot=${usedSlot}`);
394
+ }
395
+ if (epoch < stateEpoch - 1 || epoch > stateEpoch + MIN_SEED_LOOKAHEAD) {
396
+ throw new ApiError(400, `Slot ${usedSlot} is outside the PTC window of state epoch ${stateEpoch}`);
397
+ }
398
+
399
+ return {
400
+ data: {slot: usedSlot, validators: Array.from(state.getPayloadTimelinessCommittee(usedSlot))},
401
+ meta: {executionOptimistic, finalized},
402
+ };
403
+ },
404
+
377
405
  async getPendingDeposits({stateId}, context) {
378
406
  const {state, executionOptimistic, finalized} = await getState(stateId);
379
407
  const fork = state.forkName;
@@ -4,7 +4,7 @@ import {ExecutionStatus, PayloadStatus} from "@lodestar/fork-choice";
4
4
  import {ForkPostDeneb, ZERO_HASH_HEX, isForkPostDeneb, isForkPostFulu} from "@lodestar/params";
5
5
  import {computeTimeAtSlot} from "@lodestar/state-transition";
6
6
  import {BeaconState, DataColumnSidecar, DataColumnSidecars, type SignedBeaconBlock, sszTypesFor} from "@lodestar/types";
7
- import {toRootHex} from "@lodestar/utils";
7
+ import {fromHex, toRootHex} from "@lodestar/utils";
8
8
  import {getBlobKzgCommitments} from "../../../util/dataColumns.js";
9
9
  import {isOptimisticBlock} from "../../../util/forkChoice.js";
10
10
  import {getStateSlotFromBytes} from "../../../util/multifork.js";
@@ -74,46 +74,55 @@ export function getDebugApi({
74
74
 
75
75
  async getDebugForkChoiceV2() {
76
76
  const {forkChoice} = chain;
77
+ const nodes = forkChoice.getAllNodes();
78
+ const head = forkChoice.getHead();
77
79
  return {
78
80
  data: {
79
81
  justifiedCheckpoint: forkChoice.getJustifiedCheckpoint(),
80
82
  finalizedCheckpoint: forkChoice.getFinalizedCheckpoint(),
81
- forkChoiceNodes: forkChoice.getAllNodes().map((node) => {
82
- // Payload-specific fields apply only to a revealed Gloas payload = the FULL variant of a
83
- // Gloas block
84
- const ptc = node.payloadStatus === PayloadStatus.FULL ? forkChoice.getPTCVoteCounts(node.blockRoot) : null;
83
+ forkChoiceNodes: nodes.map((node) => {
84
+ const parent = node.parent === undefined ? undefined : nodes[node.parent];
85
+ const ptc = forkChoice.getPTCVoteCounts(node.blockRoot);
85
86
  return {
86
- payloadStatus: toPayloadStatusName(node.payloadStatus),
87
87
  slot: node.slot,
88
88
  blockRoot: node.blockRoot,
89
- parentRoot: node.parentRoot,
89
+ payloadStatus: toPayloadStatusName(node.payloadStatus),
90
+ parentRoot:
91
+ node.parentBlockHash !== null && node.payloadStatus !== PayloadStatus.PENDING
92
+ ? node.blockRoot
93
+ : node.parentRoot,
94
+ parentPayloadStatus: parent === undefined ? null : toPayloadStatusName(parent.payloadStatus),
95
+ justifiedCheckpoint: {epoch: node.justifiedEpoch, root: fromHex(node.justifiedRoot)},
96
+ finalizedCheckpoint: {epoch: node.finalizedEpoch, root: fromHex(node.finalizedRoot)},
90
97
  weight: node.weight,
91
98
  validity: toForkChoiceValidity(node.executionStatus),
92
99
  executionBlockHash: node.executionPayloadBlockHash ?? ZERO_HASH_HEX,
100
+ payloadAttesterCount: ptc?.attesterCount ?? 0,
101
+ payloadAvailabilityYesCount: ptc?.payloadPresentCount ?? 0,
102
+ payloadDataAvailabilityYesCount: ptc?.dataAvailableCount ?? 0,
93
103
  extraData: {
104
+ attestationScore: node.attestationScore,
94
105
  executionOptimistic: isOptimisticBlock(node),
106
+ gasLimit:
107
+ node.payloadStatus === PayloadStatus.FULL && node.executionStatus !== ExecutionStatus.PreMerge
108
+ ? node.executionPayloadGasLimit
109
+ : null,
95
110
  timestamp: computeTimeAtSlot(config, node.slot, chain.genesisTime),
111
+ stateRoot: node.stateRoot,
96
112
  target: node.targetRoot,
97
- justifiedEpoch: node.justifiedEpoch,
98
- finalizedEpoch: node.finalizedEpoch,
99
113
  unrealizedJustifiedEpoch: node.unrealizedJustifiedEpoch,
114
+ unrealizedJustifiedRoot: node.unrealizedJustifiedRoot,
100
115
  unrealizedFinalizedEpoch: node.unrealizedFinalizedEpoch,
101
- payloadAttesterCount: ptc?.attesterCount ?? null,
102
- payloadAvailabilityYesCount: ptc?.payloadPresentCount ?? null,
103
- payloadDataAvailabilityYesCount: ptc?.dataAvailableCount ?? null,
104
- gasLimit:
105
- node.payloadStatus === PayloadStatus.FULL && "executionPayloadGasLimit" in node
106
- ? node.executionPayloadGasLimit
107
- : null,
116
+ unrealizedFinalizedRoot: node.unrealizedFinalizedRoot,
108
117
  },
109
118
  };
110
119
  }),
111
120
  extraData: {
112
- unrealizedJustifiedCheckpoint: forkChoice.getUnrealizedJustifiedCheckpoint(),
113
- unrealizedFinalizedCheckpoint: forkChoice.getUnrealizedFinalizedCheckpoint(),
121
+ head: {blockRoot: head.blockRoot, payloadStatus: toPayloadStatusName(head.payloadStatus)},
114
122
  proposerBoostRoot: forkChoice.getProposerBoostRoot(),
115
123
  previousProposerBoostRoot: forkChoice.getPreviousProposerBoostRoot(),
116
- headRoot: forkChoice.getHeadRoot(),
124
+ unrealizedJustifiedCheckpoint: forkChoice.getUnrealizedJustifiedCheckpoint(),
125
+ unrealizedFinalizedCheckpoint: forkChoice.getUnrealizedFinalizedCheckpoint(),
117
126
  },
118
127
  },
119
128
  };
@@ -189,6 +189,7 @@ export enum EngineBlockSelectionReason {
189
189
  BuilderTimeout = "builder_timeout",
190
190
  BuilderPending = "builder_pending",
191
191
  BuilderNoBid = "builder_no_bid",
192
+ BuilderCircuitBreaker = "builder_circuit_breaker",
192
193
  BuilderCensorship = "builder_censorship",
193
194
  BlockValue = "block_value",
194
195
  EnginePreferred = "engine_preferred",
@@ -1160,8 +1161,21 @@ export function getValidatorApi(
1160
1161
  : {}),
1161
1162
  };
1162
1163
 
1163
- // handle shouldOverrideBuilder separately
1164
- if (
1164
+ if (circuitBreakerActive && engineResult.status === "fulfilled") {
1165
+ source = ProducedBlockSource.engine;
1166
+ bestResult = engineResult;
1167
+ metrics?.blockProductionSelectionResults.inc({
1168
+ source: ProducedBlockSource.engine,
1169
+ reason: EngineBlockSelectionReason.BuilderCircuitBreaker,
1170
+ });
1171
+ logger.info("Selected local block: builder circuit breaker is active", {
1172
+ reason: EngineBlockSelectionReason.BuilderCircuitBreaker,
1173
+ ...logCtx,
1174
+ durationMs: engineResult.durationMs,
1175
+ ...getBlockValueLogInfo(engineResult.value),
1176
+ });
1177
+ } else if (
1178
+ // handle shouldOverrideBuilder separately
1165
1179
  engineResult.status === "fulfilled" &&
1166
1180
  engineResult.value.shouldOverrideBuilder &&
1167
1181
  (builderBidExpected || bidBlockResult.status === "fulfilled")
@@ -1286,6 +1300,10 @@ export function getValidatorApi(
1286
1300
  blobs: blobsBundle.blobs,
1287
1301
  };
1288
1302
 
1303
+ if (chain.opts.persistProducedPayloadEnvelopes) {
1304
+ chain.persistExecutionPayloadEnvelope(blockContents.executionPayloadEnvelope);
1305
+ }
1306
+
1289
1307
  return {
1290
1308
  data: blockContents,
1291
1309
  meta: {version: fork, consensusBlockValue, executionPayloadValue, executionPayloadIncluded: true},
@@ -2173,6 +2191,10 @@ export function getValidatorApi(
2173
2191
  blockHash: toRootHex(executionPayload.blockHash),
2174
2192
  });
2175
2193
 
2194
+ if (chain.opts.persistProducedPayloadEnvelopes) {
2195
+ chain.persistExecutionPayloadEnvelope(envelope);
2196
+ }
2197
+
2176
2198
  return {
2177
2199
  data: envelope,
2178
2200
  meta: {
@@ -113,7 +113,9 @@ export class ArchiveStore {
113
113
  this.logger,
114
114
  this.metrics,
115
115
  this.opts.anchorState.finalizedCheckpoint.epoch,
116
- this.chain.clock.currentEpoch
116
+ this.chain.clock.currentEpoch,
117
+ this.statePruneFromSlot,
118
+ this.advanceEarliestAvailableSlot
117
119
  ),
118
120
  () => this.logger.info("Still pruning historical data, please wait..."),
119
121
  30_000,
@@ -122,26 +124,6 @@ export class ArchiveStore {
122
124
  this.statePruneFromSlot = stateCutoffSlot;
123
125
  }
124
126
 
125
- // Initialize earliestAvailableSlot from the earliest block actually retained (after any pruning
126
- // above), rather than the anchor state slot set in the constructor. On an in-place restart the DB
127
- // still holds finalized history below the anchor; leaving the value at the anchor makes the node
128
- // reject by_range requests (beacon_blocks, execution_payload_envelopes and data_column_sidecars
129
- // all gate on this slot) for data it still retains. An empty archive (e.g. a fresh checkpoint
130
- // sync with nothing below the anchor) leaves the constructor's anchor slot in place.
131
- const earliestArchivedBlockSlot = await this.db.blockArchive.firstKey();
132
- if (earliestArchivedBlockSlot != null) {
133
- const oldEarliestAvailableSlot = this.chain.earliestAvailableSlot;
134
- this.chain.earliestAvailableSlot = earliestArchivedBlockSlot;
135
- this.logger.verbose("Initialized earliestAvailableSlot from retained block archive", {
136
- oldEarliestAvailableSlot,
137
- newEarliestAvailableSlot: earliestArchivedBlockSlot,
138
- });
139
- } else {
140
- this.logger.verbose("Empty block archive on init, keeping anchor earliestAvailableSlot", {
141
- earliestAvailableSlot: this.chain.earliestAvailableSlot,
142
- });
143
- }
144
-
145
127
  if (this.opts.serveHistoricalState) {
146
128
  this.historicalStateRegen = await HistoricalStateRegen.init({
147
129
  opts: {
@@ -158,6 +140,18 @@ export class ArchiveStore {
158
140
  }
159
141
  }
160
142
 
143
+ /**
144
+ * The CLI owns the initial value; this only advances it during pruneHistory.
145
+ * Persisted before any deletion so a crash mid-prune never leaves the floor below deleted data.
146
+ */
147
+ private advanceEarliestAvailableSlot = async (blockCutoffSlot: Slot): Promise<void> => {
148
+ const earliestAvailableSlot = Math.max(this.chain.earliestAvailableSlot, blockCutoffSlot);
149
+ if (earliestAvailableSlot !== this.chain.earliestAvailableSlot) {
150
+ await this.db.earliestAvailableSlot.set(earliestAvailableSlot);
151
+ this.chain.earliestAvailableSlot = earliestAvailableSlot;
152
+ }
153
+ };
154
+
161
155
  async close(): Promise<void> {
162
156
  await this.historicalStateRegen?.close();
163
157
  }
@@ -259,17 +253,17 @@ export class ArchiveStore {
259
253
 
260
254
  if (this.opts.pruneHistory) {
261
255
  timer = this.metrics?.processFinalizedCheckpoint.durationByTask.startTimer();
262
- const {blockCutoffSlot, stateCutoffSlot} = await pruneHistory(
256
+ const {stateCutoffSlot} = await pruneHistory(
263
257
  this.chain.config,
264
258
  this.db,
265
259
  this.logger,
266
260
  this.metrics,
267
261
  finalizedEpoch,
268
262
  this.chain.clock.currentEpoch,
269
- this.statePruneFromSlot
263
+ this.statePruneFromSlot,
264
+ this.advanceEarliestAvailableSlot
270
265
  );
271
266
  this.statePruneFromSlot = stateCutoffSlot;
272
- this.chain.earliestAvailableSlot = Math.max(this.chain.earliestAvailableSlot, blockCutoffSlot);
273
267
  timer?.({source: ArchiveStoreTask.PruneHistory});
274
268
  }
275
269
 
@@ -12,7 +12,8 @@ export async function pruneHistory(
12
12
  metrics: Metrics | null | undefined,
13
13
  finalizedEpoch: Epoch,
14
14
  currentEpoch: Epoch,
15
- statePruneFromSlot: Slot = 0
15
+ statePruneFromSlot: Slot,
16
+ beforePrune: (blockCutoffSlot: Slot) => Promise<void>
16
17
  ): Promise<{blockCutoffSlot: Slot; stateCutoffSlot: Slot}> {
17
18
  const blockCutoffEpoch = Math.min(
18
19
  // set by config, with underflow protection
@@ -51,6 +52,8 @@ export async function pruneHistory(
51
52
  stateSlots: prettyPrintIndices(states),
52
53
  });
53
54
 
55
+ await beforePrune(blockCutoffSlot);
56
+
54
57
  const step1 = metrics?.pruneHistory.pruneKeys.startTimer();
55
58
  await Promise.all([
56
59
  // ->
@@ -244,6 +244,7 @@ export class BeaconChain implements IBeaconChain {
244
244
  protected readonly blockProcessor: BlockProcessor;
245
245
  protected readonly payloadEnvelopeProcessor: PayloadEnvelopeProcessor;
246
246
  protected readonly db: IBeaconDb;
247
+ private genesisStateRoot?: RootHex | null;
247
248
  // this is only available if nHistoricalStates is enabled
248
249
  private readonly cpStateDatastore?: CPStateDatastore;
249
250
  private abortController = new AbortController();
@@ -278,6 +279,7 @@ export class BeaconChain implements IBeaconChain {
278
279
  validatorMonitor,
279
280
  anchorState,
280
281
  isAnchorStateFinalized,
282
+ earliestAvailableSlot,
281
283
  executionEngine,
282
284
  executionBuilder,
283
285
  builderApiClientOpts,
@@ -297,6 +299,7 @@ export class BeaconChain implements IBeaconChain {
297
299
  validatorMonitor: ValidatorMonitor | null;
298
300
  anchorState: IBeaconStateView;
299
301
  isAnchorStateFinalized: boolean;
302
+ earliestAvailableSlot: Slot;
300
303
  executionEngine: IExecutionEngine;
301
304
  executionBuilder?: IExecutionBuilder;
302
305
  builderApiClientOpts?: BuilderApiClientOpts;
@@ -362,7 +365,7 @@ export class BeaconChain implements IBeaconChain {
362
365
  logger,
363
366
  });
364
367
 
365
- this._earliestAvailableSlot = anchorState.slot;
368
+ this._earliestAvailableSlot = earliestAvailableSlot;
366
369
 
367
370
  this.shufflingCache = new ShufflingCache(metrics, logger, this.opts, [
368
371
  {
@@ -723,6 +726,17 @@ export class BeaconChain implements IBeaconChain {
723
726
  }
724
727
  }
725
728
 
729
+ if (this.genesisStateRoot === undefined) {
730
+ const genesisBlock = await this.db.blockArchive.get(GENESIS_SLOT);
731
+ this.genesisStateRoot = genesisBlock ? toRootHex(genesisBlock.message.stateRoot) : null;
732
+ }
733
+ if (this.genesisStateRoot === stateRoot) {
734
+ const state = await this.db.stateArchive.getBinary(GENESIS_SLOT);
735
+ if (state) {
736
+ return {state, executionOptimistic: false, finalized: finalizedCheckpoint.epoch !== GENESIS_EPOCH};
737
+ }
738
+ }
739
+
726
740
  if (opts?.allowRegen) {
727
741
  const state = await this.regen.getState(stateRoot, RegenCaller.restApi);
728
742
  const block = this.forkChoice.getBlockDefaultStatus(
@@ -1524,6 +1538,22 @@ export class BeaconChain implements IBeaconChain {
1524
1538
  }
1525
1539
  }
1526
1540
 
1541
+ persistExecutionPayloadEnvelope(envelope: gloas.ExecutionPayloadEnvelope): void {
1542
+ const blockRoot = toRootHex(envelope.beaconBlockRoot);
1543
+ void this.persistSszObject(
1544
+ "ExecutionPayloadEnvelope",
1545
+ ssz.gloas.ExecutionPayloadEnvelope.serialize(envelope),
1546
+ blockRoot,
1547
+ "produced_execution_payload_envelope"
1548
+ ).catch((e) => {
1549
+ this.logger.error(
1550
+ "Error persisting produced execution payload envelope",
1551
+ {slot: envelope.payload.slotNumber, blockRoot},
1552
+ e as Error
1553
+ );
1554
+ });
1555
+ }
1556
+
1527
1557
  /**
1528
1558
  * Invalid state root error is critical and it causes the node to stale most of the time so we want to always
1529
1559
  * persist preState, postState and block for further investigation.
@@ -1719,7 +1749,7 @@ export class BeaconChain implements IBeaconChain {
1719
1749
  // remove date suffixes in file name, and check duplicate to avoid redundant persistence
1720
1750
  await writeIfNotExist(filepath, bytes);
1721
1751
 
1722
- this.logger.debug("Persisted invalid ssz object", {id: logStr, filepath});
1752
+ this.logger.debug("Persisted SSZ object", {id: logStr, filepath});
1723
1753
  }
1724
1754
 
1725
1755
  private onScrapeMetrics(metrics: Metrics): void {
@@ -1,7 +1,7 @@
1
1
  import {EventEmitter} from "node:events";
2
2
  import {StrictEventEmitter} from "strict-event-emitter-types";
3
3
  import {routes} from "@lodestar/api";
4
- import {CheckpointWithHex} from "@lodestar/fork-choice";
4
+ import {CheckpointWithHex, PtcQuorumEvent} from "@lodestar/fork-choice";
5
5
  import {IBeaconStateView} from "@lodestar/state-transition";
6
6
  import {DataColumnSidecar, RootHex, Slot, deneb, phase0} from "@lodestar/types";
7
7
  import {PeerIdStr} from "../util/peerId.js";
@@ -36,6 +36,11 @@ export enum ChainEvent {
36
36
  * This event is guaranteed to be triggered whenever the fork choice finalized checkpoint is updated. This is either in response to a newly processed block or a new clock tick.
37
37
  */
38
38
  forkChoiceFinalized = "forkChoice:finalized",
39
+ /**
40
+ * This event signals that the PTC verdict on a block was decided: a majority against payload presence or blob data
41
+ * availability, or a majority for both.
42
+ */
43
+ forkChoicePtcQuorum = "forkChoice:ptcQuorum",
39
44
  /**
40
45
  * This event signals that dependent services (e.g. custody sampling) should update to account for the new target group count.
41
46
  */
@@ -112,6 +117,7 @@ export type IChainEvents = ApiEvents & {
112
117
 
113
118
  [ChainEvent.forkChoiceJustified]: (checkpoint: CheckpointWithHex) => void;
114
119
  [ChainEvent.forkChoiceFinalized]: (checkpoint: CheckpointWithHex) => void;
120
+ [ChainEvent.forkChoicePtcQuorum]: (data: PtcQuorumEvent) => void;
115
121
 
116
122
  [ChainEvent.updateTargetCustodyGroupCount]: (targetGroupCount: number) => void;
117
123
 
@@ -124,6 +124,7 @@ export function initializeForkChoiceFromFinalizedState(
124
124
  onFinalized: (cp) => emitter.emit(ChainEvent.forkChoiceFinalized, cp),
125
125
  onFastConfirmation: ({block, slot, currentSlot}) =>
126
126
  emitter.emit(routes.events.EventType.fastConfirmation, {block, slot, currentSlot}),
127
+ onPtcQuorum: (data) => emitter.emit(ChainEvent.forkChoicePtcQuorum, data),
127
128
  }
128
129
  ),
129
130
 
@@ -222,6 +223,7 @@ export function initializeForkChoiceFromUnfinalizedState(
222
223
  onFinalized: (cp) => emitter.emit(ChainEvent.forkChoiceFinalized, cp),
223
224
  onFastConfirmation: ({block, slot, currentSlot}) =>
224
225
  emitter.emit(routes.events.EventType.fastConfirmation, {block, slot, currentSlot}),
226
+ onPtcQuorum: (data) => emitter.emit(ChainEvent.forkChoicePtcQuorum, data),
225
227
  }
226
228
  );
227
229
 
@@ -290,6 +290,7 @@ export interface IBeaconChain {
290
290
  updateBeaconProposerData(epoch: Epoch, proposers: ProposerPreparationData[]): Promise<void>;
291
291
 
292
292
  persistBlock(data: BeaconBlock | BlindedBeaconBlock, suffix?: string): void;
293
+ persistExecutionPayloadEnvelope(envelope: gloas.ExecutionPayloadEnvelope): void;
293
294
  persistInvalidStateRoot(
294
295
  preState: IBeaconStateView,
295
296
  postState: IBeaconStateView,
@@ -6,8 +6,8 @@ import {toRootHex} from "@lodestar/utils";
6
6
  *
7
7
  * The primary consumer is `validateExecutionPayloadBid`, which looks up the matching
8
8
  * preferences via `get(bid.slot, dependent_root)` to enforce the IGNORE-existence and
9
- * REJECT-equality rules from the gloas spec. The beacon API `/pool/proposer_preferences`
10
- * GET endpoint reads from the same pool via `getAll`.
9
+ * REJECT-equality rules from the gloas spec. The beacon API `getProposerPreferences`
10
+ * endpoint reads from the same pool via `getAll`.
11
11
  *
12
12
  * `validator_index` is intentionally not part of the key: gossip validation enforces
13
13
  * `proposers[proposalSlot % SLOTS_PER_EPOCH] === validatorIndex` against the shuffling
@@ -37,15 +37,19 @@ export class ProposerPreferencesPool {
37
37
  byRoot.set(rootHex, signed);
38
38
  }
39
39
 
40
- /** API read-out: flatten across branches, optionally filtered by slot. */
41
- getAll(slot?: Slot): gloas.SignedProposerPreferences[] {
42
- if (slot !== undefined) {
43
- const byRoot = this.bySlot.get(slot);
44
- return byRoot ? Array.from(byRoot.values()) : [];
45
- }
40
+ /** API read-out: flatten across branches, optionally filtered by slot and dependent root. */
41
+ getAll(slot?: Slot, dependentRootHex?: RootHex): gloas.SignedProposerPreferences[] {
46
42
  const out: gloas.SignedProposerPreferences[] = [];
47
- for (const byRoot of this.bySlot.values()) {
48
- for (const v of byRoot.values()) out.push(v);
43
+ for (const [s, byRoot] of this.bySlot) {
44
+ if (slot !== undefined && s !== slot) {
45
+ continue;
46
+ }
47
+ for (const [root, signed] of byRoot) {
48
+ if (dependentRootHex !== undefined && root !== dependentRootHex) {
49
+ continue;
50
+ }
51
+ out.push(signed);
52
+ }
49
53
  }
50
54
  return out;
51
55
  }
@@ -27,8 +27,8 @@ export type IChainOptions = BlockProcessOpts &
27
27
  blsVerifyAllMainThread?: boolean;
28
28
  blsVerifyAllMultiThread?: boolean;
29
29
  blacklistedBlocks?: string[];
30
- // TODO GLOAS: add similar option for execution payload envelopes?
31
30
  persistProducedBlocks?: boolean;
31
+ persistProducedPayloadEnvelopes?: boolean;
32
32
  /** Archive finalized Gloas payload envelopes as headers (bodies reconstructed from the EL on read) */
33
33
  dedupePayloads?: boolean;
34
34
  persistInvalidSszObjects?: boolean;
package/src/db/beacon.ts CHANGED
@@ -8,6 +8,7 @@ import {FlatFileStore} from "./flatFileStore/flatFileStore.js";
8
8
  import type {FlatFileStoreMetrics} from "./flatFileStore/metrics.js";
9
9
  import {IBeaconDb} from "./interface.js";
10
10
  import {CheckpointStateRepository} from "./repositories/checkpointState.js";
11
+ import {EarliestAvailableSlotRepository} from "./repositories/earliestAvailableSlot.js";
11
12
  import {
12
13
  AttesterSlashingRepository,
13
14
  BLSToExecutionChangeRepository,
@@ -48,6 +49,7 @@ export class BeaconDb implements IBeaconDb {
48
49
 
49
50
  stateArchive: StateArchiveRepository;
50
51
  checkpointState: CheckpointStateRepository;
52
+ earliestAvailableSlot: EarliestAvailableSlotRepository;
51
53
 
52
54
  voluntaryExit: VoluntaryExitRepository;
53
55
  proposerSlashing: ProposerSlashingRepository;
@@ -83,6 +85,7 @@ export class BeaconDb implements IBeaconDb {
83
85
 
84
86
  this.stateArchive = new StateArchiveRepository(config, db);
85
87
  this.checkpointState = new CheckpointStateRepository(config, db);
88
+ this.earliestAvailableSlot = new EarliestAvailableSlotRepository(db);
86
89
  this.voluntaryExit = new VoluntaryExitRepository(config, db);
87
90
  this.blsToExecutionChange = new BLSToExecutionChangeRepository(config, db);
88
91
  this.proposerSlashing = new ProposerSlashingRepository(config, db);
package/src/db/buckets.ts CHANGED
@@ -72,6 +72,7 @@ export enum Bucket {
72
72
 
73
73
  gloas_executionPayloadEnvelope = 59, // GLOAS BeaconBlockRoot -> SignedExecutionPayloadEnvelope
74
74
  gloas_executionPayloadEnvelopeArchive = 60, // GLOAS Slot -> SignedExecutionPayloadEnvelope, or 0x00 + SignedExecutionPayloadHeaderEnvelope
75
+ earliestAvailableSlot = 61, // singleton -> Slot
75
76
  }
76
77
 
77
78
  export function getBucketNameByValue<T extends Bucket>(enumValue: T): keyof typeof Bucket {
@@ -3,6 +3,7 @@ import {Slot} from "@lodestar/types";
3
3
  import type {IDataColumnStore} from "./dataColumnStore.js";
4
4
  import type {FlatFileStoreMetrics} from "./flatFileStore/metrics.js";
5
5
  import {CheckpointStateRepository} from "./repositories/checkpointState.js";
6
+ import {EarliestAvailableSlotRepository} from "./repositories/earliestAvailableSlot.js";
6
7
  import {
7
8
  AttesterSlashingRepository,
8
9
  BLSToExecutionChangeRepository,
@@ -46,6 +47,7 @@ export interface IBeaconDb {
46
47
  stateArchive: StateArchiveRepository;
47
48
  // checkpoint states
48
49
  checkpointState: CheckpointStateRepository;
50
+ earliestAvailableSlot: EarliestAvailableSlotRepository;
49
51
 
50
52
  // op pool
51
53
  voluntaryExit: VoluntaryExitRepository;
@@ -0,0 +1,19 @@
1
+ import {Db, encodeKey} from "@lodestar/db";
2
+ import {Slot, ssz} from "@lodestar/types";
3
+ import {Bucket, getBucketNameByValue} from "../buckets.js";
4
+
5
+ export class EarliestAvailableSlotRepository {
6
+ private readonly key = encodeKey(Bucket.earliestAvailableSlot, 0);
7
+ private readonly opts = {bucketId: getBucketNameByValue(Bucket.earliestAvailableSlot)};
8
+
9
+ constructor(private readonly db: Db) {}
10
+
11
+ async get(): Promise<Slot | null> {
12
+ const bytes = await this.db.get(this.key, this.opts);
13
+ return bytes === null ? null : ssz.Slot.deserialize(bytes);
14
+ }
15
+
16
+ async set(slot: Slot): Promise<void> {
17
+ await this.db.put(this.key, ssz.Slot.serialize(slot), this.opts);
18
+ }
19
+ }