@lodestar/beacon-node 1.47.0-dev.931ecbec99 → 1.47.0-dev.9ba9a5ce85

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 (236) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +44 -12
  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 +21 -2
  6. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  7. package/lib/api/impl/events/index.d.ts.map +1 -1
  8. package/lib/api/impl/events/index.js +2 -0
  9. package/lib/api/impl/events/index.js.map +1 -1
  10. package/lib/api/impl/lodestar/index.js +1 -1
  11. package/lib/api/impl/lodestar/index.js.map +1 -1
  12. package/lib/api/impl/validator/index.d.ts.map +1 -1
  13. package/lib/api/impl/validator/index.js +237 -49
  14. package/lib/api/impl/validator/index.js.map +1 -1
  15. package/lib/api/impl/validator/utils.js +1 -1
  16. package/lib/api/impl/validator/utils.js.map +1 -1
  17. package/lib/api/rest/base.d.ts.map +1 -1
  18. package/lib/api/rest/base.js +7 -0
  19. package/lib/api/rest/base.js.map +1 -1
  20. package/lib/chain/archiveStore/archiveStore.js +1 -1
  21. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  22. package/lib/chain/blocks/importExecutionPayload.d.ts +3 -2
  23. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  24. package/lib/chain/blocks/importExecutionPayload.js +10 -8
  25. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  26. package/lib/chain/blocks/index.d.ts.map +1 -1
  27. package/lib/chain/blocks/index.js +21 -13
  28. package/lib/chain/blocks/index.js.map +1 -1
  29. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.d.ts +2 -1
  30. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.d.ts.map +1 -1
  31. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js +6 -2
  32. package/lib/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js.map +1 -1
  33. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +14 -5
  34. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
  35. package/lib/chain/blocks/payloadEnvelopeInput/types.js +5 -0
  36. package/lib/chain/blocks/payloadEnvelopeInput/types.js.map +1 -1
  37. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  38. package/lib/chain/blocks/verifyBlock.js +5 -2
  39. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  40. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
  41. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +22 -12
  42. package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
  43. package/lib/chain/chain.d.ts +7 -3
  44. package/lib/chain/chain.d.ts.map +1 -1
  45. package/lib/chain/chain.js +16 -4
  46. package/lib/chain/chain.js.map +1 -1
  47. package/lib/chain/errors/blockError.d.ts +1 -0
  48. package/lib/chain/errors/blockError.d.ts.map +1 -1
  49. package/lib/chain/errors/blockError.js +6 -1
  50. package/lib/chain/errors/blockError.js.map +1 -1
  51. package/lib/chain/errors/executionPayloadBid.d.ts +5 -0
  52. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
  53. package/lib/chain/errors/executionPayloadBid.js +1 -0
  54. package/lib/chain/errors/executionPayloadBid.js.map +1 -1
  55. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  56. package/lib/chain/forkChoice/index.js +4 -0
  57. package/lib/chain/forkChoice/index.js.map +1 -1
  58. package/lib/chain/interface.d.ts +6 -3
  59. package/lib/chain/interface.d.ts.map +1 -1
  60. package/lib/chain/interface.js.map +1 -1
  61. package/lib/chain/opPools/deferredVoluntaryExitPool.d.ts +16 -0
  62. package/lib/chain/opPools/deferredVoluntaryExitPool.d.ts.map +1 -0
  63. package/lib/chain/opPools/deferredVoluntaryExitPool.js +57 -0
  64. package/lib/chain/opPools/deferredVoluntaryExitPool.js.map +1 -0
  65. package/lib/chain/opPools/executionPayloadBidPool.d.ts +7 -2
  66. package/lib/chain/opPools/executionPayloadBidPool.d.ts.map +1 -1
  67. package/lib/chain/opPools/executionPayloadBidPool.js +4 -4
  68. package/lib/chain/opPools/executionPayloadBidPool.js.map +1 -1
  69. package/lib/chain/opPools/index.d.ts +2 -1
  70. package/lib/chain/opPools/index.d.ts.map +1 -1
  71. package/lib/chain/opPools/index.js +1 -0
  72. package/lib/chain/opPools/index.js.map +1 -1
  73. package/lib/chain/prepareNextSlot.d.ts +5 -0
  74. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  75. package/lib/chain/prepareNextSlot.js +47 -6
  76. package/lib/chain/prepareNextSlot.js.map +1 -1
  77. package/lib/chain/produceBlock/computeNewStateRoot.d.ts.map +1 -1
  78. package/lib/chain/produceBlock/computeNewStateRoot.js +3 -25
  79. package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
  80. package/lib/chain/produceBlock/produceBlockBody.js +1 -1
  81. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  82. package/lib/chain/regen/interface.d.ts +5 -2
  83. package/lib/chain/regen/interface.d.ts.map +1 -1
  84. package/lib/chain/regen/interface.js +3 -0
  85. package/lib/chain/regen/interface.js.map +1 -1
  86. package/lib/chain/regen/queued.d.ts +2 -2
  87. package/lib/chain/regen/queued.d.ts.map +1 -1
  88. package/lib/chain/regen/queued.js +5 -5
  89. package/lib/chain/regen/queued.js.map +1 -1
  90. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +28 -1
  91. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
  92. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +121 -13
  93. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
  94. package/lib/chain/stateCache/fifoBlockStateCache.d.ts +5 -1
  95. package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -1
  96. package/lib/chain/stateCache/fifoBlockStateCache.js +6 -0
  97. package/lib/chain/stateCache/fifoBlockStateCache.js.map +1 -1
  98. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +47 -5
  99. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  100. package/lib/chain/stateCache/persistentCheckpointsCache.js +117 -7
  101. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  102. package/lib/chain/stateCache/types.d.ts +3 -3
  103. package/lib/chain/stateCache/types.d.ts.map +1 -1
  104. package/lib/chain/validation/block.d.ts.map +1 -1
  105. package/lib/chain/validation/block.js +40 -10
  106. package/lib/chain/validation/block.js.map +1 -1
  107. package/lib/chain/validation/executionPayloadBid.d.ts +15 -3
  108. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  109. package/lib/chain/validation/executionPayloadBid.js +165 -10
  110. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  111. package/lib/chain/validation/voluntaryExit.d.ts +9 -1
  112. package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
  113. package/lib/chain/validation/voluntaryExit.js +46 -1
  114. package/lib/chain/validation/voluntaryExit.js.map +1 -1
  115. package/lib/execution/builder/apiClient.d.ts +70 -0
  116. package/lib/execution/builder/apiClient.d.ts.map +1 -0
  117. package/lib/execution/builder/apiClient.js +202 -0
  118. package/lib/execution/builder/apiClient.js.map +1 -0
  119. package/lib/execution/builder/validateBid.d.ts +23 -0
  120. package/lib/execution/builder/validateBid.d.ts.map +1 -0
  121. package/lib/execution/builder/validateBid.js +119 -0
  122. package/lib/execution/builder/validateBid.js.map +1 -0
  123. package/lib/metrics/metrics/lodestar.d.ts +46 -5
  124. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  125. package/lib/metrics/metrics/lodestar.js +81 -5
  126. package/lib/metrics/metrics/lodestar.js.map +1 -1
  127. package/lib/network/gossip/topic.d.ts +13 -0
  128. package/lib/network/gossip/topic.d.ts.map +1 -1
  129. package/lib/network/gossip/topic.js +37 -0
  130. package/lib/network/gossip/topic.js.map +1 -1
  131. package/lib/network/network.d.ts.map +1 -1
  132. package/lib/network/network.js +23 -43
  133. package/lib/network/network.js.map +1 -1
  134. package/lib/network/processor/constants.d.ts +7 -0
  135. package/lib/network/processor/constants.d.ts.map +1 -0
  136. package/lib/network/processor/constants.js +7 -0
  137. package/lib/network/processor/constants.js.map +1 -0
  138. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  139. package/lib/network/processor/gossipHandlers.js +6 -2
  140. package/lib/network/processor/gossipHandlers.js.map +1 -1
  141. package/lib/network/processor/gossipQueues/indexed.d.ts.map +1 -1
  142. package/lib/network/processor/gossipQueues/indexed.js +0 -1
  143. package/lib/network/processor/gossipQueues/indexed.js.map +1 -1
  144. package/lib/network/processor/index.d.ts +3 -0
  145. package/lib/network/processor/index.d.ts.map +1 -1
  146. package/lib/network/processor/index.js +52 -23
  147. package/lib/network/processor/index.js.map +1 -1
  148. package/lib/network/util.d.ts +0 -1
  149. package/lib/network/util.d.ts.map +1 -1
  150. package/lib/network/util.js +0 -4
  151. package/lib/network/util.js.map +1 -1
  152. package/lib/node/deferredVoluntaryExitPublisher.d.ts +15 -0
  153. package/lib/node/deferredVoluntaryExitPublisher.d.ts.map +1 -0
  154. package/lib/node/deferredVoluntaryExitPublisher.js +38 -0
  155. package/lib/node/deferredVoluntaryExitPublisher.js.map +1 -0
  156. package/lib/node/nodejs.d.ts.map +1 -1
  157. package/lib/node/nodejs.js +7 -0
  158. package/lib/node/nodejs.js.map +1 -1
  159. package/lib/sync/range/batch.d.ts +23 -5
  160. package/lib/sync/range/batch.d.ts.map +1 -1
  161. package/lib/sync/range/batch.js +61 -22
  162. package/lib/sync/range/batch.js.map +1 -1
  163. package/lib/sync/range/chain.d.ts +2 -1
  164. package/lib/sync/range/chain.d.ts.map +1 -1
  165. package/lib/sync/range/chain.js +32 -12
  166. package/lib/sync/range/chain.js.map +1 -1
  167. package/lib/sync/range/range.js +1 -1
  168. package/lib/sync/range/range.js.map +1 -1
  169. package/lib/sync/types.d.ts +32 -0
  170. package/lib/sync/types.d.ts.map +1 -1
  171. package/lib/sync/types.js +33 -0
  172. package/lib/sync/types.js.map +1 -1
  173. package/lib/sync/unknownBlock.d.ts +6 -2
  174. package/lib/sync/unknownBlock.d.ts.map +1 -1
  175. package/lib/sync/unknownBlock.js +143 -68
  176. package/lib/sync/unknownBlock.js.map +1 -1
  177. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  178. package/lib/sync/utils/downloadByRange.js +16 -11
  179. package/lib/sync/utils/downloadByRange.js.map +1 -1
  180. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  181. package/lib/sync/utils/downloadByRoot.js +3 -1
  182. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  183. package/package.json +34 -34
  184. package/src/api/impl/beacon/blocks/index.ts +51 -15
  185. package/src/api/impl/beacon/pool/index.ts +22 -2
  186. package/src/api/impl/events/index.ts +3 -1
  187. package/src/api/impl/lodestar/index.ts +1 -1
  188. package/src/api/impl/validator/index.ts +290 -49
  189. package/src/api/impl/validator/utils.ts +1 -1
  190. package/src/api/rest/base.ts +7 -0
  191. package/src/chain/archiveStore/archiveStore.ts +1 -1
  192. package/src/chain/blocks/importExecutionPayload.ts +12 -10
  193. package/src/chain/blocks/index.ts +25 -13
  194. package/src/chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.ts +8 -2
  195. package/src/chain/blocks/payloadEnvelopeInput/types.ts +17 -4
  196. package/src/chain/blocks/verifyBlock.ts +5 -2
  197. package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +25 -16
  198. package/src/chain/chain.ts +18 -2
  199. package/src/chain/errors/blockError.ts +8 -2
  200. package/src/chain/errors/executionPayloadBid.ts +6 -0
  201. package/src/chain/forkChoice/index.ts +4 -0
  202. package/src/chain/interface.ts +6 -2
  203. package/src/chain/opPools/deferredVoluntaryExitPool.ts +65 -0
  204. package/src/chain/opPools/executionPayloadBidPool.ts +13 -7
  205. package/src/chain/opPools/index.ts +2 -1
  206. package/src/chain/prepareNextSlot.ts +49 -6
  207. package/src/chain/produceBlock/computeNewStateRoot.ts +3 -38
  208. package/src/chain/produceBlock/produceBlockBody.ts +1 -1
  209. package/src/chain/regen/interface.ts +5 -2
  210. package/src/chain/regen/queued.ts +5 -5
  211. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +143 -14
  212. package/src/chain/stateCache/fifoBlockStateCache.ts +8 -1
  213. package/src/chain/stateCache/persistentCheckpointsCache.ts +133 -8
  214. package/src/chain/stateCache/types.ts +3 -3
  215. package/src/chain/validation/block.ts +43 -10
  216. package/src/chain/validation/executionPayloadBid.ts +192 -12
  217. package/src/chain/validation/voluntaryExit.ts +59 -2
  218. package/src/execution/builder/apiClient.ts +264 -0
  219. package/src/execution/builder/validateBid.ts +181 -0
  220. package/src/metrics/metrics/lodestar.ts +91 -10
  221. package/src/network/gossip/topic.ts +38 -0
  222. package/src/network/network.ts +29 -54
  223. package/src/network/processor/constants.ts +6 -0
  224. package/src/network/processor/gossipHandlers.ts +6 -2
  225. package/src/network/processor/gossipQueues/indexed.ts +0 -1
  226. package/src/network/processor/index.ts +67 -30
  227. package/src/network/util.ts +0 -5
  228. package/src/node/deferredVoluntaryExitPublisher.ts +54 -0
  229. package/src/node/nodejs.ts +8 -0
  230. package/src/sync/range/batch.ts +83 -28
  231. package/src/sync/range/chain.ts +35 -13
  232. package/src/sync/range/range.ts +1 -1
  233. package/src/sync/types.ts +33 -0
  234. package/src/sync/unknownBlock.ts +167 -73
  235. package/src/sync/utils/downloadByRange.ts +21 -12
  236. package/src/sync/utils/downloadByRoot.ts +3 -1
@@ -9,6 +9,7 @@ import {
9
9
  ColumnWithSource,
10
10
  CreateFromBidProps,
11
11
  CreateFromBlockProps,
12
+ PayloadEnvelopeInputSource,
12
13
  SourceMeta,
13
14
  } from "./types.js";
14
15
 
@@ -71,6 +72,7 @@ export class PayloadEnvelopeInput {
71
72
  readonly bid: gloas.ExecutionPayloadBid;
72
73
  readonly versionedHashes: VersionedHashes;
73
74
  readonly daOutOfRange: boolean;
75
+ readonly source: PayloadEnvelopeInputSource;
74
76
 
75
77
  private columnsCache = new Map<ColumnIndex, ColumnWithSource>();
76
78
 
@@ -95,6 +97,7 @@ export class PayloadEnvelopeInput {
95
97
  custodyColumns: ColumnIndex[];
96
98
  timeCreatedSec: number;
97
99
  daOutOfRange: boolean;
100
+ source: PayloadEnvelopeInputSource;
98
101
  }) {
99
102
  this.blockRootHex = props.blockRootHex;
100
103
  this.slot = props.slot;
@@ -106,6 +109,7 @@ export class PayloadEnvelopeInput {
106
109
  this.custodyColumns = props.custodyColumns;
107
110
  this.timeCreatedSec = props.timeCreatedSec;
108
111
  this.daOutOfRange = props.daOutOfRange;
112
+ this.source = props.source;
109
113
  this.payloadEnvelopeDataPromise = createPromise();
110
114
  this.allDataPromise = createPromise();
111
115
  this.columnsDataPromise = createPromise();
@@ -133,8 +137,9 @@ export class PayloadEnvelopeInput {
133
137
  bid,
134
138
  sampledColumns: props.sampledColumns,
135
139
  custodyColumns: props.custodyColumns,
136
- timeCreatedSec: props.timeCreatedSec,
140
+ timeCreatedSec: props.seenTimestampSec,
137
141
  daOutOfRange: props.daOutOfRange,
142
+ source: props.source,
138
143
  });
139
144
  }
140
145
 
@@ -153,8 +158,9 @@ export class PayloadEnvelopeInput {
153
158
  bid: props.bid,
154
159
  sampledColumns: props.sampledColumns,
155
160
  custodyColumns: props.custodyColumns,
156
- timeCreatedSec: props.timeCreatedSec,
161
+ timeCreatedSec: props.seenTimestampSec,
157
162
  daOutOfRange: props.daOutOfRange,
163
+ source: props.source,
158
164
  });
159
165
  }
160
166
 
@@ -7,9 +7,24 @@ export enum PayloadEnvelopeInputSource {
7
7
  engine = "engine",
8
8
  byRange = "req_resp_by_range",
9
9
  byRoot = "req_resp_by_root",
10
+ // Data-column reconstruction (KZG cell recovery), NOT a cache reload
10
11
  recovery = "recovery",
12
+ // Entry reconstructed from the hot DB by SeenPayloadEnvelopeInput.getOrReload
13
+ reload = "reload",
14
+ // Entry seeded from a checkpoint anchor state's latestExecutionPayloadBid at chain init
15
+ anchorState = "anchor_state",
11
16
  }
12
17
 
18
+ /**
19
+ * Reason a PayloadEnvelopeInput is evicted from SeenPayloadEnvelopeInput. Used for the `pruned` metric
20
+ * label and the eviction log.
21
+ * - belowParent: pruned below the new head's parent (canonical, FULL, all-columns)
22
+ * - finalized: below the finalized slot
23
+ * - prune: explicit prune by root
24
+ * - cap: insertion-order backstop cap (MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE)
25
+ */
26
+ export type PayloadEnvelopeInputPruneReason = "belowParent" | "finalized" | "prune" | "cap";
27
+
13
28
  export type SourceMeta = {
14
29
  source: PayloadEnvelopeInputSource;
15
30
  seenTimestampSec: number;
@@ -20,13 +35,12 @@ export type ColumnWithSource = SourceMeta & {
20
35
  columnSidecar: gloas.DataColumnSidecar;
21
36
  };
22
37
 
23
- export type CreateFromBlockProps = {
38
+ export type CreateFromBlockProps = SourceMeta & {
24
39
  blockRootHex: RootHex;
25
40
  block: SignedBeaconBlock<ForkPostGloas>;
26
41
  forkName: ForkName;
27
42
  sampledColumns: ColumnIndex[];
28
43
  custodyColumns: ColumnIndex[];
29
- timeCreatedSec: number;
30
44
  daOutOfRange: boolean;
31
45
  };
32
46
 
@@ -35,7 +49,7 @@ export type CreateFromBlockProps = {
35
49
  * the chain from a checkpoint anchor state — we have the bid via the state but not the
36
50
  * full SignedBeaconBlock).
37
51
  */
38
- export type CreateFromBidProps = {
52
+ export type CreateFromBidProps = SourceMeta & {
39
53
  blockRootHex: RootHex;
40
54
  slot: number;
41
55
  forkName: ForkName;
@@ -43,7 +57,6 @@ export type CreateFromBidProps = {
43
57
  bid: gloas.ExecutionPayloadBid;
44
58
  sampledColumns: ColumnIndex[];
45
59
  custodyColumns: ColumnIndex[];
46
- timeCreatedSec: number;
47
60
  daOutOfRange: boolean;
48
61
  };
49
62
 
@@ -132,12 +132,15 @@ export async function verifyBlocksInEpoch(
132
132
  }> =
133
133
  fork >= ForkSeq.gloas
134
134
  ? (async () => {
135
- // Validate DA for ALL payloads in the Map, not just those paired with blockInputs.
135
+ // Range sync creates a PayloadEnvelopeInput for every Gloas block, but an entry without
136
+ // an envelope represents a valid EMPTY slot and has no payload DA to verify.
136
137
  // A checkpoint-sync batch may include a payload for a slot whose block was filtered
137
138
  // out of relevantBlocks (e.g., the anchor at the finalized slot); that payload still
138
139
  // needs DA validation so it can be imported in processBlocks.
139
140
  const payloadInputsForDa: PayloadEnvelopeInput[] =
140
- payloadEnvelopes !== null ? Array.from(payloadEnvelopes.values()) : [];
141
+ payloadEnvelopes !== null
142
+ ? Array.from(payloadEnvelopes.values()).filter((payloadInput) => payloadInput.hasPayloadEnvelope())
143
+ : [];
141
144
  const {dataAvailabilityStatuses, availableTime} = await verifyPayloadsDataAvailability(
142
145
  payloadInputsForDa,
143
146
  abortController.signal
@@ -44,22 +44,31 @@ export async function verifyBlocksStateTransitionOnly(
44
44
  // STFN - per_slot_processing() + per_block_processing()
45
45
  // NOTE: `regen.getPreState()` should have dialed forward the state already caching checkpoint states
46
46
  const useBlsBatchVerify = !opts?.disableBlsBatchVerify;
47
- const postState = preState.stateTransition(
48
- block,
49
- {
50
- // NOTE: Assume valid for now while sending payload to execution engine in parallel
51
- // Latter verifyBlocksInEpoch() will make sure that payload is indeed valid
52
- executionPayloadStatus: ExecutionPayloadStatus.valid,
53
- dataAvailabilityStatus,
54
- // false because it's verified below with better error typing
55
- verifyStateRoot: false,
56
- // if block is trusted don't verify proposer or op signature
57
- verifyProposer: !useBlsBatchVerify && !validSignatures && !validProposerSignature,
58
- verifySignatures: !useBlsBatchVerify && !validSignatures,
59
- dontTransferCache: false,
60
- },
61
- {metrics, validatorMonitor}
62
- );
47
+ let postState: IBeaconStateView;
48
+ try {
49
+ postState = preState.stateTransition(
50
+ block,
51
+ {
52
+ // NOTE: Assume valid for now while sending payload to execution engine in parallel
53
+ // Latter verifyBlocksInEpoch() will make sure that payload is indeed valid
54
+ executionPayloadStatus: ExecutionPayloadStatus.valid,
55
+ dataAvailabilityStatus,
56
+ // false because it's verified below with better error typing
57
+ verifyStateRoot: false,
58
+ // if block is trusted don't verify proposer or op signature
59
+ verifyProposer: !useBlsBatchVerify && !validSignatures && !validProposerSignature,
60
+ verifySignatures: !useBlsBatchVerify && !validSignatures,
61
+ dontTransferCache: false,
62
+ },
63
+ {metrics, validatorMonitor}
64
+ );
65
+ } catch (e) {
66
+ throw new BlockError(block, {
67
+ code: BlockErrorCode.PER_BLOCK_PROCESSING_ERROR,
68
+ blockRoot: blocks[i].blockRootHex,
69
+ error: e as Error,
70
+ });
71
+ }
63
72
 
64
73
  const hashTreeRootTimer = metrics?.stateHashTreeRootTime.startTimer({
65
74
  source: StateHashTreeRootSource.blockTransition,
@@ -61,6 +61,7 @@ import {ProcessShutdownCallback} from "@lodestar/validator";
61
61
  import {GENESIS_EPOCH, ZERO_HASH} from "../constants/index.js";
62
62
  import {IBeaconDb} from "../db/index.js";
63
63
  import {BLOB_SIDECARS_IN_WRAPPER_INDEX} from "../db/repositories/blobSidecars.js";
64
+ import {BuilderApiClient, BuilderApiClientOpts} from "../execution/builder/apiClient.js";
64
65
  import {BuilderStatus} from "../execution/builder/http.js";
65
66
  import {IExecutionBuilder, IExecutionEngine} from "../execution/index.js";
66
67
  import {Metrics} from "../metrics/index.js";
@@ -79,6 +80,7 @@ import {CheckpointBalancesCache} from "./balancesCache.js";
79
80
  import {BeaconProposerCache} from "./beaconProposerCache.js";
80
81
  import {IBlockInput, isBlockInputBlobs, isBlockInputColumns} from "./blocks/blockInput/index.js";
81
82
  import {BlockProcessor, ImportBlockOpts} from "./blocks/index.js";
83
+ import {PayloadEnvelopeInputSource} from "./blocks/payloadEnvelopeInput/index.js";
82
84
  import {PayloadEnvelopeProcessor} from "./blocks/payloadEnvelopeProcessor.js";
83
85
  import {ImportPayloadOpts} from "./blocks/types.js";
84
86
  import {persistBlockInput} from "./blocks/writeBlockInputToDb.js";
@@ -94,6 +96,7 @@ import {LightClientServer} from "./lightClient/index.js";
94
96
  import {
95
97
  AggregatedAttestationPool,
96
98
  AttestationPool,
99
+ DeferredVoluntaryExitPool,
97
100
  ExecutionPayloadBidPool,
98
101
  OpPool,
99
102
  PayloadAttestationPool,
@@ -163,6 +166,7 @@ export class BeaconChain implements IBeaconChain {
163
166
  readonly executionEngine: IExecutionEngine;
164
167
  readonly executionBuilder?: IExecutionBuilder;
165
168
  readonly builderCircuitBreaker: BuilderCircuitBreaker;
169
+ readonly builderApiClient: BuilderApiClient;
166
170
  // Expose config for convenience in modularized functions
167
171
  readonly config: BeaconConfig;
168
172
  readonly custodyConfig: CustodyConfig;
@@ -193,6 +197,7 @@ export class BeaconChain implements IBeaconChain {
193
197
  readonly payloadAttestationPool: PayloadAttestationPool;
194
198
  readonly proposerPreferencesPool = new ProposerPreferencesPool();
195
199
  readonly opPool: OpPool;
200
+ readonly deferredVoluntaryExitPool: DeferredVoluntaryExitPool;
196
201
 
197
202
  // Gossip seen cache
198
203
  readonly seenAttesters = new SeenAttesters();
@@ -272,6 +277,7 @@ export class BeaconChain implements IBeaconChain {
272
277
  isAnchorStateFinalized,
273
278
  executionEngine,
274
279
  executionBuilder,
280
+ builderApiClientOpts,
275
281
  }: {
276
282
  privateKey: PrivateKey;
277
283
  config: BeaconConfig;
@@ -289,6 +295,7 @@ export class BeaconChain implements IBeaconChain {
289
295
  isAnchorStateFinalized: boolean;
290
296
  executionEngine: IExecutionEngine;
291
297
  executionBuilder?: IExecutionBuilder;
298
+ builderApiClientOpts?: BuilderApiClientOpts;
292
299
  }
293
300
  ) {
294
301
  this.opts = opts;
@@ -320,6 +327,7 @@ export class BeaconChain implements IBeaconChain {
320
327
  this.executionPayloadBidPool = new ExecutionPayloadBidPool();
321
328
  this.payloadAttestationPool = new PayloadAttestationPool(config, clock, metrics);
322
329
  this.opPool = new OpPool(config);
330
+ this.deferredVoluntaryExitPool = new DeferredVoluntaryExitPool(logger);
323
331
 
324
332
  this.seenAggregatedAttestations = new SeenAggregatedAttestations(metrics);
325
333
  this.seenContributionAndProof = new SeenContributionAndProof(metrics);
@@ -444,6 +452,8 @@ export class BeaconChain implements IBeaconChain {
444
452
  {forkChoice, logger, metrics}
445
453
  );
446
454
 
455
+ this.builderApiClient = new BuilderApiClient(builderApiClientOpts ?? {}, config, clock, bls, metrics, logger);
456
+
447
457
  this.seenPayloadEnvelopeInputCache = new SeenPayloadEnvelopeInput({
448
458
  config,
449
459
  clock,
@@ -451,6 +461,9 @@ export class BeaconChain implements IBeaconChain {
451
461
  chainEvents: emitter,
452
462
  signal,
453
463
  serializedCache: this.serializedCache,
464
+ db,
465
+ seenBlockInputCache: this.seenBlockInputCache,
466
+ custodyConfig: this.custodyConfig,
454
467
  metrics,
455
468
  logger,
456
469
  });
@@ -466,7 +479,8 @@ export class BeaconChain implements IBeaconChain {
466
479
  bid: anchorBid,
467
480
  sampledColumns: this.custodyConfig.sampledColumns,
468
481
  custodyColumns: this.custodyConfig.custodyColumns,
469
- timeCreatedSec: Math.floor(Date.now() / 1000),
482
+ seenTimestampSec: Date.now() / 1000,
483
+ source: PayloadEnvelopeInputSource.anchorState,
470
484
  });
471
485
  }
472
486
 
@@ -1313,9 +1327,10 @@ export class BeaconChain implements IBeaconChain {
1313
1327
  }
1314
1328
  }
1315
1329
 
1316
- predictProposerHead(slot: Slot): ProtoBlock {
1330
+ predictProposerHead(): ProtoBlock {
1317
1331
  this.metrics?.forkChoice.requests.inc();
1318
1332
  const timer = this.metrics?.forkChoice.findHead.startTimer({caller: FindHeadFnName.predictProposerHead});
1333
+ const slot = this.clock.currentSlot;
1319
1334
  const secFromSlot = this.clock.secFromSlot(slot);
1320
1335
 
1321
1336
  try {
@@ -1569,6 +1584,7 @@ export class BeaconChain implements IBeaconChain {
1569
1584
  // aggregatedAttestationPool tracks metrics on its own
1570
1585
  metrics.opPool.attestationPool.size.set(this.attestationPool.getAttestationCount());
1571
1586
  metrics.opPool.attesterSlashingPoolSize.set(this.opPool.attesterSlashingsSize);
1587
+ metrics.opPool.deferredVoluntaryExitPool.size.set(this.deferredVoluntaryExitPool.size());
1572
1588
  metrics.opPool.proposerSlashingPoolSize.set(this.opPool.proposerSlashingsSize);
1573
1589
  metrics.opPool.voluntaryExitPoolSize.set(this.opPool.voluntaryExitsSize);
1574
1590
  metrics.opPool.syncCommitteeMessagePoolSize.set(this.syncCommitteeMessagePool.size);
@@ -136,7 +136,7 @@ export type BlockErrorType =
136
136
  | {code: BlockErrorCode.NON_LINEAR_PARENT_ROOTS}
137
137
  | {code: BlockErrorCode.NON_LINEAR_SLOTS}
138
138
  | {code: BlockErrorCode.ENVELOPE_BLOCK_ROOT_MISMATCH; envelopeBlockRoot: RootHex; blockRoot: RootHex}
139
- | {code: BlockErrorCode.PER_BLOCK_PROCESSING_ERROR; error: Error}
139
+ | {code: BlockErrorCode.PER_BLOCK_PROCESSING_ERROR; blockRoot: RootHex; error: Error}
140
140
  | {code: BlockErrorCode.BEACON_CHAIN_ERROR; error: Error}
141
141
  | {code: BlockErrorCode.KNOWN_BAD_BLOCK}
142
142
  | {code: BlockErrorCode.BLACKLISTED_BLOCK}
@@ -184,13 +184,19 @@ export function isBlockErrorAborted(e: unknown): e is BlockError {
184
184
  export function renderBlockErrorType(type: BlockErrorType): Record<string, string | number | null> {
185
185
  switch (type.code) {
186
186
  case BlockErrorCode.PRESTATE_MISSING:
187
- case BlockErrorCode.PER_BLOCK_PROCESSING_ERROR:
188
187
  case BlockErrorCode.BEACON_CHAIN_ERROR:
189
188
  return {
190
189
  code: type.code,
191
190
  error: type.error.message,
192
191
  };
193
192
 
193
+ case BlockErrorCode.PER_BLOCK_PROCESSING_ERROR:
194
+ return {
195
+ code: type.code,
196
+ blockRoot: type.blockRoot,
197
+ error: type.error.message,
198
+ };
199
+
194
200
  case BlockErrorCode.INVALID_SIGNATURE:
195
201
  return {
196
202
  code: type.code,
@@ -9,6 +9,7 @@ export enum ExecutionPayloadBidErrorCode {
9
9
  BID_ALREADY_KNOWN = "EXECUTION_PAYLOAD_BID_ERROR_BID_ALREADY_KNOWN",
10
10
  BID_TOO_LOW = "EXECUTION_PAYLOAD_BID_ERROR_BID_TOO_LOW",
11
11
  BID_TOO_HIGH = "EXECUTION_PAYLOAD_BID_ERROR_BID_TOO_HIGH",
12
+ BUILDER_MAY_EXIT = "EXECUTION_PAYLOAD_BID_ERROR_BUILDER_MAY_EXIT",
12
13
  TOO_MANY_KZG_COMMITMENTS = "EXECUTION_PAYLOAD_BID_ERROR_TOO_MANY_KZG_COMMITMENTS",
13
14
  UNKNOWN_BLOCK_ROOT = "EXECUTION_PAYLOAD_BID_ERROR_UNKNOWN_BLOCK_ROOT",
14
15
  UNKNOWN_PARENT_BLOCK_HASH = "EXECUTION_PAYLOAD_BID_ERROR_UNKNOWN_PARENT_BLOCK_HASH",
@@ -50,6 +51,11 @@ export type ExecutionPayloadBidErrorType =
50
51
  }
51
52
  | {code: ExecutionPayloadBidErrorCode.BID_TOO_LOW; bidValue: number; currentHighestBid: number}
52
53
  | {code: ExecutionPayloadBidErrorCode.BID_TOO_HIGH; bidValue: number; builderBalance: number}
54
+ | {
55
+ code: ExecutionPayloadBidErrorCode.BUILDER_MAY_EXIT;
56
+ builderIndex: BuilderIndex;
57
+ parentBlockRoot: RootHex;
58
+ }
53
59
  | {
54
60
  code: ExecutionPayloadBidErrorCode.TOO_MANY_KZG_COMMITMENTS;
55
61
  blobKzgCommitmentsLen: number;
@@ -134,6 +134,8 @@ export function initializeForkChoiceFromFinalizedState(
134
134
  stateRoot: toRootHex(blockHeader.stateRoot),
135
135
  blockRoot: toRootHex(checkpoint.root),
136
136
  timeliness: true, // Optimistically assume is timely
137
+ ptcTimeliness: true, // Spec: block_timeliness for anchor = [True, True]
138
+ proposerIndex: blockHeader.proposerIndex,
137
139
 
138
140
  justifiedEpoch: justifiedCheckpoint.epoch,
139
141
  justifiedRoot: toRootHex(justifiedCheckpoint.root),
@@ -230,6 +232,8 @@ export function initializeForkChoiceFromUnfinalizedState(
230
232
  blockRoot: headRoot,
231
233
  targetRoot: headRoot,
232
234
  timeliness: true, // Optimistically assume is timely
235
+ ptcTimeliness: true, // Spec: block_timeliness for anchor = [True, True]
236
+ proposerIndex: blockHeader.proposerIndex,
233
237
 
234
238
  justifiedEpoch: justifiedCheckpoint.epoch,
235
239
  justifiedRoot: toRootHex(justifiedCheckpoint.root),
@@ -24,6 +24,7 @@ import {
24
24
  rewards,
25
25
  } from "@lodestar/types";
26
26
  import {Logger} from "@lodestar/utils";
27
+ import {BuilderApiClient} from "../execution/builder/apiClient.js";
27
28
  import {IExecutionBuilder, IExecutionEngine} from "../execution/index.js";
28
29
  import {Metrics} from "../metrics/metrics.js";
29
30
  import {BufferPool} from "../util/bufferPool.js";
@@ -45,6 +46,7 @@ import {LightClientServer} from "./lightClient/index.js";
45
46
  import {AggregatedAttestationPool} from "./opPools/aggregatedAttestationPool.js";
46
47
  import {
47
48
  AttestationPool,
49
+ DeferredVoluntaryExitPool,
48
50
  ExecutionPayloadBidPool,
49
51
  OpPool,
50
52
  PayloadAttestationPool,
@@ -98,6 +100,7 @@ export interface IBeaconChain {
98
100
  readonly executionEngine: IExecutionEngine;
99
101
  readonly executionBuilder?: IExecutionBuilder;
100
102
  readonly builderCircuitBreaker: BuilderCircuitBreaker;
103
+ readonly builderApiClient: BuilderApiClient;
101
104
  // Expose config for convenience in modularized functions
102
105
  readonly config: BeaconConfig;
103
106
  readonly custodyConfig: CustodyConfig;
@@ -128,6 +131,7 @@ export interface IBeaconChain {
128
131
  readonly payloadAttestationPool: PayloadAttestationPool;
129
132
  readonly proposerPreferencesPool: ProposerPreferencesPool;
130
133
  readonly opPool: OpPool;
134
+ readonly deferredVoluntaryExitPool: DeferredVoluntaryExitPool;
131
135
 
132
136
  // Gossip seen cache
133
137
  readonly seenAttesters: SeenAttesters;
@@ -270,8 +274,8 @@ export interface IBeaconChain {
270
274
 
271
275
  recomputeForkChoiceHead(caller: ForkchoiceCaller): ProtoBlock;
272
276
 
273
- /** When proposerBoostReorg is enabled, this is called at slot n-1 to predict the head block to build on if we are proposing at slot n */
274
- predictProposerHead(slot: Slot): ProtoBlock;
277
+ /** When proposerBoostReorg is enabled, predict (as of the current slot) the head block a proposer would build on next slot */
278
+ predictProposerHead(): ProtoBlock;
275
279
 
276
280
  /** When proposerBoostReorg is enabled and we are proposing a block, this is called to determine which head block to build on */
277
281
  getProposerHead(slot: Slot): ProtoBlock;
@@ -0,0 +1,65 @@
1
+ import {Logger} from "@lodestar/logger";
2
+ import {IBeaconStateView, VoluntaryExitValidity} from "@lodestar/state-transition";
3
+ import {Epoch, ValidatorIndex} from "@lodestar/types";
4
+ import {SignedVoluntaryExit} from "@lodestar/types/phase0";
5
+ import {isTransientExitValidity} from "../validation/voluntaryExit.js";
6
+
7
+ type DeferredEntry = {
8
+ exit: SignedVoluntaryExit;
9
+ validity: VoluntaryExitValidity;
10
+ insertedAtEpoch: Epoch;
11
+ };
12
+
13
+ export class DeferredVoluntaryExitPool {
14
+ private pool = new Map<ValidatorIndex, DeferredEntry>();
15
+
16
+ constructor(
17
+ private readonly logger: Logger,
18
+ private readonly maxSize = 1024,
19
+ private readonly maxDeferEpochs = 4096
20
+ ) {}
21
+
22
+ insert(exit: SignedVoluntaryExit, validity: VoluntaryExitValidity, currentEpoch: Epoch): boolean {
23
+ if (!isTransientExitValidity(validity)) return false;
24
+ if (this.pool.size === this.maxSize) return false;
25
+ if (this.pool.has(exit.message.validatorIndex)) return false;
26
+
27
+ this.pool.set(exit.message.validatorIndex, {exit, validity, insertedAtEpoch: currentEpoch});
28
+
29
+ return true;
30
+ }
31
+
32
+ drainProcessableExits(state: IBeaconStateView): SignedVoluntaryExit[] {
33
+ const epoch = state.epoch;
34
+ const validExits: SignedVoluntaryExit[] = [];
35
+ for (const [validatorIndex, entry] of this.pool) {
36
+ try {
37
+ if (epoch - entry.insertedAtEpoch > this.maxDeferEpochs) {
38
+ this.pool.delete(validatorIndex);
39
+ this.logger.debug("Deferred voluntary exit expired", {validatorIndex, lastValidity: entry.validity});
40
+ continue;
41
+ }
42
+ const validity = state.getVoluntaryExitValidity(entry.exit, true);
43
+ if (validity === VoluntaryExitValidity.valid) {
44
+ validExits.push(entry.exit);
45
+ this.pool.delete(validatorIndex);
46
+ } else if (!isTransientExitValidity(validity)) {
47
+ this.logger.debug("Deferred voluntary exit became permanently invalid", {validatorIndex, validity});
48
+ this.pool.delete(validatorIndex);
49
+ }
50
+ // Else if still transient - keep
51
+ } catch (e) {
52
+ this.logger.debug("Processing deferred voluntary exit failed", {validatorIndex}, e as Error);
53
+ }
54
+ }
55
+ return validExits;
56
+ }
57
+
58
+ has(validatorIndex: ValidatorIndex): boolean {
59
+ return this.pool.has(validatorIndex);
60
+ }
61
+
62
+ size(): number {
63
+ return this.pool.size;
64
+ }
65
+ }
@@ -11,14 +11,20 @@ const SLOTS_RETAINED = 2;
11
11
  type BlockRootHex = string;
12
12
  type BlockHashHex = string;
13
13
 
14
+ export type PooledExecutionPayloadBid = {
15
+ signedBid: gloas.SignedExecutionPayloadBid;
16
+ /** Time in milliseconds from the slot start when the bid was received */
17
+ receivedMs: number;
18
+ };
19
+
14
20
  /**
15
21
  * Store the best signed execution payload bid per slot / (parent block root, parent block hash).
16
22
  */
17
23
  export class ExecutionPayloadBidPool {
18
24
  private readonly bidByParentHashByParentRootBySlot = new MapDef<
19
25
  Slot,
20
- MapDef<BlockRootHex, Map<BlockHashHex, gloas.SignedExecutionPayloadBid>>
21
- >(() => new MapDef<BlockRootHex, Map<BlockHashHex, gloas.SignedExecutionPayloadBid>>(() => new Map()));
26
+ MapDef<BlockRootHex, Map<BlockHashHex, PooledExecutionPayloadBid>>
27
+ >(() => new MapDef<BlockRootHex, Map<BlockHashHex, PooledExecutionPayloadBid>>(() => new Map()));
22
28
  private lowestPermissibleSlot = 0;
23
29
 
24
30
  get size(): number {
@@ -31,7 +37,7 @@ export class ExecutionPayloadBidPool {
31
37
  return count;
32
38
  }
33
39
 
34
- add(bid: gloas.SignedExecutionPayloadBid): InsertOutcome {
40
+ add(bid: gloas.SignedExecutionPayloadBid, receivedMs: number): InsertOutcome {
35
41
  const {slot, parentBlockRoot, parentBlockHash, value} = bid.message;
36
42
  const lowestPermissibleSlot = this.lowestPermissibleSlot;
37
43
 
@@ -45,16 +51,16 @@ export class ExecutionPayloadBidPool {
45
51
  const existing = bidByParentHash.get(parentHashHex);
46
52
 
47
53
  if (existing) {
48
- const existingValue = existing.message.value;
54
+ const existingValue = existing.signedBid.message.value;
49
55
  const newValue = value;
50
56
  if (newValue > existingValue) {
51
- bidByParentHash.set(parentHashHex, bid);
57
+ bidByParentHash.set(parentHashHex, {signedBid: bid, receivedMs});
52
58
  return InsertOutcome.NewData;
53
59
  }
54
60
  return newValue === existingValue ? InsertOutcome.AlreadyKnown : InsertOutcome.NotBetterThan;
55
61
  }
56
62
 
57
- bidByParentHash.set(parentHashHex, bid);
63
+ bidByParentHash.set(parentHashHex, {signedBid: bid, receivedMs});
58
64
  return InsertOutcome.NewData;
59
65
  }
60
66
 
@@ -66,7 +72,7 @@ export class ExecutionPayloadBidPool {
66
72
  slot: Slot,
67
73
  parentBlockHash: BlockHashHex | null,
68
74
  parentBlockRoot: BlockRootHex
69
- ): gloas.SignedExecutionPayloadBid | null {
75
+ ): PooledExecutionPayloadBid | null {
70
76
  if (parentBlockHash === null) return null;
71
77
  const bidByParentHash = this.bidByParentHashByParentRootBySlot.get(slot)?.get(parentBlockRoot);
72
78
  return bidByParentHash?.get(parentBlockHash) ?? null;
@@ -1,6 +1,7 @@
1
1
  export {AggregatedAttestationPool} from "./aggregatedAttestationPool.js";
2
2
  export {AttestationPool} from "./attestationPool.js";
3
- export {ExecutionPayloadBidPool} from "./executionPayloadBidPool.js";
3
+ export {DeferredVoluntaryExitPool} from "./deferredVoluntaryExitPool.js";
4
+ export {ExecutionPayloadBidPool, type PooledExecutionPayloadBid} from "./executionPayloadBidPool.js";
4
5
  export {OpPool} from "./opPool.js";
5
6
  export {PayloadAttestationPool} from "./payloadAttestationPool.js";
6
7
  export {ProposerPreferencesPool} from "./proposerPreferencesPool.js";
@@ -45,6 +45,14 @@ const PREPARE_EPOCH_LIMIT = 1;
45
45
  * Expressed in bps so it scales with slot duration (mainnet vs minimal/devnet). */
46
46
  const BUILDER_PREVERIFY_LIMIT_BPS = 2000;
47
47
 
48
+ /**
49
+ * How far before the next slot builder connections are pre-established, see `checkBuilderStatusBeforeSlot`.
50
+ *
51
+ * 1667 = 16.67% of slot (2s on mainnet). Must stay under the few seconds an idle connection survives,
52
+ * while leaving room for a round trip to a distant builder to complete before the slot begins.
53
+ */
54
+ const BUILDER_STATUS_CHECK_BEFORE_SLOT_BPS = 1667;
55
+
48
56
  /**
49
57
  * At Bellatrix, if we are responsible for proposing in next slot, we want to prepare payload
50
58
  * 4s before the start of next slot at PREPARE_NEXT_SLOT_BPS of the current slot.
@@ -151,25 +159,41 @@ export class PrepareNextSlotScheduler {
151
159
  const proposerIndex = await getProposerIndex();
152
160
  feeRecipient = this.chain.beaconProposerCache.get(proposerIndex);
153
161
 
154
- if (feeRecipient) {
155
- // If we are proposing next slot, we need to predict if we can proposer-boost-reorg or not
156
- const proposerHead = this.chain.predictProposerHead(clockSlot);
162
+ // Predict the proposer head of the next slot when either:
163
+ // - we are proposing the next slot (single-slot proposer-boost-reorg), or
164
+ // - this is an epoch transition: post-Fulu the next proposer may reorg a weak
165
+ // last-block-of-epoch and build slot 0 on the strong parent (epoch-boundary reorg),
166
+ // so we should dial the strong parent through the boundary instead of the weak head.
167
+ if (feeRecipient || isEpochTransition) {
168
+ const proposerHead = this.chain.predictProposerHead();
157
169
  const {slot: proposerHeadSlot, blockRoot: proposerHeadRoot} = proposerHead;
158
170
 
159
- // If we predict we can reorg, we build on the proposer head (parent) block instead
171
+ // If we predict a reorg, we build the epoch transition on the proposer head (parent) instead
160
172
  if (proposerHeadRoot !== headRoot || proposerHeadSlot !== headSlot) {
161
- this.logger.verbose("Weak head detected. May build on parent block instead", {
173
+ // feeRecipient set => WE propose the next slot and may reorg it out ourselves;
174
+ // otherwise it's a predicted reorg by another proposer (epoch-boundary reorg).
175
+ const logMessage = feeRecipient
176
+ ? "Weak head detected. We may build on parent block instead"
177
+ : "Weak head detected. Another proposer may build on parent block instead";
178
+ this.logger.verbose(logMessage, {
162
179
  proposerHeadSlot,
163
180
  proposerHeadRoot,
164
181
  headSlot,
165
182
  headRoot,
183
+ isEpochTransition,
166
184
  });
167
185
  this.metrics?.weakHeadDetected.inc();
186
+ if (isEpochTransition) {
187
+ this.metrics?.precomputeNextEpochTransition.predictedReorg.inc();
188
+ }
168
189
  updatedHead = proposerHead;
169
190
  }
191
+ }
170
192
 
193
+ if (feeRecipient) {
171
194
  if (isForkPostGloas(fork)) {
172
195
  this.chain.builderCircuitBreaker.update(clockSlot, updatedHead);
196
+ this.checkBuilderStatusBeforeSlot(prepareSlot);
173
197
  } else {
174
198
  // Update the builder status, if enabled shoot an api call to check status
175
199
  this.chain.updateBuilderStatus(clockSlot);
@@ -182,6 +206,7 @@ export class PrepareNextSlotScheduler {
182
206
  }
183
207
 
184
208
  // post-fulu we'll always reach here because preparedState is undefined
209
+ // we may run epoch transition not with headBlock if it's weak
185
210
  if (preparedState === undefined || updatedHead !== headBlock) {
186
211
  preparedState = await this.chain.regen.getBlockSlotState(
187
212
  updatedHead,
@@ -280,7 +305,7 @@ export class PrepareNextSlotScheduler {
280
305
  // + if next slot is a skipped slot, it'd help getting target checkpoint state faster to validate attestations
281
306
  if (isEpochTransition) {
282
307
  this.metrics?.precomputeNextEpochTransition.count.inc({result: "success"}, 1);
283
- const previousHits = this.chain.regen.updatePreComputedCheckpoint(headRoot, nextEpoch);
308
+ const previousHits = this.chain.regen.updatePreComputedCheckpoint(updatedHead.blockRoot, nextEpoch);
284
309
  if (previousHits === 0) {
285
310
  this.metrics?.precomputeNextEpochTransition.waste.inc();
286
311
  }
@@ -289,6 +314,8 @@ export class PrepareNextSlotScheduler {
289
314
  this.logger.verbose("Completed PrepareNextSlotScheduler epoch transition", {
290
315
  nextEpoch,
291
316
  headSlot,
317
+ headRoot,
318
+ updatedHeadRoot: updatedHead.blockRoot,
292
319
  prepareSlot,
293
320
  previousHits,
294
321
  durationMs: Date.now() - start,
@@ -372,6 +399,22 @@ export class PrepareNextSlotScheduler {
372
399
  }
373
400
  };
374
401
 
402
+ /**
403
+ * Pre-establish the builder connections so the handshake lands outside the bid deadline. Scheduled
404
+ * later in the slot, connecting at PREPARE_NEXT_SLOT_BPS would go cold before bids are requested.
405
+ */
406
+ private checkBuilderStatusBeforeSlot(prepareSlot: Slot): void {
407
+ const msBeforeSlot = this.config.getSlotComponentDurationMs(BUILDER_STATUS_CHECK_BEFORE_SLOT_BPS);
408
+ const msUntilCheck = -this.chain.clock.msFromSlot(prepareSlot) - msBeforeSlot;
409
+ sleep(Math.max(0, msUntilCheck), this.signal)
410
+ .then(() => this.chain.builderApiClient.checkStatus())
411
+ .catch((e) => {
412
+ if (!isErrorAborted(e)) {
413
+ this.logger.debug("Failed to check builder status", {prepareSlot}, e as Error);
414
+ }
415
+ });
416
+ }
417
+
375
418
  computeStateHashTreeRoot(state: IBeaconStateView, isEpochTransition: boolean): void {
376
419
  // cache HashObjects for faster hashTreeRoot() later, especially for computeNewStateRoot() if we need to produce a block at slot 0 of epoch
377
420
  // see https://github.com/ChainSafe/lodestar/issues/6194