@lodestar/beacon-node 1.50.0-dev.c04a499311 → 1.50.0-dev.c3aaeedc3b

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 (96) 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.map +1 -1
  11. package/lib/api/impl/validator/index.js +6 -0
  12. package/lib/api/impl/validator/index.js.map +1 -1
  13. package/lib/chain/archiveStore/archiveStore.d.ts +5 -0
  14. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  15. package/lib/chain/archiveStore/archiveStore.js +13 -23
  16. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  17. package/lib/chain/archiveStore/utils/pruneHistory.d.ts +1 -1
  18. package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
  19. package/lib/chain/archiveStore/utils/pruneHistory.js +2 -1
  20. package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
  21. package/lib/chain/chain.d.ts +4 -1
  22. package/lib/chain/chain.d.ts.map +1 -1
  23. package/lib/chain/chain.js +24 -5
  24. package/lib/chain/chain.js.map +1 -1
  25. package/lib/chain/interface.d.ts +1 -0
  26. package/lib/chain/interface.d.ts.map +1 -1
  27. package/lib/chain/opPools/aggregatedAttestationPool.d.ts +4 -2
  28. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  29. package/lib/chain/opPools/aggregatedAttestationPool.js +30 -8
  30. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  31. package/lib/chain/opPools/proposerPreferencesPool.d.ts +4 -4
  32. package/lib/chain/opPools/proposerPreferencesPool.d.ts.map +1 -1
  33. package/lib/chain/opPools/proposerPreferencesPool.js +14 -11
  34. package/lib/chain/opPools/proposerPreferencesPool.js.map +1 -1
  35. package/lib/chain/options.d.ts +1 -0
  36. package/lib/chain/options.d.ts.map +1 -1
  37. package/lib/chain/seenCache/seenGossipBlockInput.d.ts +7 -0
  38. package/lib/chain/seenCache/seenGossipBlockInput.d.ts.map +1 -1
  39. package/lib/chain/seenCache/seenGossipBlockInput.js +21 -0
  40. package/lib/chain/seenCache/seenGossipBlockInput.js.map +1 -1
  41. package/lib/chain/shufflingCache.d.ts +1 -0
  42. package/lib/chain/shufflingCache.d.ts.map +1 -1
  43. package/lib/chain/shufflingCache.js +4 -0
  44. package/lib/chain/shufflingCache.js.map +1 -1
  45. package/lib/db/beacon.d.ts +2 -0
  46. package/lib/db/beacon.d.ts.map +1 -1
  47. package/lib/db/beacon.js +3 -0
  48. package/lib/db/beacon.js.map +1 -1
  49. package/lib/db/buckets.d.ts +2 -1
  50. package/lib/db/buckets.d.ts.map +1 -1
  51. package/lib/db/buckets.js +1 -0
  52. package/lib/db/buckets.js.map +1 -1
  53. package/lib/db/interface.d.ts +2 -0
  54. package/lib/db/interface.d.ts.map +1 -1
  55. package/lib/db/repositories/blockArchiveIndex.d.ts +2 -2
  56. package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
  57. package/lib/db/repositories/earliestAvailableSlot.d.ts +11 -0
  58. package/lib/db/repositories/earliestAvailableSlot.d.ts.map +1 -0
  59. package/lib/db/repositories/earliestAvailableSlot.js +19 -0
  60. package/lib/db/repositories/earliestAvailableSlot.js.map +1 -0
  61. package/lib/metrics/metrics/lodestar.d.ts +1 -0
  62. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  63. package/lib/metrics/metrics/lodestar.js +4 -0
  64. package/lib/metrics/metrics/lodestar.js.map +1 -1
  65. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  66. package/lib/network/processor/gossipHandlers.js +59 -63
  67. package/lib/network/processor/gossipHandlers.js.map +1 -1
  68. package/lib/node/nodejs.d.ts +3 -1
  69. package/lib/node/nodejs.d.ts.map +1 -1
  70. package/lib/node/nodejs.js +2 -1
  71. package/lib/node/nodejs.js.map +1 -1
  72. package/lib/sync/range/chain.d.ts.map +1 -1
  73. package/lib/sync/range/chain.js +2 -0
  74. package/lib/sync/range/chain.js.map +1 -1
  75. package/package.json +16 -16
  76. package/src/api/impl/beacon/index.ts +15 -0
  77. package/src/api/impl/beacon/state/index.ts +31 -3
  78. package/src/api/impl/debug/index.ts +28 -19
  79. package/src/api/impl/validator/index.ts +8 -0
  80. package/src/chain/archiveStore/archiveStore.ts +18 -24
  81. package/src/chain/archiveStore/utils/pruneHistory.ts +4 -1
  82. package/src/chain/chain.ts +38 -4
  83. package/src/chain/interface.ts +1 -0
  84. package/src/chain/opPools/aggregatedAttestationPool.ts +34 -10
  85. package/src/chain/opPools/proposerPreferencesPool.ts +14 -10
  86. package/src/chain/options.ts +1 -1
  87. package/src/chain/seenCache/seenGossipBlockInput.ts +23 -0
  88. package/src/chain/shufflingCache.ts +5 -0
  89. package/src/db/beacon.ts +3 -0
  90. package/src/db/buckets.ts +1 -0
  91. package/src/db/interface.ts +2 -0
  92. package/src/db/repositories/earliestAvailableSlot.ts +19 -0
  93. package/src/metrics/metrics/lodestar.ts +4 -0
  94. package/src/network/processor/gossipHandlers.ts +90 -76
  95. package/src/node/nodejs.ts +4 -0
  96. package/src/sync/range/chain.ts +3 -0
@@ -12,9 +12,10 @@ import {
12
12
  isForkPostElectra,
13
13
  isForkPostGloas,
14
14
  } from "@lodestar/params";
15
- import {computeTimeAtSlot} from "@lodestar/state-transition";
15
+ import {computeTimeAtSlot, signedBlockToSignedHeader} from "@lodestar/state-transition";
16
16
  import {
17
17
  Root,
18
+ RootHex,
18
19
  SignedBeaconBlock,
19
20
  SingleAttestation,
20
21
  Slot,
@@ -78,6 +79,7 @@ import {
78
79
  validateGossipSyncCommittee,
79
80
  validateGossipVoluntaryExit,
80
81
  validateSyncCommitteeGossipContributionAndProof,
82
+ verifyBlockProposerSignature,
81
83
  } from "../../chain/validation/index.js";
82
84
  import {validateLightClientFinalityUpdate} from "../../chain/validation/lightClientFinalityUpdate.js";
83
85
  import {validateLightClientOptimisticUpdate} from "../../chain/validation/lightClientOptimisticUpdate.js";
@@ -148,37 +150,16 @@ export function getGossipHandlers(modules: ValidatorFnsModules, options: GossipH
148
150
  function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHandlerOpts): SequentialGossipHandlers {
149
151
  const {chain, config, metrics, logger, core} = modules;
150
152
 
151
- async function validateBeaconBlock(
153
+ /**
154
+ * Add a gossip block to the seen caches. The proposer signature of the block MUST be verified.
155
+ */
156
+ function cacheSignatureVerifiedBlock(
152
157
  signedBlock: SignedBeaconBlock,
158
+ blockRootHex: RootHex,
153
159
  fork: ForkName,
154
160
  peerIdStr: string,
155
161
  seenTimestampSec: number
156
- ): Promise<IBlockInput> {
157
- const slot = signedBlock.message.slot;
158
- const forkTypes = config.getForkTypes(slot);
159
- const blockRootHex = toRootHex(forkTypes.BeaconBlock.hashTreeRoot(signedBlock.message));
160
- const delaySec = chain.clock.secFromSlot(slot, seenTimestampSec);
161
- const recvToValLatency = Date.now() / 1000 - seenTimestampSec;
162
-
163
- // always set block to seen cache for all forks so that we don't need to download it
164
- // TODO: validate block before adding to cache
165
- // tracked in https://github.com/ChainSafe/lodestar/issues/7957
166
-
167
- const logCtx = {
168
- slot,
169
- root: blockRootHex,
170
- currentSlot: chain.clock.currentSlot,
171
- peerId: peerIdStr,
172
- delaySec,
173
- recvToValLatency,
174
- };
175
-
176
- logger.debug("Received gossip block", {...logCtx});
177
-
178
- // optimistically add gossip block to the seen cache
179
- // if validation fails, we will NOT forward this gossip block to peers
180
- // - if PARENT_BLOCK_UNKNOWN error, blockInput will then be queued inside BlockInputSync. If the gossip block is really invalid, it will be pruned there
181
- // - if other validator errors, blockInput will stay in the seen cache and will be pruned on finalization
162
+ ): BlockInput {
182
163
  const blockInput = chain.seenBlockInputCache.getByBlock({
183
164
  block: signedBlock,
184
165
  blockRootHex,
@@ -187,8 +168,7 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
187
168
  peerIdStr,
188
169
  });
189
170
 
190
- // Optimistically seed the payload-envelope cache too, mirroring seenBlockInputCache above.
191
- // This ensures we have PayloadEnvelopeInput, even through "PARENT_BLOCK_UNKNOWN" error
171
+ // Also seed the payload-envelope cache, so we have PayloadEnvelopeInput even through "PARENT_BLOCK_UNKNOWN" error
192
172
  // see https://github.com/ChainSafe/lodestar/issues/9475
193
173
  if (isForkPostGloas(fork)) {
194
174
  chain.seenPayloadEnvelopeInputCache.add({
@@ -202,8 +182,37 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
202
182
  });
203
183
  }
204
184
 
185
+ return blockInput;
186
+ }
187
+
188
+ async function validateBeaconBlock(
189
+ signedBlock: SignedBeaconBlock,
190
+ fork: ForkName,
191
+ peerIdStr: string,
192
+ seenTimestampSec: number
193
+ ): Promise<IBlockInput> {
194
+ const slot = signedBlock.message.slot;
195
+ const forkTypes = config.getForkTypes(slot);
196
+ const blockRootHex = toRootHex(forkTypes.BeaconBlock.hashTreeRoot(signedBlock.message));
197
+ const delaySec = chain.clock.secFromSlot(slot, seenTimestampSec);
198
+ const recvToValLatency = Date.now() / 1000 - seenTimestampSec;
199
+
200
+ const logCtx = {
201
+ slot,
202
+ root: blockRootHex,
203
+ currentSlot: chain.clock.currentSlot,
204
+ peerId: peerIdStr,
205
+ delaySec,
206
+ recvToValLatency,
207
+ };
208
+
209
+ logger.debug("Received gossip block", {...logCtx});
210
+
211
+ chain.seenBlockInputCache.markValidatingBlock(blockRootHex);
212
+
205
213
  try {
206
214
  const {skippedSlots} = await validateGossipBlock(config, chain, signedBlock, fork);
215
+ const blockInput = cacheSignatureVerifiedBlock(signedBlock, blockRootHex, fork, peerIdStr, seenTimestampSec);
207
216
 
208
217
  const blockInputMeta = blockInput.getLogMeta();
209
218
 
@@ -229,54 +238,54 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
229
238
  if (e instanceof BlockGossipError) {
230
239
  logger.debug("Gossip block has error", {slot, root: blockRootHex, code: e.type.code});
231
240
  if (
232
- (e.type.code === BlockErrorCode.PARENT_BLOCK_UNKNOWN ||
233
- e.type.code === BlockErrorCode.PARENT_PAYLOAD_UNKNOWN) &&
234
- blockInput
241
+ e.type.code === BlockErrorCode.PARENT_BLOCK_UNKNOWN ||
242
+ e.type.code === BlockErrorCode.PARENT_PAYLOAD_UNKNOWN
235
243
  ) {
244
+ // The block is retained for unknown parent sync without full validation. Authenticate it first, this
245
+ // does not need the parent state
246
+ const proposerIndex = signedBlock.message.proposerIndex;
247
+ await verifyBlockProposerSignature(chain, signedBlock, blockRootHex);
248
+ chain.seenBlockProposers.observeBlockRoot(
249
+ slot,
250
+ proposerIndex,
251
+ blockRootHex,
252
+ signedBlockToSignedHeader(config, signedBlock)
253
+ );
254
+
255
+ // Check again after the signature verification so concurrent proposals cannot both be retained
256
+ if (chain.seenBlockProposers.isKnown(slot, proposerIndex)) {
257
+ if (chain.seenBlockProposers.isRepeatProposal(slot, proposerIndex, blockRootHex)) {
258
+ throw new BlockGossipError(GossipAction.IGNORE, {
259
+ code: BlockErrorCode.REPEAT_PROPOSAL,
260
+ proposerIndex,
261
+ root: blockRootHex,
262
+ });
263
+ }
264
+ throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.ALREADY_KNOWN, root: blockRootHex});
265
+ }
266
+ chain.seenBlockProposers.add(slot, proposerIndex, blockRootHex);
267
+
268
+ const blockInput = cacheSignatureVerifiedBlock(signedBlock, blockRootHex, fork, peerIdStr, seenTimestampSec);
236
269
  chain.emitter.emit(ChainEvent.blockUnknownParent, {
237
270
  blockInput,
238
271
  peer: peerIdStr,
239
272
  source: BlockInputSource.gossip,
240
273
  });
241
- // throw error (don't prune the blockInput)
242
274
  throw e;
243
275
  }
244
276
 
245
- // IGNORE means the block is acceptable (e.g. FUTURE_SLOT, ALREADY_KNOWN), just not propagated.
246
- // Keep the optimistically-added cache entries; they are pruned on finalization. Only REJECT
247
- // (provably invalid), unexpected errors and repeat proposals that are not imported prune.
248
- if (e.action === GossipAction.IGNORE) {
249
- // Only a signature-verified sibling is imported by the beacon_block handler, any other repeat proposal
250
- // is dropped from the caches and re-downloaded by sync if it ever becomes relevant. Its signature was not
251
- // verified, so only its own entry is removed, never its claimed ancestors
252
- if (
253
- e.type.code === BlockErrorCode.REPEAT_PROPOSAL &&
254
- !chain.seenBlockProposers.hasBlockRoot(slot, signedBlock.message.proposerIndex, blockRootHex)
255
- ) {
256
- chain.seenBlockInputCache.remove(blockRootHex);
257
- if (isForkPostGloas(fork)) {
258
- chain.seenPayloadEnvelopeInputCache.remove(blockRootHex);
259
- }
260
- }
261
- throw e;
277
+ if (e.action === GossipAction.REJECT) {
278
+ chain.persistInvalidSszValue(
279
+ forkTypes.SignedBeaconBlock,
280
+ signedBlock,
281
+ `gossip_reject_slot_${slot}`,
282
+ blockRootHex
283
+ );
262
284
  }
263
-
264
- chain.persistInvalidSszValue(
265
- forkTypes.SignedBeaconBlock,
266
- signedBlock,
267
- `gossip_reject_slot_${slot}`,
268
- blockRootHex
269
- );
270
- }
271
-
272
- // REJECT or unexpected (non-BlockGossipError) error: drop the optimistically-added entries from
273
- // both caches, keeping them consistent. The block may carry any parent root, so only its own entry is removed
274
- chain.seenBlockInputCache.remove(blockRootHex);
275
- if (isForkPostGloas(fork)) {
276
- chain.seenPayloadEnvelopeInputCache.remove(blockRootHex);
277
285
  }
278
286
  throw e;
279
287
  } finally {
288
+ chain.seenBlockInputCache.unmarkValidatingBlock(blockRootHex);
280
289
  // The block received from the network may have established an equivocation, either by conflicting
281
290
  // with a previously observed block root (REPEAT_PROPOSAL) or with a root observed during validation
282
291
  const proposerIndex = signedBlock.message.proposerIndex;
@@ -752,18 +761,23 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
752
761
  e.type.code === BlockErrorCode.REPEAT_PROPOSAL &&
753
762
  // Only a signature-verified sibling recorded in the seen cache is imported. The cache holds at most two
754
763
  // roots per proposer and slot, which bounds full imports over gossip to one alternate
755
- chain.seenBlockProposers.hasBlockRoot(signedBlock.message.slot, e.type.proposerIndex, e.type.root)
764
+ chain.seenBlockProposers.hasBlockRoot(signedBlock.message.slot, e.type.proposerIndex, e.type.root) &&
765
+ // A sibling with an unknown parent cannot be imported, sync fetches it if its branch becomes relevant
766
+ chain.forkChoice.getBlockHexDefaultStatus(toRootHex(signedBlock.message.parentRoot)) !== null
756
767
  ) {
757
- // blockInput was optimistically seeded in validateBeaconBlock and retained on IGNORE
758
- const blockInput = chain.seenBlockInputCache.get(e.type.root);
759
- if (blockInput) {
760
- // We're returning IGNORE (thrown below), so this block is not forwarded to peers. Unlike the
761
- // happy path there is no rush to forward, so we don't need to wrap in callInNextEventLoop.
762
- chain.serializedCache.set(signedBlock, serializedData);
763
- // this is technically not a valid gossip block but gossip validation is a cheap subset of checks
764
- // this runs the full state transition, so importing an equivocating-but-valid block here is safe.
765
- handleValidBeaconBlock(blockInput, peerIdStr, seenTimestampSec);
766
- }
768
+ const blockInput = cacheSignatureVerifiedBlock(
769
+ signedBlock,
770
+ e.type.root,
771
+ topic.boundary.fork,
772
+ peerIdStr,
773
+ seenTimestampSec
774
+ );
775
+ // We're returning IGNORE (thrown below), so this block is not forwarded to peers. Unlike the
776
+ // happy path there is no rush to forward, so we don't need to wrap in callInNextEventLoop.
777
+ chain.serializedCache.set(signedBlock, serializedData);
778
+ // this is technically not a valid gossip block but gossip validation is a cheap subset of checks
779
+ // this runs the full state transition, so importing an equivocating-but-valid block here is safe.
780
+ handleValidBeaconBlock(blockInput, peerIdStr, seenTimestampSec);
767
781
  }
768
782
  // rethrow so gossipValidatorFn maps IGNORE -> TopicValidatorResult.Ignore (message not forwarded)
769
783
  throw e;
@@ -14,6 +14,7 @@ import {BeaconConfig} from "@lodestar/config";
14
14
  import type {LoggerNode} from "@lodestar/logger/node";
15
15
  import {ZERO_HASH_HEX} from "@lodestar/params";
16
16
  import {IBeaconStateView, isStatePostBellatrix, isStatePostGloas} from "@lodestar/state-transition";
17
+ import {Slot} from "@lodestar/types";
17
18
  import {sleep, toRootHex} from "@lodestar/utils";
18
19
  import {ProcessShutdownCallback} from "@lodestar/validator";
19
20
  import {BeaconRestApiServer, getApi} from "../api/index.js";
@@ -61,6 +62,7 @@ export type BeaconNodeInitModules = {
61
62
  peerStoreDir?: string;
62
63
  anchorState: IBeaconStateView;
63
64
  isAnchorStateFinalized: boolean;
65
+ earliestAvailableSlot: Slot;
64
66
  metricsRegistries?: Registry[];
65
67
  };
66
68
 
@@ -159,6 +161,7 @@ export class BeaconNode {
159
161
  peerStoreDir,
160
162
  anchorState,
161
163
  isAnchorStateFinalized,
164
+ earliestAvailableSlot,
162
165
  metricsRegistries = [],
163
166
  }: BeaconNodeInitModules): Promise<T> {
164
167
  if (hasher.name !== "hashtree") {
@@ -266,6 +269,7 @@ export class BeaconNode {
266
269
  validatorMonitor,
267
270
  anchorState,
268
271
  isAnchorStateFinalized,
272
+ earliestAvailableSlot,
269
273
  executionEngine: initializeExecutionEngine(executionEngineOpts, {
270
274
  metrics,
271
275
  signal,
@@ -225,6 +225,9 @@ export class SyncChain {
225
225
  Math.floor((localFinalizedEpoch - this.lastEpochWithProcessBlocks) / EPOCHS_PER_BATCH) * EPOCHS_PER_BATCH;
226
226
  this.advanceChain(lastEpochWithProcessBlocksAligned);
227
227
 
228
+ // stopSyncing() cleared the retry timer, but peers can still be in rate limit backoff
229
+ this.scheduleRateLimitBackoffRetry();
230
+
228
231
  // Potentially download new batches and process pending
229
232
  this.triggerBatchDownloader();
230
233
  this.triggerBatchProcessor();