@lodestar/beacon-node 1.36.0-dev.793f92c091 → 1.36.0-dev.88fbac9fcf

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 (214) hide show
  1. package/lib/api/impl/config/constants.d.ts +4 -2
  2. package/lib/api/impl/config/constants.d.ts.map +1 -1
  3. package/lib/api/impl/config/constants.js +6 -3
  4. package/lib/api/impl/config/constants.js.map +1 -1
  5. package/lib/api/impl/lodestar/index.d.ts +5 -0
  6. package/lib/api/impl/lodestar/index.d.ts.map +1 -1
  7. package/lib/api/impl/lodestar/index.js +35 -10
  8. package/lib/api/impl/lodestar/index.js.map +1 -1
  9. package/lib/api/impl/node/utils.js +1 -1
  10. package/lib/api/impl/node/utils.js.map +1 -1
  11. package/lib/api/impl/validator/index.d.ts.map +1 -1
  12. package/lib/api/impl/validator/index.js +2 -2
  13. package/lib/api/impl/validator/index.js.map +1 -1
  14. package/lib/chain/archiveStore/archiveStore.d.ts +9 -0
  15. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  16. package/lib/chain/archiveStore/archiveStore.js +24 -0
  17. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  18. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.d.ts +7 -0
  19. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.d.ts.map +1 -1
  20. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js +31 -5
  21. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js.map +1 -1
  22. package/lib/chain/beaconProposerCache.d.ts +3 -0
  23. package/lib/chain/beaconProposerCache.d.ts.map +1 -1
  24. package/lib/chain/beaconProposerCache.js +4 -6
  25. package/lib/chain/beaconProposerCache.js.map +1 -1
  26. package/lib/chain/chain.d.ts +5 -2
  27. package/lib/chain/chain.d.ts.map +1 -1
  28. package/lib/chain/chain.js +34 -18
  29. package/lib/chain/chain.js.map +1 -1
  30. package/lib/chain/errors/dataColumnSidecarError.d.ts +7 -0
  31. package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
  32. package/lib/chain/errors/dataColumnSidecarError.js +1 -0
  33. package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
  34. package/lib/chain/errors/voluntaryExitError.d.ts +16 -2
  35. package/lib/chain/errors/voluntaryExitError.d.ts.map +1 -1
  36. package/lib/chain/errors/voluntaryExitError.js +22 -1
  37. package/lib/chain/errors/voluntaryExitError.js.map +1 -1
  38. package/lib/chain/forkChoice/index.d.ts +9 -1
  39. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  40. package/lib/chain/forkChoice/index.js +109 -4
  41. package/lib/chain/forkChoice/index.js.map +1 -1
  42. package/lib/chain/interface.d.ts +2 -0
  43. package/lib/chain/interface.d.ts.map +1 -1
  44. package/lib/chain/lightClient/index.d.ts +3 -0
  45. package/lib/chain/lightClient/index.d.ts.map +1 -1
  46. package/lib/chain/lightClient/index.js +24 -13
  47. package/lib/chain/lightClient/index.js.map +1 -1
  48. package/lib/chain/opPools/syncContributionAndProofPool.d.ts +3 -1
  49. package/lib/chain/opPools/syncContributionAndProofPool.d.ts.map +1 -1
  50. package/lib/chain/opPools/syncContributionAndProofPool.js +4 -3
  51. package/lib/chain/opPools/syncContributionAndProofPool.js.map +1 -1
  52. package/lib/chain/options.d.ts +0 -2
  53. package/lib/chain/options.d.ts.map +1 -1
  54. package/lib/chain/options.js +0 -1
  55. package/lib/chain/options.js.map +1 -1
  56. package/lib/chain/stateCache/datastore/db.d.ts +12 -0
  57. package/lib/chain/stateCache/datastore/db.d.ts.map +1 -1
  58. package/lib/chain/stateCache/datastore/db.js +70 -0
  59. package/lib/chain/stateCache/datastore/db.js.map +1 -1
  60. package/lib/chain/stateCache/datastore/file.d.ts +1 -0
  61. package/lib/chain/stateCache/datastore/file.d.ts.map +1 -1
  62. package/lib/chain/stateCache/datastore/file.js +7 -0
  63. package/lib/chain/stateCache/datastore/file.js.map +1 -1
  64. package/lib/chain/stateCache/datastore/types.d.ts +1 -0
  65. package/lib/chain/stateCache/datastore/types.d.ts.map +1 -1
  66. package/lib/chain/validation/attestation.d.ts.map +1 -1
  67. package/lib/chain/validation/attestation.js +6 -7
  68. package/lib/chain/validation/attestation.js.map +1 -1
  69. package/lib/chain/validation/block.d.ts.map +1 -1
  70. package/lib/chain/validation/block.js +1 -2
  71. package/lib/chain/validation/block.js.map +1 -1
  72. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  73. package/lib/chain/validation/dataColumnSidecar.js +14 -3
  74. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  75. package/lib/chain/validation/lightClientOptimisticUpdate.d.ts.map +1 -1
  76. package/lib/chain/validation/lightClientOptimisticUpdate.js +1 -2
  77. package/lib/chain/validation/lightClientOptimisticUpdate.js.map +1 -1
  78. package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
  79. package/lib/chain/validation/voluntaryExit.js +5 -4
  80. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  81. package/lib/constants/constants.d.ts +0 -5
  82. package/lib/constants/constants.d.ts.map +1 -1
  83. package/lib/constants/constants.js +0 -5
  84. package/lib/constants/constants.js.map +1 -1
  85. package/lib/constants/network.d.ts +0 -14
  86. package/lib/constants/network.d.ts.map +1 -1
  87. package/lib/constants/network.js +0 -15
  88. package/lib/constants/network.js.map +1 -1
  89. package/lib/index.d.ts +2 -0
  90. package/lib/index.d.ts.map +1 -1
  91. package/lib/index.js +2 -0
  92. package/lib/index.js.map +1 -1
  93. package/lib/metrics/metrics/lodestar.d.ts +11 -0
  94. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  95. package/lib/metrics/metrics/lodestar.js +19 -1
  96. package/lib/metrics/metrics/lodestar.js.map +1 -1
  97. package/lib/network/core/networkCore.d.ts.map +1 -1
  98. package/lib/network/core/networkCore.js +5 -1
  99. package/lib/network/core/networkCore.js.map +1 -1
  100. package/lib/network/core/networkCoreWorker.js +2 -7
  101. package/lib/network/core/networkCoreWorker.js.map +1 -1
  102. package/lib/network/discv5/utils.d.ts.map +1 -1
  103. package/lib/network/discv5/utils.js +1 -2
  104. package/lib/network/discv5/utils.js.map +1 -1
  105. package/lib/network/discv5/worker.js +2 -7
  106. package/lib/network/discv5/worker.js.map +1 -1
  107. package/lib/network/gossip/encoding.js +1 -1
  108. package/lib/network/gossip/encoding.js.map +1 -1
  109. package/lib/network/gossip/gossipsub.d.ts.map +1 -1
  110. package/lib/network/gossip/gossipsub.js +1 -7
  111. package/lib/network/gossip/gossipsub.js.map +1 -1
  112. package/lib/network/gossip/snappy_bun.d.ts +3 -0
  113. package/lib/network/gossip/snappy_bun.d.ts.map +1 -0
  114. package/lib/network/gossip/snappy_bun.js +3 -0
  115. package/lib/network/gossip/snappy_bun.js.map +1 -0
  116. package/lib/network/metadata.d.ts +1 -1
  117. package/lib/network/metadata.d.ts.map +1 -1
  118. package/lib/network/metadata.js +1 -0
  119. package/lib/network/metadata.js.map +1 -1
  120. package/lib/network/network.d.ts.map +1 -1
  121. package/lib/network/network.js +1 -0
  122. package/lib/network/network.js.map +1 -1
  123. package/lib/network/options.d.ts +0 -1
  124. package/lib/network/options.d.ts.map +1 -1
  125. package/lib/network/options.js.map +1 -1
  126. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  127. package/lib/network/processor/gossipHandlers.js +14 -8
  128. package/lib/network/processor/gossipHandlers.js.map +1 -1
  129. package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
  130. package/lib/network/reqresp/handlers/beaconBlocksByRange.js +3 -1
  131. package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
  132. package/lib/network/reqresp/handlers/blobSidecarsByRange.js +5 -5
  133. package/lib/network/reqresp/handlers/blobSidecarsByRange.js.map +1 -1
  134. package/lib/network/reqresp/handlers/blobSidecarsByRoot.js +4 -4
  135. package/lib/network/reqresp/handlers/blobSidecarsByRoot.js.map +1 -1
  136. package/lib/network/subnets/attnetsService.d.ts +1 -1
  137. package/lib/network/subnets/attnetsService.js +6 -6
  138. package/lib/network/subnets/attnetsService.js.map +1 -1
  139. package/lib/network/subnets/util.d.ts +3 -2
  140. package/lib/network/subnets/util.d.ts.map +1 -1
  141. package/lib/network/subnets/util.js +6 -6
  142. package/lib/network/subnets/util.js.map +1 -1
  143. package/lib/node/nodejs.d.ts +2 -1
  144. package/lib/node/nodejs.d.ts.map +1 -1
  145. package/lib/node/nodejs.js +2 -1
  146. package/lib/node/nodejs.js.map +1 -1
  147. package/lib/sync/range/range.d.ts.map +1 -1
  148. package/lib/sync/range/range.js +2 -1
  149. package/lib/sync/range/range.js.map +1 -1
  150. package/lib/sync/utils/remoteSyncType.d.ts +2 -1
  151. package/lib/sync/utils/remoteSyncType.d.ts.map +1 -1
  152. package/lib/sync/utils/remoteSyncType.js +19 -4
  153. package/lib/sync/utils/remoteSyncType.js.map +1 -1
  154. package/lib/util/clock.d.ts.map +1 -1
  155. package/lib/util/clock.js +3 -4
  156. package/lib/util/clock.js.map +1 -1
  157. package/lib/util/profile.d.ts +6 -4
  158. package/lib/util/profile.d.ts.map +1 -1
  159. package/lib/util/profile.js +40 -3
  160. package/lib/util/profile.js.map +1 -1
  161. package/lib/util/sszBytes.d.ts +2 -0
  162. package/lib/util/sszBytes.d.ts.map +1 -1
  163. package/lib/util/sszBytes.js +25 -0
  164. package/lib/util/sszBytes.js.map +1 -1
  165. package/package.json +31 -24
  166. package/src/api/impl/config/constants.ts +10 -4
  167. package/src/api/impl/lodestar/index.ts +42 -10
  168. package/src/api/impl/node/utils.ts +1 -1
  169. package/src/api/impl/validator/index.ts +5 -2
  170. package/src/chain/archiveStore/archiveStore.ts +27 -0
  171. package/src/chain/archiveStore/strategies/frequencyStateArchiveStrategy.ts +32 -5
  172. package/src/chain/beaconProposerCache.ts +4 -8
  173. package/src/chain/chain.ts +50 -25
  174. package/src/chain/errors/dataColumnSidecarError.ts +8 -0
  175. package/src/chain/errors/voluntaryExitError.ts +30 -2
  176. package/src/chain/forkChoice/index.ts +178 -2
  177. package/src/chain/interface.ts +2 -0
  178. package/src/chain/lightClient/index.ts +26 -12
  179. package/src/chain/opPools/syncContributionAndProofPool.ts +3 -2
  180. package/src/chain/options.ts +0 -3
  181. package/src/chain/stateCache/datastore/db.ts +89 -1
  182. package/src/chain/stateCache/datastore/file.ts +8 -0
  183. package/src/chain/stateCache/datastore/types.ts +1 -0
  184. package/src/chain/validation/attestation.ts +6 -7
  185. package/src/chain/validation/block.ts +1 -2
  186. package/src/chain/validation/dataColumnSidecar.ts +21 -4
  187. package/src/chain/validation/lightClientOptimisticUpdate.ts +3 -2
  188. package/src/chain/validation/voluntaryExit.ts +14 -4
  189. package/src/constants/constants.ts +0 -6
  190. package/src/constants/network.ts +0 -19
  191. package/src/index.ts +2 -0
  192. package/src/metrics/metrics/lodestar.ts +22 -1
  193. package/src/network/core/networkCore.ts +5 -1
  194. package/src/network/core/networkCoreWorker.ts +2 -7
  195. package/src/network/discv5/utils.ts +1 -2
  196. package/src/network/discv5/worker.ts +2 -7
  197. package/src/network/gossip/encoding.ts +1 -1
  198. package/src/network/gossip/gossipsub.ts +1 -10
  199. package/src/network/gossip/snappy_bun.ts +2 -0
  200. package/src/network/metadata.ts +3 -1
  201. package/src/network/network.ts +1 -0
  202. package/src/network/options.ts +0 -1
  203. package/src/network/processor/gossipHandlers.ts +16 -7
  204. package/src/network/reqresp/handlers/beaconBlocksByRange.ts +3 -1
  205. package/src/network/reqresp/handlers/blobSidecarsByRange.ts +6 -6
  206. package/src/network/reqresp/handlers/blobSidecarsByRoot.ts +5 -5
  207. package/src/network/subnets/attnetsService.ts +6 -6
  208. package/src/network/subnets/util.ts +12 -12
  209. package/src/node/nodejs.ts +3 -0
  210. package/src/sync/range/range.ts +2 -1
  211. package/src/sync/utils/remoteSyncType.ts +23 -4
  212. package/src/util/clock.ts +3 -4
  213. package/src/util/profile.ts +45 -3
  214. package/src/util/sszBytes.ts +30 -0
@@ -14,6 +14,7 @@ import {
14
14
  ForkPreGloas,
15
15
  ForkSeq,
16
16
  MIN_SYNC_COMMITTEE_PARTICIPANTS,
17
+ SLOTS_PER_EPOCH,
17
18
  SYNC_COMMITTEE_SIZE,
18
19
  forkPostAltair,
19
20
  highestFork,
@@ -51,6 +52,7 @@ import {IBeaconDb} from "../../db/index.js";
51
52
  import {NUM_WITNESS, NUM_WITNESS_ELECTRA} from "../../db/repositories/lightclientSyncCommitteeWitness.js";
52
53
  import {Metrics} from "../../metrics/index.js";
53
54
  import {byteArrayEquals} from "../../util/bytes.js";
55
+ import {IClock} from "../../util/clock.js";
54
56
  import {ChainEventEmitter} from "../emitter.js";
55
57
  import {LightClientServerError, LightClientServerErrorCode} from "../errors/lightClientError.js";
56
58
  import {
@@ -86,6 +88,7 @@ export type SyncAttestedData = {
86
88
 
87
89
  type LightClientServerModules = {
88
90
  config: ChainForkConfig;
91
+ clock: IClock;
89
92
  db: IBeaconDb;
90
93
  metrics: Metrics | null;
91
94
  emitter: ChainEventEmitter;
@@ -201,6 +204,7 @@ export class LightClientServer {
201
204
  private readonly metrics: Metrics | null;
202
205
  private readonly emitter: ChainEventEmitter;
203
206
  private readonly logger: Logger;
207
+ private readonly clock: IClock;
204
208
  private readonly knownSyncCommittee = new MapDef<SyncPeriod, Set<DependentRootHex>>(() => new Set());
205
209
  private storedCurrentSyncCommittee = false;
206
210
 
@@ -221,8 +225,9 @@ export class LightClientServer {
221
225
  private readonly opts: LightClientServerOpts,
222
226
  modules: LightClientServerModules
223
227
  ) {
224
- const {config, db, metrics, emitter, logger} = modules;
228
+ const {config, clock, db, metrics, emitter, logger} = modules;
225
229
  this.config = config;
230
+ this.clock = clock;
226
231
  this.db = db;
227
232
  this.metrics = metrics;
228
233
  this.emitter = emitter;
@@ -533,12 +538,19 @@ export class LightClientServer {
533
538
  // Fork of LightClientOptimisticUpdate and LightClientFinalityUpdate is based off on attested header's fork
534
539
  const attestedFork = this.config.getForkName(attestedHeader.beacon.slot);
535
540
 
536
- // Emit update
537
- // Note: Always emit optimistic update even if we have emitted one with higher or equal attested_header.slot
538
- this.emitter.emit(routes.events.EventType.lightClientOptimisticUpdate, {
539
- version: attestedFork,
540
- data: headerUpdate,
541
- });
541
+ // Check if node is syncing / too far behind to avoid emitting stale light client updates
542
+ const isStaleLightClientUpdate = this.clock.currentSlot - signatureSlot > SLOTS_PER_EPOCH;
543
+
544
+ if (!isStaleLightClientUpdate) {
545
+ // Emit update
546
+ // Note: Always emit optimistic update even if we have emitted one with higher or equal attested_header.slot
547
+ this.emitter.emit(routes.events.EventType.lightClientOptimisticUpdate, {
548
+ version: attestedFork,
549
+ data: headerUpdate,
550
+ });
551
+ } else {
552
+ this.metrics?.lightclientServer.staleLightClientUpdates.inc();
553
+ }
542
554
 
543
555
  // Persist latest best update for getLatestHeadUpdate()
544
556
  // TODO: Once SyncAggregate are constructed from P2P too, count bits to decide "best"
@@ -569,11 +581,13 @@ export class LightClientServer {
569
581
  };
570
582
  this.metrics?.lightclientServer.onSyncAggregate.inc({event: "update_latest_finalized_update"});
571
583
 
572
- // Note: Ignores gossip rule to always emit finality_update with higher finalized_header.slot, for simplicity
573
- this.emitter.emit(routes.events.EventType.lightClientFinalityUpdate, {
574
- version: attestedFork,
575
- data: this.finalized,
576
- });
584
+ if (!isStaleLightClientUpdate) {
585
+ // Note: Ignores gossip rule to always emit finality_update with higher finalized_header.slot, for simplicity
586
+ this.emitter.emit(routes.events.EventType.lightClientFinalityUpdate, {
587
+ version: attestedFork,
588
+ data: this.finalized,
589
+ });
590
+ }
577
591
  }
578
592
  }
579
593
 
@@ -1,10 +1,10 @@
1
1
  import {Signature, aggregateSignatures} from "@chainsafe/blst";
2
2
  import {BitArray} from "@chainsafe/ssz";
3
+ import {ChainForkConfig} from "@lodestar/config";
3
4
  import {SYNC_COMMITTEE_SIZE, SYNC_COMMITTEE_SUBNET_SIZE} from "@lodestar/params";
4
5
  import {G2_POINT_AT_INFINITY} from "@lodestar/state-transition";
5
6
  import {Root, Slot, SubnetID, altair, ssz} from "@lodestar/types";
6
7
  import {Logger, MapDef, toRootHex} from "@lodestar/utils";
7
- import {MAXIMUM_GOSSIP_CLOCK_DISPARITY} from "../../constants/constants.js";
8
8
  import {Metrics} from "../../metrics/metrics.js";
9
9
  import {IClock} from "../../util/clock.js";
10
10
  import {InsertOutcome, OpPoolError, OpPoolErrorCode} from "./types.js";
@@ -51,6 +51,7 @@ export class SyncContributionAndProofPool {
51
51
  private lowestPermissibleSlot = 0;
52
52
 
53
53
  constructor(
54
+ private readonly config: ChainForkConfig,
54
55
  private readonly clock: IClock,
55
56
  private readonly metrics: Metrics | null = null,
56
57
  private logger: Logger | null = null
@@ -92,7 +93,7 @@ export class SyncContributionAndProofPool {
92
93
 
93
94
  // Reject ContributionAndProofs of previous slots
94
95
  // for api ContributionAndProofs, we allow them to be added to the pool
95
- if (!priority && slot < this.clock.slotWithPastTolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY)) {
96
+ if (!priority && slot < this.clock.slotWithPastTolerance(this.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY / 1000)) {
96
97
  return InsertOutcome.Late;
97
98
  }
98
99
 
@@ -41,8 +41,6 @@ export type IChainOptions = BlockProcessOpts &
41
41
  maxCachedBlobSidecars?: number;
42
42
  /** Max number of produced block roots (blinded or full) cached for broadcast validations */
43
43
  maxCachedProducedRoots?: number;
44
- /** Subscribe to and custody all data column sidecar subnets */
45
- supernode?: boolean;
46
44
  initialCustodyGroupCount?: number;
47
45
  broadcastValidationStrictness?: string;
48
46
  minSameMessageSignatureSetsToBatch: number;
@@ -118,7 +116,6 @@ export const defaultChainOptions: IChainOptions = {
118
116
  archiveMode: DEFAULT_ARCHIVE_MODE,
119
117
  pruneHistory: false,
120
118
  emitPayloadAttributes: false,
121
- supernode: false,
122
119
  // for gossip block validation, it's unlikely we see a reorg with 32 slots
123
120
  // for attestation validation, having this value ensures we don't have to regen states most of the time
124
121
  maxSkipSlots: 32,
@@ -1,5 +1,11 @@
1
- import {phase0, ssz} from "@lodestar/types";
1
+ import {SLOTS_PER_EPOCH} from "@lodestar/params";
2
+ import {Epoch, phase0, ssz} from "@lodestar/types";
3
+ import {MapDef} from "@lodestar/utils";
2
4
  import {IBeaconDb} from "../../../db/interface.js";
5
+ import {
6
+ getLastProcessedSlotFromBeaconStateSerialized,
7
+ getSlotFromBeaconStateSerialized,
8
+ } from "../../../util/sszBytes.js";
3
9
  import {CPStateDatastore, DatastoreKey} from "./types.js";
4
10
 
5
11
  /**
@@ -22,6 +28,13 @@ export class DbCPStateDatastore implements CPStateDatastore {
22
28
  return this.db.checkpointState.getBinary(serializedCheckpoint);
23
29
  }
24
30
 
31
+ async readLatestSafe(): Promise<Uint8Array | null> {
32
+ const allKeys = await this.readKeys();
33
+ if (allKeys.length === 0) return null;
34
+
35
+ return getLatestSafeDatastoreKey(allKeys, this.read.bind(this));
36
+ }
37
+
25
38
  async readKeys(): Promise<DatastoreKey[]> {
26
39
  return this.db.checkpointState.keys();
27
40
  }
@@ -34,3 +47,78 @@ export function datastoreKeyToCheckpoint(key: DatastoreKey): phase0.Checkpoint {
34
47
  export function checkpointToDatastoreKey(cp: phase0.Checkpoint): DatastoreKey {
35
48
  return ssz.phase0.Checkpoint.serialize(cp);
36
49
  }
50
+
51
+ /**
52
+ * Get the latest safe checkpoint state the node can use to boot from
53
+ * - it should be the checkpoint state that's unique in its epoch
54
+ * - its last processed block slot should be at epoch boundary or last slot of previous epoch
55
+ * - state slot should be at epoch boundary
56
+ * - state slot should be equal to epoch * SLOTS_PER_EPOCH
57
+ *
58
+ * return the serialized data of Current Root Checkpoint State (CRCS) or Previous Root Checkpoint State (PRCS)
59
+ *
60
+ */
61
+ export async function getLatestSafeDatastoreKey(
62
+ allKeys: DatastoreKey[],
63
+ readFn: (key: DatastoreKey) => Promise<Uint8Array | null>
64
+ ): Promise<Uint8Array | null> {
65
+ const checkpointsByEpoch = new MapDef<Epoch, DatastoreKey[]>(() => []);
66
+ for (const key of allKeys) {
67
+ const cp = datastoreKeyToCheckpoint(key);
68
+ checkpointsByEpoch.getOrDefault(cp.epoch).push(key);
69
+ }
70
+
71
+ const dataStoreKeyByEpoch: Map<Epoch, DatastoreKey> = new Map();
72
+ for (const [epoch, keys] of checkpointsByEpoch.entries()) {
73
+ // only consider epochs with a single checkpoint to avoid ambiguity from forks
74
+ if (keys.length === 1) {
75
+ dataStoreKeyByEpoch.set(epoch, keys[0]);
76
+ }
77
+ }
78
+
79
+ const epochsDesc = Array.from(dataStoreKeyByEpoch.keys()).sort((a, b) => b - a);
80
+ for (const epoch of epochsDesc) {
81
+ const datastoreKey = dataStoreKeyByEpoch.get(epoch);
82
+ if (datastoreKey == null) {
83
+ // should not happen
84
+ continue;
85
+ }
86
+
87
+ const stateBytes = await readFn(datastoreKey);
88
+ if (stateBytes == null) {
89
+ // should not happen
90
+ continue;
91
+ }
92
+
93
+ const lastProcessedSlot = getLastProcessedSlotFromBeaconStateSerialized(stateBytes);
94
+ if (lastProcessedSlot == null) {
95
+ // cannot extract last processed slot from serialized state, skip
96
+ continue;
97
+ }
98
+
99
+ const stateSlot = getSlotFromBeaconStateSerialized(stateBytes);
100
+ if (stateSlot == null) {
101
+ // cannot extract slot from serialized state, skip
102
+ continue;
103
+ }
104
+
105
+ if (lastProcessedSlot !== stateSlot && lastProcessedSlot !== stateSlot - 1) {
106
+ // not CRCS or PRCS, skip
107
+ continue;
108
+ }
109
+
110
+ if (stateSlot % SLOTS_PER_EPOCH !== 0) {
111
+ // not at epoch boundary, skip
112
+ continue;
113
+ }
114
+
115
+ if (stateSlot !== SLOTS_PER_EPOCH * epoch) {
116
+ // should not happen after above checks, but just to be safe
117
+ continue;
118
+ }
119
+
120
+ return stateBytes;
121
+ }
122
+
123
+ return null;
124
+ }
@@ -2,6 +2,7 @@ import path from "node:path";
2
2
  import {phase0, ssz} from "@lodestar/types";
3
3
  import {fromHex, toHex} from "@lodestar/utils";
4
4
  import {ensureDir, readFile, readFileNames, removeFile, writeIfNotExist} from "../../../util/file.js";
5
+ import {getLatestSafeDatastoreKey} from "./db.js";
5
6
  import {CPStateDatastore, DatastoreKey} from "./types.js";
6
7
 
7
8
  const CHECKPOINT_STATES_FOLDER = "checkpoint_states";
@@ -44,6 +45,13 @@ export class FileCPStateDatastore implements CPStateDatastore {
44
45
  return readFile(filePath);
45
46
  }
46
47
 
48
+ async readLatestSafe(): Promise<Uint8Array | null> {
49
+ const allKeys = await this.readKeys();
50
+ if (allKeys.length === 0) return null;
51
+
52
+ return getLatestSafeDatastoreKey(allKeys, this.read.bind(this));
53
+ }
54
+
47
55
  async readKeys(): Promise<DatastoreKey[]> {
48
56
  const fileNames = await readFileNames(this.folderPath);
49
57
  return fileNames
@@ -8,6 +8,7 @@ export interface CPStateDatastore {
8
8
  write: (cpKey: phase0.Checkpoint, stateBytes: Uint8Array) => Promise<DatastoreKey>;
9
9
  remove: (key: DatastoreKey) => Promise<void>;
10
10
  read: (key: DatastoreKey) => Promise<Uint8Array | null>;
11
+ readLatestSafe: () => Promise<Uint8Array | null>;
11
12
  readKeys: () => Promise<DatastoreKey[]>;
12
13
  init?: () => Promise<void>;
13
14
  }
@@ -36,7 +36,6 @@ import {
36
36
  ssz,
37
37
  } from "@lodestar/types";
38
38
  import {assert, toRootHex} from "@lodestar/utils";
39
- import {MAXIMUM_GOSSIP_CLOCK_DISPARITY_SEC} from "../../constants/index.js";
40
39
  import {sszDeserializeSingleAttestation} from "../../network/gossip/topic.js";
41
40
  import {getShufflingDependentRoot} from "../../util/dependentRoot.js";
42
41
  import {
@@ -570,8 +569,8 @@ async function validateAttestationNoSignatureCheck(
570
569
  * Note: We do not queue future attestations for later processing
571
570
  */
572
571
  export function verifyPropagationSlotRange(fork: ForkName, chain: IBeaconChain, attestationSlot: Slot): void {
573
- // slot with future tolerance of MAXIMUM_GOSSIP_CLOCK_DISPARITY_SEC
574
- const latestPermissibleSlot = chain.clock.slotWithFutureTolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY_SEC);
572
+ // slot with future tolerance of MAXIMUM_GOSSIP_CLOCK_DISPARITY
573
+ const latestPermissibleSlot = chain.clock.slotWithFutureTolerance(chain.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY / 1000);
575
574
  if (attestationSlot > latestPermissibleSlot) {
576
575
  throw new AttestationError(GossipAction.IGNORE, {
577
576
  code: AttestationErrorCode.FUTURE_SLOT,
@@ -586,9 +585,9 @@ export function verifyPropagationSlotRange(fork: ForkName, chain: IBeaconChain,
586
585
  // see: https://github.com/ethereum/consensus-specs/pull/3360
587
586
  if (ForkSeq[fork] < ForkSeq.deneb) {
588
587
  const earliestPermissibleSlot = Math.max(
589
- // slot with past tolerance of MAXIMUM_GOSSIP_CLOCK_DISPARITY_SEC
590
- // ATTESTATION_PROPAGATION_SLOT_RANGE = SLOTS_PER_EPOCH
591
- chain.clock.slotWithPastTolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY_SEC) - SLOTS_PER_EPOCH,
588
+ // slot with past tolerance of MAXIMUM_GOSSIP_CLOCK_DISPARITY
589
+ chain.clock.slotWithPastTolerance(chain.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY / 1000) -
590
+ chain.config.ATTESTATION_PROPAGATION_SLOT_RANGE,
592
591
  0
593
592
  );
594
593
 
@@ -614,7 +613,7 @@ export function verifyPropagationSlotRange(fork: ForkName, chain: IBeaconChain,
614
613
 
615
614
  // lower bound for previous epoch is same as epoch of earliestPermissibleSlot
616
615
  const currentEpochWithPastTolerance = computeEpochAtSlot(
617
- chain.clock.slotWithPastTolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY_SEC)
616
+ chain.clock.slotWithPastTolerance(chain.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY / 1000)
618
617
  );
619
618
 
620
619
  const earliestPermissiblePreviousEpoch = Math.max(currentEpochWithPastTolerance - 1, 0);
@@ -11,7 +11,6 @@ import {
11
11
  } from "@lodestar/state-transition";
12
12
  import {SignedBeaconBlock, deneb} from "@lodestar/types";
13
13
  import {sleep, toRootHex} from "@lodestar/utils";
14
- import {MAXIMUM_GOSSIP_CLOCK_DISPARITY} from "../../constants/index.js";
15
14
  import {BlockErrorCode, BlockGossipError, GossipAction} from "../errors/index.js";
16
15
  import {IBeaconChain} from "../interface.js";
17
16
  import {RegenCaller} from "../regen/index.js";
@@ -179,7 +178,7 @@ export async function validateGossipBlock(
179
178
  // gossip validation promise without any extra infrastructure.
180
179
  // Do the sleep at the end, since regen and signature validation can already take longer than `msToBlockSlot`.
181
180
  const msToBlockSlot = computeTimeAtSlot(config, blockSlot, chain.genesisTime) * 1000 - Date.now();
182
- if (msToBlockSlot <= MAXIMUM_GOSSIP_CLOCK_DISPARITY && msToBlockSlot > 0) {
181
+ if (msToBlockSlot <= config.MAXIMUM_GOSSIP_CLOCK_DISPARITY && msToBlockSlot > 0) {
183
182
  // If block is between 0 and 500 ms early, hold it in a promise. Equivalent to a pending queue.
184
183
  await sleep(msToBlockSlot);
185
184
  }
@@ -1,10 +1,14 @@
1
- import {ChainConfig} from "@lodestar/config";
1
+ import {ChainConfig, ChainForkConfig} from "@lodestar/config";
2
2
  import {
3
3
  KZG_COMMITMENTS_INCLUSION_PROOF_DEPTH,
4
4
  KZG_COMMITMENTS_SUBTREE_INDEX,
5
5
  NUMBER_OF_COLUMNS,
6
6
  } from "@lodestar/params";
7
- import {computeStartSlotAtEpoch, getBlockHeaderProposerSignatureSet} from "@lodestar/state-transition";
7
+ import {
8
+ computeEpochAtSlot,
9
+ computeStartSlotAtEpoch,
10
+ getBlockHeaderProposerSignatureSet,
11
+ } from "@lodestar/state-transition";
8
12
  import {Root, Slot, SubnetID, fulu, ssz} from "@lodestar/types";
9
13
  import {toRootHex, verifyMerkleBranch} from "@lodestar/utils";
10
14
  import {Metrics} from "../../metrics/metrics.js";
@@ -29,7 +33,7 @@ export async function validateGossipDataColumnSidecar(
29
33
  const blockHeader = dataColumnSidecar.signedBlockHeader.message;
30
34
 
31
35
  // 1) [REJECT] The sidecar is valid as verified by verify_data_column_sidecar
32
- verifyDataColumnSidecar(dataColumnSidecar);
36
+ verifyDataColumnSidecar(chain.config, dataColumnSidecar);
33
37
 
34
38
  // 2) [REJECT] The sidecar is for the correct subnet -- i.e. compute_subnet_for_data_column_sidecar(sidecar.index) == subnet_id
35
39
  if (computeSubnetForDataColumnSidecar(chain.config, dataColumnSidecar) !== gossipSubnet) {
@@ -184,7 +188,7 @@ export async function validateGossipDataColumnSidecar(
184
188
  * SPEC FUNCTION
185
189
  * https://github.com/ethereum/consensus-specs/blob/v1.6.0-alpha.4/specs/fulu/p2p-interface.md#verify_data_column_sidecar
186
190
  */
187
- function verifyDataColumnSidecar(dataColumnSidecar: fulu.DataColumnSidecar): void {
191
+ function verifyDataColumnSidecar(config: ChainForkConfig, dataColumnSidecar: fulu.DataColumnSidecar): void {
188
192
  if (dataColumnSidecar.index >= NUMBER_OF_COLUMNS) {
189
193
  throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
190
194
  code: DataColumnSidecarErrorCode.INVALID_INDEX,
@@ -201,6 +205,19 @@ function verifyDataColumnSidecar(dataColumnSidecar: fulu.DataColumnSidecar): voi
201
205
  });
202
206
  }
203
207
 
208
+ const epoch = computeEpochAtSlot(dataColumnSidecar.signedBlockHeader.message.slot);
209
+ const maxBlobsPerBlock = config.getMaxBlobsPerBlock(epoch);
210
+
211
+ if (dataColumnSidecar.kzgCommitments.length > maxBlobsPerBlock) {
212
+ throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
213
+ code: DataColumnSidecarErrorCode.TOO_MANY_KZG_COMMITMENTS,
214
+ slot: dataColumnSidecar.signedBlockHeader.message.slot,
215
+ columnIdx: dataColumnSidecar.index,
216
+ count: dataColumnSidecar.kzgCommitments.length,
217
+ limit: maxBlobsPerBlock,
218
+ });
219
+ }
220
+
204
221
  if (
205
222
  dataColumnSidecar.column.length !== dataColumnSidecar.kzgCommitments.length ||
206
223
  dataColumnSidecar.column.length !== dataColumnSidecar.kzgProofs.length
@@ -1,6 +1,5 @@
1
1
  import {ChainForkConfig} from "@lodestar/config";
2
2
  import {LightClientOptimisticUpdate} from "@lodestar/types";
3
- import {MAXIMUM_GOSSIP_CLOCK_DISPARITY} from "../../constants/index.js";
4
3
  import {assertLightClientServer} from "../../node/utils/lightclient.js";
5
4
  import {IClock} from "../../util/clock.js";
6
5
  import {GossipAction} from "../errors/index.js";
@@ -64,5 +63,7 @@ export function updateReceivedTooEarly(
64
63
  update: Pick<LightClientOptimisticUpdate, "signatureSlot">
65
64
  ): boolean {
66
65
  const fork = config.getForkName(update.signatureSlot);
67
- return clock.msFromSlot(update.signatureSlot) < config.getSyncMessageDueMs(fork) - MAXIMUM_GOSSIP_CLOCK_DISPARITY;
66
+ return (
67
+ clock.msFromSlot(update.signatureSlot) < config.getSyncMessageDueMs(fork) - config.MAXIMUM_GOSSIP_CLOCK_DISPARITY
68
+ );
68
69
  }
@@ -1,6 +1,15 @@
1
- import {getVoluntaryExitSignatureSet, isValidVoluntaryExit} from "@lodestar/state-transition";
1
+ import {
2
+ VoluntaryExitValidity,
3
+ getVoluntaryExitSignatureSet,
4
+ getVoluntaryExitValidity,
5
+ } from "@lodestar/state-transition";
2
6
  import {phase0} from "@lodestar/types";
3
- import {GossipAction, VoluntaryExitError, VoluntaryExitErrorCode} from "../errors/index.js";
7
+ import {
8
+ GossipAction,
9
+ VoluntaryExitError,
10
+ VoluntaryExitErrorCode,
11
+ voluntaryExitValidityToErrorCode,
12
+ } from "../errors/index.js";
4
13
  import {IBeaconChain} from "../index.js";
5
14
  import {RegenCaller} from "../regen/index.js";
6
15
 
@@ -43,9 +52,10 @@ async function validateVoluntaryExit(
43
52
 
44
53
  // [REJECT] All of the conditions within process_voluntary_exit pass validation.
45
54
  // verifySignature = false, verified in batch below
46
- if (!isValidVoluntaryExit(chain.config.getForkSeq(state.slot), state, voluntaryExit, false)) {
55
+ const validity = getVoluntaryExitValidity(chain.config.getForkSeq(state.slot), state, voluntaryExit, false);
56
+ if (validity !== VoluntaryExitValidity.valid) {
47
57
  throw new VoluntaryExitError(GossipAction.REJECT, {
48
- code: VoluntaryExitErrorCode.INVALID,
58
+ code: voluntaryExitValidityToErrorCode(validity),
49
59
  });
50
60
  }
51
61
 
@@ -7,9 +7,3 @@ export const ZERO_HASH = Buffer.alloc(32, 0);
7
7
  export const ZERO_HASH_HEX = "0x" + "00".repeat(32);
8
8
  export const EMPTY_SIGNATURE = Buffer.alloc(96, 0);
9
9
  export const GRAFFITI_SIZE = 32;
10
-
11
- /**
12
- * The maximum milliseconds of clock disparity assumed between honest nodes.
13
- */
14
- export const MAXIMUM_GOSSIP_CLOCK_DISPARITY = 500;
15
- export const MAXIMUM_GOSSIP_CLOCK_DISPARITY_SEC = MAXIMUM_GOSSIP_CLOCK_DISPARITY / 1000;
@@ -1,22 +1,3 @@
1
- /**
2
- * For more info on some of these constants:
3
- * https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#configuration
4
- */
5
-
6
- // Gossip constants
7
-
8
- /**
9
- * The maximum number of slots during which an attestation can be propagated.
10
- */
11
- export const ATTESTATION_PROPAGATION_SLOT_RANGE = 32;
12
-
13
- /** The maximum allowed size of uncompressed gossip messages. */
14
- export const GOSSIP_MAX_SIZE = 2 ** 20;
15
- export const GOSSIP_MAX_SIZE_BELLATRIX = 10 * GOSSIP_MAX_SIZE;
16
- /** The maximum allowed size of uncompressed req/resp chunked responses. */
17
- export const MAX_CHUNK_SIZE = 2 ** 20;
18
- export const MAX_CHUNK_SIZE_BELLATRIX = 10 * MAX_CHUNK_SIZE;
19
-
20
1
  export enum GoodByeReasonCode {
21
2
  INBOUND_DISCONNECT = -1,
22
3
  CLIENT_SHUTDOWN = 1,
package/src/index.ts CHANGED
@@ -3,6 +3,8 @@
3
3
  export type {RestApiServerMetrics, RestApiServerModules, RestApiServerOpts} from "./api/rest/base.js";
4
4
  export {RestApiServer} from "./api/rest/base.js";
5
5
  export {checkAndPersistAnchorState, initStateFromDb, initStateFromEth1} from "./chain/index.js";
6
+ export {DbCPStateDatastore} from "./chain/stateCache/datastore/db.js";
7
+ export {FileCPStateDatastore} from "./chain/stateCache/datastore/file.js";
6
8
  export {BeaconDb, type IBeaconDb} from "./db/index.js";
7
9
  export {Eth1Provider, type IEth1Provider} from "./eth1/index.js";
8
10
  // Export metrics utilities to de-duplicate validator metrics
@@ -1,5 +1,7 @@
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 {ArchiveStoreTask} from "../../chain/archiveStore/archiveStore.js";
4
+ import {FrequencyStateArchiveStep} from "../../chain/archiveStore/strategies/frequencyStateArchiveStrategy.js";
3
5
  import {BlockInputSource} from "../../chain/blocks/blockInput/index.js";
4
6
  import {JobQueueItemType} from "../../chain/bls/index.js";
5
7
  import {AttestationErrorCode, BlockErrorCode} from "../../chain/errors/index.js";
@@ -1420,6 +1422,21 @@ export function createLodestarMetrics(
1420
1422
  },
1421
1423
  },
1422
1424
 
1425
+ processFinalizedCheckpoint: {
1426
+ durationByTask: register.histogram<{source: ArchiveStoreTask}>({
1427
+ name: "lodestar_process_finalized_checkpoint_seconds",
1428
+ help: "Histogram of time to process finalized checkpoint",
1429
+ buckets: [0.1, 0.5, 1, 2, 4, 8],
1430
+ labelNames: ["source"],
1431
+ }),
1432
+ frequencyStateArchive: register.histogram<{step: FrequencyStateArchiveStep}>({
1433
+ name: "lodestar_process_finalized_checkpoint_frequency_state_archive_seconds",
1434
+ help: "Histogram of FrequencyStateArchive duration by step",
1435
+ buckets: [0.1, 0.5, 1, 2, 4, 8],
1436
+ labelNames: ["step"],
1437
+ }),
1438
+ },
1439
+
1423
1440
  regenFnCallTotal: register.gauge<{entrypoint: RegenFnName; caller: RegenCaller}>({
1424
1441
  name: "lodestar_regen_fn_call_total",
1425
1442
  help: "Total number of calls for regen functions",
@@ -1596,6 +1613,10 @@ export function createLodestarMetrics(
1596
1613
  name: "lodestar_lightclient_server_attested_data_diff_period_total",
1597
1614
  help: "Total number of times a syncAggregate is a different period than attested data",
1598
1615
  }),
1616
+ staleLightClientUpdates: register.counter({
1617
+ name: "lodestar_lightclient_server_stale_updates_total",
1618
+ help: "Total number of stale light client updates that were not emitted",
1619
+ }),
1599
1620
  },
1600
1621
 
1601
1622
  eth1: {
@@ -1857,7 +1878,7 @@ export function createLodestarMetrics(
1857
1878
  fetchKeys: register.histogram({
1858
1879
  name: "lodestar_prune_history_fetch_keys_time_seconds",
1859
1880
  help: "Time to fetch keys in seconds",
1860
- buckets: [0.001, 0.01, 0.1, 1],
1881
+ buckets: [0.001, 0.01, 0.1, 0.3, 0.5, 1],
1861
1882
  }),
1862
1883
 
1863
1884
  pruneKeys: register.histogram({
@@ -553,7 +553,11 @@ export class NetworkCore implements INetworkCore {
553
553
  // On fork boundary transition
554
554
  if (epoch === nextBoundaryEpoch) {
555
555
  // updateEth2Field() MUST be called with clock epoch, onEpoch event is emitted in response to clock events
556
- this.metadata.updateEth2Field(epoch);
556
+ const {forkDigest} = this.metadata.updateEth2Field(epoch);
557
+ // Update local status to reflect the new fork digest, otherwise we will disconnect peers that re-status us
558
+ // right after the fork transition due to incompatible forks as our fork digest is stale since we only
559
+ // update it once we import a new head or when emitting update status event.
560
+ this.statusCache.update({...this.statusCache.get(), forkDigest});
557
561
  this.reqResp.registerProtocolsAtBoundary(nextBoundary);
558
562
  }
559
563
 
@@ -1,5 +1,3 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
1
  import worker from "node:worker_threads";
4
2
  import {privateKeyFromProtobuf} from "@libp2p/crypto/keys";
5
3
  import {peerIdFromPrivateKey} from "@libp2p/peer-id";
@@ -11,7 +9,7 @@ import {RegistryMetricCreator, collectNodeJSMetrics} from "../../metrics/index.j
11
9
  import {AsyncIterableBridgeCaller, AsyncIterableBridgeHandler} from "../../util/asyncIterableToEvents.js";
12
10
  import {Clock} from "../../util/clock.js";
13
11
  import {peerIdToString} from "../../util/peerId.js";
14
- import {profileNodeJS, writeHeapSnapshot} from "../../util/profile.js";
12
+ import {ProfileThread, profileThread, writeHeapSnapshot} from "../../util/profile.js";
15
13
  import {wireEventsOnWorkerThread} from "../../util/workerEvents.js";
16
14
  import {NetworkEventBus, NetworkEventData, networkEventDirection} from "../events.js";
17
15
  import {
@@ -157,10 +155,7 @@ const libp2pWorkerApi: NetworkWorkerApi = {
157
155
  dumpDiscv5KadValues: () => core.dumpDiscv5KadValues(),
158
156
  dumpMeshPeers: () => core.dumpMeshPeers(),
159
157
  writeProfile: async (durationMs: number, dirpath: string) => {
160
- const profile = await profileNodeJS(durationMs);
161
- const filePath = path.join(dirpath, `network_thread_${new Date().toISOString()}.cpuprofile`);
162
- fs.writeFileSync(filePath, profile);
163
- return filePath;
158
+ return profileThread(ProfileThread.NETWORK, durationMs, dirpath);
164
159
  },
165
160
  writeDiscv5Profile: async (durationMs: number, dirpath: string) => {
166
161
  return core.writeDiscv5Profile(durationMs, dirpath);
@@ -1,6 +1,5 @@
1
1
  import {ENR} from "@chainsafe/enr";
2
2
  import {BeaconConfig} from "@lodestar/config";
3
- import {MAXIMUM_GOSSIP_CLOCK_DISPARITY} from "../../constants/constants.js";
4
3
  import {IClock} from "../../util/clock.js";
5
4
  import {ENRKey} from "../metadata.js";
6
5
 
@@ -35,7 +34,7 @@ export function enrRelevance(enr: ENR, config: BeaconConfig, clock: IClock): ENR
35
34
  }
36
35
 
37
36
  // Check if fork digest's fork matches ours
38
- const currentSlot = clock.slotWithFutureTolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY);
37
+ const currentSlot = clock.slotWithFutureTolerance(config.MAXIMUM_GOSSIP_CLOCK_DISPARITY / 1000);
39
38
  const localForkInfo = config.getForkInfo(currentSlot);
40
39
  // We only connect if the ENR's fork matches our current fork.
41
40
  // We also allow it to be the previous fork due to delay and infrequent update of DHT.
@@ -1,5 +1,3 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
1
  import worker from "node:worker_threads";
4
2
  import {privateKeyFromProtobuf} from "@libp2p/crypto/keys";
5
3
  import {peerIdFromPrivateKey} from "@libp2p/peer-id";
@@ -14,7 +12,7 @@ import {Gauge} from "@lodestar/utils";
14
12
  import {RegistryMetricCreator} from "../../metrics/index.js";
15
13
  import {collectNodeJSMetrics} from "../../metrics/nodeJsMetrics.js";
16
14
  import {Clock} from "../../util/clock.js";
17
- import {profileNodeJS, writeHeapSnapshot} from "../../util/profile.js";
15
+ import {ProfileThread, profileThread, writeHeapSnapshot} from "../../util/profile.js";
18
16
  import {Discv5WorkerApi, Discv5WorkerData} from "./types.js";
19
17
  import {ENRRelevance, enrRelevance} from "./utils.js";
20
18
 
@@ -108,10 +106,7 @@ const module: Discv5WorkerApi = {
108
106
  return (await metricsRegistry?.metrics()) ?? "";
109
107
  },
110
108
  writeProfile: async (durationMs: number, dirpath: string) => {
111
- const profile = await profileNodeJS(durationMs);
112
- const filePath = path.join(dirpath, `discv5_thread_${new Date().toISOString()}.cpuprofile`);
113
- fs.writeFileSync(filePath, profile);
114
- return filePath;
109
+ return profileThread(ProfileThread.DISC5, durationMs, dirpath);
115
110
  },
116
111
  writeHeapSnapshot: async (prefix: string, dirpath: string) => {
117
112
  return writeHeapSnapshot(prefix, dirpath);
@@ -1,6 +1,6 @@
1
1
  import {Message} from "@libp2p/interface";
2
- import {compress, uncompress} from "snappyjs";
3
2
  import xxhashFactory from "xxhash-wasm";
3
+ import {compress, uncompress} from "#snappy";
4
4
  import {digest} from "@chainsafe/as-sha256";
5
5
  import {RPC} from "@chainsafe/libp2p-gossipsub/message";
6
6
  import {DataTransform} from "@chainsafe/libp2p-gossipsub/types";
@@ -6,7 +6,6 @@ import {BeaconConfig, ForkBoundary} from "@lodestar/config";
6
6
  import {ATTESTATION_SUBNET_COUNT, SLOTS_PER_EPOCH, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params";
7
7
  import {SubnetID} from "@lodestar/types";
8
8
  import {Logger, Map2d, Map2dArr} from "@lodestar/utils";
9
- import {GOSSIP_MAX_SIZE, GOSSIP_MAX_SIZE_BELLATRIX} from "../../constants/network.js";
10
9
  import {RegistryMetricCreator} from "../../metrics/index.js";
11
10
  import {callInNextEventLoop} from "../../util/eventLoop.js";
12
11
  import {NetworkEvent, NetworkEventBus, NetworkEventData} from "../events.js";
@@ -117,15 +116,7 @@ export class Eth2Gossipsub extends GossipSub {
117
116
  fastMsgIdFn: fastMsgIdFn,
118
117
  msgIdFn: msgIdFn.bind(msgIdFn, gossipTopicCache),
119
118
  msgIdToStrFn: msgIdToStrFn,
120
- // Use the bellatrix max size if the merge is configured. pre-merge using this size
121
- // could only be an issue on outgoing payloads, its highly unlikely we will send out
122
- // a chunk bigger than GOSSIP_MAX_SIZE pre merge even on mainnet network.
123
- //
124
- // TODO: figure out a way to dynamically transition to the size
125
- dataTransform: new DataTransformSnappy(
126
- gossipTopicCache,
127
- Number.isFinite(config.BELLATRIX_FORK_EPOCH) ? GOSSIP_MAX_SIZE_BELLATRIX : GOSSIP_MAX_SIZE
128
- ),
119
+ dataTransform: new DataTransformSnappy(gossipTopicCache, config.MAX_PAYLOAD_SIZE),
129
120
  metricsRegister: metricsRegister as MetricsRegister | null,
130
121
  metricsTopicStrToLabel: metricsRegister
131
122
  ? getMetricsTopicStrToLabel(networkConfig, {disableLightClientServer: opts.disableLightClientServer ?? false})
@@ -0,0 +1,2 @@
1
+ import {snappy} from "@lodestar/bun";
2
+ export const {compress, uncompress} = snappy;