@@ -1221,7 +1221,7 @@ func process_historical_summaries_update*(
1221
1221
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.0/specs/electra/beacon-chain.md#new-process_pending_balance_deposits
1222
1222
func process_pending_balance_deposits * (
1223
1223
cfg: RuntimeConfig , state: var electra.BeaconState ,
1224
- cache: var StateCache ) =
1224
+ cache: var StateCache ): Result [ void , cstring ] =
1225
1225
let
1226
1226
available_for_processing = state.deposit_balance_to_consume +
1227
1227
get_activation_exit_churn_limit (cfg, state, cache)
@@ -1232,8 +1232,9 @@ func process_pending_balance_deposits*(
1232
1232
for deposit in state.pending_balance_deposits:
1233
1233
if processed_amount + deposit.amount > available_for_processing:
1234
1234
break
1235
- debugComment " do this validatorindex check properly (it truncates)"
1236
- increase_balance (state, deposit.index.ValidatorIndex , deposit.amount)
1235
+ let deposit_validator_index = ValidatorIndex .init (deposit.index).valueOr:
1236
+ return err (" process_pending_balance_deposits: deposit index out of range" )
1237
+ increase_balance (state, deposit_validator_index, deposit.amount)
1237
1238
processed_amount += deposit.amount
1238
1239
inc next_deposit_index
1239
1240
@@ -1247,8 +1248,12 @@ func process_pending_balance_deposits*(
1247
1248
state.deposit_balance_to_consume =
1248
1249
available_for_processing - processed_amount
1249
1250
1251
+ ok ()
1252
+
1250
1253
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.0/specs/electra/beacon-chain.md#new-process_pending_consolidations
1251
- func process_pending_consolidations * (cfg: RuntimeConfig , state: var electra.BeaconState ) =
1254
+ func process_pending_consolidations * (
1255
+ cfg: RuntimeConfig , state: var electra.BeaconState ):
1256
+ Result [void , cstring ] =
1252
1257
var next_pending_consolidation = 0
1253
1258
for pending_consolidation in state.pending_consolidations:
1254
1259
let source_validator =
@@ -1259,25 +1264,29 @@ func process_pending_consolidations*(cfg: RuntimeConfig, state: var electra.Beac
1259
1264
if source_validator.withdrawable_epoch > get_current_epoch (state):
1260
1265
break
1261
1266
1267
+ let
1268
+ source_validator_index = ValidatorIndex .init (
1269
+ pending_consolidation.source_index).valueOr:
1270
+ return err (" process_pending_consolidations: source index out of range" )
1271
+ target_validator_index = ValidatorIndex .init (
1272
+ pending_consolidation.target_index).valueOr:
1273
+ return err (" process_pending_consolidations: target index out of range" )
1274
+
1262
1275
# Churn any target excess active balance of target and raise its max
1263
- debugComment " truncating integer conversion"
1264
- switch_to_compounding_validator (
1265
- state, pending_consolidation.target_index.ValidatorIndex )
1276
+ switch_to_compounding_validator (state, target_validator_index)
1266
1277
1267
1278
# Move active balance to target. Excess balance is withdrawable.
1268
- debugComment " Truncating"
1269
- let active_balance = get_active_balance (
1270
- state, pending_consolidation.source_index.ValidatorIndex )
1271
- decrease_balance (
1272
- state, pending_consolidation.source_index.ValidatorIndex , active_balance)
1273
- increase_balance (
1274
- state, pending_consolidation.target_index.ValidatorIndex , active_balance)
1279
+ let active_balance = get_active_balance (state, source_validator_index)
1280
+ decrease_balance (state, source_validator_index, active_balance)
1281
+ increase_balance (state, target_validator_index, active_balance)
1275
1282
inc next_pending_consolidation
1276
1283
1277
1284
state.pending_consolidations =
1278
1285
HashList [PendingConsolidation , Limit PENDING_CONSOLIDATIONS_LIMIT ].init (
1279
1286
state.pending_consolidations.asSeq[next_pending_consolidation..^ 1 ])
1280
1287
1288
+ ok ()
1289
+
1281
1290
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/phase0/beacon-chain.md#epoch-processing
1282
1291
proc process_epoch * (
1283
1292
cfg: RuntimeConfig , state: var phase0.BeaconState , flags: UpdateFlags ,
@@ -1464,8 +1473,8 @@ proc process_epoch*(
1464
1473
process_slashings (state, info.balances.current_epoch)
1465
1474
1466
1475
process_eth1_data_reset (state)
1467
- process_pending_balance_deposits (cfg, state, cache) # [New in Electra:EIP7251]
1468
- process_pending_consolidations (cfg, state) # [New in Electra:EIP7251]
1476
+ ? process_pending_balance_deposits (cfg, state, cache) # [New in Electra:EIP7251]
1477
+ ? process_pending_consolidations (cfg, state) # [New in Electra:EIP7251]
1469
1478
process_effective_balance_updates (state) # [Modified in Electra:EIP7251]
1470
1479
process_slashings_reset (state)
1471
1480
process_randao_mixes_reset (state)
0 commit comments