@lodestar/beacon-node 1.41.0-dev.279c11da24 → 1.41.0-dev.31b0dd0873

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 (305) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +121 -3
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/state/index.js +8 -8
  5. package/lib/api/impl/beacon/state/index.js.map +1 -1
  6. package/lib/api/impl/beacon/state/utils.d.ts +3 -4
  7. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  8. package/lib/api/impl/beacon/state/utils.js +5 -24
  9. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  10. package/lib/api/impl/debug/index.d.ts.map +1 -1
  11. package/lib/api/impl/debug/index.js +5 -2
  12. package/lib/api/impl/debug/index.js.map +1 -1
  13. package/lib/api/impl/lightclient/index.d.ts.map +1 -1
  14. package/lib/api/impl/lightclient/index.js +19 -2
  15. package/lib/api/impl/lightclient/index.js.map +1 -1
  16. package/lib/api/impl/node/utils.d.ts +1 -1
  17. package/lib/api/impl/node/utils.d.ts.map +1 -1
  18. package/lib/api/impl/node/utils.js.map +1 -1
  19. package/lib/api/impl/validator/index.d.ts.map +1 -1
  20. package/lib/api/impl/validator/index.js +104 -6
  21. package/lib/api/impl/validator/index.js.map +1 -1
  22. package/lib/chain/archiveStore/archiveStore.d.ts +1 -0
  23. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  24. package/lib/chain/archiveStore/archiveStore.js +9 -0
  25. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  26. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts +5 -6
  27. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
  28. package/lib/chain/archiveStore/historicalState/getHistoricalState.js +9 -10
  29. package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
  30. package/lib/chain/archiveStore/historicalState/worker.js +3 -3
  31. package/lib/chain/archiveStore/historicalState/worker.js.map +1 -1
  32. package/lib/chain/archiveStore/utils/archivePayloads.d.ts +7 -0
  33. package/lib/chain/archiveStore/utils/archivePayloads.d.ts.map +1 -0
  34. package/lib/chain/archiveStore/utils/archivePayloads.js +10 -0
  35. package/lib/chain/archiveStore/utils/archivePayloads.js.map +1 -0
  36. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  37. package/lib/chain/blocks/importBlock.js +0 -2
  38. package/lib/chain/blocks/importBlock.js.map +1 -1
  39. package/lib/chain/blocks/index.d.ts.map +1 -1
  40. package/lib/chain/blocks/index.js +2 -1
  41. package/lib/chain/blocks/index.js.map +1 -1
  42. package/lib/chain/blocks/writeBlockInputToDb.d.ts.map +1 -1
  43. package/lib/chain/blocks/writeBlockInputToDb.js +3 -0
  44. package/lib/chain/blocks/writeBlockInputToDb.js.map +1 -1
  45. package/lib/chain/bls/multithread/index.d.ts +3 -3
  46. package/lib/chain/bls/multithread/index.d.ts.map +1 -1
  47. package/lib/chain/bls/multithread/index.js +5 -5
  48. package/lib/chain/bls/multithread/index.js.map +1 -1
  49. package/lib/chain/bls/multithread/jobItem.d.ts +2 -2
  50. package/lib/chain/bls/multithread/jobItem.d.ts.map +1 -1
  51. package/lib/chain/bls/multithread/jobItem.js +2 -2
  52. package/lib/chain/bls/multithread/jobItem.js.map +1 -1
  53. package/lib/chain/bls/singleThread.d.ts +4 -4
  54. package/lib/chain/bls/singleThread.d.ts.map +1 -1
  55. package/lib/chain/bls/singleThread.js +4 -4
  56. package/lib/chain/bls/singleThread.js.map +1 -1
  57. package/lib/chain/bls/utils.d.ts +2 -2
  58. package/lib/chain/bls/utils.d.ts.map +1 -1
  59. package/lib/chain/bls/utils.js +7 -4
  60. package/lib/chain/bls/utils.js.map +1 -1
  61. package/lib/chain/chain.d.ts +6 -9
  62. package/lib/chain/chain.d.ts.map +1 -1
  63. package/lib/chain/chain.js +32 -16
  64. package/lib/chain/chain.js.map +1 -1
  65. package/lib/chain/emitter.d.ts +2 -2
  66. package/lib/chain/emitter.d.ts.map +1 -1
  67. package/lib/chain/interface.d.ts +4 -6
  68. package/lib/chain/interface.d.ts.map +1 -1
  69. package/lib/chain/interface.js.map +1 -1
  70. package/lib/chain/lightClient/index.d.ts.map +1 -1
  71. package/lib/chain/lightClient/index.js +1 -1
  72. package/lib/chain/lightClient/index.js.map +1 -1
  73. package/lib/chain/options.d.ts.map +1 -1
  74. package/lib/chain/options.js.map +1 -1
  75. package/lib/chain/prepareNextSlot.js +3 -3
  76. package/lib/chain/prepareNextSlot.js.map +1 -1
  77. package/lib/chain/produceBlock/computeNewStateRoot.d.ts +10 -2
  78. package/lib/chain/produceBlock/computeNewStateRoot.d.ts.map +1 -1
  79. package/lib/chain/produceBlock/computeNewStateRoot.js +24 -2
  80. package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
  81. package/lib/chain/produceBlock/produceBlockBody.d.ts +22 -7
  82. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  83. package/lib/chain/produceBlock/produceBlockBody.js +110 -10
  84. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  85. package/lib/chain/validation/attestation.d.ts.map +1 -1
  86. package/lib/chain/validation/attestation.js +4 -1
  87. package/lib/chain/validation/attestation.js.map +1 -1
  88. package/lib/chain/validation/attesterSlashing.js +1 -1
  89. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  90. package/lib/chain/validation/dataColumnSidecar.d.ts +2 -2
  91. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  92. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  93. package/lib/chain/validation/payloadAttestationMessage.js +8 -1
  94. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  95. package/lib/chain/validation/proposerSlashing.js +1 -1
  96. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  97. package/lib/chain/validation/syncCommitteeContributionAndProof.js +1 -1
  98. package/lib/db/beacon.d.ts +3 -1
  99. package/lib/db/beacon.d.ts.map +1 -1
  100. package/lib/db/beacon.js +5 -1
  101. package/lib/db/beacon.js.map +1 -1
  102. package/lib/db/buckets.d.ts +3 -1
  103. package/lib/db/buckets.d.ts.map +1 -1
  104. package/lib/db/buckets.js +2 -0
  105. package/lib/db/buckets.js.map +1 -1
  106. package/lib/db/interface.d.ts +3 -1
  107. package/lib/db/interface.d.ts.map +1 -1
  108. package/lib/db/repositories/blockArchive.d.ts.map +1 -1
  109. package/lib/db/repositories/blockArchive.js +1 -2
  110. package/lib/db/repositories/blockArchive.js.map +1 -1
  111. package/lib/db/repositories/blockArchiveIndex.d.ts +2 -2
  112. package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
  113. package/lib/db/repositories/dataColumnSidecar.d.ts +5 -3
  114. package/lib/db/repositories/dataColumnSidecar.d.ts.map +1 -1
  115. package/lib/db/repositories/dataColumnSidecar.js +14 -1
  116. package/lib/db/repositories/dataColumnSidecar.js.map +1 -1
  117. package/lib/db/repositories/dataColumnSidecarArchive.d.ts +5 -3
  118. package/lib/db/repositories/dataColumnSidecarArchive.d.ts.map +1 -1
  119. package/lib/db/repositories/dataColumnSidecarArchive.js +14 -1
  120. package/lib/db/repositories/dataColumnSidecarArchive.js.map +1 -1
  121. package/lib/db/repositories/executionPayloadEnvelope.d.ts +19 -0
  122. package/lib/db/repositories/executionPayloadEnvelope.d.ts.map +1 -0
  123. package/lib/db/repositories/executionPayloadEnvelope.js +22 -0
  124. package/lib/db/repositories/executionPayloadEnvelope.js.map +1 -0
  125. package/lib/db/repositories/executionPayloadEnvelopeArchive.d.ts +18 -0
  126. package/lib/db/repositories/executionPayloadEnvelopeArchive.d.ts.map +1 -0
  127. package/lib/db/repositories/executionPayloadEnvelopeArchive.js +28 -0
  128. package/lib/db/repositories/executionPayloadEnvelopeArchive.js.map +1 -0
  129. package/lib/db/repositories/index.d.ts +2 -0
  130. package/lib/db/repositories/index.d.ts.map +1 -1
  131. package/lib/db/repositories/index.js +2 -0
  132. package/lib/db/repositories/index.js.map +1 -1
  133. package/lib/execution/engine/http.d.ts +1 -0
  134. package/lib/execution/engine/http.d.ts.map +1 -1
  135. package/lib/execution/engine/http.js +3 -0
  136. package/lib/execution/engine/http.js.map +1 -1
  137. package/lib/metrics/metrics/beacon.d.ts +1 -0
  138. package/lib/metrics/metrics/beacon.d.ts.map +1 -1
  139. package/lib/metrics/metrics/beacon.js +5 -0
  140. package/lib/metrics/metrics/beacon.js.map +1 -1
  141. package/lib/metrics/metrics/lodestar.d.ts +8 -0
  142. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  143. package/lib/metrics/metrics/lodestar.js +14 -0
  144. package/lib/metrics/metrics/lodestar.js.map +1 -1
  145. package/lib/monitoring/service.d.ts +2 -2
  146. package/lib/monitoring/service.d.ts.map +1 -1
  147. package/lib/monitoring/service.js +3 -2
  148. package/lib/monitoring/service.js.map +1 -1
  149. package/lib/network/core/networkCore.d.ts +3 -3
  150. package/lib/network/core/networkCore.d.ts.map +1 -1
  151. package/lib/network/core/networkCore.js.map +1 -1
  152. package/lib/network/core/networkCoreWorkerHandler.d.ts +3 -3
  153. package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -1
  154. package/lib/network/core/types.d.ts +2 -2
  155. package/lib/network/core/types.d.ts.map +1 -1
  156. package/lib/network/events.d.ts +2 -1
  157. package/lib/network/events.d.ts.map +1 -1
  158. package/lib/network/events.js.map +1 -1
  159. package/lib/network/gossip/encoding.d.ts +3 -3
  160. package/lib/network/gossip/encoding.d.ts.map +1 -1
  161. package/lib/network/gossip/encoding.js.map +1 -1
  162. package/lib/network/gossip/gossipsub.d.ts +13 -4
  163. package/lib/network/gossip/gossipsub.d.ts.map +1 -1
  164. package/lib/network/gossip/gossipsub.js +47 -20
  165. package/lib/network/gossip/gossipsub.js.map +1 -1
  166. package/lib/network/gossip/interface.d.ts +6 -6
  167. package/lib/network/gossip/interface.d.ts.map +1 -1
  168. package/lib/network/gossip/scoringParameters.d.ts +1 -1
  169. package/lib/network/gossip/scoringParameters.d.ts.map +1 -1
  170. package/lib/network/gossip/scoringParameters.js +1 -1
  171. package/lib/network/gossip/scoringParameters.js.map +1 -1
  172. package/lib/network/gossip/topic.d.ts +113 -63
  173. package/lib/network/gossip/topic.d.ts.map +1 -1
  174. package/lib/network/gossip/topic.js +2 -2
  175. package/lib/network/gossip/topic.js.map +1 -1
  176. package/lib/network/interface.d.ts +6 -5
  177. package/lib/network/interface.d.ts.map +1 -1
  178. package/lib/network/libp2p/index.d.ts +1 -1
  179. package/lib/network/libp2p/index.d.ts.map +1 -1
  180. package/lib/network/libp2p/index.js +29 -9
  181. package/lib/network/libp2p/index.js.map +1 -1
  182. package/lib/network/network.d.ts +5 -4
  183. package/lib/network/network.d.ts.map +1 -1
  184. package/lib/network/network.js +10 -1
  185. package/lib/network/network.js.map +1 -1
  186. package/lib/network/options.d.ts.map +1 -1
  187. package/lib/network/options.js +3 -0
  188. package/lib/network/options.js.map +1 -1
  189. package/lib/network/peers/datastore.d.ts +7 -5
  190. package/lib/network/peers/datastore.d.ts.map +1 -1
  191. package/lib/network/peers/datastore.js +10 -10
  192. package/lib/network/peers/datastore.js.map +1 -1
  193. package/lib/network/peers/peerManager.d.ts +3 -0
  194. package/lib/network/peers/peerManager.d.ts.map +1 -1
  195. package/lib/network/peers/peerManager.js +103 -53
  196. package/lib/network/peers/peerManager.js.map +1 -1
  197. package/lib/network/peers/utils/prioritizePeers.d.ts +3 -3
  198. package/lib/network/peers/utils/prioritizePeers.d.ts.map +1 -1
  199. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  200. package/lib/network/processor/gossipHandlers.js +5 -1
  201. package/lib/network/processor/gossipHandlers.js.map +1 -1
  202. package/lib/network/processor/gossipValidatorFn.js +1 -1
  203. package/lib/network/processor/types.d.ts +1 -1
  204. package/lib/network/processor/types.d.ts.map +1 -1
  205. package/lib/network/reqresp/handlers/lightClientUpdatesByRange.d.ts.map +1 -1
  206. package/lib/network/reqresp/handlers/lightClientUpdatesByRange.js +7 -1
  207. package/lib/network/reqresp/handlers/lightClientUpdatesByRange.js.map +1 -1
  208. package/lib/network/reqresp/score.d.ts.map +1 -1
  209. package/lib/network/reqresp/score.js +0 -1
  210. package/lib/network/reqresp/score.js.map +1 -1
  211. package/lib/network/util.js +2 -2
  212. package/lib/network/util.js.map +1 -1
  213. package/lib/node/nodejs.d.ts +3 -5
  214. package/lib/node/nodejs.d.ts.map +1 -1
  215. package/lib/node/nodejs.js +6 -4
  216. package/lib/node/nodejs.js.map +1 -1
  217. package/lib/util/blobs.d.ts +2 -2
  218. package/lib/util/blobs.d.ts.map +1 -1
  219. package/lib/util/blobs.js.map +1 -1
  220. package/lib/util/dataColumns.d.ts +11 -3
  221. package/lib/util/dataColumns.d.ts.map +1 -1
  222. package/lib/util/dataColumns.js +27 -0
  223. package/lib/util/dataColumns.js.map +1 -1
  224. package/lib/util/multifork.d.ts +8 -0
  225. package/lib/util/multifork.d.ts.map +1 -1
  226. package/lib/util/multifork.js +37 -0
  227. package/lib/util/multifork.js.map +1 -1
  228. package/lib/util/serializedCache.d.ts +5 -0
  229. package/lib/util/serializedCache.d.ts.map +1 -1
  230. package/lib/util/serializedCache.js +5 -0
  231. package/lib/util/serializedCache.js.map +1 -1
  232. package/package.json +38 -41
  233. package/src/api/impl/beacon/blocks/index.ts +145 -2
  234. package/src/api/impl/beacon/state/index.ts +8 -8
  235. package/src/api/impl/beacon/state/utils.ts +15 -29
  236. package/src/api/impl/debug/index.ts +8 -5
  237. package/src/api/impl/lightclient/index.ts +19 -2
  238. package/src/api/impl/node/utils.ts +3 -3
  239. package/src/api/impl/validator/index.ts +127 -5
  240. package/src/chain/archiveStore/archiveStore.ts +10 -0
  241. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +10 -11
  242. package/src/chain/archiveStore/historicalState/worker.ts +3 -3
  243. package/src/chain/archiveStore/utils/archivePayloads.ts +15 -0
  244. package/src/chain/blocks/importBlock.ts +0 -3
  245. package/src/chain/blocks/index.ts +2 -1
  246. package/src/chain/blocks/writeBlockInputToDb.ts +3 -0
  247. package/src/chain/bls/multithread/index.ts +7 -7
  248. package/src/chain/bls/multithread/jobItem.ts +3 -3
  249. package/src/chain/bls/singleThread.ts +5 -5
  250. package/src/chain/bls/utils.ts +8 -5
  251. package/src/chain/chain.ts +51 -26
  252. package/src/chain/emitter.ts +2 -2
  253. package/src/chain/interface.ts +4 -11
  254. package/src/chain/lightClient/index.ts +4 -1
  255. package/src/chain/options.ts +1 -0
  256. package/src/chain/prepareNextSlot.ts +5 -5
  257. package/src/chain/produceBlock/computeNewStateRoot.ts +35 -3
  258. package/src/chain/produceBlock/produceBlockBody.ts +163 -13
  259. package/src/chain/validation/attestation.ts +4 -1
  260. package/src/chain/validation/attesterSlashing.ts +1 -1
  261. package/src/chain/validation/dataColumnSidecar.ts +2 -5
  262. package/src/chain/validation/payloadAttestationMessage.ts +9 -1
  263. package/src/chain/validation/proposerSlashing.ts +1 -1
  264. package/src/chain/validation/syncCommitteeContributionAndProof.ts +1 -1
  265. package/src/db/beacon.ts +8 -0
  266. package/src/db/buckets.ts +3 -0
  267. package/src/db/interface.ts +5 -0
  268. package/src/db/repositories/blockArchive.ts +1 -2
  269. package/src/db/repositories/dataColumnSidecar.ts +18 -3
  270. package/src/db/repositories/dataColumnSidecarArchive.ts +18 -3
  271. package/src/db/repositories/executionPayloadEnvelope.ts +26 -0
  272. package/src/db/repositories/executionPayloadEnvelopeArchive.ts +32 -0
  273. package/src/db/repositories/index.ts +2 -0
  274. package/src/execution/engine/http.ts +3 -0
  275. package/src/metrics/metrics/beacon.ts +5 -0
  276. package/src/metrics/metrics/lodestar.ts +14 -0
  277. package/src/monitoring/service.ts +3 -2
  278. package/src/network/core/networkCore.ts +3 -3
  279. package/src/network/core/networkCoreWorkerHandler.ts +3 -3
  280. package/src/network/core/types.ts +2 -2
  281. package/src/network/events.ts +2 -1
  282. package/src/network/gossip/encoding.ts +3 -3
  283. package/src/network/gossip/gossipsub.ts +86 -25
  284. package/src/network/gossip/interface.ts +6 -6
  285. package/src/network/gossip/scoringParameters.ts +4 -4
  286. package/src/network/gossip/topic.ts +2 -1
  287. package/src/network/interface.ts +7 -4
  288. package/src/network/libp2p/index.ts +33 -10
  289. package/src/network/network.ts +24 -6
  290. package/src/network/options.ts +3 -0
  291. package/src/network/peers/datastore.ts +13 -10
  292. package/src/network/peers/peerManager.ts +118 -54
  293. package/src/network/peers/utils/prioritizePeers.ts +3 -3
  294. package/src/network/processor/gossipHandlers.ts +7 -1
  295. package/src/network/processor/gossipValidatorFn.ts +1 -1
  296. package/src/network/processor/types.ts +1 -1
  297. package/src/network/reqresp/handlers/lightClientUpdatesByRange.ts +6 -1
  298. package/src/network/reqresp/score.ts +0 -1
  299. package/src/network/util.ts +2 -2
  300. package/src/node/nodejs.ts +8 -9
  301. package/src/util/blobs.ts +3 -3
  302. package/src/util/dataColumns.ts +37 -1
  303. package/src/util/multifork.ts +45 -0
  304. package/src/util/serializedCache.ts +5 -0
  305. package/src/util/workerEvents.ts +1 -1
@@ -9,6 +9,7 @@ import {prettyPrintIndices, toHex, withTimeout} from "@lodestar/utils";
9
9
  import {GOODBYE_KNOWN_CODES, GoodByeReasonCode, Libp2pEvent} from "../../constants/index.js";
10
10
  import {IClock} from "../../util/clock.js";
11
11
  import {computeColumnsForCustodyGroup, getCustodyGroups} from "../../util/dataColumns.js";
12
+ import {callInNextEventLoop} from "../../util/eventLoop.js";
12
13
  import {NetworkCoreMetrics} from "../core/metrics.js";
13
14
  import {LodestarDiscv5Opts} from "../discv5/types.js";
14
15
  import {INetworkEventBus, NetworkEvent, NetworkEventData} from "../events.js";
@@ -161,7 +162,6 @@ export class PeerManager {
161
162
 
162
163
  // A single map of connected peers with all necessary data to handle PINGs, STATUS, and metrics
163
164
  private connectedPeers: Map<PeerIdStr, PeerData>;
164
-
165
165
  private opts: PeerManagerOpts;
166
166
  private intervals: NodeJS.Timeout[] = [];
167
167
 
@@ -196,6 +196,13 @@ export class PeerManager {
196
196
 
197
197
  this.lastStatus = this.statusCache.get();
198
198
 
199
+ // A connection may already be open before listeners are attached.
200
+ // Seed those peers so they are tracked in connectedPeers immediately.
201
+ this.bootstrapAlreadyOpenConnections();
202
+ // Defer status/ping to the next event loop tick so the heartbeat interval and
203
+ // event listeners are fully registered before we begin handshakes.
204
+ callInNextEventLoop(() => this.pingAndStatusTimeouts());
205
+
199
206
  // On start-up will connected to existing peers in libp2p.peerStore, same as autoDial behaviour
200
207
  this.heartbeat();
201
208
  this.intervals = [
@@ -472,6 +479,14 @@ export class PeerManager {
472
479
  clientAgent,
473
480
  custodyColumns,
474
481
  });
482
+
483
+ // Identify peer after status proves the connection is usable.
484
+ // This is the only place we trigger identify — avoids wasted streams on
485
+ // peers that close identify right after connection open or turn out to be
486
+ // irrelevant.
487
+ if (peerData?.agentVersion === null) {
488
+ void this.identifyPeer(peer.toString(), prettyPrintPeerId(peer), getConnection(this.libp2p, peer.toString()));
489
+ }
475
490
  }
476
491
  }
477
492
 
@@ -692,36 +707,39 @@ export class PeerManager {
692
707
  }
693
708
  }
694
709
 
695
- /**
696
- * The libp2p Upgrader has successfully upgraded a peer connection on a particular multiaddress
697
- * This event is routed through the connectionManager
698
- *
699
- * Registers a peer as connected. The `direction` parameter determines if the peer is being
700
- * dialed or connecting to us.
701
- */
702
- private onLibp2pPeerConnect = async (evt: CustomEvent<Connection>): Promise<void> => {
703
- const {direction, status, remotePeer} = evt.detail;
710
+ private bootstrapAlreadyOpenConnections(): void {
711
+ let bootstrapped = 0;
712
+
713
+ for (const {value: connections} of getConnectionsMap(this.libp2p).values()) {
714
+ for (const connection of connections) {
715
+ // trackLibp2pConnection handles deduplication via overwriteExisting: false
716
+ if (this.trackLibp2pConnection(connection, {overwriteExisting: false, triggerHandshakeNow: false})) {
717
+ bootstrapped++;
718
+ }
719
+ }
720
+ }
721
+
722
+ if (bootstrapped > 0) {
723
+ this.logger.verbose("Bootstrapped already-open libp2p peers", {bootstrapped});
724
+ }
725
+ }
726
+
727
+ private trackLibp2pConnection(
728
+ connection: Connection,
729
+ opts: {overwriteExisting: boolean; triggerHandshakeNow: boolean}
730
+ ): boolean {
731
+ const {direction, status, remotePeer} = connection;
704
732
  const remotePeerStr = remotePeer.toString();
705
733
  const remotePeerPrettyStr = prettyPrintPeerId(remotePeer);
706
- this.logger.verbose("peer connected", {peer: remotePeerPrettyStr, direction, status});
707
- // NOTE: The peerConnect event is not emitted here here, but after asserting peer relevance
708
- this.metrics?.peerConnectedEvent.inc({direction, status});
709
734
 
710
- if (evt.detail.status !== "open") {
735
+ if (status !== "open") {
711
736
  this.logger.debug("Peer disconnected before identify protocol initiated", {
712
737
  peerId: remotePeerPrettyStr,
713
- status: evt.detail.status,
738
+ status,
714
739
  });
715
- return;
740
+ return false;
716
741
  }
717
742
 
718
- // On connection:
719
- // - Outbound connections: send a STATUS and PING request
720
- // - Inbound connections: expect to be STATUS'd, schedule STATUS and PING for latter
721
- // NOTE: libp2p may emit two "peer:connect" events: One for inbound, one for outbound
722
- // If that happens, it's okay. Only the "outbound" connection triggers immediate action
723
- const now = Date.now();
724
-
725
743
  // Ethereum uses secp256k1 for node IDs, reject peers with other key types
726
744
  if (remotePeer.type !== "secp256k1") {
727
745
  this.logger.debug("Peer does not have secp256k1 key, disconnecting", {
@@ -729,52 +747,64 @@ export class PeerManager {
729
747
  type: remotePeer.type,
730
748
  });
731
749
  void this.goodbyeAndDisconnect(remotePeer, GoodByeReasonCode.IRRELEVANT_NETWORK);
732
- return;
750
+ return false;
733
751
  }
734
752
 
753
+ if (!opts.overwriteExisting && this.connectedPeers.has(remotePeerStr)) {
754
+ return false;
755
+ }
756
+
757
+ // On connection:
758
+ // - Outbound connections: send a STATUS and PING request
759
+ // - Inbound connections: expect to be STATUS'd, schedule STATUS and PING for later
760
+ // NOTE: libp2p may emit two "peer:connect" events: One for inbound, one for outbound
761
+ // If that happens, it's okay. Only the "outbound" connection triggers immediate action
762
+ const now = Date.now();
763
+ const existingPeerData = this.connectedPeers.get(remotePeerStr);
735
764
  const nodeId = computeNodeId(remotePeer);
736
765
  const peerData: PeerData = {
737
- lastReceivedMsgUnixTsMs: direction === "outbound" ? 0 : now,
766
+ // Keep existing timestamps if this peer already had another open connection.
767
+ // libp2p may emit multiple connection:open events per peer.
768
+ lastReceivedMsgUnixTsMs: existingPeerData?.lastReceivedMsgUnixTsMs ?? (direction === "outbound" ? 0 : now),
738
769
  // If inbound, request after STATUS_INBOUND_GRACE_PERIOD
739
- lastStatusUnixTsMs: direction === "outbound" ? 0 : now - STATUS_INTERVAL_MS + STATUS_INBOUND_GRACE_PERIOD,
740
- connectedUnixTsMs: now,
741
- relevantStatus: RelevantPeerStatus.Unknown,
770
+ lastStatusUnixTsMs:
771
+ existingPeerData?.lastStatusUnixTsMs ??
772
+ (direction === "outbound" ? 0 : now - STATUS_INTERVAL_MS + STATUS_INBOUND_GRACE_PERIOD),
773
+ connectedUnixTsMs: existingPeerData?.connectedUnixTsMs ?? now,
774
+ relevantStatus: existingPeerData?.relevantStatus ?? RelevantPeerStatus.Unknown,
742
775
  direction,
743
776
  nodeId,
744
777
  peerId: remotePeer,
745
- status: null,
746
- metadata: null,
747
- agentVersion: null,
748
- agentClient: null,
749
- encodingPreference: null,
778
+ status: existingPeerData?.status ?? null,
779
+ metadata: existingPeerData?.metadata ?? null,
780
+ agentVersion: existingPeerData?.agentVersion ?? null,
781
+ agentClient: existingPeerData?.agentClient ?? null,
782
+ encodingPreference: existingPeerData?.encodingPreference ?? null,
750
783
  };
751
784
  this.connectedPeers.set(remotePeerStr, peerData);
752
785
 
753
- if (direction === "outbound") {
754
- // this.pingAndStatusTimeouts();
786
+ if (direction === "outbound" && opts.triggerHandshakeNow) {
755
787
  void this.requestPing(remotePeer);
756
788
  void this.requestStatus(remotePeer, this.statusCache.get());
757
789
  }
758
790
 
759
- this.libp2p.services.identify
760
- .identify(evt.detail)
761
- .then((result) => {
762
- const agentVersion = result.agentVersion;
763
- if (agentVersion) {
764
- peerData.agentVersion = agentVersion;
765
- peerData.agentClient = getKnownClientFromAgentVersion(agentVersion);
766
- }
767
- })
768
- .catch((err) => {
769
- if (evt.detail.status !== "open") {
770
- this.logger.debug("Peer disconnected during identify protocol", {
771
- peerId: remotePeerPrettyStr,
772
- error: (err as Error).message,
773
- });
774
- } else {
775
- this.logger.debug("Error setting agentVersion for the peer", {peerId: remotePeerPrettyStr}, err);
776
- }
777
- });
791
+ return true;
792
+ }
793
+
794
+ /**
795
+ * The libp2p Upgrader has successfully upgraded a peer connection on a particular multiaddress
796
+ * This event is routed through the connectionManager
797
+ *
798
+ * Registers a peer as connected. The `direction` parameter determines if the peer is being
799
+ * dialed or connecting to us.
800
+ */
801
+ private onLibp2pPeerConnect = (evt: CustomEvent<Connection>): void => {
802
+ const {direction, status, remotePeer} = evt.detail;
803
+ this.logger.verbose("peer connected", {peer: prettyPrintPeerId(remotePeer), direction, status});
804
+ // NOTE: The peerConnect event is not emitted here here, but after asserting peer relevance
805
+ this.metrics?.peerConnectedEvent.inc({direction, status});
806
+
807
+ this.trackLibp2pConnection(evt.detail, {overwriteExisting: true, triggerHandshakeNow: true});
778
808
  };
779
809
 
780
810
  /**
@@ -784,6 +814,19 @@ export class PeerManager {
784
814
  const {direction, status, remotePeer} = evt.detail;
785
815
  const peerIdStr = remotePeer.toString();
786
816
 
817
+ const openConnections =
818
+ getConnectionsMap(this.libp2p)
819
+ .get(peerIdStr)
820
+ ?.value.filter((connection) => connection.status === "open") ?? [];
821
+ if (openConnections.length > 0) {
822
+ this.logger.debug("Ignoring peer disconnect event while another connection is still open", {
823
+ peerId: prettyPrintPeerIdStr(peerIdStr),
824
+ direction,
825
+ status,
826
+ });
827
+ return;
828
+ }
829
+
787
830
  let logMessage = "onLibp2pPeerDisconnect";
788
831
  const logContext: Record<string, string | number> = {
789
832
  peerId: prettyPrintPeerIdStr(peerIdStr),
@@ -818,6 +861,27 @@ export class PeerManager {
818
861
  }
819
862
  }
820
863
 
864
+ private async identifyPeer(peerIdStr: string, peerIdPretty: string, connection?: Connection): Promise<void> {
865
+ if (!connection || connection.status !== "open") {
866
+ this.logger.debug("Peer has no open connection for identify", {peerId: peerIdPretty});
867
+ return;
868
+ }
869
+
870
+ try {
871
+ const result = await this.libp2p.services.identify.identify(connection);
872
+ const agentVersion = result.agentVersion;
873
+ if (agentVersion) {
874
+ const connectedPeerData = this.connectedPeers.get(peerIdStr);
875
+ if (connectedPeerData) {
876
+ connectedPeerData.agentVersion = agentVersion;
877
+ connectedPeerData.agentClient = getKnownClientFromAgentVersion(agentVersion);
878
+ }
879
+ }
880
+ } catch (e) {
881
+ this.logger.debug("Error setting agentVersion for the peer", {peerId: peerIdPretty}, e as Error);
882
+ }
883
+ }
884
+
821
885
  private async goodbyeAndDisconnect(peer: PeerId, goodbye: GoodByeReasonCode): Promise<void> {
822
886
  const reason = GOODBYE_KNOWN_CODES[goodbye.toString()] || "";
823
887
  const peerIdStr = peer.toString();
@@ -1,4 +1,4 @@
1
- import {Direction, PeerId} from "@libp2p/interface";
1
+ import type {MessageStreamDirection, PeerId} from "@libp2p/interface";
2
2
  import {BitArray} from "@chainsafe/ssz";
3
3
  import {ChainConfig} from "@lodestar/config";
4
4
  import {ATTESTATION_SUBNET_COUNT, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params";
@@ -95,7 +95,7 @@ function computeStatusScore(ours: Status, theirs: Status | null, opts: Prioritiz
95
95
 
96
96
  type PeerInfo = {
97
97
  id: PeerId;
98
- direction: Direction | null;
98
+ direction: MessageStreamDirection | null;
99
99
  statusScore: StatusScore;
100
100
  attnets: phase0.AttestationSubnets;
101
101
  syncnets: altair.SyncSubnets;
@@ -137,7 +137,7 @@ export enum ExcessPeerDisconnectReason {
137
137
  export function prioritizePeers(
138
138
  connectedPeersInfo: {
139
139
  id: PeerId;
140
- direction: Direction | null;
140
+ direction: MessageStreamDirection | null;
141
141
  status: Status | null;
142
142
  attnets: phase0.AttestationSubnets | null;
143
143
  syncnets: altair.SyncSubnets | null;
@@ -548,7 +548,8 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
548
548
  seenTimestampSec,
549
549
  }: GossipHandlerParamGeneric<GossipType.data_column_sidecar>) => {
550
550
  const {serializedData} = gossipData;
551
- const dataColumnSidecar = sszDeserialize(topic, serializedData);
551
+ // TODO GLOAS: handle gloas.DataColumnSidecar
552
+ const dataColumnSidecar = sszDeserialize(topic, serializedData) as fulu.DataColumnSidecar;
552
553
  const dataColumnSlot = dataColumnSidecar.signedBlockHeader.message.slot;
553
554
  const index = dataColumnSidecar.index;
554
555
 
@@ -821,11 +822,16 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
821
822
  [GossipType.execution_payload]: async ({
822
823
  gossipData,
823
824
  topic,
825
+ seenTimestampSec,
824
826
  }: GossipHandlerParamGeneric<GossipType.execution_payload>) => {
825
827
  const {serializedData} = gossipData;
826
828
  const executionPayloadEnvelope = sszDeserialize(topic, serializedData);
827
829
  await validateGossipExecutionPayloadEnvelope(chain, executionPayloadEnvelope);
828
830
 
831
+ const slot = executionPayloadEnvelope.message.slot;
832
+ const delaySec = seenTimestampSec - computeTimeAtSlot(config, slot, chain.genesisTime);
833
+ metrics?.gossipExecutionPayloadEnvelope.elapsedTimeTillReceived.observe({source: OpSource.gossip}, delaySec);
834
+
829
835
  // TODO GLOAS: Handle valid envelope. Need an import flow that calls `processExecutionPayloadEnvelope` and fork choice
830
836
  },
831
837
  [GossipType.payload_attestation_message]: async ({
@@ -1,4 +1,4 @@
1
- import {TopicValidatorResult} from "@libp2p/interface";
1
+ import {TopicValidatorResult} from "@libp2p/gossipsub";
2
2
  import {ChainForkConfig} from "@lodestar/config";
3
3
  import {Logger} from "@lodestar/utils";
4
4
  import {AttestationError, GossipAction, GossipActionError} from "../../chain/errors/index.js";
@@ -1,4 +1,4 @@
1
- import {Message} from "@libp2p/interface";
1
+ import type {Message} from "@libp2p/gossipsub";
2
2
  import {ForkName} from "@lodestar/params";
3
3
  import {Slot, SlotOptionalRoot} from "@lodestar/types";
4
4
  import {PeerIdStr} from "../../util/peerId.js";
@@ -19,6 +19,7 @@ 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
+ let started = false;
22
23
  for (let period = requestBody.startPeriod; period < requestBody.startPeriod + count; period++) {
23
24
  try {
24
25
  const update = await chain.lightClientServer.getUpdate(period);
@@ -29,9 +30,13 @@ export async function* onLightClientUpdatesByRange(
29
30
  data: type.serialize(update),
30
31
  boundary,
31
32
  };
33
+ started = true;
32
34
  } catch (e) {
33
35
  if ((e as LightClientServerError).type?.code === LightClientServerErrorCode.RESOURCE_UNAVAILABLE) {
34
- throw new ResponseError(RespStatus.RESOURCE_UNAVAILABLE, (e as Error).message);
36
+ // Period not available, if we already started yielding, stop to
37
+ // preserve consecutive order. Otherwise skip leading gaps.
38
+ if (started) return;
39
+ continue;
35
40
  }
36
41
  throw new ResponseError(RespStatus.SERVER_ERROR, (e as Error).message);
37
42
  }
@@ -38,7 +38,6 @@ export function onOutgoingReqRespError(e: RequestError, method: ReqRespMethod):
38
38
  : PeerAction.LowToleranceError;
39
39
  // TODO: Detect SSZDecodeError and return PeerAction.Fatal
40
40
 
41
- case RequestErrorCode.TTFB_TIMEOUT:
42
41
  case RequestErrorCode.RESP_TIMEOUT:
43
42
  switch (method) {
44
43
  case ReqRespMethod.Ping:
@@ -23,7 +23,7 @@ export function getConnection(libp2p: Libp2p, peerIdStr: string): Connection | u
23
23
  return getConnectionsMap(libp2p).get(peerIdStr)?.value[0] ?? undefined;
24
24
  }
25
25
 
26
- // https://github.com/ChainSafe/js-libp2p-gossipsub/blob/3475242ed254f7647798ab7f36b21909f6cb61da/src/index.ts#L2009
26
+ // https://github.com/libp2p/js-libp2p/blob/f87cba928991736d9646b3e054c367f55cab315c/packages/gossipsub/src/gossipsub.ts#L2076
27
27
  export function isPublishToZeroPeersError(e: Error): boolean {
28
- return e.message.includes("PublishError.InsufficientPeers");
28
+ return e.message.includes("PublishError.NoPeersSubscribedToTopic");
29
29
  }
@@ -2,12 +2,11 @@ import {setMaxListeners} from "node:events";
2
2
  import {PrivateKey} from "@libp2p/interface";
3
3
  import {Registry} from "prom-client";
4
4
  import {hasher} from "@chainsafe/persistent-merkle-tree";
5
- import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
6
5
  import {BeaconApiMethods} from "@lodestar/api/beacon/server";
7
6
  import {BeaconConfig} from "@lodestar/config";
8
7
  import type {LoggerNode} from "@lodestar/logger/node";
9
8
  import {ZERO_HASH_HEX} from "@lodestar/params";
10
- import {CachedBeaconStateAllForks, Index2PubkeyCache, isExecutionCachedStateType} from "@lodestar/state-transition";
9
+ import {CachedBeaconStateAllForks, PubkeyCache, isExecutionCachedStateType} from "@lodestar/state-transition";
11
10
  import {phase0} from "@lodestar/types";
12
11
  import {sleep, toRootHex} from "@lodestar/utils";
13
12
  import {ProcessShutdownCallback} from "@lodestar/validator";
@@ -47,8 +46,7 @@ export type BeaconNodeModules = {
47
46
  export type BeaconNodeInitModules = {
48
47
  opts: IBeaconNodeOptions;
49
48
  config: BeaconConfig;
50
- pubkey2index: PubkeyIndexMap;
51
- index2pubkey: Index2PubkeyCache;
49
+ pubkeyCache: PubkeyCache;
52
50
  db: IBeaconDb;
53
51
  logger: LoggerNode;
54
52
  processShutdownCallback: ProcessShutdownCallback;
@@ -150,8 +148,7 @@ export class BeaconNode {
150
148
  static async init<T extends BeaconNode = BeaconNode>({
151
149
  opts,
152
150
  config,
153
- pubkey2index,
154
- index2pubkey,
151
+ pubkeyCache,
155
152
  db,
156
153
  logger,
157
154
  processShutdownCallback,
@@ -240,8 +237,7 @@ export class BeaconNode {
240
237
  privateKey,
241
238
  config,
242
239
  clock,
243
- pubkey2index,
244
- index2pubkey,
240
+ pubkeyCache,
245
241
  dataDir,
246
242
  db,
247
243
  dbName: opts.db.name,
@@ -364,9 +360,12 @@ export class BeaconNode {
364
360
  if (this.restApi) await this.restApi.close();
365
361
  await this.network.close();
366
362
  if (this.metricsServer) await this.metricsServer.close();
367
- if (this.monitoring) this.monitoring.close();
363
+ if (this.monitoring) await this.monitoring.close();
368
364
  await this.chain.persistToDisk();
369
365
  await this.chain.close();
366
+ // Abort signal last: close() calls above clear intervals/timeouts so no new
367
+ // operations get scheduled. If we aborted first, a still-pending interval could
368
+ // fire and schedule a new operation after abort, leaving it stuck and delaying shutdown.
370
369
  if (this.controller) this.controller.abort();
371
370
  await sleep(DELAY_BEFORE_CLOSING_DB_MS);
372
371
  await this.db.close();
package/src/util/blobs.ts CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  VERSIONED_HASH_VERSION_KZG,
14
14
  } from "@lodestar/params";
15
15
  import {signedBlockToSignedHeader} from "@lodestar/state-transition";
16
- import {BeaconBlockBody, SSZTypesFor, SignedBeaconBlock, deneb, fulu, ssz} from "@lodestar/types";
16
+ import {BeaconBlockBody, DataColumnSidecars, SSZTypesFor, SignedBeaconBlock, deneb, fulu, ssz} from "@lodestar/types";
17
17
  import {kzg} from "./kzg.js";
18
18
 
19
19
  type VersionHash = Uint8Array;
@@ -149,7 +149,7 @@ export async function dataColumnMatrixRecovery(
149
149
  * Reconstruct blobs from a set of data columns, at least 50%+ of all the columns
150
150
  * must be provided to allow to reconstruct the full data matrix
151
151
  */
152
- export async function reconstructBlobs(sidecars: fulu.DataColumnSidecars, indices?: number[]): Promise<deneb.Blobs> {
152
+ export async function reconstructBlobs(sidecars: DataColumnSidecars, indices?: number[]): Promise<deneb.Blobs> {
153
153
  if (sidecars.length < NUMBER_OF_COLUMNS / 2) {
154
154
  throw Error(
155
155
  `Expected at least ${NUMBER_OF_COLUMNS / 2} data columns to reconstruct blobs, received ${sidecars.length}`
@@ -188,7 +188,7 @@ export async function reconstructBlobs(sidecars: fulu.DataColumnSidecars, indice
188
188
  * Recover cells for specific blob indices from a set of data columns
189
189
  */
190
190
  async function recoverBlobCells(
191
- partialSidecars: fulu.DataColumnSidecar[],
191
+ partialSidecars: DataColumnSidecars,
192
192
  blobIndices: number[]
193
193
  ): Promise<Map<number, fulu.Cell[]> | null> {
194
194
  const columnCount = partialSidecars.length;
@@ -4,6 +4,7 @@ import {ChainForkConfig} from "@lodestar/config";
4
4
  import {
5
5
  ForkAll,
6
6
  ForkName,
7
+ ForkPostDeneb,
7
8
  ForkPostFulu,
8
9
  ForkPreGloas,
9
10
  KZG_COMMITMENTS_GINDEX,
@@ -15,9 +16,11 @@ import {
15
16
  BeaconBlockBody,
16
17
  ColumnIndex,
17
18
  CustodyIndex,
19
+ Root,
18
20
  SSZTypesFor,
19
21
  SignedBeaconBlock,
20
22
  SignedBeaconBlockHeader,
23
+ Slot,
21
24
  deneb,
22
25
  fulu,
23
26
  gloas,
@@ -269,7 +272,7 @@ export async function getCellsAndProofs(
269
272
  */
270
273
  export function getBlobKzgCommitments(
271
274
  fork: ForkName,
272
- signedBlock: SignedBeaconBlock<ForkPostFulu>
275
+ signedBlock: SignedBeaconBlock<ForkPostDeneb>
273
276
  ): deneb.KZGCommitment[] {
274
277
  if (isForkPostGloas(fork)) {
275
278
  return (signedBlock as gloas.SignedBeaconBlock).message.body.signedExecutionPayloadBid.message.blobKzgCommitments;
@@ -359,6 +362,39 @@ export function getDataColumnSidecarsFromColumnSidecar(
359
362
  );
360
363
  }
361
364
 
365
+ /**
366
+ * In Gloas, data column sidecars have a simplified structure with `slot` and `beaconBlockRoot`
367
+ * instead of `signedBlockHeader`, `kzgCommitments`, and `kzgCommitmentsInclusionProof`.
368
+ */
369
+ export function getDataColumnSidecarsForGloas(
370
+ slot: Slot,
371
+ beaconBlockRoot: Root,
372
+ cellsAndKzgProofs: {cells: Uint8Array[]; proofs: Uint8Array[]}[]
373
+ ): gloas.DataColumnSidecars {
374
+ // No need to create data column sidecars if there are no blobs
375
+ if (cellsAndKzgProofs.length === 0) {
376
+ return [];
377
+ }
378
+
379
+ const sidecars: gloas.DataColumnSidecars = [];
380
+ for (let columnIndex = 0; columnIndex < NUMBER_OF_COLUMNS; columnIndex++) {
381
+ const column: Uint8Array[] = [];
382
+ const kzgProofs: Uint8Array[] = [];
383
+ for (const {cells, proofs} of cellsAndKzgProofs) {
384
+ column.push(cells[columnIndex]);
385
+ kzgProofs.push(proofs[columnIndex]);
386
+ }
387
+ sidecars.push({
388
+ index: columnIndex,
389
+ column,
390
+ kzgProofs,
391
+ slot,
392
+ beaconBlockRoot,
393
+ });
394
+ }
395
+ return sidecars;
396
+ }
397
+
362
398
  /**
363
399
  * If we receive more than half of NUMBER_OF_COLUMNS (64) we should recover all remaining columns
364
400
  */
@@ -9,6 +9,11 @@ import {getSlotFromSignedBeaconBlockSerialized} from "./sszBytes.js";
9
9
  */
10
10
  const SLOT_BYTE_COUNT = 8;
11
11
 
12
+ /**
13
+ * SSZ offset uint32
14
+ */
15
+ const OFFSET_BYTE_COUNT = 4;
16
+
12
17
  /**
13
18
  * 8 + 32 = 40
14
19
  * ```
@@ -67,3 +72,43 @@ export function getLightClientHeaderTypeFromBytes(
67
72
  );
68
73
  return config.getPostAltairForkTypes(slot).LightClientHeader;
69
74
  }
75
+
76
+ /**
77
+ * Position of first offset in DataColumnSidecar (after index field)
78
+ *
79
+ * Fulu DataColumnSidecar (6 fields):
80
+ * index: uint64 [fixed - 8 bytes]
81
+ * column: List [variable - 4-byte offset]
82
+ * kzgCommitments: List [variable - 4-byte offset]
83
+ * kzgProofs: List [variable - 4-byte offset]
84
+ * signedBlockHeader: Container [fixed - 208 bytes]
85
+ * kzgCommitmentsInclusionProof: Vector[Bytes32, 4] [fixed - 128 bytes]
86
+ * => First offset value = 8 + 4 + 4 + 4 + 208 + 128 = 356
87
+ *
88
+ * Gloas DataColumnSidecar (5 fields):
89
+ * index: uint64 [fixed - 8 bytes]
90
+ * column: List [variable - 4-byte offset]
91
+ * kzgProofs: List [variable - 4-byte offset]
92
+ * slot: uint64 [fixed - 8 bytes]
93
+ * beaconBlockRoot: Bytes32 [fixed - 32 bytes]
94
+ * => First offset value = 8 + 4 + 4 + 8 + 32 = 56
95
+ */
96
+ const FIRST_OFFSET_POSITION_IN_DATA_COLUMN_SIDECAR = 8;
97
+ const GLOAS_DATA_COLUMN_SIDECAR_FIRST_OFFSET = 56;
98
+
99
+ /**
100
+ * Determines if DataColumnSidecar bytes are from Gloas fork by checking the SSZ offset structure.
101
+ *
102
+ * The first offset (bytes 8-12) indicates where variable-size data begins:
103
+ * - Gloas: 56 (small fixed section)
104
+ * - Fulu: 356
105
+ */
106
+ export function isGloasDataColumnSidecarBytes(bytes: Uint8Array): boolean {
107
+ const firstOffset = bytesToInt(
108
+ bytes.subarray(
109
+ FIRST_OFFSET_POSITION_IN_DATA_COLUMN_SIDECAR,
110
+ FIRST_OFFSET_POSITION_IN_DATA_COLUMN_SIDECAR + OFFSET_BYTE_COUNT
111
+ )
112
+ );
113
+ return firstOffset === GLOAS_DATA_COLUMN_SIDECAR_FIRST_OFFSET;
114
+ }
@@ -14,6 +14,11 @@ export class SerializedCache {
14
14
  this.map.set(obj, serialized);
15
15
  }
16
16
 
17
+ /**
18
+ * Replace the internal WeakMap to force GC of all cached entries.
19
+ * Must only be called after all DB writes that may read from this cache have completed,
20
+ * otherwise cached serialized bytes will be unavailable and data will be re-serialized unnecessarily.
21
+ */
17
22
  clear(): void {
18
23
  this.map = new WeakMap();
19
24
  }
@@ -1,5 +1,5 @@
1
1
  import {MessagePort, Worker} from "node:worker_threads";
2
- import {Message} from "@libp2p/interface";
2
+ import type {Message} from "@libp2p/gossipsub";
3
3
  import {Thread} from "@chainsafe/threads";
4
4
  import {Logger} from "@lodestar/logger";
5
5
  import {sleep} from "@lodestar/utils";