Skip to content

Commit

Permalink
Return Nil Error if Pre-Genesis in P2P Service Healthz Check (#5355)
Browse files Browse the repository at this point in the history
* pregenesis healthz check:

* optimal

* right order

* Update beacon-chain/p2p/service.go

Co-Authored-By: Preston Van Loon <[email protected]>

* Update beacon-chain/p2p/service.go

Co-Authored-By: Preston Van Loon <[email protected]>

* no comment

Co-authored-by: Preston Van Loon <[email protected]>
  • Loading branch information
rauljordan and prestonvanloon authored Apr 8, 2020
1 parent 54830f1 commit e02f4f4
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions beacon-chain/p2p/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,25 @@ const maxBadResponses = 3

// Service for managing peer to peer (p2p) networking.
type Service struct {
beaconDB db.Database
ctx context.Context
cancel context.CancelFunc
started bool
isPreGenesis bool
pingMethod func(ctx context.Context, id peer.ID) error
cancel context.CancelFunc
cfg *Config
startupErr error
peers *peers.Status
dht *kaddht.IpfsDHT
privKey *ecdsa.PrivateKey
exclusionList *ristretto.Cache
metaData *pb.MetaData
pubsub *pubsub.PubSub
beaconDB db.Database
dv5Listener Listener
startupErr error
stateNotifier statefeed.Notifier
ctx context.Context
host host.Host
pubsub *pubsub.PubSub
exclusionList *ristretto.Cache
privKey *ecdsa.PrivateKey
dht *kaddht.IpfsDHT
peers *peers.Status
genesisTime time.Time
genesisValidatorsRoot []byte
metaData *pb.MetaData
stateNotifier statefeed.Notifier
pingMethod func(ctx context.Context, id peer.ID) error
}

// NewService initializes a new p2p service compatible with shared.Service interface. No
Expand All @@ -98,6 +99,7 @@ func NewService(cfg *Config) (*Service, error) {
cancel: cancel,
cfg: cfg,
exclusionList: cache,
isPreGenesis: true,
}

dv5Nodes, kadDHTNodes := parseBootStrapAddrs(s.cfg.BootstrapNodeAddr)
Expand Down Expand Up @@ -184,6 +186,7 @@ func (s *Service) Start() {
} else {
s.awaitStateInitialized()
}
s.isPreGenesis = false

var peersToWatch []string
if s.cfg.RelayNodeAddr != "" {
Expand Down Expand Up @@ -295,9 +298,15 @@ func (s *Service) Stop() error {
// Status of the p2p service. Will return an error if the service is considered unhealthy to
// indicate that this node should not serve traffic until the issue has been resolved.
func (s *Service) Status() error {
if s.isPreGenesis {
return nil
}
if !s.started {
return errors.New("not running")
}
if s.startupErr != nil {
return s.startupErr
}
return nil
}

Expand Down

0 comments on commit e02f4f4

Please sign in to comment.