-
Notifications
You must be signed in to change notification settings - Fork 672
/
health.go
44 lines (39 loc) · 1.14 KB
/
health.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
43
44
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package platformvm
import (
"context"
"fmt"
"time"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/utils/constants"
)
func (vm *VM) HealthCheck(context.Context) (interface{}, error) {
localPrimaryValidator, err := vm.state.GetCurrentValidator(
constants.PrimaryNetworkID,
vm.ctx.NodeID,
)
switch err {
case nil:
vm.metrics.SetTimeUntilUnstake(time.Until(localPrimaryValidator.EndTime))
case database.ErrNotFound:
vm.metrics.SetTimeUntilUnstake(0)
default:
return nil, fmt.Errorf("couldn't get current local validator: %w", err)
}
for subnetID := range vm.TrackedSubnets {
localSubnetValidator, err := vm.state.GetCurrentValidator(
subnetID,
vm.ctx.NodeID,
)
switch err {
case nil:
vm.metrics.SetTimeUntilSubnetUnstake(subnetID, time.Until(localSubnetValidator.EndTime))
case database.ErrNotFound:
vm.metrics.SetTimeUntilSubnetUnstake(subnetID, 0)
default:
return nil, fmt.Errorf("couldn't get current subnet validator of %q: %w", subnetID, err)
}
}
return nil, nil
}