mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-31 12:08:37 +00:00
22 lines
409 B
Go
22 lines
409 B
Go
package health
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
var (
|
|
errNotEnoughPeers = errors.New("not enough peers")
|
|
)
|
|
|
|
func checkMinPeers(ec ethClient, minPeerCount uint) error {
|
|
peerCount, err := ec.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
|
|
}
|