github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/health.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package platformvm
     5  
     6  import (
     7  	"context"
     8  	"fmt"
     9  	"time"
    10  
    11  	"github.com/MetalBlockchain/metalgo/database"
    12  	"github.com/MetalBlockchain/metalgo/utils/constants"
    13  )
    14  
    15  func (vm *VM) HealthCheck(context.Context) (interface{}, error) {
    16  	localPrimaryValidator, err := vm.state.GetCurrentValidator(
    17  		constants.PrimaryNetworkID,
    18  		vm.ctx.NodeID,
    19  	)
    20  	switch err {
    21  	case nil:
    22  		vm.metrics.SetTimeUntilUnstake(time.Until(localPrimaryValidator.EndTime))
    23  	case database.ErrNotFound:
    24  		vm.metrics.SetTimeUntilUnstake(0)
    25  	default:
    26  		return nil, fmt.Errorf("couldn't get current local validator: %w", err)
    27  	}
    28  
    29  	for subnetID := range vm.TrackedSubnets {
    30  		localSubnetValidator, err := vm.state.GetCurrentValidator(
    31  			subnetID,
    32  			vm.ctx.NodeID,
    33  		)
    34  		switch err {
    35  		case nil:
    36  			vm.metrics.SetTimeUntilSubnetUnstake(subnetID, time.Until(localSubnetValidator.EndTime))
    37  		case database.ErrNotFound:
    38  			vm.metrics.SetTimeUntilSubnetUnstake(subnetID, 0)
    39  		default:
    40  			return nil, fmt.Errorf("couldn't get current subnet validator of %q: %w", subnetID, err)
    41  		}
    42  	}
    43  	return nil, nil
    44  }