@lodestar/beacon-node 1.51.0-dev.3da261f88e → 1.51.0-dev.3ff306e42b

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 (272) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +17 -27
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/pool/index.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/pool/index.js +5 -2
  6. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  7. package/lib/api/impl/beacon/state/utils.d.ts +1 -1
  8. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  9. package/lib/api/impl/validator/index.d.ts +6 -0
  10. package/lib/api/impl/validator/index.d.ts.map +1 -1
  11. package/lib/api/impl/validator/index.js +42 -26
  12. package/lib/api/impl/validator/index.js.map +1 -1
  13. package/lib/chain/GetBlobsTracker.d.ts +11 -0
  14. package/lib/chain/GetBlobsTracker.d.ts.map +1 -1
  15. package/lib/chain/GetBlobsTracker.js +85 -27
  16. package/lib/chain/GetBlobsTracker.js.map +1 -1
  17. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  18. package/lib/chain/archiveStore/archiveStore.js +1 -0
  19. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  20. package/lib/chain/archiveStore/utils/archiveBlocks.d.ts +4 -0
  21. package/lib/chain/archiveStore/utils/archiveBlocks.d.ts.map +1 -1
  22. package/lib/chain/archiveStore/utils/archiveBlocks.js +61 -97
  23. package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
  24. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  25. package/lib/chain/blocks/importBlock.js +6 -5
  26. package/lib/chain/blocks/importBlock.js.map +1 -1
  27. package/lib/chain/blocks/importExecutionPayload.d.ts +6 -11
  28. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  29. package/lib/chain/blocks/importExecutionPayload.js +8 -15
  30. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  31. package/lib/chain/blocks/index.js +2 -2
  32. package/lib/chain/blocks/index.js.map +1 -1
  33. package/lib/chain/blocks/payloadEnvelopeProcessor.d.ts +12 -9
  34. package/lib/chain/blocks/payloadEnvelopeProcessor.d.ts.map +1 -1
  35. package/lib/chain/blocks/payloadEnvelopeProcessor.js +24 -19
  36. package/lib/chain/blocks/payloadEnvelopeProcessor.js.map +1 -1
  37. package/lib/chain/blocks/types.d.ts +4 -1
  38. package/lib/chain/blocks/types.d.ts.map +1 -1
  39. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  40. package/lib/chain/blocks/verifyBlock.js +18 -7
  41. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  42. package/lib/chain/blocks/verifyBlocksDataAvailability.d.ts.map +1 -1
  43. package/lib/chain/blocks/verifyBlocksDataAvailability.js +8 -1
  44. package/lib/chain/blocks/verifyBlocksDataAvailability.js.map +1 -1
  45. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  46. package/lib/chain/blocks/verifyBlocksSignatures.js +7 -5
  47. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  48. package/lib/chain/blocks/verifyPayloadsDataAvailability.d.ts +3 -3
  49. package/lib/chain/blocks/verifyPayloadsDataAvailability.d.ts.map +1 -1
  50. package/lib/chain/blocks/verifyPayloadsDataAvailability.js +11 -6
  51. package/lib/chain/blocks/verifyPayloadsDataAvailability.js.map +1 -1
  52. package/lib/chain/bls/interface.d.ts +2 -0
  53. package/lib/chain/bls/interface.d.ts.map +1 -1
  54. package/lib/chain/bls/multithread/index.d.ts.map +1 -1
  55. package/lib/chain/bls/multithread/index.js +13 -11
  56. package/lib/chain/bls/multithread/index.js.map +1 -1
  57. package/lib/chain/bls/multithread/types.d.ts +1 -1
  58. package/lib/chain/bls/multithread/types.d.ts.map +1 -1
  59. package/lib/chain/bls/multithread/worker.js +1 -1
  60. package/lib/chain/bls/multithread/worker.js.map +1 -1
  61. package/lib/chain/bls/singleThread.js +1 -1
  62. package/lib/chain/bls/singleThread.js.map +1 -1
  63. package/lib/chain/bls/utils.js +1 -1
  64. package/lib/chain/bls/utils.js.map +1 -1
  65. package/lib/chain/chain.d.ts +1 -1
  66. package/lib/chain/chain.d.ts.map +1 -1
  67. package/lib/chain/chain.js +4 -4
  68. package/lib/chain/chain.js.map +1 -1
  69. package/lib/chain/errors/blockError.d.ts +1 -1
  70. package/lib/chain/errors/blockError.d.ts.map +1 -1
  71. package/lib/chain/errors/blockError.js +1 -1
  72. package/lib/chain/errors/blockError.js.map +1 -1
  73. package/lib/chain/interface.d.ts +2 -3
  74. package/lib/chain/interface.d.ts.map +1 -1
  75. package/lib/chain/interface.js.map +1 -1
  76. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  77. package/lib/chain/opPools/aggregatedAttestationPool.js +23 -10
  78. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  79. package/lib/chain/opPools/attestationPool.d.ts +1 -1
  80. package/lib/chain/opPools/attestationPool.d.ts.map +1 -1
  81. package/lib/chain/opPools/attestationPool.js +15 -4
  82. package/lib/chain/opPools/attestationPool.js.map +1 -1
  83. package/lib/chain/opPools/payloadAttestationPool.d.ts.map +1 -1
  84. package/lib/chain/opPools/payloadAttestationPool.js +17 -7
  85. package/lib/chain/opPools/payloadAttestationPool.js.map +1 -1
  86. package/lib/chain/opPools/syncCommitteeMessagePool.d.ts.map +1 -1
  87. package/lib/chain/opPools/syncCommitteeMessagePool.js +9 -3
  88. package/lib/chain/opPools/syncCommitteeMessagePool.js.map +1 -1
  89. package/lib/chain/opPools/syncContributionAndProofPool.d.ts.map +1 -1
  90. package/lib/chain/opPools/syncContributionAndProofPool.js +11 -3
  91. package/lib/chain/opPools/syncContributionAndProofPool.js.map +1 -1
  92. package/lib/chain/opPools/utils.d.ts +1 -1
  93. package/lib/chain/opPools/utils.d.ts.map +1 -1
  94. package/lib/chain/opPools/utils.js +1 -1
  95. package/lib/chain/opPools/utils.js.map +1 -1
  96. package/lib/chain/options.d.ts +0 -1
  97. package/lib/chain/options.d.ts.map +1 -1
  98. package/lib/chain/options.js +0 -1
  99. package/lib/chain/options.js.map +1 -1
  100. package/lib/chain/validation/executionPayloadBid.js +13 -13
  101. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  102. package/lib/db/beacon.d.ts +7 -0
  103. package/lib/db/beacon.d.ts.map +1 -1
  104. package/lib/db/beacon.js +34 -0
  105. package/lib/db/beacon.js.map +1 -1
  106. package/lib/db/dataColumnStore.d.ts +1 -1
  107. package/lib/db/dataColumnStore.d.ts.map +1 -1
  108. package/lib/db/dataColumnStore.js +1 -4
  109. package/lib/db/dataColumnStore.js.map +1 -1
  110. package/lib/db/flatFileStore/flatFileStore.js +5 -5
  111. package/lib/db/flatFileStore/flatFileStore.js.map +1 -1
  112. package/lib/db/flatFileStore/slotIndex.d.ts.map +1 -1
  113. package/lib/db/flatFileStore/slotIndex.js +2 -2
  114. package/lib/db/flatFileStore/slotIndex.js.map +1 -1
  115. package/lib/db/interface.d.ts +1 -0
  116. package/lib/db/interface.d.ts.map +1 -1
  117. package/lib/db/repositories/dataColumnSidecarArchive.d.ts +6 -0
  118. package/lib/db/repositories/dataColumnSidecarArchive.d.ts.map +1 -1
  119. package/lib/db/repositories/dataColumnSidecarArchive.js +19 -0
  120. package/lib/db/repositories/dataColumnSidecarArchive.js.map +1 -1
  121. package/lib/execution/builder/apiClient.d.ts +14 -8
  122. package/lib/execution/builder/apiClient.d.ts.map +1 -1
  123. package/lib/execution/builder/apiClient.js +12 -10
  124. package/lib/execution/builder/apiClient.js.map +1 -1
  125. package/lib/execution/builder/http.d.ts +2 -0
  126. package/lib/execution/builder/http.d.ts.map +1 -1
  127. package/lib/execution/builder/http.js +2 -0
  128. package/lib/execution/builder/http.js.map +1 -1
  129. package/lib/execution/engine/index.d.ts +1 -1
  130. package/lib/execution/engine/index.d.ts.map +1 -1
  131. package/lib/execution/engine/index.js +1 -1
  132. package/lib/execution/engine/index.js.map +1 -1
  133. package/lib/execution/engine/interface.d.ts +1 -1
  134. package/lib/execution/engine/interface.d.ts.map +1 -1
  135. package/lib/execution/engine/interface.js.map +1 -1
  136. package/lib/execution/engine/types.d.ts.map +1 -1
  137. package/lib/execution/engine/types.js +2 -2
  138. package/lib/execution/engine/types.js.map +1 -1
  139. package/lib/index.d.ts +1 -0
  140. package/lib/index.d.ts.map +1 -1
  141. package/lib/index.js +2 -0
  142. package/lib/index.js.map +1 -1
  143. package/lib/metrics/metrics/lodestar.d.ts +4 -0
  144. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  145. package/lib/metrics/metrics/lodestar.js +10 -0
  146. package/lib/metrics/metrics/lodestar.js.map +1 -1
  147. package/lib/metrics/server/http.js +5 -5
  148. package/lib/metrics/server/http.js.map +1 -1
  149. package/lib/monitoring/service.js +1 -1
  150. package/lib/monitoring/service.js.map +1 -1
  151. package/lib/network/core/networkCore.d.ts +2 -0
  152. package/lib/network/core/networkCore.d.ts.map +1 -1
  153. package/lib/network/core/networkCore.js +3 -0
  154. package/lib/network/core/networkCore.js.map +1 -1
  155. package/lib/network/core/networkCoreWorker.js +1 -0
  156. package/lib/network/core/networkCoreWorker.js.map +1 -1
  157. package/lib/network/core/networkCoreWorkerHandler.d.ts +2 -0
  158. package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -1
  159. package/lib/network/core/networkCoreWorkerHandler.js +3 -0
  160. package/lib/network/core/networkCoreWorkerHandler.js.map +1 -1
  161. package/lib/network/core/types.d.ts +2 -0
  162. package/lib/network/core/types.d.ts.map +1 -1
  163. package/lib/network/interface.d.ts +2 -0
  164. package/lib/network/interface.d.ts.map +1 -1
  165. package/lib/network/libp2p/index.d.ts.map +1 -1
  166. package/lib/network/libp2p/index.js +5 -1
  167. package/lib/network/libp2p/index.js.map +1 -1
  168. package/lib/network/network.d.ts +2 -0
  169. package/lib/network/network.d.ts.map +1 -1
  170. package/lib/network/network.js +6 -1
  171. package/lib/network/network.js.map +1 -1
  172. package/lib/network/options.d.ts +2 -0
  173. package/lib/network/options.d.ts.map +1 -1
  174. package/lib/network/options.js.map +1 -1
  175. package/lib/network/peers/peerManager.d.ts +2 -1
  176. package/lib/network/peers/peerManager.d.ts.map +1 -1
  177. package/lib/network/peers/peerManager.js.map +1 -1
  178. package/lib/network/peers/utils/assertPeerRelevance.d.ts +9 -1
  179. package/lib/network/peers/utils/assertPeerRelevance.d.ts.map +1 -1
  180. package/lib/network/peers/utils/assertPeerRelevance.js +32 -21
  181. package/lib/network/peers/utils/assertPeerRelevance.js.map +1 -1
  182. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  183. package/lib/network/processor/gossipHandlers.js +9 -8
  184. package/lib/network/processor/gossipHandlers.js.map +1 -1
  185. package/lib/node/nodejs.d.ts +1 -1
  186. package/lib/node/nodejs.d.ts.map +1 -1
  187. package/lib/node/nodejs.js +11 -2
  188. package/lib/node/nodejs.js.map +1 -1
  189. package/lib/node/options.d.ts +3 -1
  190. package/lib/node/options.d.ts.map +1 -1
  191. package/lib/node/options.js +4 -2
  192. package/lib/node/options.js.map +1 -1
  193. package/lib/sync/interface.d.ts.map +1 -1
  194. package/lib/sync/interface.js.map +1 -1
  195. package/lib/sync/sync.d.ts +7 -0
  196. package/lib/sync/sync.d.ts.map +1 -1
  197. package/lib/sync/sync.js +61 -3
  198. package/lib/sync/sync.js.map +1 -1
  199. package/lib/util/file.d.ts.map +1 -1
  200. package/lib/util/file.js +8 -9
  201. package/lib/util/file.js.map +1 -1
  202. package/lib/util/queue/itemQueue.js +1 -1
  203. package/lib/util/queue/itemQueue.js.map +1 -1
  204. package/lib/util/sszBytes.js +2 -2
  205. package/lib/util/sszBytes.js.map +1 -1
  206. package/package.json +16 -17
  207. package/src/api/impl/beacon/blocks/index.ts +35 -45
  208. package/src/api/impl/beacon/pool/index.ts +5 -1
  209. package/src/api/impl/beacon/state/utils.ts +1 -1
  210. package/src/api/impl/validator/index.ts +47 -30
  211. package/src/chain/GetBlobsTracker.ts +97 -38
  212. package/src/chain/archiveStore/archiveStore.ts +1 -0
  213. package/src/chain/archiveStore/utils/archiveBlocks.ts +76 -130
  214. package/src/chain/blocks/importBlock.ts +8 -7
  215. package/src/chain/blocks/importExecutionPayload.ts +13 -21
  216. package/src/chain/blocks/index.ts +6 -2
  217. package/src/chain/blocks/payloadEnvelopeProcessor.ts +35 -24
  218. package/src/chain/blocks/types.ts +4 -1
  219. package/src/chain/blocks/verifyBlock.ts +31 -16
  220. package/src/chain/blocks/verifyBlocksDataAvailability.ts +10 -1
  221. package/src/chain/blocks/verifyBlocksSignatures.ts +7 -5
  222. package/src/chain/blocks/verifyPayloadsDataAvailability.ts +14 -6
  223. package/src/chain/bls/interface.ts +2 -0
  224. package/src/chain/bls/multithread/index.ts +14 -10
  225. package/src/chain/bls/multithread/types.ts +1 -1
  226. package/src/chain/bls/multithread/worker.ts +1 -5
  227. package/src/chain/bls/singleThread.ts +1 -1
  228. package/src/chain/bls/utils.ts +1 -1
  229. package/src/chain/chain.ts +5 -5
  230. package/src/chain/errors/blockError.ts +1 -1
  231. package/src/chain/interface.ts +2 -3
  232. package/src/chain/opPools/aggregatedAttestationPool.ts +25 -9
  233. package/src/chain/opPools/attestationPool.ts +16 -4
  234. package/src/chain/opPools/payloadAttestationPool.ts +18 -7
  235. package/src/chain/opPools/syncCommitteeMessagePool.ts +10 -3
  236. package/src/chain/opPools/syncContributionAndProofPool.ts +13 -3
  237. package/src/chain/opPools/utils.ts +1 -1
  238. package/src/chain/options.ts +0 -2
  239. package/src/chain/validation/executionPayloadBid.ts +14 -13
  240. package/src/db/beacon.ts +44 -0
  241. package/src/db/dataColumnStore.ts +2 -4
  242. package/src/db/flatFileStore/flatFileStore.ts +7 -7
  243. package/src/db/flatFileStore/slotIndex.ts +4 -3
  244. package/src/db/interface.ts +2 -0
  245. package/src/db/repositories/dataColumnSidecarArchive.ts +20 -0
  246. package/src/execution/builder/apiClient.ts +16 -13
  247. package/src/execution/builder/http.ts +4 -0
  248. package/src/execution/engine/index.ts +1 -1
  249. package/src/execution/engine/interface.ts +1 -1
  250. package/src/execution/engine/types.ts +3 -1
  251. package/src/index.ts +2 -0
  252. package/src/metrics/metrics/lodestar.ts +10 -0
  253. package/src/metrics/server/http.ts +5 -5
  254. package/src/monitoring/service.ts +1 -1
  255. package/src/network/core/networkCore.ts +5 -0
  256. package/src/network/core/networkCoreWorker.ts +1 -0
  257. package/src/network/core/networkCoreWorkerHandler.ts +4 -0
  258. package/src/network/core/types.ts +2 -0
  259. package/src/network/interface.ts +2 -0
  260. package/src/network/libp2p/index.ts +5 -1
  261. package/src/network/network.ts +8 -1
  262. package/src/network/options.ts +2 -0
  263. package/src/network/peers/peerManager.ts +1 -1
  264. package/src/network/peers/utils/assertPeerRelevance.ts +39 -23
  265. package/src/network/processor/gossipHandlers.ts +9 -8
  266. package/src/node/nodejs.ts +25 -7
  267. package/src/node/options.ts +9 -6
  268. package/src/sync/interface.ts +1 -0
  269. package/src/sync/sync.ts +65 -4
  270. package/src/util/file.ts +8 -9
  271. package/src/util/queue/itemQueue.ts +1 -1
  272. package/src/util/sszBytes.ts +2 -2
@@ -1,11 +1,18 @@
1
1
  import path from "node:path";
2
2
  import {ChainForkConfig} from "@lodestar/config";
3
3
  import {KeyValue} from "@lodestar/db";
4
- import {CheckpointWithHex, ExecutionStatus, IForkChoice, PayloadStatus, ProtoBlock} from "@lodestar/fork-choice";
4
+ import {
5
+ CheckpointWithHex,
6
+ ExecutionStatus,
7
+ IForkChoice,
8
+ PayloadStatus,
9
+ ProtoBlock,
10
+ isGloasBlock,
11
+ } from "@lodestar/fork-choice";
5
12
  import {ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params";
6
13
  import {computeEpochAtSlot, computeStartSlotAtEpoch, getBlobDataRetentionStartEpoch} from "@lodestar/state-transition";
7
14
  import {Epoch, Slot} from "@lodestar/types";
8
- import {Logger, fromAsync, fromHex, prettyPrintIndices, toRootHex} from "@lodestar/utils";
15
+ import {Logger, fromHex, prettyPrintIndices, toRootHex} from "@lodestar/utils";
9
16
  import {IBeaconDb} from "../../../db/index.js";
10
17
  import {BlockArchiveBatchPutBinaryItem, encodeArchivedHeaderEnvelope} from "../../../db/repositories/index.js";
11
18
  import {Metrics} from "../../../metrics/metrics.js";
@@ -49,6 +56,17 @@ async function persistOrphanedBlock(
49
56
  await writeIfNotExist(filepath, bytes);
50
57
  }
51
58
 
59
+ /**
60
+ * Oldest epoch for which data column sidecars are kept
61
+ */
62
+ export function getDataColumnSidecarsMinEpoch(
63
+ config: ChainForkConfig,
64
+ currentEpoch: Epoch,
65
+ archiveDataEpochs?: number
66
+ ): Epoch {
67
+ return Math.min(getBlobDataRetentionStartEpoch(config, currentEpoch), currentEpoch - (archiveDataEpochs ?? 0));
68
+ }
69
+
52
70
  /**
53
71
  * Archives finalized blocks from active bucket to archive bucket.
54
72
  *
@@ -136,23 +154,6 @@ export async function archiveBlocks(
136
154
  logger.verbose("Migrated blobSidecars from hot DB to cold DB", {...logCtx, migratedEntries});
137
155
  }
138
156
 
139
- // Keep the normal LevelDB hot-to-cold flow for legacy columns. New columns are written
140
- // directly to flat files, so this only moves fallback data left by older versions.
141
- if (finalizedPostFulu) {
142
- const migratedSlots = await migrateDataColumnSidecarsFromHotToColdDb(
143
- config,
144
- db,
145
- logger,
146
- finalizedCanonicalBlocks,
147
- currentEpoch
148
- );
149
- logger.verbose("Migrated legacy dataColumnSidecars from hot DB to cold DB", {
150
- ...logCtx,
151
- migratedEntries: migratedSlots.length,
152
- slotRange: prettyPrintIndices(migratedSlots),
153
- });
154
- }
155
-
156
157
  if (finalizedPostGloas) {
157
158
  const migratedSlots = await migrateExecutionPayloadEnvelopesFromHotToColdDb(
158
159
  config,
@@ -169,44 +170,34 @@ export async function archiveBlocks(
169
170
  }
170
171
  }
171
172
 
172
- // deleteNonCanonicalBlocks
173
- // loop through forkchoice single time
173
+ const canonicalRoots = new Set(finalizedCanonicalBlocks.map((block) => block.blockRoot));
174
+ const orphanedBlocks: ProtoBlock[] = [];
175
+ const orphanedPayloads: ProtoBlock[] = [];
174
176
 
175
- const nonCanonicalBlockRoots = finalizedNonCanonicalBlocks.map((summary) => fromHex(summary.blockRoot));
176
- if (nonCanonicalBlockRoots.length > 0) {
177
- if (persistOrphanedBlocks) {
178
- // Persist orphaned blocks to disk before deleting them from hot db
179
- await Promise.all(
180
- nonCanonicalBlockRoots.map(async (root, index) => {
181
- const block = finalizedNonCanonicalBlocks[index];
182
- const blockBytes = await db.block.getBinary(root);
183
- const blockLogCtx = {slot: block.slot, root: block.blockRoot};
184
- if (blockBytes) {
185
- await persistOrphanedBlock(block.slot, block.blockRoot, blockBytes, {
186
- persistOrphanedBlocksDir: persistOrphanedBlocksDir ?? "orphaned_blocks",
187
- });
188
- logger.verbose("Persisted orphaned block", {...logCtx, ...blockLogCtx});
189
- } else {
190
- logger.warn("Tried to persist orphaned block but no block found", {...logCtx, ...blockLogCtx});
191
- }
192
- })
193
- );
177
+ for (const block of finalizedNonCanonicalBlocks) {
178
+ if (block.payloadStatus === PayloadStatus.FULL) {
179
+ orphanedPayloads.push(block);
194
180
  }
181
+ // Every Gloas block gets EMPTY before FULL. If only FULL survives pruning, an earlier archive run
182
+ // already handled the root's block-level data.
183
+ const isBlockNode = !isGloasBlock(block) || block.payloadStatus === PayloadStatus.EMPTY;
184
+ if (isBlockNode && !canonicalRoots.has(block.blockRoot)) {
185
+ orphanedBlocks.push(block);
186
+ }
187
+ }
188
+ const orphanedBlockRoots = orphanedBlocks.map((block) => fromHex(block.blockRoot));
195
189
 
196
- const nonCanonicalSlots = finalizedNonCanonicalBlocks.map((summary) => summary.slot).sort((a, b) => a - b);
197
- const nonCanonicalLogCtx = {
190
+ if (orphanedPayloads.length > 0) {
191
+ const orphanedPayloadRoots = orphanedPayloads.map((block) => fromHex(block.blockRoot));
192
+ const orphanedPayloadLogCtx = {
198
193
  ...logCtx,
199
- count: nonCanonicalBlockRoots.length,
200
- slotRange: prettyPrintIndices(nonCanonicalSlots),
194
+ count: orphanedPayloads.length,
195
+ slotRange: prettyPrintIndices(orphanedPayloads.map((block) => block.slot).sort((a, b) => a - b)),
201
196
  };
202
197
 
203
- const columnItems = finalizedNonCanonicalBlocks
204
- // Gloas EMPTY and FULL variants share a block root. EMPTY has no sidecars, so deleting by its root could
205
- // remove the canonical FULL variant's columns. Pre-Gloas blocks are always FULL.
206
- .filter(
207
- (summary) => config.getForkSeq(summary.slot) >= ForkSeq.fulu && summary.payloadStatus === PayloadStatus.FULL
208
- )
209
- .map((summary) => ({slot: summary.slot, blockRoot: summary.blockRoot}));
198
+ const columnItems = orphanedPayloads
199
+ .filter((block) => config.getForkSeq(block.slot) >= ForkSeq.fulu)
200
+ .map((block) => ({slot: block.slot, blockRoot: block.blockRoot}));
210
201
  if (columnItems.length > 0) {
211
202
  // Delete sidecars first so their block roots remain available to retry cleanup after a failure or crash.
212
203
  await db.dataColumns.deleteMany(columnItems);
@@ -217,20 +208,44 @@ export async function archiveBlocks(
217
208
  });
218
209
  }
219
210
 
220
- await db.block.batchDelete(nonCanonicalBlockRoots);
221
- logger.verbose("Deleted non canonical blocks from hot DB", nonCanonicalLogCtx);
222
-
223
211
  if (finalizedPostDeneb) {
224
- await db.blobSidecars.batchDelete(nonCanonicalBlockRoots);
225
- logger.verbose("Deleted non canonical blobSidecars from hot DB", nonCanonicalLogCtx);
212
+ await db.blobSidecars.batchDelete(orphanedPayloadRoots);
213
+ logger.verbose("Deleted non canonical blobSidecars from hot DB", orphanedPayloadLogCtx);
226
214
  }
227
215
 
228
216
  if (finalizedPostGloas) {
229
- await db.executionPayloadEnvelope.batchDelete(nonCanonicalBlockRoots);
230
- logger.verbose("Deleted non canonical executionPayloadEnvelopes from hot DB", nonCanonicalLogCtx);
217
+ await db.executionPayloadEnvelope.batchDelete(orphanedPayloadRoots);
218
+ logger.verbose("Deleted non canonical executionPayloadEnvelopes from hot DB", orphanedPayloadLogCtx);
231
219
  }
232
220
  }
233
221
 
222
+ if (orphanedBlocks.length > 0) {
223
+ if (persistOrphanedBlocks) {
224
+ // Persist orphaned blocks to disk before deleting them from hot db
225
+ await Promise.all(
226
+ orphanedBlocks.map(async (block) => {
227
+ const blockBytes = await db.block.getBinary(fromHex(block.blockRoot));
228
+ const blockLogCtx = {slot: block.slot, root: block.blockRoot};
229
+ if (blockBytes) {
230
+ await persistOrphanedBlock(block.slot, block.blockRoot, blockBytes, {
231
+ persistOrphanedBlocksDir: persistOrphanedBlocksDir ?? "orphaned_blocks",
232
+ });
233
+ logger.verbose("Persisted orphaned block", {...logCtx, ...blockLogCtx});
234
+ } else {
235
+ logger.debug("Tried to persist orphaned block but no block found", {...logCtx, ...blockLogCtx});
236
+ }
237
+ })
238
+ );
239
+ }
240
+
241
+ await db.block.batchDelete(orphanedBlockRoots);
242
+ logger.verbose("Deleted non canonical blocks from hot DB", {
243
+ ...logCtx,
244
+ count: orphanedBlocks.length,
245
+ slotRange: prettyPrintIndices(orphanedBlocks.map((block) => block.slot).sort((a, b) => a - b)),
246
+ });
247
+ }
248
+
234
249
  // Delete expired blobs
235
250
  // Keep only `[current_epoch - max(MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS, archiveDataEpochs)]`
236
251
  // if archiveDataEpochs set to Infinity do not prune`
@@ -256,10 +271,7 @@ export async function archiveBlocks(
256
271
  // Keep only `[min(compute_blob_data_retention_start_epoch(current_epoch), current_epoch - archiveDataEpochs)]`
257
272
  if (finalizedPostFulu) {
258
273
  if (archiveDataEpochs !== Infinity) {
259
- const dataColumnSidecarsMinEpoch = Math.min(
260
- getBlobDataRetentionStartEpoch(config, currentEpoch),
261
- currentEpoch - (archiveDataEpochs ?? 0)
262
- );
274
+ const dataColumnSidecarsMinEpoch = getDataColumnSidecarsMinEpoch(config, currentEpoch, archiveDataEpochs);
263
275
  if (dataColumnSidecarsMinEpoch >= config.FULU_FORK_EPOCH) {
264
276
  const columnsPruneSlot = computeStartSlotAtEpoch(dataColumnSidecarsMinEpoch);
265
277
  const prunedColumnSlots = await db.dataColumns.pruneBefore(columnsPruneSlot);
@@ -283,9 +295,9 @@ export async function archiveBlocks(
283
295
  }
284
296
  }
285
297
 
286
- // Prunning potential checkpoint data
298
+ // Pruning potential checkpoint data
287
299
  const finalizedCanonicalNonCheckpointBlocks = getNonCheckpointBlocks(finalizedCanonicalBlockRoots);
288
- const nonCheckpointBlockRoots: Uint8Array[] = [...nonCanonicalBlockRoots];
300
+ const nonCheckpointBlockRoots: Uint8Array[] = [...orphanedBlockRoots];
289
301
  for (const block of finalizedCanonicalNonCheckpointBlocks) {
290
302
  nonCheckpointBlockRoots.push(block.root);
291
303
  }
@@ -408,72 +420,6 @@ async function migrateBlobSidecarsFromHotToColdDb(
408
420
  return migratedWrappedBlobSidecars;
409
421
  }
410
422
 
411
- // TODO: This function can be simplified further by reducing layers of promises in a loop
412
- /**
413
- * Post-gloas the data columns of a Gloas block are tied to its execution payload envelope.
414
- * Columns only exist once the FULL variant of the block is in the proto-array. Pre-Gloas
415
- * blocks only have a FULL variant, so the payload-status filter passes them all.
416
- */
417
- async function migrateDataColumnSidecarsFromHotToColdDb(
418
- config: ChainForkConfig,
419
- db: IBeaconDb,
420
- logger: Logger,
421
- canonicalBlocks: ProtoBlock[],
422
- currentEpoch: Epoch
423
- ): Promise<Slot[]> {
424
- const columnBlocks = canonicalBlocks.filter(
425
- (block) => config.getForkSeq(block.slot) < ForkSeq.gloas || block.payloadStatus === PayloadStatus.FULL
426
- );
427
- if (columnBlocks.length === 0) return [];
428
- const blocks: BlockRootSlot[] = columnBlocks.map((block) => ({slot: block.slot, root: fromHex(block.blockRoot)}));
429
-
430
- const migratedSlots: Slot[] = [];
431
- for (let i = 0; i < blocks.length; i += BLOB_SIDECAR_BATCH_SIZE) {
432
- const toIdx = Math.min(i + BLOB_SIDECAR_BATCH_SIZE, blocks.length);
433
- const batch = blocks.slice(i, toIdx);
434
- if (batch.length === 0) break;
435
-
436
- const promises: Promise<void>[] = [];
437
- for (const block of batch) {
438
- const blockEpoch = computeEpochAtSlot(block.slot);
439
- if (
440
- config.getForkSeq(block.slot) < ForkSeq.fulu ||
441
- blockEpoch < getBlobDataRetentionStartEpoch(config, currentEpoch)
442
- ) {
443
- continue;
444
- }
445
-
446
- const dataColumnSidecarBytes = await fromAsync(db.dataColumnSidecar.valuesStreamBinary(block.root));
447
- if (dataColumnSidecarBytes.length === 0) {
448
- logger.debug("DataColumnSidecars in forkchoice but missing in hot db, could be already archived", {
449
- slot: block.slot,
450
- root: toRootHex(block.root),
451
- });
452
- continue;
453
- }
454
- logger.verbose("Migrated legacy dataColumnSidecars for block", {
455
- currentEpoch,
456
- slot: block.slot,
457
- root: toRootHex(block.root),
458
- numSidecars: dataColumnSidecarBytes.length,
459
- });
460
- promises.push(
461
- db.dataColumnSidecarArchive.putManyBinary(
462
- block.slot,
463
- dataColumnSidecarBytes.map((entry) => ({key: entry.id, value: entry.value}))
464
- )
465
- );
466
- migratedSlots.push(block.slot);
467
- }
468
-
469
- await Promise.all(promises);
470
- await db.dataColumnSidecar.deleteMany(batch.map((block) => block.root));
471
- }
472
-
473
- // Ancestor walk is newest to oldest; sort ascending so `prettyPrintIndices` renders cleanly.
474
- return migratedSlots.sort((a, b) => a - b);
475
- }
476
-
477
423
  /**
478
424
  * Post-gloas given a finalized checkpoint at a block root, payload of that block root
479
425
  * is not considered finalized, hence they are archived in the next run.
@@ -21,7 +21,7 @@ import {
21
21
  IBeaconStateView,
22
22
  RootCache,
23
23
  computeEpochAtSlot,
24
- computeTimeAtSlot,
24
+ computeTimeAtSlotMs,
25
25
  getBeaconCommittees,
26
26
  isStatePostAltair,
27
27
  isStatePostBellatrix,
@@ -105,8 +105,9 @@ export async function importBlock(
105
105
  const currentEpoch = computeEpochAtSlot(currentSlot);
106
106
  const blockEpoch = computeEpochAtSlot(blockSlot);
107
107
  const prevFinalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
108
- const receiveDelaySec =
109
- fullyVerifiedBlock.seenTimestampSec - computeTimeAtSlot(this.config, blockSlot, postState.genesisTime);
108
+ const receiveDelayMs =
109
+ Math.round(fullyVerifiedBlock.seenTimestampSec * 1000) -
110
+ computeTimeAtSlotMs(this.config, blockSlot, postState.genesisTime * 1000);
110
111
  const recvToValLatency = Date.now() / 1000 - (opts.seenTimestampSec ?? Date.now() / 1000);
111
112
  const fork = this.config.getForkSeq(blockSlot);
112
113
 
@@ -148,12 +149,12 @@ export async function importBlock(
148
149
  executionStatus = parentBlock.executionStatus;
149
150
  }
150
151
 
151
- const importDelaySec = this.clock.secFromSlot(blockSlot);
152
+ const importDelayMs = this.clock.msFromSlot(blockSlot);
152
153
  const blockSummary = this.forkChoice.onBlock(
153
154
  block.message,
154
155
  postState,
155
- receiveDelaySec,
156
- importDelaySec,
156
+ receiveDelayMs,
157
+ importDelayMs,
157
158
  currentSlot,
158
159
  executionStatus,
159
160
  dataAvailabilityStatus
@@ -417,7 +418,7 @@ export async function importBlock(
417
418
  // 4) Block meets the criteria of being re-orged out (this is also checked inside the function)
418
419
  const result = this.forkChoice.shouldOverrideForkChoiceUpdate(
419
420
  blockSummary,
420
- this.clock.secFromSlot(currentSlot),
421
+ this.clock.msFromSlot(currentSlot),
421
422
  currentSlot
422
423
  );
423
424
  shouldOverrideFcu = result.shouldOverrideFcu;
@@ -26,7 +26,6 @@ import {
26
26
  verifyExecutionPayloadEnvelope,
27
27
  verifyExecutionPayloadEnvelopeSignature,
28
28
  } from "./verifyExecutionPayloadEnvelope.js";
29
- import {verifyPayloadsDataAvailability} from "./verifyPayloadsDataAvailability.js";
30
29
 
31
30
  const EVENTSTREAM_EMIT_RECENT_EXECUTION_PAYLOAD_SLOTS = 64;
32
31
 
@@ -37,6 +36,7 @@ export enum PayloadErrorCode {
37
36
  MISS_BLOCK_STATE = "PAYLOAD_ERROR_MISS_BLOCK_STATE",
38
37
  ENVELOPE_VERIFICATION_ERROR = "PAYLOAD_ERROR_ENVELOPE_VERIFICATION_ERROR",
39
38
  INVALID_SIGNATURE = "PAYLOAD_ERROR_INVALID_SIGNATURE",
39
+ DATA_UNAVAILABLE = "PAYLOAD_ERROR_DATA_UNAVAILABLE",
40
40
  }
41
41
 
42
42
  export type PayloadErrorType =
@@ -64,6 +64,9 @@ export type PayloadErrorType =
64
64
  }
65
65
  | {
66
66
  code: PayloadErrorCode.INVALID_SIGNATURE;
67
+ }
68
+ | {
69
+ code: PayloadErrorCode.DATA_UNAVAILABLE;
67
70
  };
68
71
 
69
72
  export class PayloadError extends Error {
@@ -95,7 +98,8 @@ function toForkChoiceExecutionStatus(status: ExecutionPayloadStatus): PayloadExe
95
98
  * are applied on the next block via processParentExecutionPayload.
96
99
  *
97
100
  * The DA wait must have run upstream (range sync awaits DA in `verifyBlocksInEpoch` for the
98
- * whole segment; gossip / API path uses the `processExecutionPayload` wrapper below).
101
+ * whole segment; the gossip / API / unknown-payload sync path waits in `PayloadEnvelopeProcessor`
102
+ * before the import is queued).
99
103
  *
100
104
  * Steps:
101
105
  * 1. Emit `execution_payload_available` event for payload attestation
@@ -329,7 +333,13 @@ export async function importExecutionPayload(
329
333
 
330
334
  // 7. Queue notifyForkchoiceUpdate to engine api
331
335
  const head = this.forkChoice.getHead();
332
- if (!this.opts.disableImportExecutionFcU && blockRootHex === head.blockRoot) {
336
+ if (
337
+ !this.opts.disableImportExecutionFcU &&
338
+ blockRootHex === head.blockRoot &&
339
+ // Skip a payload that does not satisfy the inclusion list constraints, fork choice keeps the EMPTY
340
+ // variant as head and the next prepare fcU keeps the engine on the parent payload
341
+ this.forkChoice.isPayloadInclusionListSatisfied(blockRootHex)
342
+ ) {
333
343
  const safeBlockHash = getSafeExecutionBlockHash(this.forkChoice, this.logger);
334
344
  const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice);
335
345
  this.executionEngine.notifyForkchoiceUpdate(fork, blockHashHex, safeBlockHash, finalizedBlockHash).catch((e) => {
@@ -368,21 +378,3 @@ export async function importExecutionPayload(
368
378
  delaySec,
369
379
  });
370
380
  }
371
-
372
- /**
373
- * Process an execution payload envelope end-to-end: wait for DA, then import.
374
- *
375
- * Used by the PayloadEnvelopeProcessor queue (gossip / API / unknown-payload sync) — i.e.
376
- * callers that have NOT already awaited DA themselves. Range sync's inline dispatch in
377
- * processBlocks skips this wrapper and calls `importExecutionPayload` directly, since
378
- * `verifyBlocksInEpoch` already awaited DA for the segment.
379
- */
380
- export async function processExecutionPayload(
381
- this: BeaconChain,
382
- payloadInput: PayloadEnvelopeInput,
383
- signal: AbortSignal,
384
- opts: ImportPayloadOpts = {}
385
- ): Promise<void> {
386
- const {dataAvailabilityStatuses} = await verifyPayloadsDataAvailability([payloadInput], signal);
387
- await importExecutionPayload.call(this, payloadInput, dataAvailabilityStatuses[0], opts);
388
- }
@@ -147,7 +147,7 @@ export async function processBlocks(
147
147
  proposerBalanceDelta: proposerBalanceDeltas[i],
148
148
  indexedAttestations: indexedAttestationsByBlock[i],
149
149
  // TODO: Make this param mandatory and capture in gossip
150
- seenTimestampSec: opts.seenTimestampSec ?? Math.floor(Date.now() / 1000),
150
+ seenTimestampSec: opts.seenTimestampSec ?? Date.now() / 1000,
151
151
  });
152
152
  }
153
153
 
@@ -292,7 +292,11 @@ async function importPayloadEnvelopesOfKnownBlocks(
292
292
  return result;
293
293
  }
294
294
 
295
- const {dataAvailabilityStatuses} = await verifyPayloadsDataAvailability(payloadInputs, new AbortController().signal);
295
+ const {dataAvailabilityStatuses} = await verifyPayloadsDataAvailability(
296
+ this.config,
297
+ payloadInputs,
298
+ new AbortController().signal
299
+ );
296
300
  for (let i = 0; i < payloadInputs.length; i++) {
297
301
  this.logger.debug("Importing payload envelope of known block", {
298
302
  slot: payloadInputs[i].slot,
@@ -1,32 +1,37 @@
1
+ import {DataAvailabilityStatus} from "@lodestar/state-transition";
1
2
  import {Metrics} from "../../metrics/metrics.js";
2
3
  import {JobItemQueue} from "../../util/queue/index.js";
3
4
  import type {BeaconChain} from "../chain.js";
4
5
  import {PayloadEnvelopeInput} from "../seenCache/seenPayloadEnvelopeInput.js";
5
- import {processExecutionPayload} from "./importExecutionPayload.js";
6
+ import {importExecutionPayload} from "./importExecutionPayload.js";
6
7
  import {ImportPayloadOpts} from "./types.js";
8
+ import {verifyPayloadsDataAvailability} from "./verifyPayloadsDataAvailability.js";
7
9
 
8
10
  // TODO GLOAS: Set to be equal to DEFAULT_MAX_PENDING_UNFINALIZED_PAYLOAD_ENVELOPE_WRITES for now
9
11
  const QUEUE_MAX_LENGTH = 16;
10
12
 
11
13
  /**
12
- * PayloadEnvelopeProcessor processes payload envelope jobs in a queued fashion, one after the other.
14
+ * PayloadEnvelopeProcessor imports payload envelopes in a queued fashion, one after the other.
13
15
  *
14
- * Jobs are enqueued only on envelope arrival (gossip or API). The envelope may reach us before
15
- * the sampled data columns; importExecutionPayload awaits `verifyPayloadsDataAvailability`
16
- * internally, so a queued job can pend for up to `PAYLOAD_DATA_AVAILABILITY_TIMEOUT` while
17
- * waiting for columns. Duplicate triggers for the same payloadInput are deduped by sharing the
18
- * in-flight import promise: every caller observes the real import outcome. Resolving duplicates
19
- * early instead would let BlockInputSync mark a still-pending payload as processed, re-queue it,
20
- * and spin re-processing the same root until OOM while the import is blocked (e.g. EL syncing).
16
+ * Jobs are triggered only on envelope arrival (gossip or API). The envelope may reach us before the
17
+ * sampled data columns, the data availability wait runs before the job is queued. Duplicate
18
+ * triggers for the same payloadInput are deduped by sharing the in-flight promise: every caller
19
+ * observes the real import outcome. Resolving duplicates early instead would let
20
+ * BlockInputSync mark a still-pending payload as processed, re-queue it, and spin re-processing
21
+ * the same root until OOM while the import is blocked (e.g. EL syncing).
21
22
  */
22
23
  export class PayloadEnvelopeProcessor {
23
- readonly jobQueue: JobItemQueue<[PayloadEnvelopeInput, ImportPayloadOpts], void>;
24
+ readonly jobQueue: JobItemQueue<[PayloadEnvelopeInput, DataAvailabilityStatus, ImportPayloadOpts], void>;
24
25
  private readonly imports = new WeakMap<PayloadEnvelopeInput, Promise<void>>();
25
26
 
26
- constructor(chain: BeaconChain, metrics: Metrics | null, signal: AbortSignal) {
27
- this.jobQueue = new JobItemQueue<[PayloadEnvelopeInput, ImportPayloadOpts], void>(
28
- (payloadInput, opts) => {
29
- return processExecutionPayload.call(chain, payloadInput, signal, opts);
27
+ constructor(
28
+ private readonly chain: BeaconChain,
29
+ metrics: Metrics | null,
30
+ private readonly signal: AbortSignal
31
+ ) {
32
+ this.jobQueue = new JobItemQueue<[PayloadEnvelopeInput, DataAvailabilityStatus, ImportPayloadOpts], void>(
33
+ (payloadInput, dataAvailabilityStatus, opts) => {
34
+ return importExecutionPayload.call(chain, payloadInput, dataAvailabilityStatus, opts);
30
35
  },
31
36
  {maxLength: QUEUE_MAX_LENGTH, noYieldIfOneItem: true, signal},
32
37
  metrics?.payloadEnvelopeProcessorQueue ?? undefined
@@ -35,19 +40,11 @@ export class PayloadEnvelopeProcessor {
35
40
 
36
41
  async processPayloadEnvelopeJob(payloadInput: PayloadEnvelopeInput, opts: ImportPayloadOpts = {}): Promise<void> {
37
42
  const existing = this.imports.get(payloadInput);
38
- if (existing) {
43
+ if (existing !== undefined) {
39
44
  return existing;
40
45
  }
41
46
 
42
- await this.jobQueue.waitForSpace();
43
-
44
- // Re-check after await, as another call may have queued this payload.
45
- const queued = this.imports.get(payloadInput);
46
- if (queued) {
47
- return queued;
48
- }
49
-
50
- const importPromise = this.jobQueue.push(payloadInput, opts);
47
+ const importPromise = this.waitForDataAndImport(payloadInput, opts);
51
48
  this.imports.set(payloadInput, importPromise);
52
49
 
53
50
  try {
@@ -59,4 +56,18 @@ export class PayloadEnvelopeProcessor {
59
56
  throw e;
60
57
  }
61
58
  }
59
+
60
+ private async waitForDataAndImport(payloadInput: PayloadEnvelopeInput, opts: ImportPayloadOpts): Promise<void> {
61
+ const {dataAvailabilityStatuses} = await verifyPayloadsDataAvailability(
62
+ this.chain.config,
63
+ [payloadInput],
64
+ this.signal
65
+ );
66
+
67
+ while (this.jobQueue.jobLen >= QUEUE_MAX_LENGTH) {
68
+ await this.jobQueue.waitForSpace();
69
+ }
70
+
71
+ return this.jobQueue.push(payloadInput, dataAvailabilityStatuses[0], opts);
72
+ }
62
73
  }
@@ -109,7 +109,10 @@ export type FullyVerifiedBlock = {
109
109
  parentBlockSlot: Slot;
110
110
  proposerBalanceDelta: number;
111
111
  dataAvailabilityStatus: DataAvailabilityStatus;
112
- /** Pre-computed indexed attestations from signature verification to avoid duplicate work */
112
+ /**
113
+ * Pre-computed indexed attestations from signature verification to avoid duplicate work.
114
+ * Their `attestingIndices` are in committee order, not sorted, so they are not spec-valid `IndexedAttestation`s.
115
+ */
113
116
  indexedAttestations: IndexedAttestation[];
114
117
  /** Seen timestamp seconds */
115
118
  seenTimestampSec: number;
@@ -4,7 +4,7 @@ import {
4
4
  DataAvailabilityStatus,
5
5
  IBeaconStateView,
6
6
  computeEpochAtSlot,
7
- getIndexedAttestation,
7
+ getAttestingIndices,
8
8
  signedBlockToSignedHeader,
9
9
  } from "@lodestar/state-transition";
10
10
  import {IndexedAttestation, Slot, deneb} from "@lodestar/types";
@@ -119,7 +119,13 @@ export async function verifyBlocksInEpoch(
119
119
  const shuffling =
120
120
  this.shufflingCache.getSync(attEpoch, preState0.getShufflingDecisionRoot(attEpoch)) ??
121
121
  preState0.getShufflingAtEpoch(attEpoch);
122
- return getIndexedAttestation(shuffling, fork, attestation);
122
+ // Unlike getIndexedAttestation, keep attestingIndices in committee order: sorting them dominates building
123
+ // these on mainnet blocks. See FullyVerifiedBlock.indexedAttestations.
124
+ return {
125
+ attestingIndices: getAttestingIndices(shuffling, fork, attestation),
126
+ data: attestation.data,
127
+ signature: attestation.signature,
128
+ };
123
129
  });
124
130
  }
125
131
 
@@ -143,6 +149,7 @@ export async function verifyBlocksInEpoch(
143
149
  ? Array.from(payloadEnvelopes.values()).filter((payloadInput) => payloadInput.hasPayloadEnvelope())
144
150
  : [];
145
151
  const {dataAvailabilityStatuses, availableTime} = await verifyPayloadsDataAvailability(
152
+ this.config,
146
153
  payloadInputsForDa,
147
154
  abortController.signal
148
155
  );
@@ -174,16 +181,29 @@ export async function verifyBlocksInEpoch(
174
181
  const [
175
182
  segmentExecStatus,
176
183
  {blockDAStatuses, payloadDAStatuses, availableTime},
177
- {postStates, proposerBalanceDeltas, verifyStateTime},
178
184
  {verifySignaturesTime},
185
+ {postStates, proposerBalanceDeltas, verifyStateTime},
179
186
  ] = await Promise.all([
180
187
  verifyExecutionPayloadsPromise,
181
188
 
182
189
  // data availability (fork-specific; see daAvailabilityPromise above)
183
190
  daAvailabilityPromise,
184
191
 
192
+ // All signatures at once. Must be called before verifyBlocksStateTransitionOnly()
193
+ // so we hand the BLS job to the worker pool before the main thread
194
+ // is busy with the state transition.
195
+ verifyBlocksSignatures(
196
+ this.config,
197
+ this.bls,
198
+ this.logger,
199
+ this.metrics,
200
+ preState0,
201
+ blocks,
202
+ indexedAttestationsByBlock,
203
+ opts
204
+ ),
205
+
185
206
  // Run state transition only
186
- // TODO: Ensure it yields to allow flushing to workers and engine API
187
207
  verifyBlocksStateTransitionOnly(
188
208
  preState0,
189
209
  blockInputs,
@@ -197,22 +217,17 @@ export async function verifyBlocksInEpoch(
197
217
  opts
198
218
  ),
199
219
 
200
- // All signatures at once
201
- verifyBlocksSignatures(
202
- this.config,
203
- this.bls,
204
- this.logger,
205
- this.metrics,
206
- preState0,
207
- blocks,
208
- indexedAttestationsByBlock,
209
- opts
210
- ),
211
-
212
220
  // TODO GLOAS: can verify payload signatures in batch too
213
221
  // maybe chain with the above verifyBlocksSignatures()
214
222
  ]);
215
223
 
224
+ if (blockInputs.length === 1 && opts.seenTimestampSec !== undefined) {
225
+ const consensusVerifiedTime = Math.max(verifyStateTime, verifySignaturesTime);
226
+ this.metrics?.gossipBlock.receivedToConsensusVerifiedTime.observe(
227
+ consensusVerifiedTime / 1000 - opts.seenTimestampSec
228
+ );
229
+ }
230
+
216
231
  for (const blockInput of blockInputs) {
217
232
  const block = blockInput.getBlock();
218
233
  const {slot, proposerIndex} = block.message;
@@ -1,4 +1,6 @@
1
1
  import {DataAvailabilityStatus} from "@lodestar/state-transition";
2
+ import {TimeoutError} from "@lodestar/utils";
3
+ import {BlockError, BlockErrorCode} from "../errors/index.js";
2
4
  import {DAData, DAType, IBlockInput} from "./blockInput/index.js";
3
5
 
4
6
  // we can now wait for full 12 seconds because unavailable block sync will try pulling
@@ -22,7 +24,14 @@ export async function verifyBlocksDataAvailability(
22
24
  for (const blockInput of blocks) {
23
25
  // block verification is triggered on a verified gossip block so we only need to wait for all data
24
26
  if (!blockInput.hasAllData()) {
25
- promises.push(blockInput.waitForAllData(BLOB_AVAILABILITY_TIMEOUT, signal));
27
+ promises.push(
28
+ blockInput.waitForAllData(BLOB_AVAILABILITY_TIMEOUT, signal).catch((e) => {
29
+ if (e instanceof TimeoutError) {
30
+ throw new BlockError(blockInput.getBlock(), {code: BlockErrorCode.DATA_UNAVAILABLE});
31
+ }
32
+ throw e;
33
+ })
34
+ );
26
35
  }
27
36
  }
28
37
  await Promise.all(promises);
@@ -36,10 +36,9 @@ export async function verifyBlocksSignatures(
36
36
  ? preState0.currentSyncCommitteeIndexed
37
37
  : new SyncCommitteeCacheEmpty();
38
38
 
39
- // Verifies signatures after running state transition, so all SyncCommittee signed roots are known at this point.
40
- // We must ensure block.slot <= state.slot before running getAllBlockSignatureSets().
41
- // NOTE: If in the future multiple blocks signatures are verified at once, all blocks must be in the same epoch
42
- // so the attester and proposer shufflings are correct.
39
+ // Runs concurrently with the state transition. Signature sets are built from preState0, which
40
+ // verifyBlocksInEpoch() guarantees is in the same epoch as every block, so the proposer and attester shufflings
41
+ // and the sync committee are the ones the blocks were signed under.
43
42
  for (const [i, block] of blocks.entries()) {
44
43
  // Use [i] to make clear that the index has to be correct to blame the right block below on BlockError()
45
44
  isValidPromises[i] = opts.validSignatures
@@ -50,7 +49,10 @@ export async function verifyBlocksSignatures(
50
49
  bls.verifySignatureSets(
51
50
  getBlockSignatureSets(config, currentSyncCommitteeIndexed, preState0, block, indexedAttestationsByBlock[i], {
52
51
  skipProposerSignature: opts.validProposerSignature,
53
- })
52
+ }),
53
+ // Prioritize block verification over attestations, since
54
+ // attestations already buffer up to `MAX_BUFFER_WAIT_MS`
55
+ {priority: true}
54
56
  );
55
57
 
56
58
  // getBlockSignatureSets() takes 45ms in benchmarks for 2022Q2 mainnet blocks (100 sigs). When syncing a 32 blocks