Skip to content

Commit

Permalink
mark extra validators as withdrawable
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Nov 1, 2024
1 parent e64bc74 commit c6c68c3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
4 changes: 4 additions & 0 deletions mod/consensus-types/pkg/types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ func (v *Validator) SetEffectiveBalance(balance math.Gwei) {
v.EffectiveBalance = balance
}

func (v *Validator) SetWithdrawableEpoch(e math.Epoch) {
v.WithdrawableEpoch = e
}

// GetWithdrawableEpoch returns the epoch when the validator can withdraw.
func (v Validator) GetWithdrawableEpoch() math.Epoch {
return v.WithdrawableEpoch
Expand Down
32 changes: 27 additions & 5 deletions mod/state-transition/pkg/core/state_processor_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,38 @@ func (sp *StateProcessor[
math.Gwei(sp.cs.MaxEffectiveBalance()),
)

// TODO: This is a bug that lives on bArtio. Delete this eventually.
if sp.cs.DepositEth1ChainID() == bArtioChainID {
if err := st.AddValidatorBartio(val); err != nil {
// BeaconKit enforces a cap on the validator set size. If a deposit is made
// that would breach the cap, we mark the validator as immediately
// withdrawable, so that it will be evicted in the next block along with
// the amount deposited.
validators, err := st.GetValidators()
if err != nil {
return err
}

//#nosec:G701 // can't overflow.
if uint32(len(validators)) >= sp.cs.GetValidatorsSetCapSize() {
var slot math.Slot
slot, err = st.GetSlot()
if err != nil {
return err
}
} else if err := st.AddValidator(val); err != nil {

epoch := sp.cs.SlotToEpoch(slot)
val.SetWithdrawableEpoch(epoch)
}

// TODO: This is a bug that lives on bArtio. Delete this eventually.
if sp.cs.DepositEth1ChainID() == bArtioChainID {
return st.AddValidatorBartio(val)
}

if err = st.AddValidator(val); err != nil {
return err
}

idx, err := st.ValidatorIndexByPubkey(val.GetPubkey())
var idx math.U64
idx, err = st.ValidatorIndexByPubkey(val.GetPubkey())
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions mod/state-transition/pkg/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ type Validator[
SetEffectiveBalance(math.Gwei)
// GetWithdrawableEpoch returns the epoch when the validator can withdraw.
GetWithdrawableEpoch() math.Epoch

SetWithdrawableEpoch(math.Epoch)
}

type Validators interface {
Expand Down

0 comments on commit c6c68c3

Please sign in to comment.