Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio2002 committed Apr 8, 2024
1 parent a8c2c42 commit 482cba7
Showing 1 changed file with 53 additions and 4 deletions.
57 changes: 53 additions & 4 deletions cl/persistence/state/static_validator_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,51 @@ func (s *StaticValidator) ToValidator(v solid.Validator, slot uint64) {
v.SetWithdrawableEpoch(s.WithdrawableEpoch(slot))
}

func (s *StaticValidator) Reset(slot uint64) {
for i := 0; i < len(s.publicKeys); i++ {
if s.publicKeys[i].Slot > slot {
s.publicKeys = s.publicKeys[:i]
break
}
}
for i := 0; i < len(s.withdrawalCredentials); i++ {
if s.withdrawalCredentials[i].Slot > slot {
s.withdrawalCredentials = s.withdrawalCredentials[:i]
break
}
}
for i := 0; i < len(s.slashed); i++ {
if s.slashed[i].Slot > slot {
s.slashed = s.slashed[:i]
break
}
}
for i := 0; i < len(s.activationEligibility); i++ {
if s.activationEligibility[i].Slot > slot {
s.activationEligibility = s.activationEligibility[:i]
break
}
}
for i := 0; i < len(s.activationEpoch); i++ {
if s.activationEpoch[i].Slot > slot {
s.activationEpoch = s.activationEpoch[:i]
break
}
}
for i := 0; i < len(s.exitEpoch); i++ {
if s.exitEpoch[i].Slot > slot {
s.exitEpoch = s.exitEpoch[:i]
break
}
}
for i := 0; i < len(s.withdrawableEpoch); i++ {
if s.withdrawableEpoch[i].Slot > slot {
s.withdrawableEpoch = s.withdrawableEpoch[:i]
break
}
}
}

type staticValidatorField[V any] struct {
Slot uint64
Field V
Expand Down Expand Up @@ -230,7 +275,7 @@ func (s *StaticValidatorTable) AddValidator(v solid.Validator, validatorIndex, s
return nil
}
s.validatorTable = append(s.validatorTable, NewStaticValidatorFromValidator(v, slot))
if validatorIndex >= uint64(len(s.validatorTable)) {
if validatorIndex != uint64(len(s.validatorTable)) {
return fmt.Errorf("validator index mismatch")
}
return nil
Expand Down Expand Up @@ -376,12 +421,16 @@ func (s *StaticValidatorTable) GetStaticValidator(validatorIndex uint64) *Static
func (s *StaticValidatorTable) SetSlot(slot uint64) {
s.sync.Lock()
defer s.sync.Unlock()
if slot <= s.slot && s.slot != 0 {
return
}
s.resetTable(slot)
s.slot = slot
}

func (s *StaticValidatorTable) resetTable(slot uint64) {
for _, v := range s.validatorTable {
v.Reset(slot)
}
}

func (s *StaticValidatorTable) Slot() uint64 {
s.sync.RLock()
defer s.sync.RUnlock()
Expand Down

0 comments on commit 482cba7

Please sign in to comment.