@lodestar/beacon-node 1.39.0-dev.aceb5b7416 → 1.39.0-dev.b37f2bd1bd

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 (248) hide show
  1. package/lib/api/impl/beacon/blocks/utils.js +1 -1
  2. package/lib/api/impl/beacon/blocks/utils.js.map +1 -1
  3. package/lib/chain/chain.d.ts +4 -1
  4. package/lib/chain/chain.d.ts.map +1 -1
  5. package/lib/chain/chain.js +12 -2
  6. package/lib/chain/chain.js.map +1 -1
  7. package/lib/chain/genesis/genesis.d.ts +51 -0
  8. package/lib/chain/genesis/genesis.d.ts.map +1 -0
  9. package/lib/chain/genesis/genesis.js +123 -0
  10. package/lib/chain/genesis/genesis.js.map +1 -0
  11. package/lib/chain/genesis/interface.d.ts +13 -0
  12. package/lib/chain/genesis/interface.d.ts.map +1 -0
  13. package/lib/chain/genesis/interface.js +2 -0
  14. package/lib/chain/genesis/interface.js.map +1 -0
  15. package/lib/chain/initState.d.ts +14 -1
  16. package/lib/chain/initState.d.ts.map +1 -1
  17. package/lib/chain/initState.js +62 -1
  18. package/lib/chain/initState.js.map +1 -1
  19. package/lib/chain/interface.d.ts +2 -0
  20. package/lib/chain/interface.d.ts.map +1 -1
  21. package/lib/chain/interface.js.map +1 -1
  22. package/lib/chain/prepareNextSlot.d.ts +4 -0
  23. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  24. package/lib/chain/prepareNextSlot.js +21 -1
  25. package/lib/chain/prepareNextSlot.js.map +1 -1
  26. package/lib/chain/produceBlock/produceBlockBody.d.ts +1 -0
  27. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  28. package/lib/chain/produceBlock/produceBlockBody.js +9 -6
  29. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  30. package/lib/db/beacon.d.ts +7 -1
  31. package/lib/db/beacon.d.ts.map +1 -1
  32. package/lib/db/beacon.js +12 -1
  33. package/lib/db/beacon.js.map +1 -1
  34. package/lib/db/buckets.d.ts +6 -0
  35. package/lib/db/buckets.d.ts.map +1 -1
  36. package/lib/db/buckets.js +7 -6
  37. package/lib/db/buckets.js.map +1 -1
  38. package/lib/db/interface.d.ts +7 -1
  39. package/lib/db/interface.d.ts.map +1 -1
  40. package/lib/db/repositories/blockArchiveIndex.d.ts +2 -2
  41. package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
  42. package/lib/db/repositories/depositDataRoot.d.ts +22 -0
  43. package/lib/db/repositories/depositDataRoot.d.ts.map +1 -0
  44. package/lib/db/repositories/depositDataRoot.js +62 -0
  45. package/lib/db/repositories/depositDataRoot.js.map +1 -0
  46. package/lib/db/repositories/depositEvent.d.ts +13 -0
  47. package/lib/db/repositories/depositEvent.d.ts.map +1 -0
  48. package/lib/db/repositories/depositEvent.js +27 -0
  49. package/lib/db/repositories/depositEvent.js.map +1 -0
  50. package/lib/db/repositories/eth1Data.d.ts +13 -0
  51. package/lib/db/repositories/eth1Data.d.ts.map +1 -0
  52. package/lib/db/repositories/eth1Data.js +26 -0
  53. package/lib/db/repositories/eth1Data.js.map +1 -0
  54. package/lib/db/repositories/index.d.ts +3 -0
  55. package/lib/db/repositories/index.d.ts.map +1 -1
  56. package/lib/db/repositories/index.js +3 -0
  57. package/lib/db/repositories/index.js.map +1 -1
  58. package/lib/db/single/index.d.ts +3 -0
  59. package/lib/db/single/index.d.ts.map +1 -0
  60. package/lib/db/single/index.js +3 -0
  61. package/lib/db/single/index.js.map +1 -0
  62. package/lib/db/single/preGenesisState.d.ts +16 -0
  63. package/lib/db/single/preGenesisState.d.ts.map +1 -0
  64. package/lib/db/single/preGenesisState.js +29 -0
  65. package/lib/db/single/preGenesisState.js.map +1 -0
  66. package/lib/db/single/preGenesisStateLastProcessedBlock.d.ts +14 -0
  67. package/lib/db/single/preGenesisStateLastProcessedBlock.d.ts.map +1 -0
  68. package/lib/db/single/preGenesisStateLastProcessedBlock.js +27 -0
  69. package/lib/db/single/preGenesisStateLastProcessedBlock.js.map +1 -0
  70. package/lib/eth1/errors.d.ts +66 -0
  71. package/lib/eth1/errors.d.ts.map +1 -0
  72. package/lib/eth1/errors.js +27 -0
  73. package/lib/eth1/errors.js.map +1 -0
  74. package/lib/eth1/eth1DataCache.d.ts +19 -0
  75. package/lib/eth1/eth1DataCache.d.ts.map +1 -0
  76. package/lib/eth1/eth1DataCache.js +19 -0
  77. package/lib/eth1/eth1DataCache.js.map +1 -0
  78. package/lib/eth1/eth1DepositDataTracker.d.ts +80 -0
  79. package/lib/eth1/eth1DepositDataTracker.d.ts.map +1 -0
  80. package/lib/eth1/eth1DepositDataTracker.js +317 -0
  81. package/lib/eth1/eth1DepositDataTracker.js.map +1 -0
  82. package/lib/eth1/eth1DepositsCache.d.ts +42 -0
  83. package/lib/eth1/eth1DepositsCache.d.ts.map +1 -0
  84. package/lib/eth1/eth1DepositsCache.js +119 -0
  85. package/lib/eth1/eth1DepositsCache.js.map +1 -0
  86. package/lib/eth1/index.d.ts +31 -0
  87. package/lib/eth1/index.d.ts.map +1 -0
  88. package/lib/eth1/index.js +71 -0
  89. package/lib/eth1/index.js.map +1 -0
  90. package/lib/eth1/interface.d.ts +74 -0
  91. package/lib/eth1/interface.d.ts.map +1 -0
  92. package/lib/eth1/interface.js +8 -0
  93. package/lib/eth1/interface.js.map +1 -0
  94. package/lib/eth1/options.d.ts +22 -0
  95. package/lib/eth1/options.d.ts.map +1 -0
  96. package/lib/eth1/options.js +8 -0
  97. package/lib/eth1/options.js.map +1 -0
  98. package/lib/eth1/provider/eth1Provider.d.ts +39 -0
  99. package/lib/eth1/provider/eth1Provider.d.ts.map +1 -0
  100. package/lib/eth1/provider/eth1Provider.js +147 -0
  101. package/lib/eth1/provider/eth1Provider.js.map +1 -0
  102. package/lib/{execution/engine → eth1/provider}/jsonRpcHttpClient.d.ts +1 -1
  103. package/lib/eth1/provider/jsonRpcHttpClient.d.ts.map +1 -0
  104. package/lib/eth1/provider/jsonRpcHttpClient.js.map +1 -0
  105. package/lib/eth1/provider/jwt.d.ts.map +1 -0
  106. package/lib/eth1/provider/jwt.js.map +1 -0
  107. package/lib/eth1/provider/utils.d.ts +65 -0
  108. package/lib/eth1/provider/utils.d.ts.map +1 -0
  109. package/lib/eth1/provider/utils.js +120 -0
  110. package/lib/eth1/provider/utils.js.map +1 -0
  111. package/lib/eth1/stream.d.ts +15 -0
  112. package/lib/eth1/stream.d.ts.map +1 -0
  113. package/lib/eth1/stream.js +54 -0
  114. package/lib/eth1/stream.js.map +1 -0
  115. package/lib/eth1/utils/depositContract.d.ts +14 -0
  116. package/lib/eth1/utils/depositContract.d.ts.map +1 -0
  117. package/lib/eth1/utils/depositContract.js +33 -0
  118. package/lib/eth1/utils/depositContract.js.map +1 -0
  119. package/lib/eth1/utils/deposits.d.ts +8 -0
  120. package/lib/eth1/utils/deposits.d.ts.map +1 -0
  121. package/lib/eth1/utils/deposits.js +47 -0
  122. package/lib/eth1/utils/deposits.js.map +1 -0
  123. package/lib/eth1/utils/eth1Data.d.ts +22 -0
  124. package/lib/eth1/utils/eth1Data.d.ts.map +1 -0
  125. package/lib/eth1/utils/eth1Data.js +77 -0
  126. package/lib/eth1/utils/eth1Data.js.map +1 -0
  127. package/lib/eth1/utils/eth1DepositEvent.d.ts +7 -0
  128. package/lib/eth1/utils/eth1DepositEvent.d.ts.map +1 -0
  129. package/lib/eth1/utils/eth1DepositEvent.js +13 -0
  130. package/lib/eth1/utils/eth1DepositEvent.js.map +1 -0
  131. package/lib/eth1/utils/eth1Vote.d.ts +17 -0
  132. package/lib/eth1/utils/eth1Vote.d.ts.map +1 -0
  133. package/lib/eth1/utils/eth1Vote.js +111 -0
  134. package/lib/eth1/utils/eth1Vote.js.map +1 -0
  135. package/lib/eth1/utils/groupDepositEventsByBlock.d.ts +9 -0
  136. package/lib/eth1/utils/groupDepositEventsByBlock.d.ts.map +1 -0
  137. package/lib/eth1/utils/groupDepositEventsByBlock.js +17 -0
  138. package/lib/eth1/utils/groupDepositEventsByBlock.js.map +1 -0
  139. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.d.ts +10 -0
  140. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.d.ts.map +1 -0
  141. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.js +14 -0
  142. package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.js.map +1 -0
  143. package/lib/execution/engine/http.d.ts +1 -1
  144. package/lib/execution/engine/http.d.ts.map +1 -1
  145. package/lib/execution/engine/http.js +3 -2
  146. package/lib/execution/engine/http.js.map +1 -1
  147. package/lib/execution/engine/index.d.ts.map +1 -1
  148. package/lib/execution/engine/index.js +1 -1
  149. package/lib/execution/engine/index.js.map +1 -1
  150. package/lib/execution/engine/interface.d.ts +1 -1
  151. package/lib/execution/engine/interface.d.ts.map +1 -1
  152. package/lib/execution/engine/interface.js.map +1 -1
  153. package/lib/execution/engine/mock.d.ts.map +1 -1
  154. package/lib/execution/engine/mock.js +1 -1
  155. package/lib/execution/engine/mock.js.map +1 -1
  156. package/lib/execution/engine/payloadIdCache.d.ts +1 -1
  157. package/lib/execution/engine/payloadIdCache.d.ts.map +1 -1
  158. package/lib/execution/engine/types.d.ts +1 -1
  159. package/lib/execution/engine/types.d.ts.map +1 -1
  160. package/lib/execution/engine/types.js +1 -1
  161. package/lib/execution/engine/types.js.map +1 -1
  162. package/lib/execution/engine/utils.d.ts +2 -64
  163. package/lib/execution/engine/utils.d.ts.map +1 -1
  164. package/lib/execution/engine/utils.js +2 -91
  165. package/lib/execution/engine/utils.js.map +1 -1
  166. package/lib/index.d.ts +2 -1
  167. package/lib/index.d.ts.map +1 -1
  168. package/lib/index.js +2 -1
  169. package/lib/index.js.map +1 -1
  170. package/lib/metrics/metrics/lodestar.d.ts +35 -0
  171. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  172. package/lib/metrics/metrics/lodestar.js +90 -0
  173. package/lib/metrics/metrics/lodestar.js.map +1 -1
  174. package/lib/node/nodejs.d.ts.map +1 -1
  175. package/lib/node/nodejs.js +9 -0
  176. package/lib/node/nodejs.js.map +1 -1
  177. package/lib/node/options.d.ts +2 -0
  178. package/lib/node/options.d.ts.map +1 -1
  179. package/lib/node/options.js +2 -0
  180. package/lib/node/options.js.map +1 -1
  181. package/lib/node/utils/interop/deposits.d.ts +1 -2
  182. package/lib/node/utils/interop/deposits.d.ts.map +1 -1
  183. package/lib/node/utils/interop/deposits.js.map +1 -1
  184. package/lib/node/utils/interop/state.d.ts +1 -1
  185. package/lib/node/utils/interop/state.d.ts.map +1 -1
  186. package/lib/node/utils/state.d.ts +7 -1
  187. package/lib/node/utils/state.d.ts.map +1 -1
  188. package/lib/node/utils/state.js +14 -1
  189. package/lib/node/utils/state.js.map +1 -1
  190. package/package.json +20 -14
  191. package/src/api/impl/beacon/blocks/utils.ts +1 -1
  192. package/src/chain/chain.ts +15 -1
  193. package/src/chain/genesis/genesis.ts +190 -0
  194. package/src/chain/genesis/interface.ts +14 -0
  195. package/src/chain/initState.ts +97 -1
  196. package/src/chain/interface.ts +2 -0
  197. package/src/chain/prepareNextSlot.ts +28 -1
  198. package/src/chain/produceBlock/produceBlockBody.ts +10 -6
  199. package/src/db/beacon.ts +15 -0
  200. package/src/db/buckets.ts +7 -6
  201. package/src/db/interface.ts +13 -0
  202. package/src/db/repositories/depositDataRoot.ts +80 -0
  203. package/src/db/repositories/depositEvent.ts +32 -0
  204. package/src/db/repositories/eth1Data.ts +33 -0
  205. package/src/db/repositories/index.ts +3 -0
  206. package/src/db/single/index.ts +2 -0
  207. package/src/db/single/preGenesisState.ts +37 -0
  208. package/src/db/single/preGenesisStateLastProcessedBlock.ts +34 -0
  209. package/src/eth1/errors.ts +40 -0
  210. package/src/eth1/eth1DataCache.ts +26 -0
  211. package/src/eth1/eth1DepositDataTracker.ts +410 -0
  212. package/src/eth1/eth1DepositsCache.ts +141 -0
  213. package/src/eth1/index.ts +94 -0
  214. package/src/eth1/interface.ts +87 -0
  215. package/src/eth1/options.ts +28 -0
  216. package/src/eth1/provider/eth1Provider.ts +229 -0
  217. package/src/{execution/engine → eth1/provider}/jsonRpcHttpClient.ts +1 -1
  218. package/src/eth1/provider/utils.ts +136 -0
  219. package/src/eth1/stream.ts +75 -0
  220. package/src/eth1/utils/depositContract.ts +37 -0
  221. package/src/eth1/utils/deposits.ts +70 -0
  222. package/src/eth1/utils/eth1Data.ts +100 -0
  223. package/src/eth1/utils/eth1DepositEvent.ts +12 -0
  224. package/src/eth1/utils/eth1Vote.ts +142 -0
  225. package/src/eth1/utils/groupDepositEventsByBlock.ts +19 -0
  226. package/src/eth1/utils/optimizeNextBlockDiffForGenesis.ts +18 -0
  227. package/src/execution/engine/http.ts +9 -8
  228. package/src/execution/engine/index.ts +1 -1
  229. package/src/execution/engine/interface.ts +1 -1
  230. package/src/execution/engine/mock.ts +2 -1
  231. package/src/execution/engine/payloadIdCache.ts +1 -1
  232. package/src/execution/engine/types.ts +9 -9
  233. package/src/execution/engine/utils.ts +5 -111
  234. package/src/index.ts +2 -1
  235. package/src/metrics/metrics/lodestar.ts +92 -0
  236. package/src/node/nodejs.ts +9 -0
  237. package/src/node/options.ts +3 -0
  238. package/src/node/utils/interop/deposits.ts +1 -3
  239. package/src/node/utils/interop/state.ts +1 -1
  240. package/src/node/utils/state.ts +18 -3
  241. package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +0 -1
  242. package/lib/execution/engine/jsonRpcHttpClient.js.map +0 -1
  243. package/lib/execution/engine/jwt.d.ts.map +0 -1
  244. package/lib/execution/engine/jwt.js.map +0 -1
  245. /package/lib/{execution/engine → eth1/provider}/jsonRpcHttpClient.js +0 -0
  246. /package/lib/{execution/engine → eth1/provider}/jwt.d.ts +0 -0
  247. /package/lib/{execution/engine → eth1/provider}/jwt.js +0 -0
  248. /package/src/{execution/engine → eth1/provider}/jwt.ts +0 -0
@@ -25,6 +25,7 @@ import {
25
25
  phase0,
26
26
  } from "@lodestar/types";
27
27
  import {Logger} from "@lodestar/utils";
28
+ import {IEth1ForBlockProduction} from "../eth1/index.js";
28
29
  import {IExecutionBuilder, IExecutionEngine} from "../execution/index.js";
29
30
  import {Metrics} from "../metrics/metrics.js";
30
31
  import {BufferPool} from "../util/bufferPool.js";
@@ -87,6 +88,7 @@ export interface IBeaconChain {
87
88
  readonly genesisTime: UintNum64;
88
89
  readonly genesisValidatorsRoot: Root;
89
90
  readonly earliestAvailableSlot: Slot;
91
+ readonly eth1: IEth1ForBlockProduction;
90
92
  readonly executionEngine: IExecutionEngine;
91
93
  readonly executionBuilder?: IExecutionBuilder;
92
94
  // Expose config for convenience in modularized functions
@@ -1,8 +1,9 @@
1
1
  import {routes} from "@lodestar/api";
2
2
  import {ChainForkConfig} from "@lodestar/config";
3
3
  import {getSafeExecutionBlockHash} from "@lodestar/fork-choice";
4
- import {ForkPostBellatrix, ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params";
4
+ import {ForkPostBellatrix, ForkSeq, SLOTS_PER_EPOCH, isForkPostElectra} from "@lodestar/params";
5
5
  import {
6
+ BeaconStateElectra,
6
7
  CachedBeaconStateAllForks,
7
8
  CachedBeaconStateExecutions,
8
9
  StateHashTreeRootSource,
@@ -221,6 +222,9 @@ export class PrepareNextSlotScheduler {
221
222
  }
222
223
  this.metrics?.precomputeNextEpochTransition.hits.set(previousHits ?? 0);
223
224
 
225
+ // Check if we can stop polling eth1 data
226
+ this.stopEth1Polling();
227
+
224
228
  this.logger.verbose("Completed PrepareNextSlotScheduler epoch transition", {
225
229
  nextEpoch,
226
230
  headSlot,
@@ -248,4 +252,27 @@ export class PrepareNextSlotScheduler {
248
252
  state.hashTreeRoot();
249
253
  hashTreeRootTimer?.();
250
254
  }
255
+
256
+ /**
257
+ * Stop eth1 data polling after eth1_deposit_index has reached deposit_requests_start_index in Electra as described in EIP-6110
258
+ */
259
+ stopEth1Polling(): void {
260
+ // Only continue if eth1 is still polling and finalized checkpoint is in Electra. State regen is expensive
261
+ if (this.chain.eth1.isPollingEth1Data()) {
262
+ const finalizedCheckpoint = this.chain.forkChoice.getFinalizedCheckpoint();
263
+ const checkpointFork = this.config.getForkInfoAtEpoch(finalizedCheckpoint.epoch).name;
264
+
265
+ if (isForkPostElectra(checkpointFork)) {
266
+ const finalizedState = this.chain.getStateByCheckpoint(finalizedCheckpoint)?.state;
267
+
268
+ if (
269
+ finalizedState !== undefined &&
270
+ finalizedState.eth1DepositIndex === Number((finalizedState as BeaconStateElectra).depositRequestsStartIndex)
271
+ ) {
272
+ // Signal eth1 to stop polling eth1Data
273
+ this.chain.eth1.stopPollingEth1Data();
274
+ }
275
+ }
276
+ }
277
+ }
251
278
  }
@@ -45,7 +45,7 @@ import {
45
45
  } from "@lodestar/types";
46
46
  import {Logger, sleep, toHex, toPubkeyHex, toRootHex} from "@lodestar/utils";
47
47
  import {ZERO_HASH_HEX} from "../../constants/index.js";
48
- import {numToQuantity} from "../../execution/engine/utils.js";
48
+ import {numToQuantity} from "../../eth1/provider/utils.js";
49
49
  import {
50
50
  IExecutionBuilder,
51
51
  IExecutionEngine,
@@ -78,6 +78,7 @@ export enum BlockProductionStep {
78
78
  voluntaryExits = "voluntaryExits",
79
79
  blsToExecutionChanges = "blsToExecutionChanges",
80
80
  attestations = "attestations",
81
+ eth1DataAndDeposits = "eth1DataAndDeposits",
81
82
  syncAggregate = "syncAggregate",
82
83
  executionPayload = "executionPayload",
83
84
  }
@@ -666,17 +667,20 @@ export async function produceCommonBlockBody<T extends BlockType>(
666
667
  step: BlockProductionStep.attestations,
667
668
  });
668
669
 
670
+ const endEth1DataAndDeposits = stepsMetrics?.startTimer();
671
+ const {eth1Data, deposits} = await this.eth1.getEth1DataAndDeposits(currentState);
672
+ endEth1DataAndDeposits?.({
673
+ step: BlockProductionStep.eth1DataAndDeposits,
674
+ });
675
+
669
676
  const blockBody: Omit<CommonBlockBody, "blsToExecutionChanges" | "syncAggregate"> = {
670
677
  randaoReveal,
671
678
  graffiti,
672
- // Eth1 data voting is no longer required since electra
673
- eth1Data: currentState.eth1Data,
679
+ eth1Data,
674
680
  proposerSlashings,
675
681
  attesterSlashings,
676
682
  attestations,
677
- // Since electra, deposits are processed by the execution layer,
678
- // we no longer support handling deposits from earlier forks.
679
- deposits: [],
683
+ deposits,
680
684
  voluntaryExits,
681
685
  };
682
686
 
package/src/db/beacon.ts CHANGED
@@ -14,12 +14,16 @@ import {
14
14
  CheckpointHeaderRepository,
15
15
  DataColumnSidecarArchiveRepository,
16
16
  DataColumnSidecarRepository,
17
+ DepositDataRootRepository,
18
+ DepositEventRepository,
19
+ Eth1DataRepository,
17
20
  ProposerSlashingRepository,
18
21
  StateArchiveRepository,
19
22
  SyncCommitteeRepository,
20
23
  SyncCommitteeWitnessRepository,
21
24
  VoluntaryExitRepository,
22
25
  } from "./repositories/index.js";
26
+ import {PreGenesisState, PreGenesisStateLastProcessedBlock} from "./single/index.js";
23
27
 
24
28
  export type BeaconDbModules = {
25
29
  config: ChainForkConfig;
@@ -41,8 +45,14 @@ export class BeaconDb implements IBeaconDb {
41
45
  voluntaryExit: VoluntaryExitRepository;
42
46
  proposerSlashing: ProposerSlashingRepository;
43
47
  attesterSlashing: AttesterSlashingRepository;
48
+ depositEvent: DepositEventRepository;
44
49
  blsToExecutionChange: BLSToExecutionChangeRepository;
45
50
 
51
+ depositDataRoot: DepositDataRootRepository;
52
+ eth1Data: Eth1DataRepository;
53
+ preGenesisState: PreGenesisState;
54
+ preGenesisStateLastProcessedBlock: PreGenesisStateLastProcessedBlock;
55
+
46
56
  // lightclient
47
57
  bestLightClientUpdate: BestLightClientUpdateRepository;
48
58
  checkpointHeader: CheckpointHeaderRepository;
@@ -70,6 +80,11 @@ export class BeaconDb implements IBeaconDb {
70
80
  this.blsToExecutionChange = new BLSToExecutionChangeRepository(config, db);
71
81
  this.proposerSlashing = new ProposerSlashingRepository(config, db);
72
82
  this.attesterSlashing = new AttesterSlashingRepository(config, db);
83
+ this.depositEvent = new DepositEventRepository(config, db);
84
+ this.depositDataRoot = new DepositDataRootRepository(config, db);
85
+ this.eth1Data = new Eth1DataRepository(config, db);
86
+ this.preGenesisState = new PreGenesisState(config, db);
87
+ this.preGenesisStateLastProcessedBlock = new PreGenesisStateLastProcessedBlock(config, db);
73
88
 
74
89
  // lightclient
75
90
  this.bestLightClientUpdate = new BestLightClientUpdateRepository(config, db);
package/src/db/buckets.ts CHANGED
@@ -16,13 +16,14 @@ export enum Bucket {
16
16
  index_mainChain = 6, // Slot -> Root<BeaconBlock>
17
17
  // justified, finalized state and block hashes
18
18
  index_chainInfo = 7, // Key -> Number64 | stateHash | blockHash
19
- // phase0_eth1Data = 8, // DEPRECATED - eth1 deposit tracking is not required since electra
20
- // index_depositDataRoot = 9, // DEPRECATED - eth1 deposit tracking is not required since electra
19
+ // eth1 processing
20
+ phase0_eth1Data = 8, // timestamp -> Eth1Data
21
+ index_depositDataRoot = 9, // depositIndex -> Root<DepositData>
21
22
 
22
23
  // op pool
23
24
  // phase0_attestation = 10, // DEPRECATED on v0.25.0
24
25
  // phase0_aggregateAndProof = 11, // Root -> AggregateAndProof, DEPRECATED on v.27.0
25
- // phase0_depositData = 12, // DEPRECATED - eth1 deposit tracking is not required since electra
26
+ phase0_depositData = 12, // [DEPRECATED] index -> DepositData
26
27
  phase0_exit = 13, // ValidatorIndex -> VoluntaryExit
27
28
  phase0_proposerSlashing = 14, // ValidatorIndex -> ProposerSlashing
28
29
  allForks_attesterSlashing = 15, // Root -> AttesterSlashing
@@ -31,15 +32,15 @@ export enum Bucket {
31
32
  allForks_checkpointState = 17, // Root -> BeaconState
32
33
 
33
34
  // allForks_pendingBlock = 25, // Root -> SignedBeaconBlock // DEPRECATED on v0.30.0
34
- // phase0_depositEvent = 19, // DEPRECATED - eth1 deposit tracking is not required since electra
35
+ phase0_depositEvent = 19, // depositIndex -> DepositEvent
35
36
 
36
37
  index_stateArchiveRootIndex = 26, // State Root -> slot
37
38
 
38
39
  deneb_blobSidecars = 27, // DENEB BeaconBlockRoot -> BlobSidecars
39
40
  deneb_blobSidecarsArchive = 28, // DENEB BeaconBlockSlot -> BlobSidecars
40
41
 
41
- // phase0_preGenesisState = 30, // DEPRECATED - genesis from eth1 is no longer supported
42
- // phase0_preGenesisStateLastProcessedBlock = 31, // DEPRECATED - genesis from eth1 is no longer supported
42
+ phase0_preGenesisState = 30, // Single = phase0.BeaconState
43
+ phase0_preGenesisStateLastProcessedBlock = 31, // Single = Uint8
43
44
 
44
45
  // Lightclient server
45
46
  // altair_bestUpdatePerCommitteePeriod = 30, // DEPRECATED on v0.32.0
@@ -12,12 +12,16 @@ import {
12
12
  CheckpointHeaderRepository,
13
13
  DataColumnSidecarArchiveRepository,
14
14
  DataColumnSidecarRepository,
15
+ DepositDataRootRepository,
16
+ DepositEventRepository,
17
+ Eth1DataRepository,
15
18
  ProposerSlashingRepository,
16
19
  StateArchiveRepository,
17
20
  SyncCommitteeRepository,
18
21
  SyncCommitteeWitnessRepository,
19
22
  VoluntaryExitRepository,
20
23
  } from "./repositories/index.js";
24
+ import {PreGenesisState, PreGenesisStateLastProcessedBlock} from "./single/index.js";
21
25
 
22
26
  /**
23
27
  * The DB service manages the data layer of the beacon chain
@@ -44,8 +48,17 @@ export interface IBeaconDb {
44
48
  voluntaryExit: VoluntaryExitRepository;
45
49
  proposerSlashing: ProposerSlashingRepository;
46
50
  attesterSlashing: AttesterSlashingRepository;
51
+ depositEvent: DepositEventRepository;
47
52
  blsToExecutionChange: BLSToExecutionChangeRepository;
48
53
 
54
+ // eth1 processing
55
+ preGenesisState: PreGenesisState;
56
+ preGenesisStateLastProcessedBlock: PreGenesisStateLastProcessedBlock;
57
+
58
+ // all deposit data roots and merkle tree
59
+ depositDataRoot: DepositDataRootRepository;
60
+ eth1Data: Eth1DataRepository;
61
+
49
62
  // lightclient
50
63
  bestLightClientUpdate: BestLightClientUpdateRepository;
51
64
  checkpointHeader: CheckpointHeaderRepository;
@@ -0,0 +1,80 @@
1
+ import {ByteVectorType, CompositeViewDU, ListCompositeType} from "@chainsafe/ssz";
2
+ import {ChainForkConfig} from "@lodestar/config";
3
+ import {Db, KeyValue, Repository} from "@lodestar/db";
4
+ import {Root, ssz} from "@lodestar/types";
5
+ import {bytesToInt} from "@lodestar/utils";
6
+ import {Bucket, getBucketNameByValue} from "../buckets.js";
7
+
8
+ // TODO: Review where is best to put this type
9
+ export type DepositTree = CompositeViewDU<ListCompositeType<ByteVectorType>>;
10
+
11
+ export class DepositDataRootRepository extends Repository<number, Root> {
12
+ private depositRootTree?: DepositTree;
13
+
14
+ constructor(config: ChainForkConfig, db: Db) {
15
+ const bucket = Bucket.index_depositDataRoot;
16
+ super(config, db, bucket, ssz.Root, getBucketNameByValue(bucket));
17
+ }
18
+
19
+ decodeKey(data: Buffer): number {
20
+ return bytesToInt(super.decodeKey(data) as unknown as Uint8Array, "be");
21
+ }
22
+
23
+ // depositDataRoots stored by depositData index
24
+ getId(_value: Root): number {
25
+ throw new Error("Unable to create depositIndex from root");
26
+ }
27
+
28
+ async put(index: number, value: Root): Promise<void> {
29
+ await super.put(index, value);
30
+ await this.depositRootTreeSet(index, value);
31
+ }
32
+
33
+ async batchPut(items: KeyValue<number, Root>[]): Promise<void> {
34
+ await super.batchPut(items);
35
+ for (const {key, value} of items) {
36
+ await this.depositRootTreeSet(key, value);
37
+ }
38
+ }
39
+
40
+ async putList(roots: Root[]): Promise<void> {
41
+ await this.batchPut(roots.map((root, index) => ({key: index, value: root})));
42
+ }
43
+
44
+ async batchPutValues(values: {index: number; root: Root}[]): Promise<void> {
45
+ await this.batchPut(
46
+ values.map(({index, root}) => ({
47
+ key: index,
48
+ value: root,
49
+ }))
50
+ );
51
+ }
52
+
53
+ async getDepositRootTree(): Promise<DepositTree> {
54
+ if (!this.depositRootTree) {
55
+ const values = await this.values();
56
+ this.depositRootTree = ssz.phase0.DepositDataRootList.toViewDU(values);
57
+ }
58
+ return this.depositRootTree;
59
+ }
60
+
61
+ async getDepositRootTreeAtIndex(depositIndex: number): Promise<DepositTree> {
62
+ const depositRootTree = await this.getDepositRootTree();
63
+ return depositRootTree.sliceTo(depositIndex);
64
+ }
65
+
66
+ private async depositRootTreeSet(index: number, value: Uint8Array): Promise<void> {
67
+ const depositRootTree = await this.getDepositRootTree();
68
+
69
+ // TODO: Review and fix properly
70
+ if (index > depositRootTree.length) {
71
+ throw Error(`Error setting depositRootTree index ${index} > length ${depositRootTree.length}`);
72
+ }
73
+
74
+ if (index === depositRootTree.length) {
75
+ depositRootTree.push(value);
76
+ } else {
77
+ depositRootTree.set(index, value);
78
+ }
79
+ }
80
+ }
@@ -0,0 +1,32 @@
1
+ import {ChainForkConfig} from "@lodestar/config";
2
+ import {Db, Repository} from "@lodestar/db";
3
+ import {phase0, ssz} from "@lodestar/types";
4
+ import {Bucket, getBucketNameByValue} from "../buckets.js";
5
+
6
+ /**
7
+ * DepositData indexed by deposit index
8
+ * Removed when included on chain or old
9
+ */
10
+ export class DepositEventRepository extends Repository<number, phase0.DepositEvent> {
11
+ constructor(config: ChainForkConfig, db: Db) {
12
+ const bucket = Bucket.phase0_depositEvent;
13
+ super(config, db, bucket, ssz.phase0.DepositEvent, getBucketNameByValue(bucket));
14
+ }
15
+
16
+ async deleteOld(depositCount: number): Promise<void> {
17
+ const firstDepositIndex = await this.firstKey();
18
+ if (firstDepositIndex === null) {
19
+ return;
20
+ }
21
+ await this.batchDelete(Array.from({length: depositCount - firstDepositIndex}, (_, i) => i + firstDepositIndex));
22
+ }
23
+
24
+ async batchPutValues(depositEvents: phase0.DepositEvent[]): Promise<void> {
25
+ await this.batchPut(
26
+ depositEvents.map((depositEvent) => ({
27
+ key: depositEvent.index,
28
+ value: depositEvent,
29
+ }))
30
+ );
31
+ }
32
+ }
@@ -0,0 +1,33 @@
1
+ import {ChainForkConfig} from "@lodestar/config";
2
+ import {Db, Repository} from "@lodestar/db";
3
+ import {phase0, ssz} from "@lodestar/types";
4
+ import {bytesToInt} from "@lodestar/utils";
5
+ import {Bucket, getBucketNameByValue} from "../buckets.js";
6
+
7
+ export class Eth1DataRepository extends Repository<number, phase0.Eth1DataOrdered> {
8
+ constructor(config: ChainForkConfig, db: Db) {
9
+ const bucket = Bucket.phase0_eth1Data;
10
+ super(config, db, bucket, ssz.phase0.Eth1DataOrdered, getBucketNameByValue(bucket));
11
+ }
12
+
13
+ decodeKey(data: Buffer): number {
14
+ return bytesToInt(super.decodeKey(data) as unknown as Uint8Array, "be");
15
+ }
16
+
17
+ getId(_value: phase0.Eth1Data): number {
18
+ throw new Error("Unable to create timestamp from block hash");
19
+ }
20
+
21
+ async batchPutValues(eth1Datas: (phase0.Eth1DataOrdered & {timestamp: number})[]): Promise<void> {
22
+ await this.batchPut(
23
+ eth1Datas.map((eth1Data) => ({
24
+ key: eth1Data.timestamp,
25
+ value: eth1Data,
26
+ }))
27
+ );
28
+ }
29
+
30
+ async deleteOld(timestamp: number): Promise<void> {
31
+ await this.batchDelete(await this.keys({lt: timestamp}));
32
+ }
33
+ }
@@ -8,6 +8,9 @@ export {BlockArchiveRepository} from "./blockArchive.js";
8
8
  export {BLSToExecutionChangeRepository} from "./blsToExecutionChange.js";
9
9
  export {DataColumnSidecarRepository} from "./dataColumnSidecar.js";
10
10
  export {DataColumnSidecarArchiveRepository} from "./dataColumnSidecarArchive.js";
11
+ export {DepositDataRootRepository} from "./depositDataRoot.js";
12
+ export {DepositEventRepository} from "./depositEvent.js";
13
+ export {Eth1DataRepository} from "./eth1Data.js";
11
14
  export {BestLightClientUpdateRepository} from "./lightclientBestUpdate.js";
12
15
  export {CheckpointHeaderRepository} from "./lightclientCheckpointHeader.js";
13
16
  export {SyncCommitteeRepository} from "./lightclientSyncCommittee.js";
@@ -0,0 +1,2 @@
1
+ export {PreGenesisState} from "./preGenesisState.js";
2
+ export {PreGenesisStateLastProcessedBlock} from "./preGenesisStateLastProcessedBlock.js";
@@ -0,0 +1,37 @@
1
+ import {ChainForkConfig} from "@lodestar/config";
2
+ import {Db, DbReqOpts} from "@lodestar/db";
3
+ import {ForkAll, GENESIS_SLOT} from "@lodestar/params";
4
+ import {BeaconStateAllForks} from "@lodestar/state-transition";
5
+ import {SSZTypesFor} from "@lodestar/types";
6
+ import {Bucket, getBucketNameByValue} from "../buckets.js";
7
+
8
+ export class PreGenesisState {
9
+ private readonly config: ChainForkConfig;
10
+ private readonly bucket: Bucket;
11
+ private readonly db: Db;
12
+ private readonly key: Uint8Array;
13
+ private readonly type: SSZTypesFor<ForkAll, "BeaconState">;
14
+ private readonly dbReqOpts: DbReqOpts;
15
+
16
+ constructor(config: ChainForkConfig, db: Db) {
17
+ this.config = config;
18
+ this.db = db;
19
+ this.bucket = Bucket.phase0_preGenesisState;
20
+ this.key = new Uint8Array([this.bucket]);
21
+ this.type = this.config.getForkTypes(GENESIS_SLOT).BeaconState;
22
+ this.dbReqOpts = {bucketId: getBucketNameByValue(this.bucket)};
23
+ }
24
+
25
+ async put(value: BeaconStateAllForks): Promise<void> {
26
+ await this.db.put(this.key, value.serialize(), this.dbReqOpts);
27
+ }
28
+
29
+ async get(): Promise<BeaconStateAllForks | null> {
30
+ const value = await this.db.get(this.key, this.dbReqOpts);
31
+ return value ? this.type.deserializeToViewDU(value) : null;
32
+ }
33
+
34
+ async delete(): Promise<void> {
35
+ await this.db.delete(this.key, this.dbReqOpts);
36
+ }
37
+ }
@@ -0,0 +1,34 @@
1
+ import {UintNumberType} from "@chainsafe/ssz";
2
+ import {ChainForkConfig} from "@lodestar/config";
3
+ import {Db, DbReqOpts} from "@lodestar/db";
4
+ import {ssz} from "@lodestar/types";
5
+ import {Bucket, getBucketNameByValue} from "../buckets.js";
6
+
7
+ export class PreGenesisStateLastProcessedBlock {
8
+ private readonly bucket: Bucket;
9
+ private readonly type: UintNumberType;
10
+ private readonly db: Db;
11
+ private readonly key: Uint8Array;
12
+ private readonly dbReqOpts: DbReqOpts;
13
+
14
+ constructor(_config: ChainForkConfig, db: Db) {
15
+ this.db = db;
16
+ this.type = ssz.UintNum64;
17
+ this.bucket = Bucket.phase0_preGenesisStateLastProcessedBlock;
18
+ this.key = new Uint8Array([this.bucket]);
19
+ this.dbReqOpts = {bucketId: getBucketNameByValue(this.bucket)};
20
+ }
21
+
22
+ async put(value: number): Promise<void> {
23
+ await this.db.put(this.key, this.type.serialize(value), this.dbReqOpts);
24
+ }
25
+
26
+ async get(): Promise<number | null> {
27
+ const value = await this.db.get(this.key, this.dbReqOpts);
28
+ return value ? this.type.deserialize(value) : null;
29
+ }
30
+
31
+ async delete(): Promise<void> {
32
+ await this.db.delete(this.key, this.dbReqOpts);
33
+ }
34
+ }
@@ -0,0 +1,40 @@
1
+ import {LodestarError} from "@lodestar/utils";
2
+
3
+ export enum Eth1ErrorCode {
4
+ /** Deposit index too high */
5
+ DEPOSIT_INDEX_TOO_HIGH = "ETH1_ERROR_DEPOSIT_INDEX_TOO_HIGH",
6
+ /** Not enough deposits in DB */
7
+ NOT_ENOUGH_DEPOSITS = "ETH1_ERROR_NOT_ENOUGH_DEPOSITS",
8
+ /** Too many deposits returned by DB */
9
+ TOO_MANY_DEPOSITS = "ETH1_ERROR_TOO_MANY_DEPOSITS",
10
+ /** Deposit root tree does not match current eth1Data */
11
+ WRONG_DEPOSIT_ROOT = "ETH1_ERROR_WRONG_DEPOSIT_ROOT",
12
+
13
+ /** No deposits found for block range */
14
+ NO_DEPOSITS_FOR_BLOCK_RANGE = "ETH1_ERROR_NO_DEPOSITS_FOR_BLOCK_RANGE",
15
+ /** No depositRoot for depositCount */
16
+ NO_DEPOSIT_ROOT = "ETH1_ERROR_NO_DEPOSIT_ROOT",
17
+ /** Not enough deposit roots for index */
18
+ NOT_ENOUGH_DEPOSIT_ROOTS = "ETH1_ERROR_NOT_ENOUGH_DEPOSIT_ROOTS",
19
+
20
+ /** Attempted to insert a duplicate log for same index into the Eth1DepositsCache */
21
+ DUPLICATE_DISTINCT_LOG = "ETH1_ERROR_DUPLICATE_DISTINCT_LOG",
22
+ /** Attempted to insert a log with index != prev + 1 into the Eth1DepositsCache */
23
+ NON_CONSECUTIVE_LOGS = "ETH1_ERROR_NON_CONSECUTIVE_LOGS",
24
+ /** Expected a deposit log in the db for the index, missing log implies a corrupted db */
25
+ MISSING_DEPOSIT_LOG = "ETH1_ERROR_MISSING_DEPOSIT_LOG",
26
+ }
27
+
28
+ export type Eth1ErrorType =
29
+ | {code: Eth1ErrorCode.DEPOSIT_INDEX_TOO_HIGH; depositIndex: number; depositCount: number}
30
+ | {code: Eth1ErrorCode.NOT_ENOUGH_DEPOSITS; len: number; expectedLen: number}
31
+ | {code: Eth1ErrorCode.TOO_MANY_DEPOSITS; len: number; expectedLen: number}
32
+ | {code: Eth1ErrorCode.WRONG_DEPOSIT_ROOT; root: string; expectedRoot: string}
33
+ | {code: Eth1ErrorCode.NO_DEPOSITS_FOR_BLOCK_RANGE; fromBlock: number; toBlock: number}
34
+ | {code: Eth1ErrorCode.NO_DEPOSIT_ROOT; depositCount: number}
35
+ | {code: Eth1ErrorCode.NOT_ENOUGH_DEPOSIT_ROOTS; index: number; treeLength: number}
36
+ | {code: Eth1ErrorCode.DUPLICATE_DISTINCT_LOG; newIndex: number; lastLogIndex: number}
37
+ | {code: Eth1ErrorCode.NON_CONSECUTIVE_LOGS; newIndex: number; lastLogIndex: number}
38
+ | {code: Eth1ErrorCode.MISSING_DEPOSIT_LOG; newIndex: number; lastLogIndex: number};
39
+
40
+ export class Eth1Error extends LodestarError<Eth1ErrorType> {}
@@ -0,0 +1,26 @@
1
+ import {ChainForkConfig} from "@lodestar/config";
2
+ import {phase0} from "@lodestar/types";
3
+ import {IBeaconDb} from "../db/index.js";
4
+
5
+ export class Eth1DataCache {
6
+ db: IBeaconDb;
7
+ config: ChainForkConfig;
8
+
9
+ constructor(config: ChainForkConfig, db: IBeaconDb) {
10
+ this.config = config;
11
+ this.db = db;
12
+ }
13
+
14
+ async get({timestampRange}: {timestampRange: {gte: number; lte: number}}): Promise<phase0.Eth1DataOrdered[]> {
15
+ return this.db.eth1Data.values(timestampRange);
16
+ }
17
+
18
+ async add(eth1Datas: (phase0.Eth1DataOrdered & {timestamp: number})[]): Promise<void> {
19
+ await this.db.eth1Data.batchPutValues(eth1Datas);
20
+ }
21
+
22
+ async getHighestCachedBlockNumber(): Promise<number | null> {
23
+ const highestEth1Data = await this.db.eth1Data.lastValue();
24
+ return highestEth1Data?.blockNumber ?? null;
25
+ }
26
+ }