@lodestar/beacon-node 1.36.0-dev.a2a22d66ef → 1.36.0-dev.aec301c48f

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 (259) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +41 -22
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/config/constants.d.ts +4 -2
  5. package/lib/api/impl/config/constants.d.ts.map +1 -1
  6. package/lib/api/impl/config/constants.js +6 -3
  7. package/lib/api/impl/config/constants.js.map +1 -1
  8. package/lib/api/impl/lodestar/index.d.ts +5 -0
  9. package/lib/api/impl/lodestar/index.d.ts.map +1 -1
  10. package/lib/api/impl/lodestar/index.js +35 -10
  11. package/lib/api/impl/lodestar/index.js.map +1 -1
  12. package/lib/api/impl/node/utils.js +1 -1
  13. package/lib/api/impl/node/utils.js.map +1 -1
  14. package/lib/api/impl/validator/index.d.ts.map +1 -1
  15. package/lib/api/impl/validator/index.js +2 -2
  16. package/lib/api/impl/validator/index.js.map +1 -1
  17. package/lib/chain/archiveStore/archiveStore.d.ts +9 -0
  18. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  19. package/lib/chain/archiveStore/archiveStore.js +24 -0
  20. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  21. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.d.ts +7 -0
  22. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.d.ts.map +1 -1
  23. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js +31 -5
  24. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js.map +1 -1
  25. package/lib/chain/beaconProposerCache.d.ts +3 -0
  26. package/lib/chain/beaconProposerCache.d.ts.map +1 -1
  27. package/lib/chain/beaconProposerCache.js +4 -6
  28. package/lib/chain/beaconProposerCache.js.map +1 -1
  29. package/lib/chain/chain.d.ts +5 -2
  30. package/lib/chain/chain.d.ts.map +1 -1
  31. package/lib/chain/chain.js +34 -18
  32. package/lib/chain/chain.js.map +1 -1
  33. package/lib/chain/errors/dataColumnSidecarError.d.ts +23 -13
  34. package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
  35. package/lib/chain/errors/dataColumnSidecarError.js +5 -0
  36. package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
  37. package/lib/chain/errors/voluntaryExitError.d.ts +16 -2
  38. package/lib/chain/errors/voluntaryExitError.d.ts.map +1 -1
  39. package/lib/chain/errors/voluntaryExitError.js +22 -1
  40. package/lib/chain/errors/voluntaryExitError.js.map +1 -1
  41. package/lib/chain/forkChoice/index.d.ts +9 -1
  42. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  43. package/lib/chain/forkChoice/index.js +109 -4
  44. package/lib/chain/forkChoice/index.js.map +1 -1
  45. package/lib/chain/interface.d.ts +2 -0
  46. package/lib/chain/interface.d.ts.map +1 -1
  47. package/lib/chain/lightClient/index.d.ts +3 -0
  48. package/lib/chain/lightClient/index.d.ts.map +1 -1
  49. package/lib/chain/lightClient/index.js +24 -13
  50. package/lib/chain/lightClient/index.js.map +1 -1
  51. package/lib/chain/opPools/syncContributionAndProofPool.d.ts +3 -1
  52. package/lib/chain/opPools/syncContributionAndProofPool.d.ts.map +1 -1
  53. package/lib/chain/opPools/syncContributionAndProofPool.js +4 -3
  54. package/lib/chain/opPools/syncContributionAndProofPool.js.map +1 -1
  55. package/lib/chain/options.d.ts +0 -2
  56. package/lib/chain/options.d.ts.map +1 -1
  57. package/lib/chain/options.js +2 -2
  58. package/lib/chain/options.js.map +1 -1
  59. package/lib/chain/stateCache/datastore/db.d.ts +12 -0
  60. package/lib/chain/stateCache/datastore/db.d.ts.map +1 -1
  61. package/lib/chain/stateCache/datastore/db.js +70 -0
  62. package/lib/chain/stateCache/datastore/db.js.map +1 -1
  63. package/lib/chain/stateCache/datastore/file.d.ts +1 -0
  64. package/lib/chain/stateCache/datastore/file.d.ts.map +1 -1
  65. package/lib/chain/stateCache/datastore/file.js +7 -0
  66. package/lib/chain/stateCache/datastore/file.js.map +1 -1
  67. package/lib/chain/stateCache/datastore/types.d.ts +1 -0
  68. package/lib/chain/stateCache/datastore/types.d.ts.map +1 -1
  69. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +16 -1
  70. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  71. package/lib/chain/stateCache/persistentCheckpointsCache.js +31 -1
  72. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  73. package/lib/chain/validation/attestation.d.ts.map +1 -1
  74. package/lib/chain/validation/attestation.js +6 -7
  75. package/lib/chain/validation/attestation.js.map +1 -1
  76. package/lib/chain/validation/block.d.ts.map +1 -1
  77. package/lib/chain/validation/block.js +1 -2
  78. package/lib/chain/validation/block.js.map +1 -1
  79. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  80. package/lib/chain/validation/dataColumnSidecar.js +45 -17
  81. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  82. package/lib/chain/validation/lightClientOptimisticUpdate.d.ts.map +1 -1
  83. package/lib/chain/validation/lightClientOptimisticUpdate.js +1 -2
  84. package/lib/chain/validation/lightClientOptimisticUpdate.js.map +1 -1
  85. package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
  86. package/lib/chain/validation/voluntaryExit.js +5 -4
  87. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  88. package/lib/constants/constants.d.ts +0 -5
  89. package/lib/constants/constants.d.ts.map +1 -1
  90. package/lib/constants/constants.js +0 -5
  91. package/lib/constants/constants.js.map +1 -1
  92. package/lib/constants/network.d.ts +0 -14
  93. package/lib/constants/network.d.ts.map +1 -1
  94. package/lib/constants/network.js +0 -15
  95. package/lib/constants/network.js.map +1 -1
  96. package/lib/index.d.ts +2 -0
  97. package/lib/index.d.ts.map +1 -1
  98. package/lib/index.js +2 -0
  99. package/lib/index.js.map +1 -1
  100. package/lib/metrics/metrics/lodestar.d.ts +11 -0
  101. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  102. package/lib/metrics/metrics/lodestar.js +19 -1
  103. package/lib/metrics/metrics/lodestar.js.map +1 -1
  104. package/lib/network/core/networkCore.d.ts.map +1 -1
  105. package/lib/network/core/networkCore.js +5 -1
  106. package/lib/network/core/networkCore.js.map +1 -1
  107. package/lib/network/core/networkCoreWorker.js +8 -8
  108. package/lib/network/core/networkCoreWorker.js.map +1 -1
  109. package/lib/network/core/networkCoreWorkerHandler.js +1 -1
  110. package/lib/network/core/networkCoreWorkerHandler.js.map +1 -1
  111. package/lib/network/discv5/utils.d.ts.map +1 -1
  112. package/lib/network/discv5/utils.js +1 -2
  113. package/lib/network/discv5/utils.js.map +1 -1
  114. package/lib/network/discv5/worker.js +2 -7
  115. package/lib/network/discv5/worker.js.map +1 -1
  116. package/lib/network/events.d.ts +1 -0
  117. package/lib/network/events.d.ts.map +1 -1
  118. package/lib/network/gossip/encoding.js +1 -1
  119. package/lib/network/gossip/encoding.js.map +1 -1
  120. package/lib/network/gossip/gossipsub.d.ts.map +1 -1
  121. package/lib/network/gossip/gossipsub.js +1 -7
  122. package/lib/network/gossip/gossipsub.js.map +1 -1
  123. package/lib/network/gossip/snappy_bun.d.ts +3 -0
  124. package/lib/network/gossip/snappy_bun.d.ts.map +1 -0
  125. package/lib/network/gossip/snappy_bun.js +3 -0
  126. package/lib/network/gossip/snappy_bun.js.map +1 -0
  127. package/lib/network/metadata.d.ts +1 -1
  128. package/lib/network/metadata.d.ts.map +1 -1
  129. package/lib/network/metadata.js +1 -0
  130. package/lib/network/metadata.js.map +1 -1
  131. package/lib/network/options.d.ts +0 -1
  132. package/lib/network/options.d.ts.map +1 -1
  133. package/lib/network/options.js.map +1 -1
  134. package/lib/network/peers/discover.js +2 -2
  135. package/lib/network/peers/discover.js.map +1 -1
  136. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  137. package/lib/network/processor/gossipHandlers.js +14 -8
  138. package/lib/network/processor/gossipHandlers.js.map +1 -1
  139. package/lib/network/reqresp/ReqRespBeaconNode.d.ts.map +1 -1
  140. package/lib/network/reqresp/ReqRespBeaconNode.js +3 -1
  141. package/lib/network/reqresp/ReqRespBeaconNode.js.map +1 -1
  142. package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts +2 -1
  143. package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
  144. package/lib/network/reqresp/handlers/beaconBlocksByRange.js +14 -3
  145. package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
  146. package/lib/network/reqresp/handlers/blobSidecarsByRange.js +5 -5
  147. package/lib/network/reqresp/handlers/blobSidecarsByRange.js.map +1 -1
  148. package/lib/network/reqresp/handlers/blobSidecarsByRoot.js +4 -4
  149. package/lib/network/reqresp/handlers/blobSidecarsByRoot.js.map +1 -1
  150. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts +2 -1
  151. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
  152. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +9 -1
  153. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  154. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.d.ts +2 -1
  155. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.d.ts.map +1 -1
  156. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +9 -1
  157. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
  158. package/lib/network/reqresp/handlers/index.js +6 -6
  159. package/lib/network/reqresp/handlers/index.js.map +1 -1
  160. package/lib/network/reqresp/types.d.ts +1 -0
  161. package/lib/network/reqresp/types.d.ts.map +1 -1
  162. package/lib/network/subnets/attnetsService.d.ts +1 -1
  163. package/lib/network/subnets/attnetsService.js +6 -6
  164. package/lib/network/subnets/attnetsService.js.map +1 -1
  165. package/lib/network/subnets/util.d.ts +3 -2
  166. package/lib/network/subnets/util.d.ts.map +1 -1
  167. package/lib/network/subnets/util.js +6 -6
  168. package/lib/network/subnets/util.js.map +1 -1
  169. package/lib/node/nodejs.d.ts +2 -1
  170. package/lib/node/nodejs.d.ts.map +1 -1
  171. package/lib/node/nodejs.js +2 -1
  172. package/lib/node/nodejs.js.map +1 -1
  173. package/lib/sync/range/range.d.ts.map +1 -1
  174. package/lib/sync/range/range.js +2 -1
  175. package/lib/sync/range/range.js.map +1 -1
  176. package/lib/sync/utils/downloadByRange.d.ts +58 -13
  177. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  178. package/lib/sync/utils/downloadByRange.js +201 -82
  179. package/lib/sync/utils/downloadByRange.js.map +1 -1
  180. package/lib/sync/utils/remoteSyncType.d.ts +2 -1
  181. package/lib/sync/utils/remoteSyncType.d.ts.map +1 -1
  182. package/lib/sync/utils/remoteSyncType.js +19 -4
  183. package/lib/sync/utils/remoteSyncType.js.map +1 -1
  184. package/lib/util/blobs.d.ts +1 -1
  185. package/lib/util/blobs.d.ts.map +1 -1
  186. package/lib/util/blobs.js +53 -20
  187. package/lib/util/blobs.js.map +1 -1
  188. package/lib/util/clock.d.ts.map +1 -1
  189. package/lib/util/clock.js +3 -4
  190. package/lib/util/clock.js.map +1 -1
  191. package/lib/util/profile.d.ts +6 -4
  192. package/lib/util/profile.d.ts.map +1 -1
  193. package/lib/util/profile.js +40 -3
  194. package/lib/util/profile.js.map +1 -1
  195. package/lib/util/sszBytes.d.ts +2 -0
  196. package/lib/util/sszBytes.d.ts.map +1 -1
  197. package/lib/util/sszBytes.js +25 -0
  198. package/lib/util/sszBytes.js.map +1 -1
  199. package/package.json +31 -24
  200. package/src/api/impl/beacon/blocks/index.ts +47 -25
  201. package/src/api/impl/config/constants.ts +10 -4
  202. package/src/api/impl/lodestar/index.ts +42 -10
  203. package/src/api/impl/node/utils.ts +1 -1
  204. package/src/api/impl/validator/index.ts +5 -2
  205. package/src/chain/archiveStore/archiveStore.ts +27 -0
  206. package/src/chain/archiveStore/strategies/frequencyStateArchiveStrategy.ts +32 -5
  207. package/src/chain/beaconProposerCache.ts +4 -8
  208. package/src/chain/chain.ts +50 -25
  209. package/src/chain/errors/dataColumnSidecarError.ts +27 -13
  210. package/src/chain/errors/voluntaryExitError.ts +30 -2
  211. package/src/chain/forkChoice/index.ts +178 -2
  212. package/src/chain/interface.ts +2 -0
  213. package/src/chain/lightClient/index.ts +26 -12
  214. package/src/chain/opPools/syncContributionAndProofPool.ts +3 -2
  215. package/src/chain/options.ts +2 -3
  216. package/src/chain/stateCache/datastore/db.ts +89 -1
  217. package/src/chain/stateCache/datastore/file.ts +8 -0
  218. package/src/chain/stateCache/datastore/types.ts +1 -0
  219. package/src/chain/stateCache/persistentCheckpointsCache.ts +45 -2
  220. package/src/chain/validation/attestation.ts +6 -7
  221. package/src/chain/validation/block.ts +1 -2
  222. package/src/chain/validation/dataColumnSidecar.ts +54 -19
  223. package/src/chain/validation/lightClientOptimisticUpdate.ts +3 -2
  224. package/src/chain/validation/voluntaryExit.ts +14 -4
  225. package/src/constants/constants.ts +0 -6
  226. package/src/constants/network.ts +0 -19
  227. package/src/index.ts +2 -0
  228. package/src/metrics/metrics/lodestar.ts +22 -1
  229. package/src/network/core/networkCore.ts +5 -1
  230. package/src/network/core/networkCoreWorker.ts +9 -9
  231. package/src/network/core/networkCoreWorkerHandler.ts +1 -1
  232. package/src/network/discv5/utils.ts +1 -2
  233. package/src/network/discv5/worker.ts +2 -7
  234. package/src/network/events.ts +1 -1
  235. package/src/network/gossip/encoding.ts +1 -1
  236. package/src/network/gossip/gossipsub.ts +1 -10
  237. package/src/network/gossip/snappy_bun.ts +2 -0
  238. package/src/network/metadata.ts +3 -1
  239. package/src/network/options.ts +0 -1
  240. package/src/network/peers/discover.ts +2 -2
  241. package/src/network/processor/gossipHandlers.ts +16 -7
  242. package/src/network/reqresp/ReqRespBeaconNode.ts +3 -1
  243. package/src/network/reqresp/handlers/beaconBlocksByRange.ts +18 -3
  244. package/src/network/reqresp/handlers/blobSidecarsByRange.ts +6 -6
  245. package/src/network/reqresp/handlers/blobSidecarsByRoot.ts +5 -5
  246. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +13 -1
  247. package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +13 -1
  248. package/src/network/reqresp/handlers/index.ts +6 -6
  249. package/src/network/reqresp/types.ts +1 -0
  250. package/src/network/subnets/attnetsService.ts +6 -6
  251. package/src/network/subnets/util.ts +12 -12
  252. package/src/node/nodejs.ts +3 -0
  253. package/src/sync/range/range.ts +2 -1
  254. package/src/sync/utils/downloadByRange.ts +259 -103
  255. package/src/sync/utils/remoteSyncType.ts +23 -4
  256. package/src/util/blobs.ts +64 -20
  257. package/src/util/clock.ts +3 -4
  258. package/src/util/profile.ts +45 -3
  259. package/src/util/sszBytes.ts +30 -0
@@ -17,8 +17,10 @@ import {MapTracker} from "./mapMetrics.js";
17
17
  import {BlockStateCache, CacheItemType, CheckpointHex, CheckpointStateCache} from "./types.js";
18
18
 
19
19
  export type PersistentCheckpointStateCacheOpts = {
20
- /** Keep max n states in memory, persist the rest to disk */
20
+ /** Keep max n state epochs in memory, persist the rest to disk */
21
21
  maxCPStateEpochsInMemory?: number;
22
+ /** Keep max n state epochs on disk */
23
+ maxCPStateEpochsOnDisk?: number;
22
24
  };
23
25
 
24
26
  type PersistentCheckpointStateCacheModules = {
@@ -58,6 +60,14 @@ type LoadedStateBytesData = {persistedKey: DatastoreKey; stateBytes: Uint8Array}
58
60
  */
59
61
  export const DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY = 3;
60
62
 
63
+ /**
64
+ * By default we don't prune any persistent checkpoint states as it's not safe to delete them during
65
+ * long non-finality as we don't know the state of the chain and there could be a deep (hundreds of epochs) reorg
66
+ * if there two competing chains with similar weight but we wouldn't have a close enough state to pivot to this chain
67
+ * and instead require a resync from last finalized checkpoint state which could be very far in the past.
68
+ */
69
+ export const DEFAULT_MAX_CP_STATE_ON_DISK = Infinity;
70
+
61
71
  // TODO GLOAS: re-evaluate this timing
62
72
  const PROCESS_CHECKPOINT_STATES_BPS = 6667;
63
73
 
@@ -104,6 +114,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
104
114
  private preComputedCheckpoint: string | null = null;
105
115
  private preComputedCheckpointHits: number | null = null;
106
116
  private readonly maxEpochsInMemory: number;
117
+ private readonly maxEpochsOnDisk: number;
107
118
  private readonly datastore: CPStateDatastore;
108
119
  private readonly blockStateCache: BlockStateCache;
109
120
  private readonly bufferPool?: BufferPool | null;
@@ -139,10 +150,16 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
139
150
  this.logger = logger;
140
151
  this.clock = clock;
141
152
  this.signal = signal;
153
+
142
154
  if (opts.maxCPStateEpochsInMemory !== undefined && opts.maxCPStateEpochsInMemory < 0) {
143
155
  throw new Error("maxEpochsInMemory must be >= 0");
144
156
  }
157
+ if (opts.maxCPStateEpochsOnDisk !== undefined && opts.maxCPStateEpochsOnDisk < 0) {
158
+ throw new Error("maxCPStateEpochsOnDisk must be >= 0");
159
+ }
160
+
145
161
  this.maxEpochsInMemory = opts.maxCPStateEpochsInMemory ?? DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY;
162
+ this.maxEpochsOnDisk = opts.maxCPStateEpochsOnDisk ?? DEFAULT_MAX_CP_STATE_ON_DISK;
146
163
  // Specify different datastore for testing
147
164
  this.datastore = datastore;
148
165
  this.blockStateCache = blockStateCache;
@@ -324,6 +341,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
324
341
  this.logger.verbose("Added checkpoint state to memory", {epoch: cp.epoch, rootHex: cpHex.rootHex});
325
342
  }
326
343
  this.epochIndex.getOrDefault(cp.epoch).add(cpHex.rootHex);
344
+ this.prunePersistedStates();
327
345
  }
328
346
 
329
347
  /**
@@ -766,13 +784,38 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
766
784
  this.cache.delete(key);
767
785
  }
768
786
  this.epochIndex.delete(epoch);
769
- this.logger.verbose("Pruned finalized checkpoints states for epoch", {
787
+ this.logger.verbose("Pruned checkpoint states for epoch", {
770
788
  epoch,
771
789
  persistCount,
772
790
  rootHexes: Array.from(rootHexes).join(","),
773
791
  });
774
792
  }
775
793
 
794
+ /**
795
+ * Prune persisted checkpoint states from disk.
796
+ * Note that this should handle all possible errors and not throw.
797
+ */
798
+ private prunePersistedStates(): void {
799
+ // epochsOnDisk epochsInMemory
800
+ // |----------------------------------------------------------|----------------------|
801
+ const maxTrackedEpochs = this.maxEpochsOnDisk + this.maxEpochsInMemory;
802
+ if (this.epochIndex.size <= maxTrackedEpochs) {
803
+ return;
804
+ }
805
+
806
+ const sortedEpochs = Array.from(this.epochIndex.keys()).sort((a, b) => a - b);
807
+ const pruneEpochs = sortedEpochs.slice(0, sortedEpochs.length - maxTrackedEpochs);
808
+ for (const epoch of pruneEpochs) {
809
+ this.deleteAllEpochItems(epoch).catch((e) =>
810
+ this.logger.debug(
811
+ "Error delete all epoch items",
812
+ {epoch, maxEpochsOnDisk: this.maxEpochsOnDisk, maxEpochsInMemory: this.maxEpochsInMemory},
813
+ e as Error
814
+ )
815
+ );
816
+ }
817
+ }
818
+
776
819
  /**
777
820
  * Serialize validators to bytes leveraging the buffer pool to save memory allocation.
778
821
  * - As monitored on holesky as of Jan 2024, it helps save ~500ms state reload time (4.3s vs 3.8s)
@@ -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,13 +33,13 @@ 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) {
36
40
  throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
37
41
  code: DataColumnSidecarErrorCode.INVALID_SUBNET,
38
- columnIdx: dataColumnSidecar.index,
42
+ columnIndex: dataColumnSidecar.index,
39
43
  gossipSubnet: gossipSubnet,
40
44
  });
41
45
  }
@@ -152,7 +156,7 @@ export async function validateGossipDataColumnSidecar(
152
156
  throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
153
157
  code: DataColumnSidecarErrorCode.INCLUSION_PROOF_INVALID,
154
158
  slot: dataColumnSidecar.signedBlockHeader.message.slot,
155
- columnIdx: dataColumnSidecar.index,
159
+ columnIndex: dataColumnSidecar.index,
156
160
  });
157
161
  }
158
162
 
@@ -169,7 +173,7 @@ export async function validateGossipDataColumnSidecar(
169
173
  throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
170
174
  code: DataColumnSidecarErrorCode.INVALID_KZG_PROOF,
171
175
  slot: blockHeader.slot,
172
- columnIdx: dataColumnSidecar.index,
176
+ columnIndex: dataColumnSidecar.index,
173
177
  });
174
178
  } finally {
175
179
  kzgProofTimer?.();
@@ -184,12 +188,12 @@ 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,
191
195
  slot: dataColumnSidecar.signedBlockHeader.message.slot,
192
- columnIdx: dataColumnSidecar.index,
196
+ columnIndex: dataColumnSidecar.index,
193
197
  });
194
198
  }
195
199
 
@@ -197,7 +201,20 @@ function verifyDataColumnSidecar(dataColumnSidecar: fulu.DataColumnSidecar): voi
197
201
  throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
198
202
  code: DataColumnSidecarErrorCode.NO_COMMITMENTS,
199
203
  slot: dataColumnSidecar.signedBlockHeader.message.slot,
200
- columnIdx: dataColumnSidecar.index,
204
+ columnIndex: dataColumnSidecar.index,
205
+ });
206
+ }
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
+ columnIndex: dataColumnSidecar.index,
216
+ count: dataColumnSidecar.kzgCommitments.length,
217
+ limit: maxBlobsPerBlock,
201
218
  });
202
219
  }
203
220
 
@@ -276,7 +293,6 @@ export async function validateBlockDataColumnSidecars(
276
293
  "Block has no blob commitments but data column sidecars were provided"
277
294
  );
278
295
  }
279
-
280
296
  // Hash the first sidecar block header and compare the rest via (cheaper) equality
281
297
  const firstSidecarBlockHeader = dataColumnSidecars[0].signedBlockHeader.message;
282
298
  const firstBlockRoot = ssz.phase0.BeaconBlockHeader.hashTreeRoot(firstSidecarBlockHeader);
@@ -285,7 +301,7 @@ export async function validateBlockDataColumnSidecars(
285
301
  {
286
302
  code: DataColumnSidecarErrorCode.INCORRECT_BLOCK,
287
303
  slot: blockSlot,
288
- columnIdx: 0,
304
+ columnIndex: 0,
289
305
  expected: toRootHex(blockRoot),
290
306
  actual: toRootHex(firstBlockRoot),
291
307
  },
@@ -300,33 +316,52 @@ export async function validateBlockDataColumnSidecars(
300
316
  for (let i = 0; i < dataColumnSidecars.length; i++) {
301
317
  const columnSidecar = dataColumnSidecars[i];
302
318
 
319
+ if (!ssz.phase0.BeaconBlockHeader.equals(firstSidecarBlockHeader, columnSidecar.signedBlockHeader.message)) {
320
+ throw new DataColumnSidecarValidationError({
321
+ code: DataColumnSidecarErrorCode.INCORRECT_HEADER_ROOT,
322
+ slot: blockSlot,
323
+ expected: toRootHex(blockRoot),
324
+ actual: toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(columnSidecar.signedBlockHeader.message)),
325
+ });
326
+ }
327
+
303
328
  if (columnSidecar.index >= NUMBER_OF_COLUMNS) {
304
329
  throw new DataColumnSidecarValidationError(
305
330
  {
306
331
  code: DataColumnSidecarErrorCode.INVALID_INDEX,
307
332
  slot: blockSlot,
308
- columnIdx: columnSidecar.index,
333
+ columnIndex: columnSidecar.index,
309
334
  },
310
335
  "DataColumnSidecar has invalid index"
311
336
  );
312
337
  }
313
338
 
314
- if (columnSidecar.kzgCommitments.length !== blockBlobCount) {
339
+ if (columnSidecar.column.length !== blockBlobCount) {
315
340
  throw new DataColumnSidecarValidationError({
316
- code: DataColumnSidecarErrorCode.INCORRECT_KZG_COMMITMENTS_COUNT,
341
+ code: DataColumnSidecarErrorCode.INCORRECT_CELL_COUNT,
317
342
  slot: blockSlot,
318
- columnIdx: columnSidecar.index,
343
+ columnIndex: columnSidecar.index,
319
344
  expected: blockBlobCount,
345
+ actual: columnSidecar.column.length,
346
+ });
347
+ }
348
+
349
+ if (columnSidecar.column.length !== columnSidecar.kzgCommitments.length) {
350
+ throw new DataColumnSidecarValidationError({
351
+ code: DataColumnSidecarErrorCode.INCORRECT_KZG_COMMITMENTS_COUNT,
352
+ slot: blockSlot,
353
+ columnIndex: columnSidecar.index,
354
+ expected: columnSidecar.column.length,
320
355
  actual: columnSidecar.kzgCommitments.length,
321
356
  });
322
357
  }
323
358
 
324
- if (columnSidecar.kzgProofs.length !== columnSidecar.kzgCommitments.length) {
359
+ if (columnSidecar.column.length !== columnSidecar.kzgProofs.length) {
325
360
  throw new DataColumnSidecarValidationError({
326
361
  code: DataColumnSidecarErrorCode.INCORRECT_KZG_PROOF_COUNT,
327
362
  slot: blockSlot,
328
- columnIdx: columnSidecar.index,
329
- expected: columnSidecar.kzgCommitments.length,
363
+ columnIndex: columnSidecar.index,
364
+ expected: columnSidecar.column.length,
330
365
  actual: columnSidecar.kzgProofs.length,
331
366
  });
332
367
  }
@@ -336,7 +371,7 @@ export async function validateBlockDataColumnSidecars(
336
371
  {
337
372
  code: DataColumnSidecarErrorCode.INCLUSION_PROOF_INVALID,
338
373
  slot: blockSlot,
339
- columnIdx: columnSidecar.index,
374
+ columnIndex: columnSidecar.index,
340
375
  },
341
376
  "DataColumnSidecar has invalid inclusion proof"
342
377
  );
@@ -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 {
@@ -100,8 +98,13 @@ const core = await NetworkCore.init({
100
98
  metricsRegistry: metricsRegister,
101
99
  events,
102
100
  clock,
103
- getReqRespHandler: (method) => (req, peerId) =>
104
- reqRespBridgeRespCaller.getAsyncIterable({method, req, peerId: peerIdToString(peerId)}),
101
+ getReqRespHandler: (method) => (req, peerId, peerClient) =>
102
+ reqRespBridgeRespCaller.getAsyncIterable({
103
+ method,
104
+ req,
105
+ peerId: peerIdToString(peerId),
106
+ peerClient,
107
+ }),
105
108
  activeValidatorCount: workerData.activeValidatorCount,
106
109
  initialStatus: workerData.initialStatus,
107
110
  initialCustodyGroupCount: workerData.initialCustodyGroupCount,
@@ -157,10 +160,7 @@ const libp2pWorkerApi: NetworkWorkerApi = {
157
160
  dumpDiscv5KadValues: () => core.dumpDiscv5KadValues(),
158
161
  dumpMeshPeers: () => core.dumpMeshPeers(),
159
162
  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;
163
+ return profileThread(ProfileThread.NETWORK, durationMs, dirpath);
164
164
  },
165
165
  writeDiscv5Profile: async (durationMs: number, dirpath: string) => {
166
166
  return core.writeDiscv5Profile(durationMs, dirpath);
@@ -73,7 +73,7 @@ export class WorkerNetworkCore implements INetworkCore {
73
73
  // Handles ReqResp response from worker and calls async generator in main thread
74
74
  this.reqRespBridgeRespHandler = new AsyncIterableBridgeHandler(
75
75
  getReqRespBridgeRespEvents(this.reqRespBridgeEventBus),
76
- (data) => modules.getReqRespHandler(data.method)(data.req, peerIdFromString(data.peerId))
76
+ (data) => modules.getReqRespHandler(data.method)(data.req, peerIdFromString(data.peerId), data.peerClient)
77
77
  );
78
78
 
79
79
  wireEventsOnMainThread<NetworkEventData>(
@@ -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);
@@ -29,7 +29,7 @@ export type NetworkEventData = {
29
29
  clientAgent: string;
30
30
  };
31
31
  [NetworkEvent.peerDisconnected]: {peer: PeerIdStr};
32
- [NetworkEvent.reqRespRequest]: {request: RequestTypedContainer; peer: PeerId};
32
+ [NetworkEvent.reqRespRequest]: {request: RequestTypedContainer; peer: PeerId; peerClient: string};
33
33
  [NetworkEvent.pendingGossipsubMessage]: PendingGossipsubMessage;
34
34
  [NetworkEvent.gossipMessageValidationResult]: {
35
35
  msgId: string;
@@ -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;
@@ -126,7 +126,7 @@ export class MetadataController {
126
126
  * 2. Network MUST call this method on fork transition.
127
127
  * Current Clock implementation ensures no race conditions, epoch is correct if re-fetched
128
128
  */
129
- updateEth2Field(epoch: Epoch): void {
129
+ updateEth2Field(epoch: Epoch): phase0.ENRForkID {
130
130
  const config = this.networkConfig.config;
131
131
  const enrForkId = getENRForkID(config, epoch);
132
132
  const {forkDigest, nextForkVersion, nextForkEpoch} = enrForkId;
@@ -143,6 +143,8 @@ export class MetadataController {
143
143
  : ssz.ForkDigest.defaultValue();
144
144
  this.onSetValue(ENRKey.nfd, nextForkDigest);
145
145
  this.logger.debug("Updated nfd field in ENR", {nextForkDigest: toHex(nextForkDigest)});
146
+
147
+ return enrForkId;
146
148
  }
147
149
  }
148
150