-
Notifications
You must be signed in to change notification settings - Fork 0
/
fullnode.go
42 lines (33 loc) · 974 Bytes
/
fullnode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package healthcheck
import (
"encoding/json"
"net/http"
"time"
log "github.com/sirupsen/logrus"
"github.com/chia-network/go-chia-libs/pkg/types"
)
func (h *Healthcheck) fullNodeReceive(resp *types.WebsocketResponse) {
var blockHeight uint32
if resp.Command != "get_blockchain_state" {
return
}
block := &types.WebsocketBlockchainState{}
err := json.Unmarshal(resp.Data, block)
if err != nil {
log.Errorf("Error unmarshalling: %s\n", err.Error())
return
}
blockHeight = block.BlockchainState.Peak.OrEmpty().Height
// Edge case, but we should be sure block height is increasing
if blockHeight <= h.lastHeight {
return
}
h.lastHeight = blockHeight
h.lastHeightTime = time.Now()
}
// Healthcheck endpoint for the full node service as a whole
func (h *Healthcheck) fullNodeHealthcheck() func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
timeMetricHealthcheckHelper(h.lastHeightTime, w, r)
}
}