@lodestar/beacon-node 1.49.0-dev.57ffc39074 → 1.49.0-dev.60ba78ee68

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 (110) hide show
  1. package/lib/api/impl/beacon/pool/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/pool/index.js +4 -2
  3. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  4. package/lib/chain/archiveStore/archiveStore.d.ts +1 -2
  5. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  6. package/lib/chain/archiveStore/archiveStore.js +0 -5
  7. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  8. package/lib/chain/archiveStore/historicalState/metrics.d.ts.map +1 -1
  9. package/lib/chain/archiveStore/historicalState/metrics.js +2 -7
  10. package/lib/chain/archiveStore/historicalState/metrics.js.map +1 -1
  11. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  12. package/lib/chain/blocks/importExecutionPayload.js +13 -0
  13. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  14. package/lib/chain/produceBlock/computeNewStateRoot.d.ts.map +1 -1
  15. package/lib/chain/produceBlock/computeNewStateRoot.js +4 -2
  16. package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
  17. package/lib/db/beacon.d.ts +1 -2
  18. package/lib/db/beacon.d.ts.map +1 -1
  19. package/lib/db/beacon.js +1 -3
  20. package/lib/db/beacon.js.map +1 -1
  21. package/lib/db/buckets.d.ts +0 -1
  22. package/lib/db/buckets.d.ts.map +1 -1
  23. package/lib/db/buckets.js +1 -1
  24. package/lib/db/buckets.js.map +1 -1
  25. package/lib/db/interface.d.ts +1 -2
  26. package/lib/db/interface.d.ts.map +1 -1
  27. package/lib/db/repositories/blockArchiveIndex.d.ts +2 -2
  28. package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
  29. package/lib/db/repositories/index.d.ts +0 -1
  30. package/lib/db/repositories/index.d.ts.map +1 -1
  31. package/lib/db/repositories/index.js +0 -1
  32. package/lib/db/repositories/index.js.map +1 -1
  33. package/lib/metrics/metrics/lodestar.d.ts +7 -10
  34. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  35. package/lib/metrics/metrics/lodestar.js +15 -23
  36. package/lib/metrics/metrics/lodestar.js.map +1 -1
  37. package/lib/metrics/metrics.d.ts +3 -1
  38. package/lib/metrics/metrics.d.ts.map +1 -1
  39. package/lib/metrics/metrics.js +2 -2
  40. package/lib/metrics/metrics.js.map +1 -1
  41. package/lib/node/nodejs.d.ts +2 -7
  42. package/lib/node/nodejs.d.ts.map +1 -1
  43. package/lib/node/nodejs.js +2 -22
  44. package/lib/node/nodejs.js.map +1 -1
  45. package/lib/sync/interface.d.ts +1 -2
  46. package/lib/sync/interface.d.ts.map +1 -1
  47. package/lib/sync/options.d.ts +0 -6
  48. package/lib/sync/options.d.ts.map +1 -1
  49. package/lib/sync/options.js +0 -2
  50. package/lib/sync/options.js.map +1 -1
  51. package/lib/sync/types.d.ts +0 -2
  52. package/lib/sync/types.d.ts.map +1 -1
  53. package/lib/sync/types.js +0 -2
  54. package/lib/sync/types.js.map +1 -1
  55. package/lib/sync/unknownBlock.d.ts +5 -1
  56. package/lib/sync/unknownBlock.d.ts.map +1 -1
  57. package/lib/sync/unknownBlock.js +51 -19
  58. package/lib/sync/unknownBlock.js.map +1 -1
  59. package/lib/util/shuffle.d.ts +0 -4
  60. package/lib/util/shuffle.d.ts.map +1 -1
  61. package/lib/util/shuffle.js +0 -8
  62. package/lib/util/shuffle.js.map +1 -1
  63. package/package.json +15 -16
  64. package/src/api/impl/beacon/pool/index.ts +6 -2
  65. package/src/chain/archiveStore/archiveStore.ts +0 -6
  66. package/src/chain/archiveStore/historicalState/metrics.ts +3 -9
  67. package/src/chain/blocks/importExecutionPayload.ts +14 -0
  68. package/src/chain/produceBlock/computeNewStateRoot.ts +9 -2
  69. package/src/db/beacon.ts +0 -5
  70. package/src/db/buckets.ts +1 -1
  71. package/src/db/interface.ts +0 -3
  72. package/src/db/repositories/index.ts +0 -1
  73. package/src/metrics/metrics/lodestar.ts +17 -25
  74. package/src/metrics/metrics.ts +7 -2
  75. package/src/node/nodejs.ts +0 -27
  76. package/src/sync/interface.ts +1 -2
  77. package/src/sync/options.ts +0 -8
  78. package/src/sync/types.ts +0 -2
  79. package/src/sync/unknownBlock.ts +51 -19
  80. package/src/util/shuffle.ts +0 -9
  81. package/lib/chain/archiveStore/utils/updateBackfillRange.d.ts +0 -20
  82. package/lib/chain/archiveStore/utils/updateBackfillRange.d.ts.map +0 -1
  83. package/lib/chain/archiveStore/utils/updateBackfillRange.js +0 -40
  84. package/lib/chain/archiveStore/utils/updateBackfillRange.js.map +0 -1
  85. package/lib/db/repositories/backfilledRanges.d.ts +0 -18
  86. package/lib/db/repositories/backfilledRanges.d.ts.map +0 -1
  87. package/lib/db/repositories/backfilledRanges.js +0 -26
  88. package/lib/db/repositories/backfilledRanges.js.map +0 -1
  89. package/lib/sync/backfill/backfill.d.ts +0 -169
  90. package/lib/sync/backfill/backfill.d.ts.map +0 -1
  91. package/lib/sync/backfill/backfill.js +0 -686
  92. package/lib/sync/backfill/backfill.js.map +0 -1
  93. package/lib/sync/backfill/errors.d.ts +0 -30
  94. package/lib/sync/backfill/errors.d.ts.map +0 -1
  95. package/lib/sync/backfill/errors.js +0 -15
  96. package/lib/sync/backfill/errors.js.map +0 -1
  97. package/lib/sync/backfill/index.d.ts +0 -2
  98. package/lib/sync/backfill/index.d.ts.map +0 -1
  99. package/lib/sync/backfill/index.js +0 -2
  100. package/lib/sync/backfill/index.js.map +0 -1
  101. package/lib/sync/backfill/verify.d.ts +0 -18
  102. package/lib/sync/backfill/verify.d.ts.map +0 -1
  103. package/lib/sync/backfill/verify.js +0 -36
  104. package/lib/sync/backfill/verify.js.map +0 -1
  105. package/src/chain/archiveStore/utils/updateBackfillRange.ts +0 -50
  106. package/src/db/repositories/backfilledRanges.ts +0 -29
  107. package/src/sync/backfill/backfill.ts +0 -916
  108. package/src/sync/backfill/errors.ts +0 -23
  109. package/src/sync/backfill/index.ts +0 -1
  110. package/src/sync/backfill/verify.ts +0 -58
@@ -1,5 +1,6 @@
1
1
  /** biome-ignore-all lint/suspicious/noTemplateCurlyInString: The metric templates requires to have `${}` in a normal string */
2
2
  import {NotReorgedReason} from "@lodestar/fork-choice";
3
+ import {StateHashTreeRootSource} from "@lodestar/state-transition";
3
4
  import {ArchiveStoreTask} from "../../chain/archiveStore/archiveStore.js";
4
5
  import {FrequencyStateArchiveStep} from "../../chain/archiveStore/strategies/frequencyStateArchiveStrategy.js";
5
6
  import type {LateCanonicalBlockReason} from "../../chain/archiveStore/utils/archiveBlocks.js";
@@ -25,7 +26,6 @@ import type {FlatFileStoreOperation} from "../../db/flatFileStore/metrics.js";
25
26
  import {ExecutionPayloadStatus} from "../../execution/index.js";
26
27
  import {GossipType} from "../../network/index.js";
27
28
  import {CannotAcceptWorkReason, ReprocessRejectReason} from "../../network/processor/index.js";
28
- import {BackfillSyncMethod} from "../../sync/backfill/backfill.js";
29
29
  import {
30
30
  DeferredPayloadResult,
31
31
  DownloadResult,
@@ -409,6 +409,15 @@ export function createLodestarMetrics(
409
409
  labelNames: ["caller"],
410
410
  }),
411
411
 
412
+ // this metrics stay here instead of @lodestar/state-transition in order to prepare
413
+ // for the native zig state-transition in the future
414
+ stateHashTreeRootTime: register.histogram<{source: StateHashTreeRootSource}>({
415
+ name: "lodestar_stfn_hash_tree_root_seconds",
416
+ help: "Time to compute the hash tree root of a post state in seconds",
417
+ buckets: [0.01, 0.05, 0.1, 0.2, 0.3, 0.5],
418
+ labelNames: ["source"],
419
+ }),
420
+
412
421
  // BLS verifier thread pool and queue
413
422
 
414
423
  bls: {
@@ -1002,6 +1011,13 @@ export function createLodestarMetrics(
1002
1011
  help: "Count of errors, by error type, while processing execution payload envelopes",
1003
1012
  labelNames: ["error"],
1004
1013
  }),
1014
+ executionPayload: {
1015
+ recvToValidation: register.histogram({
1016
+ name: "lodestar_gossip_execution_payload_envelope_received_to_execution_payload_verification_seconds",
1017
+ help: "Time elapsed between execution payload envelope received and execution payload verification",
1018
+ buckets: [0.05, 0.1, 0.25, 0.5, 1, 2, 3, 4, 6, 8],
1019
+ }),
1020
+ },
1005
1021
  },
1006
1022
  gossipExecutionPayloadBid: {
1007
1023
  elapsedTimeTillReceived: register.histogram<{source: OpSource}>({
@@ -1136,30 +1152,6 @@ export function createLodestarMetrics(
1136
1152
  help: "The total result of calling notifyForkchoiceUpdate execution engine api",
1137
1153
  labelNames: ["result"],
1138
1154
  }),
1139
- backfillSync: {
1140
- backfilledTillSlot: register.gauge({
1141
- name: "lodestar_backfill_till_slot",
1142
- help: "Current lowest backfilled slot",
1143
- }),
1144
- prevFinOrWsSlot: register.gauge({
1145
- name: "lodestar_backfill_prev_fin_or_ws_slot",
1146
- help: "Slot of previous finalized or wsCheckpoint block to be validated",
1147
- }),
1148
- totalBlocks: register.gauge<{method: BackfillSyncMethod}>({
1149
- name: "lodestar_backfill_sync_blocks_total",
1150
- help: "Total amount of backfilled blocks",
1151
- labelNames: ["method"],
1152
- }),
1153
- errors: register.gauge({
1154
- name: "lodestar_backfill_sync_errors_total",
1155
- help: "Total number of errors while backfilling",
1156
- }),
1157
- status: register.gauge({
1158
- name: "lodestar_backfill_sync_status",
1159
- help: "Current backfill syncing status: [Aborted, Pending, Syncing, Completed]",
1160
- }),
1161
- },
1162
-
1163
1155
  opPool: {
1164
1156
  aggregatedAttestationPool: {
1165
1157
  size: register.gauge({
@@ -12,7 +12,12 @@ export type Metrics = BeaconMetrics &
12
12
  BeaconStateTransitionMetrics &
13
13
  LodestarMetrics & {register: RegistryMetricCreator; close: () => void};
14
14
 
15
- export function createMetrics(opts: MetricsOptions, genesisTime: number, externalRegistries: Registry[] = []): Metrics {
15
+ export function createMetrics(
16
+ opts: MetricsOptions,
17
+ genesisTime: number,
18
+ externalRegistries: Registry[] = [],
19
+ {collectNodeMetrics = true}: {collectNodeMetrics?: boolean} = {}
20
+ ): Metrics {
16
21
  const register = new RegistryMetricCreator();
17
22
  const beacon = createBeaconMetrics(register);
18
23
  const forkChoice = getForkChoiceMetrics(register);
@@ -24,7 +29,7 @@ export function createMetrics(opts: MetricsOptions, genesisTime: number, externa
24
29
  };
25
30
  process.on("unhandledRejection", onUnhandledRejection);
26
31
 
27
- const nodeJsMetricsClose = collectNodeJSMetrics(register);
32
+ const nodeJsMetricsClose = collectNodeMetrics ? collectNodeJSMetrics(register) : (): void => {};
28
33
  const close = (): void => {
29
34
  process.removeListener("unhandledRejection", onUnhandledRejection);
30
35
  nodeJsMetricsClose();
@@ -8,7 +8,6 @@ import {BeaconConfig} from "@lodestar/config";
8
8
  import type {LoggerNode} from "@lodestar/logger/node";
9
9
  import {ZERO_HASH_HEX} from "@lodestar/params";
10
10
  import {IBeaconStateView, isStatePostBellatrix, isStatePostGloas} from "@lodestar/state-transition";
11
- import {phase0} from "@lodestar/types";
12
11
  import {sleep, toRootHex} from "@lodestar/utils";
13
12
  import {ProcessShutdownCallback} from "@lodestar/validator";
14
13
  import {BeaconRestApiServer, getApi} from "../api/index.js";
@@ -19,7 +18,6 @@ import {initializeExecutionBuilder, initializeExecutionEngine} from "../executio
19
18
  import {HttpMetricsServer, Metrics, createMetrics, getHttpMetricsServer} from "../metrics/index.js";
20
19
  import {MonitoringService} from "../monitoring/index.js";
21
20
  import {Network, getReqRespHandlers} from "../network/index.js";
22
- import {BackfillSync} from "../sync/backfill/index.js";
23
21
  import {BeaconSync, IBeaconSync} from "../sync/index.js";
24
22
  import {Clock} from "../util/clock.js";
25
23
  import {startDeferredVoluntaryExitPublisher} from "./deferredVoluntaryExitPublisher.js";
@@ -38,7 +36,6 @@ export type BeaconNodeModules = {
38
36
  chain: IBeaconChain;
39
37
  api: BeaconApiMethods;
40
38
  sync: IBeaconSync;
41
- backfillSync: BackfillSync | null;
42
39
  metricsServer: HttpMetricsServer | null;
43
40
  monitoring: MonitoringService | null;
44
41
  restApi?: BeaconRestApiServer;
@@ -58,7 +55,6 @@ export type BeaconNodeInitModules = {
58
55
  peerStoreDir?: string;
59
56
  anchorState: IBeaconStateView;
60
57
  isAnchorStateFinalized: boolean;
61
- wsCheckpoint?: phase0.Checkpoint;
62
58
  metricsRegistries?: Registry[];
63
59
  };
64
60
 
@@ -70,7 +66,6 @@ export enum BeaconNodeStatus {
70
66
 
71
67
  enum LoggerModule {
72
68
  api = "api",
73
- backfill = "backfill",
74
69
  chain = "chain",
75
70
  execution = "execution",
76
71
  metrics = "metrics",
@@ -105,7 +100,6 @@ export class BeaconNode {
105
100
  api: BeaconApiMethods;
106
101
  restApi?: BeaconRestApiServer;
107
102
  sync: IBeaconSync;
108
- backfillSync: BackfillSync | null;
109
103
 
110
104
  status: BeaconNodeStatus;
111
105
  private controller?: AbortController;
@@ -123,7 +117,6 @@ export class BeaconNode {
123
117
  api,
124
118
  restApi,
125
119
  sync,
126
- backfillSync,
127
120
  controller,
128
121
  }: BeaconNodeModules) {
129
122
  this.opts = opts;
@@ -138,7 +131,6 @@ export class BeaconNode {
138
131
  this.restApi = restApi;
139
132
  this.network = network;
140
133
  this.sync = sync;
141
- this.backfillSync = backfillSync;
142
134
  this.controller = controller;
143
135
 
144
136
  this.status = BeaconNodeStatus.started;
@@ -161,7 +153,6 @@ export class BeaconNode {
161
153
  peerStoreDir,
162
154
  anchorState,
163
155
  isAnchorStateFinalized,
164
- wsCheckpoint,
165
156
  metricsRegistries = [],
166
157
  }: BeaconNodeInitModules): Promise<T> {
167
158
  if (hasher.name !== "hashtree") {
@@ -295,25 +286,9 @@ export class BeaconNode {
295
286
  chain,
296
287
  metrics,
297
288
  network,
298
- wsCheckpoint,
299
289
  logger: logger.child({module: LoggerModule.sync}),
300
290
  });
301
291
 
302
- const backfillSync =
303
- opts.sync.backfillBatchSize > 0
304
- ? await BackfillSync.init(opts.sync, {
305
- config,
306
- db,
307
- chain,
308
- metrics,
309
- network,
310
- wsCheckpoint,
311
- anchorState,
312
- logger: logger.child({module: LoggerModule.backfill}),
313
- signal,
314
- })
315
- : null;
316
-
317
292
  const api = getApi(opts.api, {
318
293
  config,
319
294
  logger: logger.child({module: LoggerModule.api}),
@@ -361,7 +336,6 @@ export class BeaconNode {
361
336
  api,
362
337
  restApi,
363
338
  sync,
364
- backfillSync,
365
339
  controller,
366
340
  }) as T;
367
341
  }
@@ -373,7 +347,6 @@ export class BeaconNode {
373
347
  if (this.status === BeaconNodeStatus.started) {
374
348
  this.status = BeaconNodeStatus.closing;
375
349
  this.sync.close();
376
- this.backfillSync?.close();
377
350
  if (this.restApi) await this.restApi.close();
378
351
  await this.network.close();
379
352
  if (this.metricsServer) await this.metricsServer.close();
@@ -1,6 +1,6 @@
1
1
  import {routes} from "@lodestar/api";
2
2
  import {BeaconConfig} from "@lodestar/config";
3
- import {Slot, phase0} from "@lodestar/types";
3
+ import {Slot} from "@lodestar/types";
4
4
  import {Logger} from "@lodestar/utils";
5
5
  import {IBeaconChain} from "../chain/index.js";
6
6
  import {IBeaconDb} from "../db/index.js";
@@ -51,5 +51,4 @@ export interface SyncModules {
51
51
  metrics: Metrics | null;
52
52
  logger: Logger;
53
53
  chain: IBeaconChain;
54
- wsCheckpoint?: phase0.Checkpoint;
55
54
  }
@@ -16,12 +16,6 @@ export type SyncOptions = {
16
16
  disableRangeSync?: boolean;
17
17
  /** USE FOR TESTING ONLY. Disable unknown block sync completely */
18
18
  disableBlockInputSync?: boolean;
19
- /**
20
- * The batch size of slots for backfill sync can attempt to sync/process before yielding
21
- * to sync loop. This number can be increased or decreased to make a suitable resource
22
- * allocation to backfill sync. The default of 0 would mean backfill sync will be skipped
23
- */
24
- backfillBatchSize: number;
25
19
  /** For testing only, MAX_PENDING_BLOCKS by default */
26
20
  maxPendingBlocks?: number;
27
21
 
@@ -39,7 +33,5 @@ export type SyncOptions = {
39
33
  export const defaultSyncOptions: SyncOptions = {
40
34
  isSingleNode: false,
41
35
  disableProcessAsChainSegment: false,
42
- /** By default skip the backfill sync */
43
- backfillBatchSize: 0,
44
36
  slotImportTolerance: SLOTS_PER_EPOCH,
45
37
  };
package/src/sync/types.ts CHANGED
@@ -105,8 +105,6 @@ export enum DroppedItemReason {
105
105
  invalidEnvelope = "invalid_envelope",
106
106
  /** a payload had an invalid signature (INVALID_SIGNATURE) */
107
107
  invalidSignature = "invalid_signature",
108
- /** a block root was given up on after exhausting download attempts (data could not be fetched) */
109
- unavailable = "unavailable",
110
108
  /** an unexpected / unhandled error code led to removal */
111
109
  unknown = "unknown",
112
110
  }
@@ -173,7 +173,7 @@ export class BlockInputSync {
173
173
  this.chain.emitter.on(routes.events.EventType.executionPayload, this.onPayloadImported);
174
174
  this.network.events.on(NetworkEvent.peerConnected, this.onPeerConnected);
175
175
  this.network.events.on(NetworkEvent.peerDisconnected, this.onPeerDisconnected);
176
- this.chain.clock.on(ClockEvent.slot, this.onClockSlot);
176
+ this.chain.clock.on(ClockEvent.slot, this.startPayloadPollAtSlot);
177
177
 
178
178
  // Seed the balancer with peers that connected before we subscribed
179
179
  for (const peerId of this.network.getConnectedPeers()) {
@@ -187,14 +187,14 @@ export class BlockInputSync {
187
187
  this.subscribedToNetworkEvents = true;
188
188
  // we subscribe mid-slot, and a root can be deferred at any point in the slot, so start this
189
189
  // slot's loop now instead of waiting for the next ClockEvent.slot
190
- this.onClockSlot(this.chain.clock.currentSlot);
190
+ this.startPayloadPollAtSlot(this.chain.clock.currentSlot);
191
191
  }
192
192
  }
193
193
 
194
194
  unsubscribeFromNetwork(): void {
195
195
  this.logger.verbose("BlockInputSync disabled.");
196
196
  this.clearRateLimitBackoffTimer();
197
- this.chain.clock.off(ClockEvent.slot, this.onClockSlot);
197
+ this.chain.clock.off(ClockEvent.slot, this.startPayloadPollAtSlot);
198
198
  this.payloadPollAbortController?.abort();
199
199
  this.payloadPollAbortController = undefined;
200
200
  this.deferredPayloadRoots.clear();
@@ -227,8 +227,11 @@ export class BlockInputSync {
227
227
  private onUnknownBlockRoot = (data: ChainEventData[ChainEvent.unknownBlockRoot]): void => {
228
228
  try {
229
229
  const isNewRoot = this.addByRootHex(data.rootHex, data.peer);
230
- if (isNewRoot) {
230
+ // A retained entry (an earlier download failed, #10018) is not new but still needs a retry pass.
231
+ if (this.pendingBlocks.get(data.rootHex)?.status === PendingBlockInputStatus.pending) {
231
232
  this.triggerUnknownBlockSearch();
233
+ }
234
+ if (isNewRoot) {
232
235
  this.metrics?.blockInputSync.requests.inc({type: PendingBlockType.UNKNOWN_BLOCK_ROOT});
233
236
  this.metrics?.blockInputSync.source.inc({source: data.source});
234
237
  }
@@ -269,7 +272,7 @@ export class BlockInputSync {
269
272
  if (data.slot === this.chain.clock.currentSlot) {
270
273
  // we receive the optimistic search, the poll loop searches it at PAYLOAD_DUE or on its next
271
274
  // tick. If that loop already returned - every root it watched was imported - this root waits
272
- // for the next slot, where onClockSlot moves it to pendingPayloads. That is not the normal
275
+ // for the next slot, where startPayloadPollAtSlot moves it to pendingPayloads. That is not the normal
273
276
  // scenario, and in a forking condition it only delays the search of the extra root
274
277
  const deferred = this.deferredPayloadRoots.get(data.rootHex);
275
278
  if (deferred === undefined) {
@@ -393,12 +396,21 @@ export class BlockInputSync {
393
396
  }
394
397
  }
395
398
 
396
- let deletedBlocks = 0;
399
+ let belowFinalizedBlocks = 0;
400
+ let agedOutBlocks = 0;
397
401
  for (const [rootHex, block] of this.pendingBlocks) {
398
402
  const slot = getBlockInputSyncCacheItemSlot(block);
399
- if (typeof slot === "number" && slot < finalizedSlot) {
403
+ if (typeof slot !== "number") {
404
+ // we may not be able to download a root, hence there is no slot for it
405
+ if (nowSec - block.timeAddedSec > maxSecInCache) {
406
+ this.pendingBlocks.delete(rootHex);
407
+ agedOutBlocks++;
408
+ }
409
+ continue;
410
+ }
411
+ if (slot < finalizedSlot) {
400
412
  this.pendingBlocks.delete(rootHex);
401
- deletedBlocks++;
413
+ belowFinalizedBlocks++;
402
414
  }
403
415
  }
404
416
 
@@ -411,16 +423,20 @@ export class BlockInputSync {
411
423
  if (agedOutPayloads > 0) {
412
424
  this.metrics?.blockInputSync.removedPayloads.inc({reason: DroppedItemReason.agedOut}, agedOutPayloads);
413
425
  }
414
- if (deletedBlocks > 0) {
415
- this.metrics?.blockInputSync.removedBlocks.inc({reason: DroppedItemReason.belowFinalized}, deletedBlocks);
426
+ if (belowFinalizedBlocks > 0) {
427
+ this.metrics?.blockInputSync.removedBlocks.inc({reason: DroppedItemReason.belowFinalized}, belowFinalizedBlocks);
428
+ }
429
+ if (agedOutBlocks > 0) {
430
+ this.metrics?.blockInputSync.removedBlocks.inc({reason: DroppedItemReason.agedOut}, agedOutBlocks);
416
431
  }
417
432
 
418
- this.logger.debug("BlockInputSync.pruneFinalized dropped pre-finalized pending items", {
433
+ this.logger.debug("BlockInputSync.pruneFinalized dropped stale pending items", {
419
434
  finalizedSlot,
420
435
  finalizedRoot: checkpoint.rootHex,
421
436
  belowFinalizedPayloads,
422
437
  agedOutPayloads,
423
- deletedBlocks,
438
+ belowFinalizedBlocks,
439
+ agedOutBlocks,
424
440
  unresolvedSlotPayloads,
425
441
  });
426
442
  };
@@ -834,7 +850,11 @@ export class BlockInputSync {
834
850
  }
835
851
  }
836
852
 
837
- private onClockSlot = (slot: Slot): void => {
853
+ /**
854
+ * Start this slot's payload poll: end the previous slot's loop, move roots it never got to
855
+ * into pendingPayloads, then poll from PAYLOAD_DUE to the end of the slot.
856
+ */
857
+ private startPayloadPollAtSlot = (slot: Slot): void => {
838
858
  if (!isForkPostGloas(this.config.getForkName(slot))) {
839
859
  return;
840
860
  }
@@ -911,7 +931,7 @@ export class BlockInputSync {
911
931
  this.triggerUnknownBlockSearch();
912
932
  if (polls < tickCount - 1) {
913
933
  // no sleep after the last tick: the loop would otherwise end right at the slot boundary,
914
- // where onClockSlot aborts it
934
+ // where startPayloadPollAtSlot aborts it
915
935
  await sleep(PAYLOAD_POLL_INTERVAL_MS, signal);
916
936
  }
917
937
  }
@@ -969,7 +989,12 @@ export class BlockInputSync {
969
989
  if (!res.err) {
970
990
  this.metrics?.blockInputSync.downloadedBlocksSuccess.inc();
971
991
  const pending = res.result;
972
- this.pendingBlocks.set(pending.blockInput.blockRootHex, pending);
992
+ // pruning may have deleted this entry while we were awaiting the network, do not resurrect it via the set below
993
+ if (!this.pendingBlocks.has(rootHex)) {
994
+ this.logger.verbose("Dropping downloaded block, entry pruned during fetch", logCtx);
995
+ return;
996
+ }
997
+ this.pendingBlocks.set(rootHex, pending);
973
998
  const blockSlot = pending.blockInput.slot;
974
999
  const finalizedSlot = this.chain.forkChoice.getFinalizedBlock().slot;
975
1000
  const delaySec = Date.now() / 1000 - computeTimeAtSlot(this.config, blockSlot, this.chain.genesisTime);
@@ -1031,8 +1056,11 @@ export class BlockInputSync {
1031
1056
  }
1032
1057
 
1033
1058
  this.metrics?.blockInputSync.downloadedBlocksError.inc();
1034
- this.logger.debug("Ignoring unknown block root after many failed downloads", logCtx, res.err);
1035
- this.removeAndDownScoreAllDescendants(block, DroppedItemReason.unavailable);
1059
+ this.logger.debug("Failed to download unknown block root, retained for retry", logCtx, res.err);
1060
+ const pendingBlock = this.pendingBlocks.get(rootHex);
1061
+ if (pendingBlock && pendingBlock.status === PendingBlockInputStatus.fetching) {
1062
+ pendingBlock.status = PendingBlockInputStatus.pending;
1063
+ }
1036
1064
  }
1037
1065
  }
1038
1066
 
@@ -1299,7 +1327,7 @@ export class BlockInputSync {
1299
1327
  }
1300
1328
 
1301
1329
  this.metrics?.blockInputSync.downloadedPayloadsResult.inc({result: DownloadResult.Failed});
1302
- this.logger.debug("Ignoring unknown payload root after failed download", logCtx, res.err);
1330
+ this.logger.debug("Failed to download unknown payload root, retained for retry", logCtx, res.err);
1303
1331
  if (!isPendingPayloadEnvelope(payload)) {
1304
1332
  payload.status = PendingPayloadInputStatus.pending;
1305
1333
  }
@@ -1759,7 +1787,11 @@ export class BlockInputSync {
1759
1787
  this.peerBalancer.onRequestCompleted(peerId);
1760
1788
  }
1761
1789
 
1762
- this.pendingBlocks.set(getBlockInputSyncCacheItemRootHex(cacheItem), cacheItem);
1790
+ const cacheItemRootHex = getBlockInputSyncCacheItemRootHex(cacheItem);
1791
+ // pruning may have dropped it mid-fetch
1792
+ if (this.pendingBlocks.has(cacheItemRootHex)) {
1793
+ this.pendingBlocks.set(cacheItemRootHex, cacheItem);
1794
+ }
1763
1795
 
1764
1796
  if (cacheItem.status === PendingBlockInputStatus.downloaded) {
1765
1797
  // download was successful, no need to go with another peer, return
@@ -10,12 +10,3 @@ export function shuffle<T>(arr: T[]): T[] {
10
10
  }
11
11
  return _arr;
12
12
  }
13
-
14
- /**
15
- * Return one random item from array
16
- */
17
- export function shuffleOne<T>(arr: T[]): T | undefined {
18
- if (arr.length === 0) return undefined;
19
-
20
- return arr[Math.floor(Math.random() * arr.length)];
21
- }
@@ -1,20 +0,0 @@
1
- import { CheckpointWithHex } from "@lodestar/fork-choice";
2
- import { Logger } from "@lodestar/logger";
3
- import { IBeaconDb } from "../../../db/interface.js";
4
- import { IBeaconChain } from "../../interface.js";
5
- /**
6
- * Backfill sync relies on verified connected ranges (which are represented as key,value
7
- * with a verified jump from a key back to value). Since the node could have progressed
8
- * ahead from, we need to save the forward progress of this node as another backfill
9
- * range entry, that backfill sync will use to jump back if this node is restarted
10
- * for any reason.
11
- * The current backfill has its own backfill entry from anchor slot to last backfilled
12
- * slot. And this would create the entry from the current finalized slot to the anchor
13
- * slot.
14
- */
15
- export declare function updateBackfillRange({ chain, db, logger }: {
16
- chain: IBeaconChain;
17
- db: IBeaconDb;
18
- logger: Logger;
19
- }, finalized: CheckpointWithHex): Promise<void>;
20
- //# sourceMappingURL=updateBackfillRange.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"updateBackfillRange.d.ts","sourceRoot":"","sources":["../../../../src/chain/archiveStore/utils/updateBackfillRange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,SAAS,EAAC,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACvC,EAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAC,EAAE;IAAC,KAAK,EAAE,YAAY,CAAC;IAAC,EAAE,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,EACzE,SAAS,EAAE,iBAAiB,GAC3B,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
@@ -1,40 +0,0 @@
1
- /**
2
- * Backfill sync relies on verified connected ranges (which are represented as key,value
3
- * with a verified jump from a key back to value). Since the node could have progressed
4
- * ahead from, we need to save the forward progress of this node as another backfill
5
- * range entry, that backfill sync will use to jump back if this node is restarted
6
- * for any reason.
7
- * The current backfill has its own backfill entry from anchor slot to last backfilled
8
- * slot. And this would create the entry from the current finalized slot to the anchor
9
- * slot.
10
- */
11
- export async function updateBackfillRange({ chain, db, logger }, finalized) {
12
- try {
13
- // Mark the sequence in backfill db from finalized block's slot till anchor slot as
14
- // filled.
15
- const finalizedBlockFC = chain.forkChoice.getBlockHexDefaultStatus(finalized.rootHex);
16
- if (finalizedBlockFC && finalizedBlockFC.slot > chain.anchorStateLatestBlockSlot) {
17
- await db.backfilledRanges.put(finalizedBlockFC.slot, chain.anchorStateLatestBlockSlot);
18
- // Clear previously marked sequence till anchorStateLatestBlockSlot, without
19
- // touching backfill sync process sequence which are at
20
- // <=anchorStateLatestBlockSlot i.e. clear >anchorStateLatestBlockSlot
21
- // and < currentSlot
22
- const filteredSeqs = await db.backfilledRanges.entries({
23
- gt: chain.anchorStateLatestBlockSlot,
24
- lt: finalizedBlockFC.slot,
25
- });
26
- logger.debug("updated backfilledRanges", {
27
- key: finalizedBlockFC.slot,
28
- value: chain.anchorStateLatestBlockSlot,
29
- });
30
- if (filteredSeqs.length > 0) {
31
- await db.backfilledRanges.batchDelete(filteredSeqs.map((entry) => entry.key));
32
- logger.debug(`Forward Sync - cleaned up backfilledRanges between ${finalizedBlockFC.slot},${chain.anchorStateLatestBlockSlot}`, { seqs: JSON.stringify(filteredSeqs) });
33
- }
34
- }
35
- }
36
- catch (e) {
37
- logger.error("Error updating backfilledRanges on finalization", { epoch: finalized.epoch }, e);
38
- }
39
- }
40
- //# sourceMappingURL=updateBackfillRange.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"updateBackfillRange.js","sourceRoot":"","sources":["../../../../src/chain/archiveStore/utils/updateBackfillRange.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,EAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAuD,EACzE,SAA4B;IAE5B,IAAI,CAAC;QACH,mFAAmF;QACnF,UAAU;QACV,MAAM,gBAAgB,GAAG,KAAK,CAAC,UAAU,CAAC,wBAAwB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACtF,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,IAAI,GAAG,KAAK,CAAC,0BAA0B,EAAE,CAAC;YACjF,MAAM,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAEvF,4EAA4E;YAC5E,uDAAuD;YACvD,sEAAsE;YACtE,oBAAoB;YACpB,MAAM,YAAY,GAAG,MAAM,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC;gBACrD,EAAE,EAAE,KAAK,CAAC,0BAA0B;gBACpC,EAAE,EAAE,gBAAgB,CAAC,IAAI;aAC1B,CAAC,CAAC;YACH,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;gBACvC,GAAG,EAAE,gBAAgB,CAAC,IAAI;gBAC1B,KAAK,EAAE,KAAK,CAAC,0BAA0B;aACxC,CAAC,CAAC;YACH,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC5B,MAAM,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC9E,MAAM,CAAC,KAAK,CACV,sDAAsD,gBAAgB,CAAC,IAAI,IAAI,KAAK,CAAC,0BAA0B,EAAE,EACjH,EAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAC,CACrC,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,CAAC,KAAK,CAAC,iDAAiD,EAAE,EAAC,KAAK,EAAE,SAAS,CAAC,KAAK,EAAC,EAAE,CAAU,CAAC,CAAC;IACxG,CAAC;AACH,CAAC"}
@@ -1,18 +0,0 @@
1
- import { ChainForkConfig } from "@lodestar/config";
2
- import { DatabaseController, Repository } from "@lodestar/db";
3
- import { Slot } from "@lodestar/types";
4
- /**
5
- * Slot to slot ranges that ensure that block range is fully backfilled
6
- *
7
- * If node starts backfilling at slots 1000, and backfills to 800, there will be an entry
8
- * 1000 -> 800
9
- *
10
- * When the node is backfilling if it starts at 1200 and backfills to 1000, it will find this sequence and,
11
- * jump directly to 800 and delete the key 1000.
12
- */
13
- export declare class BackfilledRanges extends Repository<Slot, Slot> {
14
- constructor(config: ChainForkConfig, db: DatabaseController<Uint8Array, Uint8Array>);
15
- decodeKey(data: Buffer): number;
16
- getId(_value: Slot): number;
17
- }
18
- //# sourceMappingURL=backfilledRanges.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"backfilledRanges.d.ts","sourceRoot":"","sources":["../../../src/db/repositories/backfilledRanges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAC,kBAAkB,EAAE,UAAU,EAAC,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAC,IAAI,EAAM,MAAM,iBAAiB,CAAC;AAI1C;;;;;;;;GAQG;AACH,qBAAa,gBAAiB,SAAQ,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC;IAC1D,YAAY,MAAM,EAAE,eAAe,EAAE,EAAE,EAAE,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,EAGlF;IAED,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9B;IAED,KAAK,CAAC,MAAM,EAAE,IAAI,GAAG,MAAM,CAE1B;CACF"}
@@ -1,26 +0,0 @@
1
- import { Repository } from "@lodestar/db";
2
- import { ssz } from "@lodestar/types";
3
- import { bytesToInt } from "@lodestar/utils";
4
- import { Bucket, getBucketNameByValue } from "../buckets.js";
5
- /**
6
- * Slot to slot ranges that ensure that block range is fully backfilled
7
- *
8
- * If node starts backfilling at slots 1000, and backfills to 800, there will be an entry
9
- * 1000 -> 800
10
- *
11
- * When the node is backfilling if it starts at 1200 and backfills to 1000, it will find this sequence and,
12
- * jump directly to 800 and delete the key 1000.
13
- */
14
- export class BackfilledRanges extends Repository {
15
- constructor(config, db) {
16
- const bucket = Bucket.backfilled_ranges;
17
- super(config, db, bucket, ssz.Slot, getBucketNameByValue(bucket));
18
- }
19
- decodeKey(data) {
20
- return bytesToInt(super.decodeKey(data), "be");
21
- }
22
- getId(_value) {
23
- throw new Error("Cannot get the db key from slot");
24
- }
25
- }
26
- //# sourceMappingURL=backfilledRanges.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"backfilledRanges.js","sourceRoot":"","sources":["../../../src/db/repositories/backfilledRanges.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,UAAU,EAAC,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAO,GAAG,EAAC,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAC,MAAM,EAAE,oBAAoB,EAAC,MAAM,eAAe,CAAC;AAE3D;;;;;;;;GAQG;AACH,MAAM,OAAO,gBAAiB,SAAQ,UAAsB;IAC1D,YAAY,MAAuB,EAAE,EAA8C;QACjF,MAAM,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC;QACxC,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,SAAS,CAAC,IAAY;QACpB,OAAO,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAA0B,EAAE,IAAI,CAAC,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,MAAY;QAChB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;CACF"}