-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Electra: upgrade #13933
Conversation
beacon-chain/core/electra/upgrade.go
Outdated
} | ||
|
||
// Sorting preActivation based on a custom criteria | ||
sort.Slice(preActivation, func(i, j int) bool { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
DepositReceiptsStartIndex: params.BeaconConfig().UnsetDepositReceiptsStartIndex, | ||
ExitBalanceToConsume: helpers.ActivationExitChurnLimit(math.Gwei(tab)), | ||
EarliestConsolidationEpoch: helpers.ActivationExitEpoch(slots.ToEpoch(preState.Slot())), | ||
ConsolidationBalanceToConsume: helpers.ConsolidationChurnLimit(math.Gwei(tab)), |
There was a problem hiding this comment.
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
There was a problem hiding this 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
beacon-chain/core/electra/upgrade.go
Outdated
} | ||
|
||
// Find the earliest exit epoch | ||
exitEpochs := make([]primitives.Epoch, 0) |
There was a problem hiding this comment.
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
// 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 | ||
}) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
beacon-chain/core/electra/upgrade.go
Outdated
PendingBalanceDeposits: nil, | ||
PendingPartialWithdrawals: nil, | ||
PendingConsolidations: nil, |
There was a problem hiding this comment.
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
beacon-chain/core/electra/upgrade.go
Outdated
// 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 |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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
@@ -115,7 +116,7 @@ type ReadOnlyValidator interface { | |||
WithdrawableEpoch() primitives.Epoch | |||
ExitEpoch() primitives.Epoch | |||
PublicKey() [fieldparams.BLSPubkeyLength]byte | |||
WithdrawalCredentials() []byte | |||
GetWithdrawalCredentials() []byte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
type WithWithdrawalCredentials interface { | ||
GetWithdrawalCredentials() []byte | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
return state_native.InitializeFromProtoElectra(st) | ||
} | ||
|
||
func buildGenesisBeaconStateElectra(genesisTime uint64, preState state.BeaconState, eth1Data *ethpb.Eth1Data) (state.BeaconState, error) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will try that
Co-authored-by: Radosław Kapka <[email protected]>
Co-authored-by: Radosław Kapka <[email protected]>
Co-authored-by: Radosław Kapka <[email protected]>
* 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]>
* 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]>
What type of PR is this?
Feature
What does this PR do? Why is it needed?
NewGenesisBlockForState
returns Electra stateUpgradeToElectra
upgrades Deneb state to ElectraCanUpgradeToElectra
returns true if it's Electra epochProcessSlots
andReplayProcessSlots
can upgrade to ElectraWhich issues(s) does this PR fix?
part of PSM-371
Other notes for review
dependency