Skip to content
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

Provide validator beacon status in api #229

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,14 @@ func (m *ApiService) handleMemoryValidators(w http.ResponseWriter, req *http.Req

validatorsResp := make([]httpOkValidatorInfo, 0)
for _, v := range validators {
beaconState, found := m.Onchain.Validators()[phase0.ValidatorIndex(v.ValidatorIndex)]
if !found {
log.Warn("could not find validator in beacon state: ", v.ValidatorIndex)
continue
}
validatorsResp = append(validatorsResp, httpOkValidatorInfo{
ValidatorStatus: v.ValidatorStatus.String(),
BeaconValidatorStatus: beaconState.Status.String(),
AccumulatedRewardsWei: v.AccumulatedRewardsWei.String(),
PendingRewardsWei: v.PendingRewardsWei.String(),
CollateralWei: v.CollateralWei.String(),
Expand Down Expand Up @@ -589,8 +595,14 @@ func (m *ApiService) handleMemoryValidatorsByIndex(w http.ResponseWriter, req *h
for _, index := range indices {
if validator, found := m.oracle.State().Validators[index]; found {
// Convert ValidatorInfo to httpOkValidatorInfo. This is done to return strings instead of bigInts
beaconState, found := m.Onchain.Validators()[phase0.ValidatorIndex(validator.ValidatorIndex)]
if !found {
log.Warn("could not find validator in beacon state: ", validator.ValidatorIndex)
continue
}
foundValidator := httpOkValidatorInfo{
ValidatorStatus: validator.ValidatorStatus.String(),
BeaconValidatorStatus: beaconState.Status.String(),
AccumulatedRewardsWei: validator.AccumulatedRewardsWei.String(),
PendingRewardsWei: validator.PendingRewardsWei.String(),
CollateralWei: validator.CollateralWei.String(),
Expand Down Expand Up @@ -658,9 +670,9 @@ func (m *ApiService) handleMemoryValidatorsByWithdrawal(w http.ResponseWriter, r
}

// Skip validators that cannot be subscribed
if !oracle.CanValidatorSubscribeToPool(validator) {
continue
}
//if !oracle.CanValidatorSubscribeToPool(validator) {
// continue
//}

requestedValidators[uint64(valIndex)] = &oracle.ValidatorInfo{
ValidatorStatus: oracle.Untracked,
Expand Down Expand Up @@ -736,8 +748,14 @@ func (m *ApiService) handleMemoryValidatorsByWithdrawal(w http.ResponseWriter, r

validatorsResp := make([]httpOkValidatorInfo, 0)
for _, v := range values {
beaconState, found := m.Onchain.Validators()[phase0.ValidatorIndex(v.ValidatorIndex)]
if !found {
log.Warn("could not find validator in beacon state: ", v.ValidatorIndex)
continue
}
validatorsResp = append(validatorsResp, httpOkValidatorInfo{
ValidatorStatus: v.ValidatorStatus.String(),
BeaconValidatorStatus: beaconState.Status.String(),
AccumulatedRewardsWei: v.AccumulatedRewardsWei.String(),
PendingRewardsWei: v.PendingRewardsWei.String(),
CollateralWei: v.CollateralWei.String(),
Expand Down
1 change: 1 addition & 0 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ type httpOkBlock struct {

type httpOkValidatorInfo struct {
ValidatorStatus string `json:"status"`
BeaconValidatorStatus string `json:"beacon_status"`
AccumulatedRewardsWei string `json:"accumulated_rewards_wei"`
PendingRewardsWei string `json:"pending_rewards_wei"`
CollateralWei string `json:"collateral_wei"`
Expand Down
Loading