Skip to content

Commit

Permalink
#2 fix checkpoint sync issue (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
antares-sw authored Dec 5, 2022
1 parent efa22eb commit 8116151
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions clients/eth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ func (e *eth2Client) Liveness(w http.ResponseWriter, r *http.Request) {
Code int `json:"code"`
Message string `json:"message"`
}{}
var dataCheckpointSync = struct {
Data struct {
BackFillSyncing struct {
Completed int `json:"completed"`
Remaining int `json:"remaining"`
} `json:"BackFillSyncing"`
} `json:"data"`
}{}

_, err := e.client.R().
SetHeader("Content-Type", "application/json").
Expand All @@ -91,6 +99,15 @@ func (e *eth2Client) Liveness(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
}

_, err = e.client.R().
SetHeader("Content-Type", "application/json").
SetResult(&dataCheckpointSync).
SetError(&dataError).
Get(e.addr + "/eth/v1/node/syncing")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
}

resp, err := e.client.R().
SetHeader("Content-Type", "application/json").
Get(e.addr + "/eth/v1/node/health")
Expand All @@ -100,12 +117,22 @@ func (e *eth2Client) Liveness(w http.ResponseWriter, r *http.Request) {
return
}

syncDistance, _ := strconv.Atoi(data.Data.SyncDistance)
if resp.StatusCode() == http.StatusOK && syncDistance < 50 {
fmt.Fprintf(w, "StatusOK. Beacon node is healthy.")
if dataCheckpointSync.Data.BackFillSyncing.Remaining != 0 {
if dataCheckpointSync.Data.BackFillSyncing.Remaining-dataCheckpointSync.Data.BackFillSyncing.Completed < 50 {
fmt.Fprintf(w, "StatusOK. Beacon node is healthy.")
} else {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
} else {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
syncDistance, _ := strconv.Atoi(data.Data.SyncDistance)
if resp.StatusCode() == http.StatusOK && syncDistance < 50 {
fmt.Fprintf(w, "StatusOK. Beacon node is healthy.")
} else {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
}
}

0 comments on commit 8116151

Please sign in to comment.