diff --git a/beacon-chain/core/electra/upgrade.go b/beacon-chain/core/electra/upgrade.go index 2364db01f43..c18735f9575 100644 --- a/beacon-chain/core/electra/upgrade.go +++ b/beacon-chain/core/electra/upgrade.go @@ -187,14 +187,15 @@ func UpgradeToElectra(beaconState state.BeaconState) (state.BeaconState, error) } // [New in Electra:EIP7251] - earliestExitEpoch := time.CurrentEpoch(beaconState) + farFutureEpoch := params.BeaconConfig().FarFutureEpoch + earliestExitEpoch := farFutureEpoch preActivationIndices := make([]primitives.ValidatorIndex, 0) compoundWithdrawalIndices := make([]primitives.ValidatorIndex, 0) if err = beaconState.ReadFromEveryValidator(func(index int, val state.ReadOnlyValidator) error { - if val.ExitEpoch() != params.BeaconConfig().FarFutureEpoch && val.ExitEpoch() > earliestExitEpoch { + if val.ExitEpoch() < earliestExitEpoch { earliestExitEpoch = val.ExitEpoch() } - if val.ActivationEpoch() == params.BeaconConfig().FarFutureEpoch { + if val.ActivationEpoch() == farFutureEpoch { preActivationIndices = append(preActivationIndices, primitives.ValidatorIndex(index)) } if helpers.HasCompoundingWithdrawalCredential(val) { @@ -205,14 +206,10 @@ func UpgradeToElectra(beaconState state.BeaconState) (state.BeaconState, error) return nil, err } - earliestExitEpoch++ // Increment to find the earliest possible exit epoch - - // note: should be the same in prestate and post beaconState. - // we are deviating from the specs a bit as it calls for using the post beaconState - tab, err := helpers.TotalActiveBalance(beaconState) - if err != nil { - return nil, errors.Wrap(err, "failed to get total active balance") + if earliestExitEpoch == farFutureEpoch { + earliestExitEpoch = time.CurrentEpoch(beaconState) } + earliestExitEpoch++ // Increment to find the earliest possible exit epoch s := ðpb.BeaconStateElectra{ GenesisTime: beaconState.GenesisTime(), @@ -268,9 +265,9 @@ func UpgradeToElectra(beaconState state.BeaconState) (state.BeaconState, error) DepositRequestsStartIndex: params.BeaconConfig().UnsetDepositRequestsStartIndex, DepositBalanceToConsume: 0, - ExitBalanceToConsume: helpers.ActivationExitChurnLimit(primitives.Gwei(tab)), + ExitBalanceToConsume: 0, EarliestExitEpoch: earliestExitEpoch, - ConsolidationBalanceToConsume: helpers.ConsolidationChurnLimit(primitives.Gwei(tab)), + ConsolidationBalanceToConsume: 0, EarliestConsolidationEpoch: helpers.ActivationExitEpoch(slots.ToEpoch(beaconState.Slot())), PendingDeposits: make([]*ethpb.PendingDeposit, 0), PendingPartialWithdrawals: make([]*ethpb.PendingPartialWithdrawal, 0), diff --git a/beacon-chain/core/electra/upgrade_test.go b/beacon-chain/core/electra/upgrade_test.go index 40f2f754c5a..b58ae39d2ac 100644 --- a/beacon-chain/core/electra/upgrade_test.go +++ b/beacon-chain/core/electra/upgrade_test.go @@ -130,40 +130,37 @@ func TestUpgradeToElectra(t *testing.T) { } require.DeepEqual(t, wanted, protoHeader) - nwi, err := mSt.NextWithdrawalIndex() + nextWithdrawalIndex, err := mSt.NextWithdrawalIndex() require.NoError(t, err) - require.Equal(t, uint64(0), nwi) + require.Equal(t, uint64(0), nextWithdrawalIndex) - lwvi, err := mSt.NextWithdrawalValidatorIndex() + nextWithdrawalValidatorIndex, err := mSt.NextWithdrawalValidatorIndex() require.NoError(t, err) - require.Equal(t, primitives.ValidatorIndex(0), lwvi) + require.Equal(t, primitives.ValidatorIndex(0), nextWithdrawalValidatorIndex) summaries, err := mSt.HistoricalSummaries() require.NoError(t, err) require.Equal(t, 0, len(summaries)) - startIndex, err := mSt.DepositRequestsStartIndex() + depositRequestsStartIndex, err := mSt.DepositRequestsStartIndex() require.NoError(t, err) - require.Equal(t, params.BeaconConfig().UnsetDepositRequestsStartIndex, startIndex) + require.Equal(t, params.BeaconConfig().UnsetDepositRequestsStartIndex, depositRequestsStartIndex) - balance, err := mSt.DepositBalanceToConsume() + depositBalanceToConsume, err := mSt.DepositBalanceToConsume() require.NoError(t, err) - require.Equal(t, primitives.Gwei(0), balance) + require.Equal(t, primitives.Gwei(0), depositBalanceToConsume) - tab, err := helpers.TotalActiveBalance(mSt) + exitBalanceToConsume, err := mSt.ExitBalanceToConsume() require.NoError(t, err) + require.Equal(t, primitives.Gwei(0), exitBalanceToConsume) - ebtc, err := mSt.ExitBalanceToConsume() + earliestExitEpoch, err := mSt.EarliestExitEpoch() require.NoError(t, err) - require.Equal(t, helpers.ActivationExitChurnLimit(primitives.Gwei(tab)), ebtc) + require.Equal(t, primitives.Epoch(1), earliestExitEpoch) - eee, err := mSt.EarliestExitEpoch() + consolidationBalanceToConsume, err := mSt.ConsolidationBalanceToConsume() require.NoError(t, err) - require.Equal(t, primitives.Epoch(1), eee) - - cbtc, err := mSt.ConsolidationBalanceToConsume() - require.NoError(t, err) - require.Equal(t, helpers.ConsolidationChurnLimit(primitives.Gwei(tab)), cbtc) + require.Equal(t, primitives.Gwei(0), consolidationBalanceToConsume) earliestConsolidationEpoch, err := mSt.EarliestConsolidationEpoch() require.NoError(t, err) @@ -178,8 +175,8 @@ func TestUpgradeToElectra(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(0), numPendingPartialWithdrawals) - consolidations, err := mSt.PendingConsolidations() + pendingConsolidations, err := mSt.PendingConsolidations() require.NoError(t, err) - require.Equal(t, 0, len(consolidations)) + require.Equal(t, 0, len(pendingConsolidations)) }