@lodestar/beacon-node 1.46.0-dev.ba5ee9aff0 → 1.46.0-dev.ba701016f3

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 (131) hide show
  1. package/lib/api/impl/config/constants.d.ts +1 -0
  2. package/lib/api/impl/config/constants.d.ts.map +1 -1
  3. package/lib/api/impl/config/constants.js +2 -1
  4. package/lib/api/impl/config/constants.js.map +1 -1
  5. package/lib/api/impl/lodestar/index.d.ts.map +1 -1
  6. package/lib/api/impl/lodestar/index.js +2 -3
  7. package/lib/api/impl/lodestar/index.js.map +1 -1
  8. package/lib/api/impl/validator/index.js +1 -1
  9. package/lib/api/impl/validator/index.js.map +1 -1
  10. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  11. package/lib/chain/archiveStore/archiveStore.js +17 -3
  12. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  13. package/lib/chain/archiveStore/historicalState/historicalStateRegen.d.ts.map +1 -1
  14. package/lib/chain/archiveStore/historicalState/historicalStateRegen.js +0 -1
  15. package/lib/chain/archiveStore/historicalState/historicalStateRegen.js.map +1 -1
  16. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.js +1 -1
  17. package/lib/chain/blocks/verifyExecutionPayloadEnvelope.js.map +1 -1
  18. package/lib/chain/bls/multithread/index.d.ts.map +1 -1
  19. package/lib/chain/bls/multithread/index.js +0 -1
  20. package/lib/chain/bls/multithread/index.js.map +1 -1
  21. package/lib/chain/errors/executionPayloadBid.d.ts +11 -4
  22. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
  23. package/lib/chain/errors/executionPayloadBid.js +1 -0
  24. package/lib/chain/errors/executionPayloadBid.js.map +1 -1
  25. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  26. package/lib/chain/opPools/aggregatedAttestationPool.js +2 -1
  27. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  28. package/lib/chain/prepareNextSlot.js +1 -1
  29. package/lib/chain/prepareNextSlot.js.map +1 -1
  30. package/lib/chain/produceBlock/produceBlockBody.js +4 -4
  31. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  32. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts +6 -5
  33. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts.map +1 -1
  34. package/lib/chain/seenCache/seenExecutionPayloadBids.js +16 -8
  35. package/lib/chain/seenCache/seenExecutionPayloadBids.js.map +1 -1
  36. package/lib/chain/validation/blobSidecar.js +1 -1
  37. package/lib/chain/validation/executionPayloadBid.d.ts +0 -5
  38. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  39. package/lib/chain/validation/executionPayloadBid.js +70 -24
  40. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  41. package/lib/chain/validation/proposerPreferences.js +8 -8
  42. package/lib/chain/validation/proposerPreferences.js.map +1 -1
  43. package/lib/chain/validatorMonitor.js +1 -1
  44. package/lib/chain/validatorMonitor.js.map +1 -1
  45. package/lib/execution/engine/interface.d.ts +1 -1
  46. package/lib/execution/engine/types.js +1 -1
  47. package/lib/execution/engine/types.js.map +1 -1
  48. package/lib/metrics/nodeJsMetrics.js +1 -1
  49. package/lib/metrics/nodeJsMetrics.js.map +1 -1
  50. package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -1
  51. package/lib/network/core/networkCoreWorkerHandler.js +2 -7
  52. package/lib/network/core/networkCoreWorkerHandler.js.map +1 -1
  53. package/lib/network/discv5/index.d.ts.map +1 -1
  54. package/lib/network/discv5/index.js +1 -4
  55. package/lib/network/discv5/index.js.map +1 -1
  56. package/lib/network/gossip/topic.d.ts +5 -5
  57. package/lib/network/libp2p/index.d.ts.map +1 -1
  58. package/lib/network/libp2p/index.js +2 -9
  59. package/lib/network/libp2p/index.js.map +1 -1
  60. package/lib/network/peers/datastore.d.ts +1 -1
  61. package/lib/network/peers/datastore.d.ts.map +1 -1
  62. package/lib/network/peers/datastore.js +1 -1
  63. package/lib/network/peers/datastore.js.map +1 -1
  64. package/lib/network/processor/index.d.ts.map +1 -1
  65. package/lib/network/processor/index.js +2 -1
  66. package/lib/network/processor/index.js.map +1 -1
  67. package/lib/network/reqresp/handlers/lightClientUpdatesByRange.d.ts.map +1 -1
  68. package/lib/network/reqresp/handlers/lightClientUpdatesByRange.js +5 -1
  69. package/lib/network/reqresp/handlers/lightClientUpdatesByRange.js.map +1 -1
  70. package/lib/sync/constants.d.ts +6 -5
  71. package/lib/sync/constants.d.ts.map +1 -1
  72. package/lib/sync/constants.js +6 -5
  73. package/lib/sync/constants.js.map +1 -1
  74. package/lib/sync/range/batch.d.ts +10 -1
  75. package/lib/sync/range/batch.d.ts.map +1 -1
  76. package/lib/sync/range/batch.js +28 -10
  77. package/lib/sync/range/batch.js.map +1 -1
  78. package/lib/sync/range/chain.d.ts.map +1 -1
  79. package/lib/sync/range/chain.js +30 -15
  80. package/lib/sync/range/chain.js.map +1 -1
  81. package/lib/sync/range/utils/batches.d.ts +18 -0
  82. package/lib/sync/range/utils/batches.d.ts.map +1 -1
  83. package/lib/sync/range/utils/batches.js +39 -0
  84. package/lib/sync/range/utils/batches.js.map +1 -1
  85. package/lib/util/profile.d.ts +3 -0
  86. package/lib/util/profile.d.ts.map +1 -1
  87. package/lib/util/profile.js +1 -27
  88. package/lib/util/profile.js.map +1 -1
  89. package/lib/util/sszBytes.js +1 -1
  90. package/package.json +25 -36
  91. package/src/api/impl/config/constants.ts +2 -0
  92. package/src/api/impl/lodestar/index.ts +2 -3
  93. package/src/api/impl/validator/index.ts +1 -1
  94. package/src/chain/archiveStore/archiveStore.ts +20 -3
  95. package/src/chain/archiveStore/historicalState/historicalStateRegen.ts +0 -1
  96. package/src/chain/blocks/verifyExecutionPayloadEnvelope.ts +1 -1
  97. package/src/chain/bls/multithread/index.ts +0 -1
  98. package/src/chain/errors/executionPayloadBid.ts +12 -4
  99. package/src/chain/opPools/aggregatedAttestationPool.ts +3 -1
  100. package/src/chain/prepareNextSlot.ts +1 -1
  101. package/src/chain/produceBlock/produceBlockBody.ts +5 -5
  102. package/src/chain/seenCache/seenExecutionPayloadBids.ts +22 -9
  103. package/src/chain/validation/blobSidecar.ts +1 -1
  104. package/src/chain/validation/executionPayloadBid.ts +87 -26
  105. package/src/chain/validation/proposerPreferences.ts +8 -8
  106. package/src/chain/validatorMonitor.ts +1 -1
  107. package/src/execution/engine/interface.ts +1 -1
  108. package/src/execution/engine/types.ts +1 -1
  109. package/src/metrics/nodeJsMetrics.ts +1 -1
  110. package/src/network/core/networkCoreWorkerHandler.ts +2 -6
  111. package/src/network/discv5/index.ts +1 -4
  112. package/src/network/libp2p/index.ts +2 -10
  113. package/src/network/peers/datastore.ts +1 -1
  114. package/src/network/processor/index.ts +2 -1
  115. package/src/network/reqresp/handlers/lightClientUpdatesByRange.ts +5 -1
  116. package/src/sync/constants.ts +6 -5
  117. package/src/sync/range/batch.ts +31 -10
  118. package/src/sync/range/chain.ts +36 -16
  119. package/src/sync/range/utils/batches.ts +44 -0
  120. package/src/util/profile.ts +1 -31
  121. package/src/util/sszBytes.ts +1 -1
  122. package/lib/bun-wrappers/prometheus-gc-stats.d.ts +0 -2
  123. package/lib/bun-wrappers/prometheus-gc-stats.d.ts.map +0 -1
  124. package/lib/bun-wrappers/prometheus-gc-stats.js +0 -8
  125. package/lib/bun-wrappers/prometheus-gc-stats.js.map +0 -1
  126. package/lib/network/peers/datastore_bun.d.ts +0 -3
  127. package/lib/network/peers/datastore_bun.d.ts.map +0 -1
  128. package/lib/network/peers/datastore_bun.js +0 -3
  129. package/lib/network/peers/datastore_bun.js.map +0 -1
  130. package/src/bun-wrappers/prometheus-gc-stats.ts +0 -7
  131. package/src/network/peers/datastore_bun.ts +0 -3
@@ -1,5 +1,5 @@
1
1
  import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
2
- import {GENESIS_SLOT, MIN_SEED_LOOKAHEAD, SLOTS_PER_EPOCH} from "@lodestar/params";
2
+ import {GENESIS_EPOCH, GENESIS_SLOT, MIN_SEED_LOOKAHEAD, SLOTS_PER_EPOCH} from "@lodestar/params";
3
3
  import {
4
4
  computeEpochAtSlot,
5
5
  computeStartSlotAtEpoch,
@@ -24,9 +24,10 @@ export async function validateGossipProposerPreferences(
24
24
  const dependentRootHex = toRootHex(dependentRoot);
25
25
  const proposalEpoch = computeEpochAtSlot(proposalSlot);
26
26
 
27
- // [IGNORE] `preferences.proposal_slot` is within the proposer lookahead.
28
- const currentEpoch = chain.clock.currentEpoch;
29
- if (proposalEpoch < currentEpoch || proposalEpoch > currentEpoch + MIN_SEED_LOOKAHEAD) {
27
+ // [IGNORE] `preferences.proposal_slot` is within the proposer lookahead,
28
+ // allowing for `MAXIMUM_GOSSIP_CLOCK_DISPARITY`.
29
+ const currentEpoch = computeEpochAtSlot(chain.clock.currentSlotWithGossipDisparity);
30
+ if (proposalEpoch > currentEpoch + MIN_SEED_LOOKAHEAD) {
30
31
  throw new ProposerPreferencesError(GossipAction.IGNORE, {
31
32
  code: ProposerPreferencesErrorCode.INVALID_EPOCH,
32
33
  proposalSlot,
@@ -36,12 +37,11 @@ export async function validateGossipProposerPreferences(
36
37
 
37
38
  // [IGNORE] `preferences.proposal_slot` has not already passed, i.e. `proposal_slot > current_slot`,
38
39
  // allowing for `MAXIMUM_GOSSIP_CLOCK_DISPARITY`.
39
- const currentSlot = chain.clock.currentSlotWithGossipDisparity;
40
- if (proposalSlot <= currentSlot) {
40
+ if (chain.clock.msFromSlot(proposalSlot) > chain.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY) {
41
41
  throw new ProposerPreferencesError(GossipAction.IGNORE, {
42
42
  code: ProposerPreferencesErrorCode.PROPOSAL_SLOT_PASSED,
43
43
  proposalSlot,
44
- currentSlot,
44
+ currentSlot: chain.clock.currentSlot,
45
45
  });
46
46
  }
47
47
 
@@ -55,7 +55,7 @@ export async function validateGossipProposerPreferences(
55
55
  });
56
56
  }
57
57
 
58
- const dependentEpoch = proposalEpoch - MIN_SEED_LOOKAHEAD;
58
+ const dependentEpoch = Math.max(GENESIS_EPOCH, proposalEpoch - MIN_SEED_LOOKAHEAD);
59
59
  const dependentRootSlot = getDependentRootSlot(dependentEpoch);
60
60
 
61
61
  // [REJECT] The slot of the block with root `preferences.dependent_root` is strictly less than
@@ -469,7 +469,7 @@ export function createValidatorMonitor(
469
469
  proposerIndex,
470
470
  src,
471
471
  builderIndex: bid.builderIndex,
472
- gasLimit: bid.gasLimit,
472
+ gasLimit: Number(bid.gasLimit),
473
473
  value: bid.value.toString(),
474
474
  parentBlockRoot: toRootHex(bid.parentBlockRoot),
475
475
  parentBlockHash: toRootHex(bid.parentBlockHash),
@@ -98,7 +98,7 @@ export type PayloadAttributes = {
98
98
  withdrawals?: capella.Withdrawal[];
99
99
  parentBeaconBlockRoot?: Uint8Array;
100
100
  slotNumber?: number; // EIP-7843
101
- targetGasLimit?: number; // GLOAS (PayloadAttributesV4, execution-apis#796)
101
+ targetGasLimit?: bigint; // GLOAS (PayloadAttributesV4, execution-apis#796)
102
102
  };
103
103
 
104
104
  export type VersionedHashes = Uint8Array[];
@@ -458,7 +458,7 @@ export function deserializePayloadAttributes(data: PayloadAttributesRpc): Payloa
458
458
  withdrawals: data.withdrawals?.map((withdrawal) => deserializeWithdrawal(withdrawal)),
459
459
  parentBeaconBlockRoot: data.parentBeaconBlockRoot ? dataToBytes(data.parentBeaconBlockRoot, 32) : undefined,
460
460
  slotNumber: data.slotNumber !== undefined ? quantityToNum(data.slotNumber) : undefined,
461
- targetGasLimit: data.targetGasLimit !== undefined ? quantityToNum(data.targetGasLimit) : undefined,
461
+ targetGasLimit: data.targetGasLimit !== undefined ? quantityToBigint(data.targetGasLimit) : undefined,
462
462
  };
463
463
  }
464
464
 
@@ -1,5 +1,5 @@
1
1
  import {Registry, collectDefaultMetrics} from "prom-client";
2
- import {gcStats} from "#prometheus-gc-stats-wrapper";
2
+ import {gcStats} from "@chainsafe/prometheus-gc-stats";
3
3
 
4
4
  export function collectNodeJSMetrics(register: Registry, prefix?: string): () => void {
5
5
  collectDefaultMetrics({
@@ -132,10 +132,6 @@ export class WorkerNetworkCore implements INetworkCore {
132
132
 
133
133
  const workerOpts: ConstructorParameters<typeof Worker>[1] = {
134
134
  workerData,
135
- };
136
- if (globalThis.Bun) {
137
- workerOpts.suppressTranspileTS = true;
138
- } else {
139
135
  /**
140
136
  * maxYoungGenerationSizeMb defaults to 152mb through the cli option defaults.
141
137
  * That default value was determined via https://github.com/ChainSafe/lodestar/issues/2115 and
@@ -147,8 +143,8 @@ export class WorkerNetworkCore implements INetworkCore {
147
143
  * showed that there is a pretty big window of "correct" values but we can always tune as
148
144
  * necessary
149
145
  */
150
- workerOpts.resourceLimits = {maxYoungGenerationSizeMb: opts.maxYoungGenerationSizeMb};
151
- }
146
+ resourceLimits: {maxYoungGenerationSizeMb: opts.maxYoungGenerationSizeMb},
147
+ };
152
148
 
153
149
  const worker = new Worker(path.join(workerDir, "networkCoreWorker.js"), workerOpts);
154
150
 
@@ -51,10 +51,7 @@ export class Discv5Worker extends (EventEmitter as {new (): StrictEventEmitter<E
51
51
  loggerOpts: opts.logger.toOpts(),
52
52
  genesisTime: opts.genesisTime,
53
53
  };
54
- const worker = new Worker("./worker.js", {
55
- suppressTranspileTS: Boolean(globalThis.Bun),
56
- workerData,
57
- } as ConstructorParameters<typeof Worker>[1]);
54
+ const worker = new Worker("./worker.js", {workerData} as ConstructorParameters<typeof Worker>[1]);
58
55
 
59
56
  const workerApi = await spawn<Discv5WorkerApi>(worker, {
60
57
  // A Lodestar Node may do very expensive task at start blocking the event loop and causing
@@ -9,7 +9,7 @@ import {Libp2pInit, createLibp2p} from "libp2p";
9
9
  import {Registry} from "prom-client";
10
10
  import {ENR} from "@chainsafe/enr";
11
11
  import {noise} from "@chainsafe/libp2p-noise";
12
- import {asCrypto, defaultCrypto} from "@chainsafe/libp2p-noise/crypto";
12
+ import {defaultCrypto} from "@chainsafe/libp2p-noise/crypto";
13
13
  import {quic} from "@chainsafe/libp2p-quic";
14
14
  import {Libp2p, LodestarComponents} from "../interface.js";
15
15
  import {NetworkOptions, defaultNetworkOptions} from "../options.js";
@@ -111,14 +111,6 @@ export async function createNodeJsLibp2p(
111
111
  }
112
112
  }
113
113
 
114
- const noiseCrypto = {
115
- ...defaultCrypto,
116
- };
117
- if (globalThis.Bun) {
118
- noiseCrypto.chaCha20Poly1305Decrypt = asCrypto.chaCha20Poly1305Decrypt;
119
- noiseCrypto.chaCha20Poly1305Encrypt = asCrypto.chaCha20Poly1305Encrypt;
120
- }
121
-
122
114
  return createLibp2p({
123
115
  privateKey,
124
116
  nodeInfo: {
@@ -130,7 +122,7 @@ export async function createNodeJsLibp2p(
130
122
  listen: localMultiaddrs,
131
123
  announce: [],
132
124
  },
133
- connectionEncrypters: [noise({crypto: noiseCrypto})],
125
+ connectionEncrypters: [noise({crypto: defaultCrypto})],
134
126
  transports,
135
127
  streamMuxers: [mplex({disconnectThreshold})],
136
128
  peerDiscovery,
@@ -1,7 +1,7 @@
1
1
  import {AbortOptions} from "@libp2p/interface";
2
2
  import {BaseDatastore} from "datastore-core";
3
+ import {LevelDatastore} from "datastore-level";
3
4
  import {Key, KeyQuery, Pair, Query} from "interface-datastore";
4
- import {LevelDatastore} from "#datastore-wrapper";
5
5
 
6
6
  type MemoryItem = {
7
7
  lastAccessedMs: number;
@@ -461,7 +461,8 @@ export class NetworkProcessor {
461
461
  break;
462
462
  }
463
463
  case GossipType.execution_payload_bid: {
464
- // instead of searching for the message root, this searches for the parent root
464
+ // Search for the parent independently of current head compatibility. A bid may arrive
465
+ // before its parent block, so compatibility is checked later during gossip validation.
465
466
  const parentBlockRoot = getParentBlockRootFromSignedExecutionPayloadBidSerialized(message.msg.data);
466
467
  const parentBlockHash = getParentBlockHashFromSignedExecutionPayloadBidSerialized(message.msg.data);
467
468
  if (
@@ -19,8 +19,12 @@ export async function* onLightClientUpdatesByRange(
19
19
  assertLightClientServer(chain.lightClientServer);
20
20
 
21
21
  const count = Math.min(MAX_REQUEST_LIGHT_CLIENT_UPDATES, requestBody.count);
22
+ if (!Number.isSafeInteger(requestBody.startPeriod)) {
23
+ throw new ResponseError(RespStatus.INVALID_REQUEST, "startPeriod out of range");
24
+ }
22
25
  let started = false;
23
- for (let period = requestBody.startPeriod; period < requestBody.startPeriod + count; period++) {
26
+ for (let i = 0; i < count; i++) {
27
+ const period = requestBody.startPeriod + i;
24
28
  try {
25
29
  const update = await chain.lightClientServer.getUpdate(period);
26
30
  const boundary = chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(update.signatureSlot));
@@ -15,12 +15,13 @@ export const MAX_BATCH_DOWNLOAD_ATTEMPTS = 5;
15
15
  export const RATE_LIMITED_PEER_BACKOFF_MS = 5_000;
16
16
 
17
17
  /**
18
- * Consider batch faulty after downloading and processing this number of times
19
- * as in https://github.com/ChainSafe/lodestar/issues/8147 we cannot proceed the sync chain if there is unknown parent
20
- * from prior batch. For example a peer may send us a non-canonical chain segment or not returning all blocks
21
- * in that case we should throw error and `RangeSync` should remove that error chain and add a new one.
18
+ * Consider a batch faulty once its failed processing attempts EXCEED this number, i.e. the batch is
19
+ * processed up to `MAX_BATCH_PROCESSING_ATTEMPTS + 1` times before teardown (the check is `>`, same
20
+ * convention as `MAX_BATCH_DOWNLOAD_ATTEMPTS`).
21
+ * Some processing failures can be caused by a different batch, so range sync classifies the fault
22
+ * before deciding which batch to redownload.
22
23
  **/
23
- export const MAX_BATCH_PROCESSING_ATTEMPTS = 0;
24
+ export const MAX_BATCH_PROCESSING_ATTEMPTS = 3;
24
25
 
25
26
  /**
26
27
  * Number of slots to offset batches.
@@ -64,6 +64,7 @@ export type DownloadSuccessState = {
64
64
  status: BatchStatus.AwaitingProcessing;
65
65
  blocks: IBlockInput[];
66
66
  payloadEnvelopes: Map<Slot, PayloadEnvelopeInput> | null;
67
+ attempt: Attempt;
67
68
  };
68
69
 
69
70
  export type BatchState =
@@ -589,7 +590,11 @@ export class Batch {
589
590
  }
590
591
 
591
592
  if (allComplete) {
592
- this.state = {status: BatchStatus.AwaitingProcessing, blocks, payloadEnvelopes: newPayloadEnvelopes};
593
+ const attempt: Attempt = {
594
+ peers: this.getSuccessfulPeers(),
595
+ hash: hashBlocks(blocks, this.config),
596
+ };
597
+ this.state = {status: BatchStatus.AwaitingProcessing, blocks, payloadEnvelopes: newPayloadEnvelopes, attempt};
593
598
  } else {
594
599
  this.state = {status: BatchStatus.AwaitingDownload, blocks, payloadEnvelopes: newPayloadEnvelopes};
595
600
  this.requests = this.getRequests(blocks);
@@ -646,15 +651,11 @@ export class Batch {
646
651
  throw new BatchError(this.wrongStatusErrorType(BatchStatus.AwaitingProcessing));
647
652
  }
648
653
 
649
- const blocks = this.state.blocks;
650
- const payloadEnvelopes = this.state.payloadEnvelopes;
651
- const hash = hashBlocks(blocks, this.config); // tracks blocks to report peer on processing error
652
- // Reset successfulDownloads in case another download attempt needs to be made. When Attempt is successful or not
653
- // the peers that the data came from will be handled by the Attempt that goes for processing.
654
- const peers = this.getSuccessfulPeers();
654
+ const {blocks, payloadEnvelopes, attempt} = this.state;
655
+ // No need to track successfulDownloads anymore, the batch goes to Processing status.
655
656
  this.successfulDownloads.clear();
656
- this.state = {status: BatchStatus.Processing, blocks, payloadEnvelopes, attempt: {peers, hash}};
657
- return {blocks, payloadEnvelopes, peers};
657
+ this.state = {status: BatchStatus.Processing, blocks, payloadEnvelopes, attempt};
658
+ return {blocks, payloadEnvelopes, peers: attempt.peers};
658
659
  }
659
660
 
660
661
  /**
@@ -673,6 +674,26 @@ export class Batch {
673
674
  };
674
675
  }
675
676
 
677
+ /**
678
+ * Processing -> AwaitingProcessing
679
+ *
680
+ * The batch's own blocks are valid but processing failed because a previous batch did not
681
+ * deliver the parent. Keep the downloaded blocks and process them again once the previous
682
+ * batch is repaired.
683
+ */
684
+ retainForReprocessing(): void {
685
+ if (this.state.status !== BatchStatus.Processing) {
686
+ throw new BatchError(this.wrongStatusErrorType(BatchStatus.Processing));
687
+ }
688
+
689
+ this.state = {
690
+ status: BatchStatus.AwaitingProcessing,
691
+ blocks: this.state.blocks,
692
+ payloadEnvelopes: this.state.payloadEnvelopes,
693
+ attempt: this.state.attempt,
694
+ };
695
+ }
696
+
676
697
  /**
677
698
  * Processing -> AwaitingDownload
678
699
  */
@@ -750,7 +771,7 @@ export enum BatchErrorCode {
750
771
  INVALID_COUNT = "BATCH_ERROR_INVALID_COUNT",
751
772
  MAX_DOWNLOAD_ATTEMPTS = "BATCH_ERROR_MAX_DOWNLOAD_ATTEMPTS",
752
773
  MAX_PROCESSING_ATTEMPTS = "BATCH_ERROR_MAX_PROCESSING_ATTEMPTS",
753
- MAX_EXECUTION_ENGINE_ERROR_ATTEMPTS = "MAX_EXECUTION_ENGINE_ERROR_ATTEMPTS",
774
+ MAX_EXECUTION_ENGINE_ERROR_ATTEMPTS = "BATCH_ERROR_MAX_EXECUTION_ENGINE_ERROR_ATTEMPTS",
754
775
  }
755
776
 
756
777
  type BatchErrorType =
@@ -23,7 +23,9 @@ import {Batch, BatchError, BatchErrorCode, BatchMetadata, BatchStatus} from "./b
23
23
  import {
24
24
  ChainPeersBalancer,
25
25
  PeerSyncInfo,
26
+ ProcessingFaultKind,
26
27
  batchStartEpochIsAfterSlot,
28
+ classifyProcessingFault,
27
29
  computeHighestTarget,
28
30
  getBatchSlotRange,
29
31
  getNextBatchToProcess,
@@ -708,23 +710,41 @@ export class SyncChain {
708
710
  this.triggerBatchProcessor();
709
711
  } else {
710
712
  this.logger.verbose("Batch process error", logCtx, res.err);
711
- batch.processingError(res.err); // Throws after MAX_BATCH_PROCESSING_ATTEMPTS
712
-
713
- // At least one block was successfully verified and imported, so we can be sure all
714
- // previous batches are valid and we only need to download the current failed batch.
715
- // TODO: Disabled for now
716
- // if (res.err instanceof ChainSegmentError && res.err.importedBlocks > 0) {
717
- // this.advanceChain(batch.startEpoch);
718
- // }
719
-
720
- // The current batch could not be processed, so either this or previous batches are invalid.
721
- // All previous batches (AwaitingValidation) are potentially faulty and marked for retry.
722
- // Progress will be drop back to `this.startEpoch`
723
- for (const pendingBatch of this.batches.values()) {
724
- if (pendingBatch.startEpoch < batch.startEpoch) {
725
- this.logger.verbose("Batch validation error", {id: this.logId, ...pendingBatch.getMetadata()});
726
- pendingBatch.validationError(res.err); // Throws after MAX_BATCH_PROCESSING_ATTEMPTS
713
+
714
+ const invalidatePreviousBatches = (): number => {
715
+ let invalidatedCount = 0;
716
+ for (const pendingBatch of this.batches.values()) {
717
+ if (
718
+ pendingBatch.startEpoch < batch.startEpoch &&
719
+ pendingBatch.state.status === BatchStatus.AwaitingValidation
720
+ ) {
721
+ this.logger.verbose("Batch validation error", {id: this.logId, ...pendingBatch.getMetadata()});
722
+ pendingBatch.validationError(res.err);
723
+ invalidatedCount++;
724
+ }
727
725
  }
726
+ return invalidatedCount;
727
+ };
728
+
729
+ const prevBatch = this.batches.get(batch.startEpoch - EPOCHS_PER_BATCH);
730
+ switch (classifyProcessingFault(res.err, batch, prevBatch)) {
731
+ case ProcessingFaultKind.CurrentBatch:
732
+ batch.processingError(res.err);
733
+ break;
734
+
735
+ case ProcessingFaultKind.PreviousBatch:
736
+ // If no previous batch was invalidated, it means the error is on this batch
737
+ if (invalidatePreviousBatches() === 0) {
738
+ batch.processingError(res.err);
739
+ } else {
740
+ batch.retainForReprocessing();
741
+ }
742
+ break;
743
+
744
+ case ProcessingFaultKind.Ambiguous:
745
+ batch.processingError(res.err);
746
+ invalidatePreviousBatches();
747
+ break;
728
748
  }
729
749
  }
730
750
 
@@ -1,6 +1,7 @@
1
1
  import {SLOTS_PER_EPOCH} from "@lodestar/params";
2
2
  import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
3
3
  import {Epoch, Slot} from "@lodestar/types";
4
+ import {BlockError, BlockErrorCode} from "../../../chain/errors/index.js";
4
5
  import {BATCH_SLOT_OFFSET, EPOCHS_PER_BATCH} from "../../constants.js";
5
6
  import {Batch, BatchStatus} from "../batch.js";
6
7
 
@@ -117,3 +118,46 @@ export function isSyncChainDone(batches: Batch[], lastEpochWithProcessBlocks: Ep
117
118
 
118
119
  return batchStartEpochIsAfterSlot(lastEpochWithProcessBlocks, targetSlot);
119
120
  }
121
+
122
+ /**
123
+ * Where a batch processing error should be attributed.
124
+ */
125
+ export enum ProcessingFaultKind {
126
+ /** This batch's own blocks are bad or incomplete, so redownload this batch. */
127
+ CurrentBatch = "CurrentBatch",
128
+ /** This batch is valid, but a previous batch did not deliver the parent. */
129
+ PreviousBatch = "PreviousBatch",
130
+ /** The fault could be in this batch or a previous batch, so hedge both ways. */
131
+ Ambiguous = "Ambiguous",
132
+ }
133
+
134
+ /**
135
+ * Classify a processChainSegment error for a batch so range sync only redownloads
136
+ * the batch or batches that could actually be at fault.
137
+ * Note that range sync is supposed to only handle linear chain, for forky condition we'll handle it via backward sync
138
+ * in BlockInputSync or the upcoming/TODO beacon_blocks_by_head req/resp.
139
+ */
140
+ export function classifyProcessingFault(err: Error, batch: Batch, prevBatch: Batch | undefined): ProcessingFaultKind {
141
+ if (!(err instanceof BlockError)) {
142
+ return ProcessingFaultKind.CurrentBatch;
143
+ }
144
+
145
+ const {code} = err.type;
146
+ if (code !== BlockErrorCode.PARENT_BLOCK_UNKNOWN && code !== BlockErrorCode.PARENT_PAYLOAD_UNKNOWN) {
147
+ return ProcessingFaultKind.CurrentBatch;
148
+ }
149
+
150
+ const firstErrorSlot = err.signedBlock.message.slot;
151
+ if (firstErrorSlot === batch.startSlot) {
152
+ // note that range sync is for linear chain, so this is clearly an issue of the previous batch
153
+ return prevBatch === undefined ? ProcessingFaultKind.CurrentBatch : ProcessingFaultKind.PreviousBatch;
154
+ }
155
+
156
+ const prevTailSlot = batch.startSlot - 1;
157
+ const prevHasFullTail =
158
+ code === BlockErrorCode.PARENT_PAYLOAD_UNKNOWN
159
+ ? (prevBatch?.getPayloadEnvelopes()?.get(prevTailSlot)?.hasPayloadEnvelope() ?? false)
160
+ : (prevBatch?.getBlocks().some((b) => b.slot === prevTailSlot) ?? false);
161
+
162
+ return prevHasFullTail ? ProcessingFaultKind.CurrentBatch : ProcessingFaultKind.Ambiguous;
163
+ }
@@ -8,21 +8,10 @@ export enum ProfileThread {
8
8
  DISC5 = "discv5",
9
9
  }
10
10
 
11
- /**
12
- * The time to take a Bun profile.
13
- * If we increase this time it'll potentiall cause the app to crash.
14
- * If we decrease this time, profile recorded will be fragmented and hard to analyze.
15
- */
16
- const BUN_PROFILE_MS = 3 * 1000;
17
-
18
- export async function profileThread(thread: ProfileThread, durationMs: number, dirpath: string): Promise<string> {
19
- return globalThis.Bun ? profileBun(thread, durationMs) : profileNodeJS(thread, durationMs, dirpath);
20
- }
21
-
22
11
  /**
23
12
  * Take `durationMs` profile of the current thread and return the persisted file path.
24
13
  */
25
- async function profileNodeJS(thread: ProfileThread, durationMs: number, dirpath: string): Promise<string> {
14
+ export async function profileThread(thread: ProfileThread, durationMs: number, dirpath: string): Promise<string> {
26
15
  const inspector = await import("node:inspector");
27
16
 
28
17
  // due to some typing issues, not able to use promisify here
@@ -54,25 +43,6 @@ async function profileNodeJS(thread: ProfileThread, durationMs: number, dirpath:
54
43
  return filePath;
55
44
  }
56
45
 
57
- /**
58
- * Unlike NodeJS, Bun console.profile() api flush data to the inspector,
59
- * so this api returns ms taken of this profile instead of file path.
60
- */
61
- async function profileBun(thread: ProfileThread, durationMs: number): Promise<string> {
62
- const start = Date.now();
63
- let now = Date.now();
64
- while (now - start < durationMs) {
65
- // biome-ignore lint/suspicious/noConsole: need to use console api to profile in Bun
66
- console.profile(String(now));
67
- await sleep(BUN_PROFILE_MS);
68
- // biome-ignore lint/suspicious/noConsole: need to use console api to profile in Bun
69
- console.profileEnd(String(now));
70
- now = Date.now();
71
- }
72
-
73
- return `Successfully take Bun ${thread} thread profile in ${now - start}ms. Check your inspector to see the profile.`;
74
- }
75
-
76
46
  /**
77
47
  * Write heap snapshot of the current thread to the specified file.
78
48
  */
@@ -706,7 +706,7 @@ export function getBlockRootFromPayloadAttestationMessageSerialized(data: Uint8A
706
706
  * blockHash: Bytes32 (32 bytes)
707
707
  * prevRandao: Bytes32 (32 bytes)
708
708
  * feeRecipient: ExecutionAddress(20 bytes)
709
- * gasLimit: UintNum64 (8 bytes)
709
+ * gasLimit: UintBn64 (8 bytes)
710
710
  * builderIndex: BuilderIndex (8 bytes)
711
711
  * slot: Slot (8 bytes) ← absolute offset 264
712
712
  */
@@ -1,2 +0,0 @@
1
- export declare function gcStats(): () => void;
2
- //# sourceMappingURL=prometheus-gc-stats.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prometheus-gc-stats.d.ts","sourceRoot":"","sources":["../../src/bun-wrappers/prometheus-gc-stats.ts"],"names":[],"mappings":"AAIA,wBAAgB,OAAO,eAEtB"}
@@ -1,8 +0,0 @@
1
- // Bun does not support `GCProfiler` from `node:v8`a
2
- // Which is exposed from `@chainsafe/prometheus-gc-stats` and used in `packages/beacon-node/src/metrics/nodeJsMetrics.ts`
3
- // So we expose a dummy function for Bun runtime which do nothing for now
4
- // TODO: May look get some useful data from `bun:jsc`
5
- export function gcStats() {
6
- return () => { };
7
- }
8
- //# sourceMappingURL=prometheus-gc-stats.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prometheus-gc-stats.js","sourceRoot":"","sources":["../../src/bun-wrappers/prometheus-gc-stats.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,yHAAyH;AACzH,yEAAyE;AACzE,qDAAqD;AACrD,MAAM,UAAU,OAAO,GAAG;IACxB,OAAO,GAAG,EAAE,CAAC,EAAC,CAAC,CAAC;AAAA,CACjB"}
@@ -1,3 +0,0 @@
1
- import { FsDatastore } from "datastore-fs";
2
- export declare const LevelDatastore: typeof FsDatastore;
3
- //# sourceMappingURL=datastore_bun.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"datastore_bun.d.ts","sourceRoot":"","sources":["../../../src/network/peers/datastore_bun.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAEzC,eAAO,MAAM,cAAc,oBAAc,CAAC"}
@@ -1,3 +0,0 @@
1
- import { FsDatastore } from "datastore-fs";
2
- export const LevelDatastore = FsDatastore;
3
- //# sourceMappingURL=datastore_bun.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"datastore_bun.js","sourceRoot":"","sources":["../../../src/network/peers/datastore_bun.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAEzC,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC"}
@@ -1,7 +0,0 @@
1
- // Bun does not support `GCProfiler` from `node:v8`a
2
- // Which is exposed from `@chainsafe/prometheus-gc-stats` and used in `packages/beacon-node/src/metrics/nodeJsMetrics.ts`
3
- // So we expose a dummy function for Bun runtime which do nothing for now
4
- // TODO: May look get some useful data from `bun:jsc`
5
- export function gcStats() {
6
- return () => {};
7
- }
@@ -1,3 +0,0 @@
1
- import {FsDatastore} from "datastore-fs";
2
-
3
- export const LevelDatastore = FsDatastore;