@@ -4,17 +4,19 @@ import {
4
4
EFFECTIVE_BALANCE_INCREMENT ,
5
5
EPOCHS_PER_HISTORICAL_VECTOR ,
6
6
ForkName ,
7
+ ForkSeq ,
7
8
GENESIS_EPOCH ,
8
9
GENESIS_SLOT ,
9
10
MAX_EFFECTIVE_BALANCE ,
10
11
UNSET_DEPOSIT_RECEIPTS_START_INDEX ,
11
12
} from "@lodestar/params" ;
12
13
import { Bytes32 , phase0 , Root , ssz , TimeSeconds } from "@lodestar/types" ;
13
14
14
- import { CachedBeaconStateAllForks , BeaconStateAllForks } from "../types.js" ;
15
+ import { CachedBeaconStateAllForks , BeaconStateAllForks , CachedBeaconStateElectra } from "../types.js" ;
15
16
import { createCachedBeaconState } from "../cache/stateCache.js" ;
16
17
import { EpochCacheImmutableData } from "../cache/epochCache.js" ;
17
18
import { processDeposit } from "../block/processDeposit.js" ;
19
+ import { increaseBalance } from "../index.js" ;
18
20
import { computeEpochAtSlot } from "./epoch.js" ;
19
21
import { getActiveValidatorIndices } from "./validator.js" ;
20
22
import { getTemporaryBlockHeader } from "./blockRoot.js" ;
@@ -127,6 +129,7 @@ export function applyTimestamp(config: ChainForkConfig, state: CachedBeaconState
127
129
* @returns active validator indices
128
130
*/
129
131
export function applyDeposits (
132
+ fork : ForkSeq ,
130
133
config : ChainForkConfig ,
131
134
state : CachedBeaconStateAllForks ,
132
135
newDeposits : phase0 . Deposit [ ] ,
@@ -164,6 +167,16 @@ export function applyDeposits(
164
167
processDeposit ( fork , state , deposit ) ;
165
168
}
166
169
170
+ // Process deposit balance updates
171
+ if ( fork >= ForkSeq . electra ) {
172
+ const stateElectra = state as CachedBeaconStateElectra ;
173
+ stateElectra . commit ( ) ;
174
+ for ( const { index : validatorIndex , amount} of stateElectra . pendingBalanceDeposits . getAllReadonly ( ) ) {
175
+ increaseBalance ( state , validatorIndex , Number ( amount ) ) ;
176
+ }
177
+ stateElectra . pendingBalanceDeposits = ssz . electra . PendingBalanceDeposits . defaultViewDU ( ) ;
178
+ }
179
+
167
180
// Process activations
168
181
const { epochCtx} = state ;
169
182
const balancesArr = state . balances . getAll ( ) ;
@@ -226,6 +239,8 @@ export function initializeBeaconStateFromEth1(
226
239
getTemporaryBlockHeader ( config , config . getForkTypes ( GENESIS_SLOT ) . BeaconBlock . defaultValue ( ) )
227
240
) ;
228
241
242
+ const fork = config . getForkSeq ( GENESIS_SLOT ) ;
243
+
229
244
// We need a CachedBeaconState to run processDeposit() which uses various caches.
230
245
// However at this point the state's syncCommittees are not known.
231
246
// This function can be called by:
@@ -240,13 +255,13 @@ export function initializeBeaconStateFromEth1(
240
255
applyEth1BlockHash ( state , eth1BlockHash ) ;
241
256
242
257
// Process deposits
243
- applyDeposits ( config , state , deposits , fullDepositDataRootList ) ;
258
+ applyDeposits ( fork , config , state , deposits , fullDepositDataRootList ) ;
244
259
245
260
// Commit before reading all validators in `getActiveValidatorIndices()`
246
261
state . commit ( ) ;
247
262
const activeValidatorIndices = getActiveValidatorIndices ( state , computeEpochAtSlot ( GENESIS_SLOT ) ) ;
248
263
249
- if ( GENESIS_SLOT >= config . ALTAIR_FORK_EPOCH ) {
264
+ if ( fork >= ForkSeq . altair ) {
250
265
const { syncCommittee} = getNextSyncCommittee (
251
266
state ,
252
267
activeValidatorIndices ,
@@ -259,7 +274,7 @@ export function initializeBeaconStateFromEth1(
259
274
stateAltair . nextSyncCommittee = ssz . altair . SyncCommittee . toViewDU ( syncCommittee ) ;
260
275
}
261
276
262
- if ( GENESIS_SLOT >= config . BELLATRIX_FORK_EPOCH ) {
277
+ if ( fork >= ForkSeq . bellatrix ) {
263
278
const stateBellatrix = state as CompositeViewDU < typeof ssz . bellatrix . BeaconState > ;
264
279
stateBellatrix . fork . previousVersion = config . BELLATRIX_FORK_VERSION ;
265
280
stateBellatrix . fork . currentVersion = config . BELLATRIX_FORK_VERSION ;
@@ -268,7 +283,7 @@ export function initializeBeaconStateFromEth1(
268
283
ssz . bellatrix . ExecutionPayloadHeader . defaultViewDU ( ) ;
269
284
}
270
285
271
- if ( GENESIS_SLOT >= config . CAPELLA_FORK_EPOCH ) {
286
+ if ( fork >= ForkSeq . capella ) {
272
287
const stateCapella = state as CompositeViewDU < typeof ssz . capella . BeaconState > ;
273
288
stateCapella . fork . previousVersion = config . CAPELLA_FORK_VERSION ;
274
289
stateCapella . fork . currentVersion = config . CAPELLA_FORK_VERSION ;
@@ -277,7 +292,7 @@ export function initializeBeaconStateFromEth1(
277
292
ssz . capella . ExecutionPayloadHeader . defaultViewDU ( ) ;
278
293
}
279
294
280
- if ( GENESIS_SLOT >= config . DENEB_FORK_EPOCH ) {
295
+ if ( fork >= ForkSeq . deneb ) {
281
296
const stateDeneb = state as CompositeViewDU < typeof ssz . deneb . BeaconState > ;
282
297
stateDeneb . fork . previousVersion = config . DENEB_FORK_VERSION ;
283
298
stateDeneb . fork . currentVersion = config . DENEB_FORK_VERSION ;
@@ -286,7 +301,7 @@ export function initializeBeaconStateFromEth1(
286
301
ssz . deneb . ExecutionPayloadHeader . defaultViewDU ( ) ;
287
302
}
288
303
289
- if ( GENESIS_SLOT >= config . ELECTRA_FORK_EPOCH ) {
304
+ if ( fork >= ForkSeq . electra ) {
290
305
const stateElectra = state as CompositeViewDU < typeof ssz . electra . BeaconState > ;
291
306
stateElectra . fork . previousVersion = config . ELECTRA_FORK_VERSION ;
292
307
stateElectra . fork . currentVersion = config . ELECTRA_FORK_VERSION ;
0 commit comments