mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-23 20:17:17 +00:00
423b4f68ac
adding in unit tests for healthchecks
29 lines
522 B
Go
29 lines
522 B
Go
package health
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
var (
|
|
errNotEnoughPeers = errors.New("not enough peers")
|
|
)
|
|
|
|
func checkMinPeers(minPeerCount uint, api NetAPI) error {
|
|
if api == nil {
|
|
return fmt.Errorf("no connection to the Erigon server or `net` namespace isn't enabled")
|
|
}
|
|
|
|
peerCount, err := api.PeerCount(context.TODO())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if uint64(peerCount) < uint64(minPeerCount) {
|
|
return fmt.Errorf("%w: %d (minimum %d)", errNotEnoughPeers, peerCount, minPeerCount)
|
|
}
|
|
|
|
return nil
|
|
}
|