Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
domiwei committed Oct 24, 2024
1 parent 55af820 commit 3a2e97c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cl/transition/impl/eth2/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,26 +236,46 @@ func (I *impl) ProcessDeposit(s abstract.BeaconState, deposit *cltypes.Deposit)

}

func getPendingBalanceToWithdraw(s abstract.BeaconState, validatorIndex uint64) uint64 {
ws := s.GetPendingPartialWithdrawals()
balance := uint64(0)
ws.Range(func(index int, withdrawal *solid.PendingPartialWithdrawal, length int) bool {
if withdrawal.Index == validatorIndex {
balance += withdrawal.Amount
}
return true
})
return balance
}

func IsVoluntaryExitApplicable(s abstract.BeaconState, voluntaryExit *cltypes.VoluntaryExit) error {
currentEpoch := state.Epoch(s)
validator, err := s.ValidatorForValidatorIndex(int(voluntaryExit.ValidatorIndex))
if err != nil {
return err
}
// Verify the validator is active
if !validator.Active(currentEpoch) {
return errors.New("ProcessVoluntaryExit: validator is not active")
}
// Verify exit has not been initiated
if validator.ExitEpoch() != s.BeaconConfig().FarFutureEpoch {
return errors.New(
"ProcessVoluntaryExit: another exit for the same validator is already getting processed",
)
}
// Exits must specify an epoch when they become valid; they are not valid before then
if currentEpoch < voluntaryExit.Epoch {
return errors.New("ProcessVoluntaryExit: exit is happening in the future")
}
// Verify the validator has been active long enough
if currentEpoch < validator.ActivationEpoch()+s.BeaconConfig().ShardCommitteePeriod {
return errors.New("ProcessVoluntaryExit: exit is happening too fast")
}
// Only exit validator if it has no pending withdrawals in the queue
if b := getPendingBalanceToWithdraw(s, voluntaryExit.ValidatorIndex); b > 0 {
return fmt.Errorf("ProcessVoluntaryExit: validator has pending balance to withdraw: %d", b)
}
return nil
}

Expand Down
5 changes: 5 additions & 0 deletions cl/transition/impl/eth2/statechange/process_epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func ProcessEpoch(s abstract.BeaconState) error {

// fmt.Println("ProcessSlashings", time.Since(start))
ProcessEth1DataReset(s)
if s.Version() >= clparams.ElectraVersion {
ProcessPendingDeposits(s)
ProcessPendingConsolidations(s)
}

start = time.Now()
if err := ProcessEffectiveBalanceUpdates(s); err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package statechange

import (
"errors"

"github.com/erigontech/erigon/cl/abstract"
)

func ProcessPendingConsolidations(s abstract.BeaconState) error {
return errors.New("not implemented")
}
11 changes: 11 additions & 0 deletions cl/transition/impl/eth2/statechange/process_pending_deposits.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package statechange

import (
"errors"

"github.com/erigontech/erigon/cl/abstract"
)

func ProcessPendingDeposits(s abstract.BeaconState) error {
return errors.New("not implemented")
}

0 comments on commit 3a2e97c

Please sign in to comment.