Skip to content

Commit

Permalink
return unknown validators
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo committed May 17, 2024
1 parent 1eea970 commit 0de6598
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
7 changes: 3 additions & 4 deletions listener/cmd/listener/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ func main() {
apiCron.RemoveOldSignatures(dbCollection, 720)

})
// c.AddFunc("* * * * *", func() {
// apiCron.RemoveUnknownSignatures(dbCollection, config.BeaconNodeURLs)

// })
c.AddFunc("* * * * *", func() {
apiCron.RemoveUnknownSignatures(dbCollection, config.BeaconNodeURLs)
})
c.Start()

// Set up signal handling for graceful shutdown
Expand Down
8 changes: 6 additions & 2 deletions listener/internal/api/handlers/postNewSignature.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ func filterAndVerifySignatures(requests []types.SignatureRequestDecoded, validat
validSignatures := []types.SignatureRequestDecodedWithStatus{}
for _, req := range requests {
status, ok := validatorsStatusMap[req.Pubkey]
if !ok || status == types.Inactive {
logger.Warn("Validator not found or inactive: " + req.Pubkey)
if !ok {
logger.Warn("Validator not found: " + req.Pubkey)
continue
}
if status == types.Inactive {
logger.Warn("Inactive validator: " + req.Pubkey)
continue
}
reqWithStatus := types.SignatureRequestDecodedWithStatus{
Expand Down
13 changes: 9 additions & 4 deletions listener/internal/api/validation/GetValidatorsStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func GetValidatorsStatus(pubkeys []string, beaconNodeUrl string) (map[string]typ
return nil, fmt.Errorf("no public keys provided to retrieve active validators from beacon node")
}

// Use a map to store validator statuses
statusMap := make(map[string]types.Status)

// Serialize the request body to JSON
// See https://ethereum.github.io/beacon-APIs/#/Beacon/postStateValidators
// returns only active validators
Expand All @@ -64,15 +67,19 @@ func GetValidatorsStatus(pubkeys []string, beaconNodeUrl string) (map[string]typ
// Make API call
resp, err := client.Post(apiUrl, "application/json", bytes.NewBuffer(jsonData))
if err != nil {
return nil, fmt.Errorf("error making API call to " + apiUrl + ": " + err.Error())
logger.Error("Failed to make request to beacon node: " + err.Error())
// return the pubkeys to be stored with status unknown
for _, pubkey := range pubkeys {
statusMap[pubkey] = types.Unknown
}
return statusMap, nil
}
defer resp.Body.Close()

// Check if it's any server error 5xx
if resp.StatusCode >= 500 && resp.StatusCode < 600 {
logger.Error("internal server error due to server issue, keeping signatures to be stored with status unknown: " + resp.Status)
// return the pubkeys to be stored with status unknown
statusMap := make(map[string]types.Status)
for _, pubkey := range pubkeys {
statusMap[pubkey] = types.Unknown
}
Expand All @@ -90,8 +97,6 @@ func GetValidatorsStatus(pubkeys []string, beaconNodeUrl string) (map[string]typ
return nil, fmt.Errorf("error decoding response data from beacon node: " + err.Error())
}

// Use a map to store validator statuses
statusMap := make(map[string]types.Status)
for _, pubkey := range pubkeys {
statusMap[pubkey] = types.Inactive
}
Expand Down

0 comments on commit 0de6598

Please sign in to comment.