Skip to content

Commit

Permalink
use existing ConnectToCanonicalValidators to set up for the test
Browse files Browse the repository at this point in the history
  • Loading branch information
iansuvak committed Jan 23, 2025
1 parent 8adf571 commit d770db5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions signature-aggregator/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (
var (
// Errors
errNotEnoughSignatures = errors.New("failed to collect a threshold of signatures")
errNotEnoughConnectedStake = errors.New("failed to connect to a threshold of stake")
ErrNotEnoughConnectedStake = errors.New("failed to connect to a threshold of stake")
)

type SignatureAggregator struct {
Expand Down Expand Up @@ -149,7 +149,7 @@ func (s *SignatureAggregator) CreateSignedMessage(
zap.Uint64("quorumPercentage", quorumPercentage),
)
s.metrics.FailuresToConnectToSufficientStake.Inc()
return nil, errNotEnoughConnectedStake
return nil, ErrNotEnoughConnectedStake
}

accumulatedSignatureWeight := big.NewInt(0)
Expand Down
30 changes: 20 additions & 10 deletions signature-aggregator/healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,38 @@ package healthcheck

import (
"context"
"fmt"
"math/big"
"net/http"

"github.com/alexliesenfeld/health"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/coreth/precompile/contracts/warp"
"github.com/ava-labs/icm-services/peers"
"github.com/ava-labs/icm-services/signature-aggregator/aggregator"
"github.com/ava-labs/icm-services/utils"
)

func HandleHealthCheckRequest(uint16 apiPort) {
func HandleHealthCheckRequest(network peers.AppRequestNetwork) {
healthChecker := health.NewChecker(
health.WithCheck(health.Check{
Name: "signature-aggregator-health",
Check: func(context.Context) error {
connectedValidators, err := network.ConnectToCanonicalValidators(constants.PrimaryNetworkID)
if err != nil {
return fmt.Errorf("Failed to connect to primary network validators: %w", err)
}
if !utils.CheckStakeWeightExceedsThreshold(
big.NewInt(0).SetUint64(connectedValidators.ConnectedWeight),
connectedValidators.TotalValidatorWeight,
warp.WarpDefaultQuorumNumerator,
) {
return aggregator.ErrNotEnoughConnectedStake
}
return nil
},
}),
)

readinessCheck := health.NewChecker(
health.WithCheck(health.Check{
Name: "signature-aggregator-readiness",
Check: func(context.Context) error {

},
}),
)
http.Handle("/health", health.NewHandler(healthChecker))
http.Handle("/ready", health.NewHandler(readinessCheck))
}
2 changes: 1 addition & 1 deletion signature-aggregator/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func main() {
metricsInstance,
signatureAggregator,
)
healthcheck.HandleHealthCheckRequest(cfg.APIPort)
healthcheck.HandleHealthCheckRequest(network)

logger.Info("Initialization complete")
err = http.ListenAndServe(fmt.Sprintf(":%d", cfg.APIPort), nil)
Expand Down

0 comments on commit d770db5

Please # to comment.