@lodestar/beacon-node 1.50.0-dev.fda8006fc3 → 1.50.0-dev.fe4e7408b4

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 (244) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +7 -2
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/state/index.js +26 -5
  6. package/lib/api/impl/beacon/state/index.js.map +1 -1
  7. package/lib/api/impl/validator/index.d.ts.map +1 -1
  8. package/lib/api/impl/validator/index.js +42 -3
  9. package/lib/api/impl/validator/index.js.map +1 -1
  10. package/lib/chain/archiveStore/archiveStore.d.ts +5 -0
  11. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  12. package/lib/chain/archiveStore/archiveStore.js +13 -23
  13. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  14. package/lib/chain/archiveStore/utils/pruneHistory.d.ts +1 -1
  15. package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
  16. package/lib/chain/archiveStore/utils/pruneHistory.js +2 -1
  17. package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
  18. package/lib/chain/beaconProposerCache.d.ts +6 -0
  19. package/lib/chain/beaconProposerCache.d.ts.map +1 -1
  20. package/lib/chain/beaconProposerCache.js +16 -0
  21. package/lib/chain/beaconProposerCache.js.map +1 -1
  22. package/lib/chain/blocks/blockInput/blockInput.d.ts +1 -1
  23. package/lib/chain/blocks/blockInput/blockInput.d.ts.map +1 -1
  24. package/lib/chain/blocks/blockInput/blockInput.js.map +1 -1
  25. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  26. package/lib/chain/blocks/importBlock.js +14 -8
  27. package/lib/chain/blocks/importBlock.js.map +1 -1
  28. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  29. package/lib/chain/blocks/verifyBlock.js +6 -6
  30. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  31. package/lib/chain/chain.d.ts +3 -1
  32. package/lib/chain/chain.d.ts.map +1 -1
  33. package/lib/chain/chain.js +55 -19
  34. package/lib/chain/chain.js.map +1 -1
  35. package/lib/chain/interface.d.ts +3 -1
  36. package/lib/chain/interface.d.ts.map +1 -1
  37. package/lib/chain/opPools/aggregatedAttestationPool.d.ts +4 -2
  38. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  39. package/lib/chain/opPools/aggregatedAttestationPool.js +30 -8
  40. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  41. package/lib/chain/opPools/opPool.d.ts.map +1 -1
  42. package/lib/chain/opPools/opPool.js +1 -23
  43. package/lib/chain/opPools/opPool.js.map +1 -1
  44. package/lib/chain/opPools/proposerPreferencesPool.d.ts +4 -0
  45. package/lib/chain/opPools/proposerPreferencesPool.d.ts.map +1 -1
  46. package/lib/chain/opPools/proposerPreferencesPool.js +13 -1
  47. package/lib/chain/opPools/proposerPreferencesPool.js.map +1 -1
  48. package/lib/chain/opPools/utils.d.ts +11 -0
  49. package/lib/chain/opPools/utils.d.ts.map +1 -1
  50. package/lib/chain/opPools/utils.js +22 -0
  51. package/lib/chain/opPools/utils.js.map +1 -1
  52. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  53. package/lib/chain/prepareNextSlot.js +11 -3
  54. package/lib/chain/prepareNextSlot.js.map +1 -1
  55. package/lib/chain/produceBlock/computeNewStateRoot.d.ts.map +1 -1
  56. package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
  57. package/lib/chain/produceBlock/produceBlockBody.d.ts +8 -0
  58. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  59. package/lib/chain/produceBlock/produceBlockBody.js +48 -34
  60. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  61. package/lib/chain/seenCache/seenGossipBlockInput.d.ts +7 -0
  62. package/lib/chain/seenCache/seenGossipBlockInput.d.ts.map +1 -1
  63. package/lib/chain/seenCache/seenGossipBlockInput.js +22 -1
  64. package/lib/chain/seenCache/seenGossipBlockInput.js.map +1 -1
  65. package/lib/chain/shufflingCache.d.ts +18 -8
  66. package/lib/chain/shufflingCache.d.ts.map +1 -1
  67. package/lib/chain/shufflingCache.js +72 -18
  68. package/lib/chain/shufflingCache.js.map +1 -1
  69. package/lib/db/beacon.d.ts +4 -1
  70. package/lib/db/beacon.d.ts.map +1 -1
  71. package/lib/db/beacon.js +6 -1
  72. package/lib/db/beacon.js.map +1 -1
  73. package/lib/db/buckets.d.ts +3 -1
  74. package/lib/db/buckets.d.ts.map +1 -1
  75. package/lib/db/buckets.js +2 -0
  76. package/lib/db/buckets.js.map +1 -1
  77. package/lib/db/interface.d.ts +4 -1
  78. package/lib/db/interface.d.ts.map +1 -1
  79. package/lib/db/repositories/blockArchive.js +2 -2
  80. package/lib/db/repositories/blockArchive.js.map +1 -1
  81. package/lib/db/repositories/blockArchiveIndex.d.ts +3 -3
  82. package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
  83. package/lib/db/repositories/blockArchiveIndex.js +1 -2
  84. package/lib/db/repositories/blockArchiveIndex.js.map +1 -1
  85. package/lib/db/repositories/earliestAvailableSlot.d.ts +11 -0
  86. package/lib/db/repositories/earliestAvailableSlot.d.ts.map +1 -0
  87. package/lib/db/repositories/earliestAvailableSlot.js +19 -0
  88. package/lib/db/repositories/earliestAvailableSlot.js.map +1 -0
  89. package/lib/db/repositories/index.d.ts +1 -0
  90. package/lib/db/repositories/index.d.ts.map +1 -1
  91. package/lib/db/repositories/index.js +1 -0
  92. package/lib/db/repositories/index.js.map +1 -1
  93. package/lib/db/repositories/proposerPreferences.d.ts +14 -0
  94. package/lib/db/repositories/proposerPreferences.d.ts.map +1 -0
  95. package/lib/db/repositories/proposerPreferences.js +21 -0
  96. package/lib/db/repositories/proposerPreferences.js.map +1 -0
  97. package/lib/execution/engine/blobVersionedHashes.d.ts +9 -0
  98. package/lib/execution/engine/blobVersionedHashes.d.ts.map +1 -0
  99. package/lib/execution/engine/blobVersionedHashes.js +74 -0
  100. package/lib/execution/engine/blobVersionedHashes.js.map +1 -0
  101. package/lib/execution/engine/http.d.ts +45 -13
  102. package/lib/execution/engine/http.d.ts.map +1 -1
  103. package/lib/execution/engine/http.js +236 -198
  104. package/lib/execution/engine/http.js.map +1 -1
  105. package/lib/execution/engine/index.d.ts +3 -2
  106. package/lib/execution/engine/index.d.ts.map +1 -1
  107. package/lib/execution/engine/index.js +33 -8
  108. package/lib/execution/engine/index.js.map +1 -1
  109. package/lib/execution/engine/interface.d.ts +1 -1
  110. package/lib/execution/engine/interface.d.ts.map +1 -1
  111. package/lib/execution/engine/jsonRpcTransport.d.ts +25 -0
  112. package/lib/execution/engine/jsonRpcTransport.d.ts.map +1 -0
  113. package/lib/execution/engine/jsonRpcTransport.js +158 -0
  114. package/lib/execution/engine/jsonRpcTransport.js.map +1 -0
  115. package/lib/execution/engine/restHttpClient.d.ts +71 -0
  116. package/lib/execution/engine/restHttpClient.d.ts.map +1 -0
  117. package/lib/execution/engine/restHttpClient.js +201 -0
  118. package/lib/execution/engine/restHttpClient.js.map +1 -0
  119. package/lib/execution/engine/restTransport.d.ts +46 -0
  120. package/lib/execution/engine/restTransport.d.ts.map +1 -0
  121. package/lib/execution/engine/restTransport.js +399 -0
  122. package/lib/execution/engine/restTransport.js.map +1 -0
  123. package/lib/execution/engine/sszTypes.d.ts +1261 -0
  124. package/lib/execution/engine/sszTypes.d.ts.map +1 -0
  125. package/lib/execution/engine/sszTypes.js +216 -0
  126. package/lib/execution/engine/sszTypes.js.map +1 -0
  127. package/lib/execution/engine/transport.d.ts +39 -0
  128. package/lib/execution/engine/transport.d.ts.map +1 -0
  129. package/lib/execution/engine/transport.js +2 -0
  130. package/lib/execution/engine/transport.js.map +1 -0
  131. package/lib/execution/engine/types.d.ts +2 -0
  132. package/lib/execution/engine/types.d.ts.map +1 -1
  133. package/lib/execution/engine/types.js +24 -57
  134. package/lib/execution/engine/types.js.map +1 -1
  135. package/lib/execution/engine/utils.d.ts.map +1 -1
  136. package/lib/execution/engine/utils.js +9 -2
  137. package/lib/execution/engine/utils.js.map +1 -1
  138. package/lib/metrics/metrics/lodestar.d.ts +10 -0
  139. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  140. package/lib/metrics/metrics/lodestar.js +22 -0
  141. package/lib/metrics/metrics/lodestar.js.map +1 -1
  142. package/lib/network/core/events.d.ts +5 -1
  143. package/lib/network/core/events.d.ts.map +1 -1
  144. package/lib/network/core/events.js +8 -0
  145. package/lib/network/core/events.js.map +1 -1
  146. package/lib/network/gossip/topic.d.ts +0 -14
  147. package/lib/network/gossip/topic.d.ts.map +1 -1
  148. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  149. package/lib/network/processor/gossipHandlers.js +60 -64
  150. package/lib/network/processor/gossipHandlers.js.map +1 -1
  151. package/lib/network/processor/index.js +3 -3
  152. package/lib/network/processor/index.js.map +1 -1
  153. package/lib/node/nodejs.d.ts +3 -1
  154. package/lib/node/nodejs.d.ts.map +1 -1
  155. package/lib/node/nodejs.js +2 -1
  156. package/lib/node/nodejs.js.map +1 -1
  157. package/lib/node/options.d.ts +3 -2
  158. package/lib/node/options.d.ts.map +1 -1
  159. package/lib/node/options.js +2 -2
  160. package/lib/node/options.js.map +1 -1
  161. package/lib/sync/range/batch.d.ts +5 -5
  162. package/lib/sync/range/batch.d.ts.map +1 -1
  163. package/lib/sync/range/batch.js +11 -17
  164. package/lib/sync/range/batch.js.map +1 -1
  165. package/lib/sync/range/chain.d.ts +4 -4
  166. package/lib/sync/range/chain.d.ts.map +1 -1
  167. package/lib/sync/range/chain.js +7 -5
  168. package/lib/sync/range/chain.js.map +1 -1
  169. package/lib/sync/range/range.d.ts.map +1 -1
  170. package/lib/sync/range/range.js +25 -11
  171. package/lib/sync/range/range.js.map +1 -1
  172. package/lib/sync/unknownBlock.d.ts +5 -2
  173. package/lib/sync/unknownBlock.d.ts.map +1 -1
  174. package/lib/sync/unknownBlock.js +44 -20
  175. package/lib/sync/unknownBlock.js.map +1 -1
  176. package/lib/sync/utils/downloadByRange.d.ts +38 -14
  177. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  178. package/lib/sync/utils/downloadByRange.js +84 -39
  179. package/lib/sync/utils/downloadByRange.js.map +1 -1
  180. package/lib/util/asyncIterableToEvents.d.ts +10 -2
  181. package/lib/util/asyncIterableToEvents.d.ts.map +1 -1
  182. package/lib/util/asyncIterableToEvents.js +29 -3
  183. package/lib/util/asyncIterableToEvents.js.map +1 -1
  184. package/lib/util/metadata.d.ts.map +1 -1
  185. package/lib/util/metadata.js +2 -1
  186. package/lib/util/metadata.js.map +1 -1
  187. package/lib/util/sszBytes.d.ts +2 -2
  188. package/lib/util/sszBytes.d.ts.map +1 -1
  189. package/lib/util/sszBytes.js +21 -14
  190. package/lib/util/sszBytes.js.map +1 -1
  191. package/package.json +17 -16
  192. package/src/api/impl/beacon/blocks/index.ts +10 -3
  193. package/src/api/impl/beacon/state/index.ts +41 -5
  194. package/src/api/impl/validator/index.ts +57 -5
  195. package/src/chain/archiveStore/archiveStore.ts +18 -24
  196. package/src/chain/archiveStore/utils/pruneHistory.ts +4 -1
  197. package/src/chain/beaconProposerCache.ts +19 -1
  198. package/src/chain/blocks/blockInput/blockInput.ts +1 -1
  199. package/src/chain/blocks/importBlock.ts +17 -7
  200. package/src/chain/blocks/verifyBlock.ts +7 -6
  201. package/src/chain/chain.ts +68 -18
  202. package/src/chain/interface.ts +4 -1
  203. package/src/chain/opPools/aggregatedAttestationPool.ts +34 -10
  204. package/src/chain/opPools/opPool.ts +1 -31
  205. package/src/chain/opPools/proposerPreferencesPool.ts +20 -1
  206. package/src/chain/opPools/utils.ts +31 -0
  207. package/src/chain/prepareNextSlot.ts +15 -3
  208. package/src/chain/produceBlock/computeNewStateRoot.ts +9 -2
  209. package/src/chain/produceBlock/produceBlockBody.ts +78 -39
  210. package/src/chain/seenCache/seenGossipBlockInput.ts +25 -1
  211. package/src/chain/shufflingCache.ts +84 -22
  212. package/src/db/beacon.ts +6 -0
  213. package/src/db/buckets.ts +2 -0
  214. package/src/db/interface.ts +4 -0
  215. package/src/db/repositories/blockArchive.ts +2 -2
  216. package/src/db/repositories/blockArchiveIndex.ts +2 -3
  217. package/src/db/repositories/earliestAvailableSlot.ts +19 -0
  218. package/src/db/repositories/index.ts +1 -0
  219. package/src/db/repositories/proposerPreferences.ts +23 -0
  220. package/src/execution/engine/blobVersionedHashes.ts +72 -0
  221. package/src/execution/engine/http.ts +304 -271
  222. package/src/execution/engine/index.ts +41 -7
  223. package/src/execution/engine/interface.ts +1 -1
  224. package/src/execution/engine/jsonRpcTransport.ts +247 -0
  225. package/src/execution/engine/restHttpClient.ts +269 -0
  226. package/src/execution/engine/restTransport.ts +544 -0
  227. package/src/execution/engine/sszTypes.ts +354 -0
  228. package/src/execution/engine/transport.ts +61 -0
  229. package/src/execution/engine/types.ts +34 -74
  230. package/src/execution/engine/utils.ts +12 -2
  231. package/src/metrics/metrics/lodestar.ts +23 -0
  232. package/src/network/core/events.ts +16 -1
  233. package/src/network/processor/gossipHandlers.ts +91 -77
  234. package/src/network/processor/index.ts +3 -3
  235. package/src/node/nodejs.ts +4 -0
  236. package/src/node/options.ts +10 -1
  237. package/src/sync/range/batch.ts +14 -19
  238. package/src/sync/range/chain.ts +9 -7
  239. package/src/sync/range/range.ts +26 -12
  240. package/src/sync/unknownBlock.ts +57 -21
  241. package/src/sync/utils/downloadByRange.ts +123 -58
  242. package/src/util/asyncIterableToEvents.ts +44 -5
  243. package/src/util/metadata.ts +2 -1
  244. package/src/util/sszBytes.ts +25 -12
@@ -22,6 +22,7 @@ import {
22
22
  RootCache,
23
23
  computeEpochAtSlot,
24
24
  computeTimeAtSlot,
25
+ getBeaconCommittees,
25
26
  isStatePostAltair,
26
27
  isStatePostBellatrix,
27
28
  } from "@lodestar/state-transition";
@@ -129,11 +130,17 @@ export async function importBlock(
129
130
 
130
131
  // Should compute checkpoint balances before forkchoice.onBlock
131
132
  this.checkpointBalancesCache.processState(blockRootHex, postState);
132
- if (fork >= ForkSeq.gloas) {
133
+ if (isGloasBeaconBlock(block.message)) {
134
+ // A gloas block has no payload of its own, it inherits the status of the payload it builds on,
135
+ // i.e. the parent variant matching the bid's parent block hash. The parent's default (PENDING)
136
+ // variant does not reflect a SYNCING parent payload, and onBlock would then mark that payload VALID.
133
137
  const parentRootHex = toRootHex(block.message.parentRoot);
134
- const parentBlock = this.forkChoice.getBlockHexDefaultStatus(parentRootHex);
138
+ const parentBlockHashHex = toRootHex(block.message.body.signedExecutionPayloadBid.message.parentBlockHash);
139
+ const parentBlock = this.forkChoice.getBlockHexAndBlockHash(parentRootHex, parentBlockHashHex);
135
140
  if (parentBlock === null) {
136
- throw Error(`Parent block not found in forkChoice, parentRoot=${parentRootHex}`);
141
+ throw Error(
142
+ `Parent block not found in forkChoice, parentRoot=${parentRootHex} parentBlockHash=${parentBlockHashHex}`
143
+ );
137
144
  }
138
145
  if (parentBlock.executionStatus === ExecutionStatus.Invalid) {
139
146
  throw Error(`Parent block has invalid execution status, parentRoot=${parentRootHex}`);
@@ -400,9 +407,8 @@ export async function importBlock(
400
407
  const proposalSlot = blockSlot + 1;
401
408
  try {
402
409
  const proposerIndex = postState.getBeaconProposer(proposalSlot);
403
- const feeRecipient = this.beaconProposerCache.get(proposerIndex);
404
410
 
405
- if (feeRecipient) {
411
+ if (this.beaconProposerCache.has(proposerIndex)) {
406
412
  // We would set this to true if
407
413
  // 1) This is a gossip block
408
414
  // 2) We are proposer of next slot
@@ -657,8 +663,12 @@ export function addAttestationPostElectra(
657
663
  } else {
658
664
  const attSlot = attestation.data.slot;
659
665
  const attEpoch = computeEpochAtSlot(attSlot);
660
- const decisionRoot = state.getShufflingDecisionRoot(attEpoch);
661
- const committees = this.shufflingCache.getBeaconCommittees(attEpoch, decisionRoot, attSlot, committeeIndices);
666
+ // calling getShufflingAtEpoch may take some time for NativeBeaconStateView
667
+ // we should have the shuffling inside ShufflingCache most of the time
668
+ const shuffling =
669
+ this.shufflingCache.getSync(attEpoch, state.getShufflingDecisionRoot(attEpoch)) ??
670
+ state.getShufflingAtEpoch(attEpoch);
671
+ const committees = getBeaconCommittees(shuffling, attSlot, committeeIndices);
662
672
  const aggregationBools = attestation.aggregationBits.toBoolArray();
663
673
  let offset = 0;
664
674
  for (let i = 0; i < committees.length; i++) {
@@ -4,6 +4,7 @@ import {
4
4
  DataAvailabilityStatus,
5
5
  IBeaconStateView,
6
6
  computeEpochAtSlot,
7
+ getIndexedAttestation,
7
8
  signedBlockToSignedHeader,
8
9
  } from "@lodestar/state-transition";
9
10
  import {IndexedAttestation, Slot, deneb} from "@lodestar/types";
@@ -81,10 +82,6 @@ export async function verifyBlocksInEpoch(
81
82
  throw new BlockError(block0, {code: BlockErrorCode.PRESTATE_MISSING, error: e as Error});
82
83
  });
83
84
 
84
- // in forky condition, make sure to populate ShufflingCache with regened state
85
- // otherwise it may fail to get indexed attestations from shuffling cache later
86
- this.shufflingCache.processState(preState0);
87
-
88
85
  if (!preState0.isStateValidatorsNodesPopulated()) {
89
86
  this.logger.verbose("verifyBlocksInEpoch preState0 SSZ cache stats", {
90
87
  slot: preState0.slot,
@@ -117,8 +114,12 @@ export async function verifyBlocksInEpoch(
117
114
  for (const [i, block] of blocks.entries()) {
118
115
  indexedAttestationsByBlock[i] = block.message.body.attestations.map((attestation) => {
119
116
  const attEpoch = computeEpochAtSlot(attestation.data.slot);
120
- const decisionRoot = preState0.getShufflingDecisionRoot(attEpoch);
121
- return this.shufflingCache.getIndexedAttestation(attEpoch, decisionRoot, fork, attestation);
117
+ // calling getShufflingAtEpoch may take some time for NativeBeaconStateView
118
+ // we should have the shuffling inside ShufflingCache most of the time
119
+ const shuffling =
120
+ this.shufflingCache.getSync(attEpoch, preState0.getShufflingDecisionRoot(attEpoch)) ??
121
+ preState0.getShufflingAtEpoch(attEpoch);
122
+ return getIndexedAttestation(shuffling, fork, attestation);
122
123
  });
123
124
  }
124
125
 
@@ -128,7 +128,7 @@ import {SeenAggregatedAttestations} from "./seenCache/seenAggregateAndProof.js";
128
128
  import {SeenAttestationDatas} from "./seenCache/seenAttestationData.js";
129
129
  import {SeenBlockAttesters} from "./seenCache/seenBlockAttesters.js";
130
130
  import {SeenBlockInput} from "./seenCache/seenGossipBlockInput.js";
131
- import {ShufflingCache} from "./shufflingCache.js";
131
+ import {ShufflingCache, ShufflingPromiseCancelReason} from "./shufflingCache.js";
132
132
  import {DbCPStateDatastore, checkpointToDatastoreKey} from "./stateCache/datastore/db.js";
133
133
  import {FileCPStateDatastore} from "./stateCache/datastore/file.js";
134
134
  import {CPStateDatastore} from "./stateCache/datastore/types.js";
@@ -279,6 +279,7 @@ export class BeaconChain implements IBeaconChain {
279
279
  validatorMonitor,
280
280
  anchorState,
281
281
  isAnchorStateFinalized,
282
+ earliestAvailableSlot,
282
283
  executionEngine,
283
284
  executionBuilder,
284
285
  builderApiClientOpts,
@@ -298,6 +299,7 @@ export class BeaconChain implements IBeaconChain {
298
299
  validatorMonitor: ValidatorMonitor | null;
299
300
  anchorState: IBeaconStateView;
300
301
  isAnchorStateFinalized: boolean;
302
+ earliestAvailableSlot: Slot;
301
303
  executionEngine: IExecutionEngine;
302
304
  executionBuilder?: IExecutionBuilder;
303
305
  builderApiClientOpts?: BuilderApiClientOpts;
@@ -326,7 +328,7 @@ export class BeaconChain implements IBeaconChain {
326
328
 
327
329
  this.blacklistedBlocks = new Map((opts.blacklistedBlocks ?? []).map((hex) => [hex, null]));
328
330
  this.attestationPool = new AttestationPool(config, clock, this.opts?.preaggregateSlotDistance, metrics);
329
- this.aggregatedAttestationPool = new AggregatedAttestationPool(this.config, metrics);
331
+ this.aggregatedAttestationPool = new AggregatedAttestationPool(this.config, metrics, logger);
330
332
  this.syncCommitteeMessagePool = new SyncCommitteeMessagePool(config, clock, this.opts?.preaggregateSlotDistance);
331
333
  this.syncContributionAndProofPool = new SyncContributionAndProofPool(config, clock, metrics, logger);
332
334
  this.executionPayloadBidPool = new ExecutionPayloadBidPool();
@@ -363,7 +365,7 @@ export class BeaconChain implements IBeaconChain {
363
365
  logger,
364
366
  });
365
367
 
366
- this._earliestAvailableSlot = anchorState.slot;
368
+ this._earliestAvailableSlot = earliestAvailableSlot;
367
369
 
368
370
  this.shufflingCache = new ShufflingCache(metrics, logger, this.opts, [
369
371
  {
@@ -574,7 +576,11 @@ export class BeaconChain implements IBeaconChain {
574
576
  }
575
577
 
576
578
  seenBlock(blockRoot: RootHex): boolean {
577
- return this.seenBlockInputCache.hasBlock(blockRoot) || this.forkChoice.hasBlockHexUnsafe(blockRoot);
579
+ return (
580
+ this.seenBlockInputCache.hasBlock(blockRoot) ||
581
+ this.seenBlockInputCache.isValidatingBlock(blockRoot) ||
582
+ this.forkChoice.hasBlockHexUnsafe(blockRoot)
583
+ );
578
584
  }
579
585
 
580
586
  seenPayloadEnvelope(blockRoot: RootHex): boolean {
@@ -614,12 +620,14 @@ export class BeaconChain implements IBeaconChain {
614
620
  async loadFromDisk(): Promise<void> {
615
621
  await this.regen.init();
616
622
  await this.opPool.fromPersisted(this.db, this.getHeadState(), this.bls, this.clock.currentSlot);
623
+ await this.proposerPreferencesPool.fromPersisted(this.db, this.clock.currentSlot);
617
624
  }
618
625
 
619
626
  /** Persist in-memory data to the DB. Call at least once before stopping the process */
620
627
  async persistToDisk(): Promise<void> {
621
628
  await this.archiveStore.persistToDisk();
622
629
  await this.opPool.toPersisted(this.db);
630
+ await this.proposerPreferencesPool.toPersisted(this.db);
623
631
  }
624
632
 
625
633
  getHeadState(): IBeaconStateView {
@@ -1623,21 +1631,48 @@ export class BeaconChain implements IBeaconChain {
1623
1631
  const blockEpoch = computeEpochAtSlot(attHeadBlock.slot);
1624
1632
 
1625
1633
  let state: IBeaconStateView;
1626
- if (blockEpoch < attEpoch - 1) {
1627
- // thanks to one epoch look ahead, we don't need to dial up to attEpoch
1628
- const targetSlot = computeStartSlotAtEpoch(attEpoch - 1);
1629
- this.metrics?.gossipAttestation.useHeadBlockStateDialedToTargetEpoch.inc({caller: regenCaller});
1630
- state = await this.regen.getBlockSlotState(attHeadBlock, targetSlot, {dontTransferCache: true}, regenCaller);
1631
- } else if (blockEpoch > attEpoch) {
1632
- // should not happen, handled inside attestation verification code
1633
- throw Error(`Block epoch ${blockEpoch} is after attestation epoch ${attEpoch}`);
1634
- } else {
1635
- // should use either current or next shuffling of head state
1636
- // it's not likely to hit this since these shufflings are cached already
1637
- // so handle just in case
1638
- this.metrics?.gossipAttestation.useHeadBlockState.inc({caller: regenCaller});
1639
- state = await this.regen.getState(attHeadBlock.stateRoot, regenCaller);
1634
+ try {
1635
+ if (blockEpoch < attEpoch - 1) {
1636
+ // thanks to one epoch look ahead, we don't need to dial up to attEpoch
1637
+ const targetSlot = computeStartSlotAtEpoch(attEpoch - 1);
1638
+ this.metrics?.gossipAttestation.useHeadBlockStateDialedToTargetEpoch.inc({caller: regenCaller});
1639
+ state = await this.regen.getBlockSlotState(attHeadBlock, targetSlot, {dontTransferCache: true}, regenCaller);
1640
+ } else if (blockEpoch > attEpoch) {
1641
+ // should not happen, handled inside attestation verification code
1642
+ throw Error(`Block epoch ${blockEpoch} is after attestation epoch ${attEpoch}`);
1643
+ } else {
1644
+ // should use either current or next shuffling of head state
1645
+ // it's not likely to hit this since these shufflings are cached already
1646
+ // so handle just in case
1647
+ this.metrics?.gossipAttestation.useHeadBlockState.inc({caller: regenCaller});
1648
+ state = await this.regen.getState(attHeadBlock.stateRoot, regenCaller);
1649
+ }
1650
+ } catch (e) {
1651
+ this.shufflingCache.cancelPromise(attEpoch, shufflingDependentRoot, ShufflingPromiseCancelReason.regenError);
1652
+ throw e;
1653
+ }
1654
+
1655
+ const stateDecisionRoot = state.getShufflingDecisionRoot(attEpoch);
1656
+ if (stateDecisionRoot !== shufflingDependentRoot) {
1657
+ // the promise would never be resolved by the state's shuffling
1658
+ this.shufflingCache.cancelPromise(
1659
+ attEpoch,
1660
+ shufflingDependentRoot,
1661
+ ShufflingPromiseCancelReason.decisionRootMismatch
1662
+ );
1663
+ this.logger.debug("Shuffling decision root mismatch on attestation regen", {
1664
+ slot: attHeadBlock.slot,
1665
+ root: attHeadBlock.blockRoot,
1666
+ epoch: attEpoch,
1667
+ shufflingDependentRoot,
1668
+ stateDecisionRoot,
1669
+ });
1670
+
1671
+ throw Error(
1672
+ `Shuffling decision root mismatch epoch=${attEpoch} slot=${attHeadBlock.slot} root=${attHeadBlock.blockRoot} expected=${shufflingDependentRoot} actual=${stateDecisionRoot}`
1673
+ );
1640
1674
  }
1675
+
1641
1676
  // resolve the promise to unblock other calls of the same epoch and dependent root
1642
1677
  this.shufflingCache.processState(state);
1643
1678
  return state.getShufflingAtEpoch(attEpoch);
@@ -1901,6 +1936,21 @@ export class BeaconChain implements IBeaconChain {
1901
1936
  }
1902
1937
  }
1903
1938
 
1939
+ async updateAttachedValidators(epoch: Epoch, validatorIndices: ValidatorIndex[]): Promise<void> {
1940
+ let hasNewValidators = false;
1941
+ for (const validatorIndex of validatorIndices) {
1942
+ if (this.beaconProposerCache.track(epoch, validatorIndex)) {
1943
+ hasNewValidators = true;
1944
+ }
1945
+ }
1946
+
1947
+ // Only update validator custody if we discovered new validators
1948
+ if (hasNewValidators) {
1949
+ const finalizedCheckpoint = this.forkChoice.getFinalizedCheckpoint();
1950
+ await this.updateValidatorsCustodyRequirement(finalizedCheckpoint);
1951
+ }
1952
+ }
1953
+
1904
1954
  private async updateValidatorsCustodyRequirement(finalizedCheckpoint: CheckpointWithHex): Promise<void> {
1905
1955
  if (this.custodyConfig.targetCustodyGroupCount === this.config.NUMBER_OF_CUSTODY_GROUPS) {
1906
1956
  // Custody requirements can only be increased, we can disable dynamic custody updates
@@ -288,6 +288,8 @@ export interface IBeaconChain {
288
288
  waitForBlock(slot: Slot, root: RootHex): Promise<boolean>;
289
289
 
290
290
  updateBeaconProposerData(epoch: Epoch, proposers: ProposerPreparationData[]): Promise<void>;
291
+ /** Track validators that use this node for duties, e.g. by subscribing to attestation subnets */
292
+ updateAttachedValidators(epoch: Epoch, validatorIndices: ValidatorIndex[]): Promise<void>;
291
293
 
292
294
  persistBlock(data: BeaconBlock | BlindedBeaconBlock, suffix?: string): void;
293
295
  persistExecutionPayloadEnvelope(envelope: gloas.ExecutionPayloadEnvelope): void;
@@ -329,6 +331,7 @@ export type SSZObjectType =
329
331
  | "syncCommittee"
330
332
  | "contributionAndProof";
331
333
 
332
- export type CommonBlockBody = phase0.BeaconBlockBody &
334
+ export type CommonBlockBody = Omit<phase0.BeaconBlockBody, "eth1Data" | "deposits"> &
335
+ Partial<Pick<phase0.BeaconBlockBody, "eth1Data" | "deposits">> &
333
336
  Pick<capella.BeaconBlockBody, "blsToExecutionChanges"> &
334
337
  Pick<altair.BeaconBlockBody, "syncAggregate">;
@@ -30,7 +30,7 @@ import {
30
30
  isStatePostGloas,
31
31
  } from "@lodestar/state-transition";
32
32
  import {Attestation, Epoch, RootHex, Slot, electra, isElectraAttestation, phase0, ssz} from "@lodestar/types";
33
- import {MapDef, assert, toRootHex} from "@lodestar/utils";
33
+ import {Logger, MapDef, assert, toRootHex} from "@lodestar/utils";
34
34
  import {Metrics} from "../../metrics/metrics.js";
35
35
  import {IntersectResult, intersectUint8Arrays} from "../../util/bitArray.js";
36
36
  import {getShufflingDependentRoot} from "../../util/dependentRoot.js";
@@ -58,7 +58,7 @@ export type AttestationsConsolidation = {
58
58
 
59
59
  /**
60
60
  * This function returns not seen participation for a given epoch and slot and committee index.
61
- * Return null if all validators are seen or no info to check.
61
+ * Return an empty set if all validators are seen, or null if the committee cannot be computed (e.g. missing shuffling).
62
62
  */
63
63
  type GetNotSeenValidatorsFn = (epoch: Epoch, slot: Slot, committeeIndex: number) => Set<number> | null;
64
64
 
@@ -140,7 +140,8 @@ export class AggregatedAttestationPool {
140
140
 
141
141
  constructor(
142
142
  private readonly config: BeaconConfig,
143
- private readonly metrics: Metrics | null = null
143
+ private readonly metrics: Metrics | null = null,
144
+ private readonly logger: Logger | null = null
144
145
  ) {
145
146
  metrics?.opPool.aggregatedAttestationPool.attDataPerSlot.addCollect(() => this.onScrapeMetrics(metrics));
146
147
  }
@@ -244,6 +245,7 @@ export class AggregatedAttestationPool {
244
245
  const consolidations = new Map<AttestationsConsolidation, number>();
245
246
  let scannedSlots = 0;
246
247
  let stopReason: ScannedSlotsTerminationReason | null = null;
248
+ const missingShufflingCommitteesByEpoch = new Map<Epoch, number>();
247
249
  slot: for (const slot of slots) {
248
250
  const attestationGroupByIndexByDataHash = this.attestationGroupByIndexByDataHexBySlot.get(slot);
249
251
  // should not happen
@@ -295,7 +297,12 @@ export class AggregatedAttestationPool {
295
297
 
296
298
  for (const [committeeIndex, attestationGroup] of attestationGroupByIndex.entries()) {
297
299
  const notSeenCommitteeMembers = notSeenValidatorsFn(epoch, slot, committeeIndex);
298
- if (notSeenCommitteeMembers === null || notSeenCommitteeMembers.size === 0) {
300
+ if (notSeenCommitteeMembers === null) {
301
+ // skip this committee instead of failing the whole block production, other epochs may still have shuffling
302
+ missingShufflingCommitteesByEpoch.set(epoch, (missingShufflingCommitteesByEpoch.get(epoch) ?? 0) + 1);
303
+ continue;
304
+ }
305
+ if (notSeenCommitteeMembers.size === 0) {
299
306
  this.metrics?.opPool.aggregatedAttestationPool.packedAttestations.seenCommittees.inc();
300
307
  continue;
301
308
  }
@@ -386,6 +393,18 @@ export class AggregatedAttestationPool {
386
393
  scannedSlots++;
387
394
  }
388
395
 
396
+ for (const [epoch, missingCommittees] of missingShufflingCommitteesByEpoch) {
397
+ this.metrics?.opPool.aggregatedAttestationPool.packedAttestations.missingShufflingCommittees.inc(
398
+ missingCommittees
399
+ );
400
+ this.logger?.debug("Missing shuffling when packing attestations, skipped committees", {
401
+ slot: stateSlot,
402
+ epoch,
403
+ decisionRoot: state.getShufflingDecisionRoot(epoch),
404
+ missingCommittees,
405
+ });
406
+ }
407
+
389
408
  this.metrics?.opPool.aggregatedAttestationPool.packedAttestations.totalConsolidations.set(consolidations.size);
390
409
 
391
410
  const sortedConsolidationsByScore = Array.from(consolidations.entries())
@@ -770,13 +789,18 @@ export function getNotSeenValidatorsFn(
770
789
  }
771
790
  const cacheKey = slot + "_" + committeeIndex;
772
791
  let notSeenCommitteeMembers = cachedNotSeenValidators.get(cacheKey);
773
- if (notSeenCommitteeMembers != null) {
774
- // if all validators are seen then return null, we don't need to check for any attestations of same committee again
775
- return notSeenCommitteeMembers.size === 0 ? null : notSeenCommitteeMembers;
792
+ if (notSeenCommitteeMembers !== undefined) {
793
+ return notSeenCommitteeMembers;
776
794
  }
777
795
 
778
796
  const decisionRoot = state.getShufflingDecisionRoot(computeEpochAtSlot(slot));
779
- const committee = shufflingCache.getBeaconCommittee(epoch, decisionRoot, slot, committeeIndex);
797
+ const committee = shufflingCache.getBeaconCommitteeOrNull(epoch, decisionRoot, slot, committeeIndex);
798
+ if (committee === null) {
799
+ // attestations in the pool were validated against a cached shuffling of the previous or current epoch,
800
+ // so a miss is a ShufflingCache bug. Return null so the caller tracks it via metrics/logs without failing
801
+ // block production. Don't fall back to the state's shuffling, that would hide the bug
802
+ return null;
803
+ }
780
804
  notSeenCommitteeMembers = new Set<number>();
781
805
  for (const [i, validatorIndex] of committee.entries()) {
782
806
  // no need to check flagIsTimelySource as if validator is not seen, it's participation status is 0
@@ -786,8 +810,8 @@ export function getNotSeenValidatorsFn(
786
810
  }
787
811
  }
788
812
  cachedNotSeenValidators.set(cacheKey, notSeenCommitteeMembers);
789
- // if all validators are seen then return null, we don't need to check for any attestations of same committee again
790
- return notSeenCommitteeMembers.size === 0 ? null : notSeenCommitteeMembers;
813
+ // an empty set means all validators are seen, we don't need to check for any attestations of same committee again
814
+ return notSeenCommitteeMembers;
791
815
  };
792
816
  }
793
817
 
@@ -1,5 +1,4 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
- import {DbBatch, Id, Repository} from "@lodestar/db";
3
2
  import {
4
3
  BLS_WITHDRAWAL_PREFIX,
5
4
  ForkName,
@@ -42,6 +41,7 @@ import {
42
41
  getAttesterSlashingSignatureDomains,
43
42
  getProposerSlashingSignatureDomain,
44
43
  isValidBlsToExecutionChangeForBlockInclusion,
44
+ persistDiff,
45
45
  } from "./utils.js";
46
46
 
47
47
  type HexRoot = string;
@@ -500,33 +500,3 @@ function isVoluntaryExitSignatureIncludable(stateFork: ForkSeq, voluntaryExitFor
500
500
  function isSlashableAtEpoch(validator: phase0.Validator, epoch: Epoch): boolean {
501
501
  return !validator.slashed && validator.activationEpoch <= epoch && epoch < validator.withdrawableEpoch;
502
502
  }
503
-
504
- /**
505
- * Persist target items `items` in `dbRepo` doing minimum put and delete writes.
506
- * Reads all keys in repository to compute the diff between current persisted data and target data.
507
- */
508
- async function persistDiff<K extends Id, V>(
509
- dbRepo: Repository<K, V>,
510
- items: {key: K; value: V}[],
511
- serializeKey: (key: K) => number | string,
512
- opts: {updateExisting?: boolean} = {}
513
- ): Promise<void> {
514
- const persistedKeys = await dbRepo.keys();
515
- const batch: DbBatch<K, V> = [];
516
-
517
- const persistedKeysSerialized = new Set(persistedKeys.map(serializeKey));
518
- for (const item of items) {
519
- if (opts.updateExisting || !persistedKeysSerialized.has(serializeKey(item.key))) {
520
- batch.push({type: "put", key: item.key, value: item.value});
521
- }
522
- }
523
-
524
- const targetKeysSerialized = new Set(items.map((item) => serializeKey(item.key)));
525
- for (const persistedKey of persistedKeys) {
526
- if (!targetKeysSerialized.has(serializeKey(persistedKey))) {
527
- batch.push({type: "del", key: persistedKey});
528
- }
529
- }
530
-
531
- if (batch.length > 0) await dbRepo.batch(batch);
532
- }
@@ -1,5 +1,7 @@
1
1
  import {RootHex, Slot, ValidatorIndex, gloas} from "@lodestar/types";
2
- import {toRootHex} from "@lodestar/utils";
2
+ import {toHex, toRootHex} from "@lodestar/utils";
3
+ import {IBeaconDb} from "../../db/index.js";
4
+ import {persistDiff} from "./utils.js";
3
5
 
4
6
  /**
5
7
  * Pool of validated `SignedProposerPreferences` indexed by `(slot, dependent_root)`.
@@ -64,4 +66,21 @@ export class ProposerPreferencesPool {
64
66
  if (slot < currentSlot) this.bySlot.delete(slot);
65
67
  }
66
68
  }
69
+
70
+ /** Restore the preferences of upcoming slots, they were validated before they were persisted */
71
+ async fromPersisted(db: IBeaconDb, currentSlot: Slot): Promise<void> {
72
+ for (const signed of await db.proposerPreferences.values()) {
73
+ if (signed.message.proposalSlot >= currentSlot) {
74
+ this.add(signed);
75
+ }
76
+ }
77
+ }
78
+
79
+ async toPersisted(db: IBeaconDb): Promise<void> {
80
+ await persistDiff(
81
+ db.proposerPreferences,
82
+ this.getAll().map((signed) => ({key: db.proposerPreferences.getId(signed), value: signed})),
83
+ toHex
84
+ );
85
+ }
67
86
  }
@@ -1,5 +1,6 @@
1
1
  import {Signature} from "@chainsafe/lodestar-z/blst";
2
2
  import {BeaconConfig} from "@lodestar/config";
3
+ import {DbBatch, Id, Repository} from "@lodestar/db";
3
4
  import {BLS_WITHDRAWAL_PREFIX, DOMAIN_BEACON_ATTESTER, DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
4
5
  import {IBeaconStateView, computeStartSlotAtEpoch} from "@lodestar/state-transition";
5
6
  import {AttesterSlashing, Domain, Slot, capella, phase0} from "@lodestar/types";
@@ -91,3 +92,33 @@ export function isValidBlsToExecutionChangeForBlockInclusion(
91
92
  export function isElectraAggregate(aggregate: AggregateFast): aggregate is AggregateFastElectra {
92
93
  return (aggregate as AggregateFastElectra).committeeBits !== undefined;
93
94
  }
95
+
96
+ /**
97
+ * Persist target items `items` in `dbRepo` doing minimum put and delete writes.
98
+ * Reads all keys in repository to compute the diff between current persisted data and target data.
99
+ */
100
+ export async function persistDiff<K extends Id, V>(
101
+ dbRepo: Repository<K, V>,
102
+ items: {key: K; value: V}[],
103
+ serializeKey: (key: K) => number | string,
104
+ opts: {updateExisting?: boolean} = {}
105
+ ): Promise<void> {
106
+ const persistedKeys = await dbRepo.keys();
107
+ const batch: DbBatch<K, V> = [];
108
+
109
+ const persistedKeysSerialized = new Set(persistedKeys.map(serializeKey));
110
+ for (const item of items) {
111
+ if (opts.updateExisting || !persistedKeysSerialized.has(serializeKey(item.key))) {
112
+ batch.push({type: "put", key: item.key, value: item.value});
113
+ }
114
+ }
115
+
116
+ const targetKeysSerialized = new Set(items.map((item) => serializeKey(item.key)));
117
+ for (const persistedKey of persistedKeys) {
118
+ if (!targetKeysSerialized.has(serializeKey(persistedKey))) {
119
+ batch.push({type: "del", key: persistedKey});
120
+ }
121
+ }
122
+
123
+ if (batch.length > 0) await dbRepo.batch(batch);
124
+ }
@@ -22,7 +22,7 @@ import {
22
22
  isStatePostGloas,
23
23
  } from "@lodestar/state-transition";
24
24
  import {Bytes32, Slot, ValidatorIndex} from "@lodestar/types";
25
- import {Logger, fromHex, isErrorAborted, sleep} from "@lodestar/utils";
25
+ import {Logger, fromHex, isErrorAborted, sleep, toHex} from "@lodestar/utils";
26
26
  import {GENESIS_SLOT} from "../constants/constants.js";
27
27
  import {BuilderStatus} from "../execution/builder/http.js";
28
28
  import {PayloadAttributes} from "../execution/index.js";
@@ -31,7 +31,11 @@ import {ClockEvent} from "../util/clock.js";
31
31
  import {isQueueErrorAborted} from "../util/queue/index.js";
32
32
  import {ForkchoiceCaller} from "./forkChoice/index.js";
33
33
  import {IBeaconChain} from "./interface.js";
34
- import {getPayloadAttributesForSSE, prepareExecutionPayload} from "./produceBlock/produceBlockBody.js";
34
+ import {
35
+ getPayloadAttributesForSSE,
36
+ getPooledProposerPreferences,
37
+ prepareExecutionPayload,
38
+ } from "./produceBlock/produceBlockBody.js";
35
39
  import {RegenCaller} from "./regen/index.js";
36
40
 
37
41
  // TODO GLOAS: re-evaluate this timing
@@ -158,7 +162,15 @@ export class PrepareNextSlotScheduler {
158
162
  };
159
163
 
160
164
  const proposerIndex = await getProposerIndex();
161
- feeRecipient = this.chain.beaconProposerCache.get(proposerIndex);
165
+ if (this.chain.beaconProposerCache.has(proposerIndex)) {
166
+ const pooledPreferences = isForkPostGloas(fork)
167
+ ? getPooledProposerPreferences(this.chain, prepareSlot, headRoot)
168
+ : null;
169
+ feeRecipient =
170
+ pooledPreferences !== null
171
+ ? toHex(pooledPreferences.feeRecipient)
172
+ : this.chain.beaconProposerCache.getOrDefault(proposerIndex);
173
+ }
162
174
 
163
175
  // Predict the proposer head of the next slot when either:
164
176
  // - we are proposing the next slot (single-slot proposer-boost-reorg), or
@@ -1,5 +1,12 @@
1
1
  import {EMPTY_SIGNATURE, IBeaconStateView, StateHashTreeRootSource} from "@lodestar/state-transition";
2
- import {BeaconBlock, BlindedBeaconBlock, Gwei, Root} from "@lodestar/types";
2
+ import {
3
+ BeaconBlock,
4
+ BlindedBeaconBlock,
5
+ Gwei,
6
+ Root,
7
+ SignedBeaconBlock,
8
+ SignedBlindedBeaconBlock,
9
+ } from "@lodestar/types";
3
10
  import {Metrics} from "../../metrics/index.js";
4
11
 
5
12
  /**
@@ -13,7 +20,7 @@ export function computeNewStateRoot(
13
20
  block: BeaconBlock | BlindedBeaconBlock
14
21
  ): {newStateRoot: Root; proposerReward: Gwei; postState: IBeaconStateView} {
15
22
  // Set signature to zero to re-use stateTransition() function which requires the SignedBeaconBlock type
16
- const signedBlock = {message: block, signature: EMPTY_SIGNATURE};
23
+ const signedBlock = {message: block, signature: EMPTY_SIGNATURE} as SignedBeaconBlock | SignedBlindedBeaconBlock;
17
24
  const {newStateRoot, proposerReward, postState, hashTreeRootTime} = state.computeNewStateRoot(
18
25
  {block: signedBlock},
19
26
  {metrics: metrics?.stateTransition}