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

Electra: upgrade #13933

Merged
merged 42 commits into from
May 8, 2024
Merged

Electra: upgrade #13933

merged 42 commits into from
May 8, 2024

Conversation

james-prysm
Copy link
Contributor

@james-prysm james-prysm commented Apr 29, 2024

What type of PR is this?
Feature

What does this PR do? Why is it needed?

  • NewGenesisBlockForState returns Electra state
  • UpgradeToElectra upgrades Deneb state to Electra
  • CanUpgradeToElectra returns true if it's Electra epoch
  • ProcessSlots and ReplayProcessSlots can upgrade to Electra
  • Add spec test for upgrade

Which issues(s) does this PR fix?

part of PSM-371

Other notes for review

dependency

@james-prysm james-prysm changed the title electra - fork logic Electra - fork logic Apr 29, 2024
@james-prysm james-prysm changed the title Electra - fork logic Electra: fork logic Apr 29, 2024
@james-prysm james-prysm changed the title Electra: fork logic Electra: upgrade Apr 29, 2024
@james-prysm james-prysm added the Blocked Blocked by research or external factors label Apr 29, 2024
@prestonvanloon prestonvanloon removed the Blocked Blocked by research or external factors label May 6, 2024
}

// Sorting preActivation based on a custom criteria
sort.Slice(preActivation, func(i, j int) bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part of the code needs more unit testing

@@ -290,6 +290,7 @@ var mainnetBeaconConfig = &BeaconChainConfig{
MaxPendingPartialsPerWithdrawalsSweep: 8,
FullExitRequestAmount: 0,
MaxWithdrawalRequestsPerPayload: 16,
UnsetDepositReceiptsStartIndex: math.MaxUint64,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

double check if constant should go here?

Copy link
Member

Choose a reason for hiding this comment

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

LGTM

@james-prysm james-prysm marked this pull request as ready for review May 7, 2024 14:14
DepositReceiptsStartIndex: params.BeaconConfig().UnsetDepositReceiptsStartIndex,
ExitBalanceToConsume: helpers.ActivationExitChurnLimit(math.Gwei(tab)),
EarliestConsolidationEpoch: helpers.ActivationExitEpoch(slots.ToEpoch(preState.Slot())),
ConsolidationBalanceToConsume: helpers.ConsolidationChurnLimit(math.Gwei(tab)),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wondering how important to set value of earliest exit here

Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

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

I only reviewed UpgradeToElectra. Happy to review the helpers tomorrow, just let me know

}

// Find the earliest exit epoch
exitEpochs := make([]primitives.Epoch, 0)
Copy link
Member

Choose a reason for hiding this comment

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

You dont need a list here. You can save on memory. Just track a single variable of primitives.Epoch, first set it to time.CurrentEpoch(beaconState), then override it if there's a higher one. Finally, increment it by one

Comment on lines +298 to +305
// Sorting preActivationIndices based on a custom criteria
sort.Slice(preActivationIndices, func(i, j int) bool {
// Comparing based on ActivationEligibilityEpoch and then by index if the epochs are the same
if s.Validators[preActivationIndices[i]].ActivationEligibilityEpoch == s.Validators[preActivationIndices[j]].ActivationEligibilityEpoch {
return preActivationIndices[i] < preActivationIndices[j]
}
return s.Validators[preActivationIndices[i]].ActivationEligibilityEpoch < s.Validators[preActivationIndices[j]].ActivationEligibilityEpoch
})
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to sort here? I know spec says it but why? We should avoid wasteful compute if we can

Copy link
Contributor Author

Choose a reason for hiding this comment

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

validators might have different ActivationEligibilityEpoch and should be sorted based on that value, there is also a tie breaker situation. i don't have a good solution to replace this right now.

Comment on lines 293 to 295
PendingBalanceDeposits: nil,
PendingPartialWithdrawals: nil,
PendingConsolidations: nil,
Copy link
Contributor

Choose a reason for hiding this comment

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

In the spec these are [] which I understand as empty slices. Having this nil might cause a panic the first time we access the field

// Find the earliest exit epoch
exitEpochs := make([]primitives.Epoch, 0)
// [New in Electra:EIP7251]
// add validators that are not yet active to pending balance deposits
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment feels out of place


// Find the earliest exit epoch
exitEpochs := make([]primitives.Epoch, 0)
// [New in Electra:EIP7251]
Copy link
Contributor

@rkapka rkapka May 8, 2024

Choose a reason for hiding this comment

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

nitpick: I think this comment should come before exitEpochs declaration

beacon-chain/core/electra/upgrade.go Outdated Show resolved Hide resolved
@@ -115,7 +116,7 @@ type ReadOnlyValidator interface {
WithdrawableEpoch() primitives.Epoch
ExitEpoch() primitives.Epoch
PublicKey() [fieldparams.BLSPubkeyLength]byte
WithdrawalCredentials() []byte
GetWithdrawalCredentials() []byte
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It needs to follow the interface

Copy link
Contributor

Choose a reason for hiding this comment

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

the WithWithdrawalCredentials interface? I think that interface's function can also be called WithdrawalCredentials and it shouldn't cause an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the protobuf doesn't have WithdrawalCredentials as a function, only GetWithdrawalCredentials

beacon-chain/state/stategen/replay.go Show resolved Hide resolved
Comment on lines +3 to +5
type WithWithdrawalCredentials interface {
GetWithdrawalCredentials() []byte
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's used in the helper function so that readOnly validator and protovalidator both can be passed in.

testing/util/electra_state.go Outdated Show resolved Hide resolved
testing/util/electra_state.go Outdated Show resolved Hide resolved
return state_native.InitializeFromProtoElectra(st)
}

func buildGenesisBeaconStateElectra(genesisTime uint64, preState state.BeaconState, eth1Data *ethpb.Eth1Data) (state.BeaconState, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly to my comment in the upgrade function, I would set PendingBalanceDeposits, PendingPartialWithdrawals and PendingConsolidations to an empty array

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will try that

@james-prysm james-prysm enabled auto-merge May 8, 2024 15:15
@james-prysm james-prysm added this pull request to the merge queue May 8, 2024
Merged via the queue into develop with commit 2fa3694 May 8, 2024
16 of 17 checks passed
@james-prysm james-prysm deleted the electra-fork-logic branch May 8, 2024 15:23
ErnestK pushed a commit to ErnestK/prysm that referenced this pull request May 19, 2024
* wip fork logic upgrade

* fixing replay and fork.go

* improving process function and adding tests for transition

* updating unit tests and temporarily removing some fields on state_trie.go

* updating state

* wip adding upgrade to electra code

* adding some comments

* adding spec tests

* fixing values used in state transition logic

* updating upgrade test

* gofmt

* avoid dup word linting

* fixing spec tests for fork

* gaz

* fixing tests

* improving unit test with new getters

* fixing bazel for minimal fork test

* adding bazel file

* Update beacon-chain/core/electra/upgrade.go

Co-authored-by: Preston Van Loon <[email protected]>

* addressing some comments and adding more tests

* addressing more feedback

* one more feedback

* changing value to interface after talking to preston

* adding missed review feedback

* fixing linting

* noticed I was using the wrong function in the state upgrade

* fixing and ignoring some deepsource issues

* moving core electra validator functions to helper to remove circular dependencies in other PRs

* missed deepsource complaint

* Update upgrade.go

Co-authored-by: Radosław Kapka <[email protected]>

* Update testing/util/electra_state.go

Co-authored-by: Radosław Kapka <[email protected]>

* Update testing/util/electra_state.go

Co-authored-by: Radosław Kapka <[email protected]>

* addressing feedback

* removing deepsoure ignore comments

---------

Co-authored-by: Preston Van Loon <[email protected]>
Co-authored-by: Radosław Kapka <[email protected]>
nisdas pushed a commit that referenced this pull request Jul 4, 2024
* wip fork logic upgrade

* fixing replay and fork.go

* improving process function and adding tests for transition

* updating unit tests and temporarily removing some fields on state_trie.go

* updating state

* wip adding upgrade to electra code

* adding some comments

* adding spec tests

* fixing values used in state transition logic

* updating upgrade test

* gofmt

* avoid dup word linting

* fixing spec tests for fork

* gaz

* fixing tests

* improving unit test with new getters

* fixing bazel for minimal fork test

* adding bazel file

* Update beacon-chain/core/electra/upgrade.go

Co-authored-by: Preston Van Loon <[email protected]>

* addressing some comments and adding more tests

* addressing more feedback

* one more feedback

* changing value to interface after talking to preston

* adding missed review feedback

* fixing linting

* noticed I was using the wrong function in the state upgrade

* fixing and ignoring some deepsource issues

* moving core electra validator functions to helper to remove circular dependencies in other PRs

* missed deepsource complaint

* Update upgrade.go

Co-authored-by: Radosław Kapka <[email protected]>

* Update testing/util/electra_state.go

Co-authored-by: Radosław Kapka <[email protected]>

* Update testing/util/electra_state.go

Co-authored-by: Radosław Kapka <[email protected]>

* addressing feedback

* removing deepsoure ignore comments

---------

Co-authored-by: Preston Van Loon <[email protected]>
Co-authored-by: Radosław Kapka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Electra electra hardfork
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants