Skip to content

Commit

Permalink
Better handling of validator state when no balance is present.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Aug 1, 2024
1 parent f925432 commit b3d8c14
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.21.10:
- better validator state when balance not supplied

0.21.9:
- enable custom timeouts for POSTs

Expand Down
2 changes: 1 addition & 1 deletion api/v1/validatorstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func ValidatorToState(validator *phase0.Validator,
}

return ValidatorStateExitedUnslashed
case balance != nil && *balance == 0:
case (balance != nil && *balance == 0) || (balance == nil && validator.EffectiveBalance == 0):
return ValidatorStateWithdrawalDone
default:
return ValidatorStateWithdrawalPossible
Expand Down
17 changes: 16 additions & 1 deletion api/v1/validatorstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ func TestValidatorToState(t *testing.T) {
ActivationEpoch: currentEpoch - 40,
ExitEpoch: currentEpoch - 30,
WithdrawableEpoch: currentEpoch - 20,
EffectiveBalance: 1,
},
state: api.ValidatorStateWithdrawalPossible,
},
Expand All @@ -316,6 +317,7 @@ func TestValidatorToState(t *testing.T) {
ActivationEpoch: currentEpoch - 40,
ExitEpoch: currentEpoch - 30,
WithdrawableEpoch: currentEpoch - 20,
EffectiveBalance: 1,
Slashed: true,
},
state: api.ValidatorStateWithdrawalPossible,
Expand All @@ -327,6 +329,7 @@ func TestValidatorToState(t *testing.T) {
ActivationEpoch: currentEpoch - 40,
ExitEpoch: currentEpoch - 30,
WithdrawableEpoch: currentEpoch - 20,
EffectiveBalance: 1,
},
balance: gweiPtr(5),
state: api.ValidatorStateWithdrawalPossible,
Expand All @@ -338,10 +341,22 @@ func TestValidatorToState(t *testing.T) {
ActivationEpoch: currentEpoch - 40,
ExitEpoch: currentEpoch - 30,
WithdrawableEpoch: currentEpoch - 20,
EffectiveBalance: 0,
},
balance: gweiPtr(0),
state: api.ValidatorStateWithdrawalDone,
},
{
name: "WithdrawalDoneNoBalance",
validator: &phase0.Validator{
ActivationEligibilityEpoch: currentEpoch - 50,
ActivationEpoch: currentEpoch - 40,
ExitEpoch: currentEpoch - 30,
WithdrawableEpoch: currentEpoch - 20,
EffectiveBalance: 0,
},
state: api.ValidatorStateWithdrawalDone,
},
}

for _, test := range tests {
Expand Down Expand Up @@ -436,7 +451,7 @@ func TestMarshalJSON(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
require.NotPanics(t, func() {
res, err := json.Marshal(&test.state) //test.state.MarshalJSON()
res, err := json.Marshal(&test.state)
test.errFunc(t, err)
require.Equal(t, test.expected, res)
})
Expand Down
2 changes: 1 addition & 1 deletion http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

// defaultUserAgent is sent with requests if no other user agent has been supplied.
const defaultUserAgent = "go-eth2-client/0.21.9"
const defaultUserAgent = "go-eth2-client/0.21.10"

// post sends an HTTP post request and returns the body.
func (s *Service) post(ctx context.Context, endpoint string, body io.Reader) (io.Reader, error) {
Expand Down

0 comments on commit b3d8c14

Please sign in to comment.