Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some issues in UpgradeToElectra #14598

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- Simplified `ExitedValidatorIndices`.
- Simplified `EjectedValidatorIndices`.
- `engine_newPayloadV4`,`engine_getPayloadV4` are changes due to new execution request serialization decisions, [PR](https://github.com/prysmaticlabs/prysm/pull/14580)
- Fix initial values for `ExitBalanceToConsume` and `ConsolidationBalanceToConsume` when upgrading to Electra.

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/electra/deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ func processDepositRequest(beaconState state.BeaconState, request *enginev1.Depo
}
if err := beaconState.AppendPendingDeposit(&ethpb.PendingDeposit{
PublicKey: bytesutil.SafeCopyBytes(request.Pubkey),
Amount: request.Amount,
WithdrawalCredentials: bytesutil.SafeCopyBytes(request.WithdrawalCredentials),
Amount: request.Amount,
Signature: bytesutil.SafeCopyBytes(request.Signature),
Slot: beaconState.Slot(),
}); err != nil {
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/core/electra/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var (
ProcessParticipationFlagUpdates = altair.ProcessParticipationFlagUpdates
ProcessSyncCommitteeUpdates = altair.ProcessSyncCommitteeUpdates
AttestationsDelta = altair.AttestationsDelta
ProcessSyncAggregate = altair.ProcessSyncAggregate
)

// ProcessEpoch describes the per epoch operations that are performed on the beacon state.
Expand Down
11 changes: 2 additions & 9 deletions beacon-chain/core/electra/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,6 @@ func UpgradeToElectra(beaconState state.BeaconState) (state.BeaconState, error)

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")
}

s := &ethpb.BeaconStateElectra{
GenesisTime: beaconState.GenesisTime(),
GenesisValidatorsRoot: beaconState.GenesisValidatorsRoot(),
Expand Down Expand Up @@ -268,9 +261,9 @@ func UpgradeToElectra(beaconState state.BeaconState) (state.BeaconState, error)

DepositRequestsStartIndex: params.BeaconConfig().UnsetDepositRequestsStartIndex,
DepositBalanceToConsume: 0,
ExitBalanceToConsume: helpers.ActivationExitChurnLimit(primitives.Gwei(tab)),
ExitBalanceToConsume: 0,
Comment on lines -271 to +264
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this is right either. We should assign them to churn limit based on total active balances

    post.exit_balance_to_consume = get_activation_exit_churn_limit(post)
    post.consolidation_balance_to_consume = get_consolidation_churn_limit(post)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. Once again you're right. I'm going to close this.

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),
Expand Down
35 changes: 16 additions & 19 deletions beacon-chain/core/electra/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))

}
Loading