Skip to content

Commit

Permalink
Add BLS healthcheck to communicate incorrect BLS key configuration (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Jan 5, 2025
1 parent fd9acbe commit 7efd463
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import (
"github.com/ava-labs/avalanchego/trace"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/dynamicip"
"github.com/ava-labs/avalanchego/utils/filesystem"
"github.com/ava-labs/avalanchego/utils/hashing"
Expand Down Expand Up @@ -1495,6 +1496,32 @@ func (n *Node) initHealthAPI() error {
return fmt.Errorf("couldn't register resource health check: %w", err)
}

wrongBLSKeyCheck := health.CheckerFunc(func(context.Context) (interface{}, error) {
vdr, ok := n.vdrs.GetValidator(constants.PrimaryNetworkID, n.ID)
if !ok {
return "node is not a validator", nil
}

vdrPK := vdr.PublicKey
if vdrPK == nil {
return "validator doesn't have a BLS key", nil
}

nodePK := n.Config.StakingSigningKey.PublicKey()
if nodePK.Equals(vdrPK) {
return "node has the correct BLS key", nil
}
return nil, fmt.Errorf("node has BLS key 0x%x, but is registered to the validator set with 0x%x",
bls.PublicKeyToCompressedBytes(nodePK),
bls.PublicKeyToCompressedBytes(vdrPK),
)
})

err = n.health.RegisterHealthCheck("bls", wrongBLSKeyCheck, health.ApplicationTag)
if err != nil {
return fmt.Errorf("couldn't register bls health check: %w", err)
}

handler, err := health.NewGetAndPostHandler(n.Log, n.health)
if err != nil {
return err
Expand Down

0 comments on commit 7efd463

Please sign in to comment.