Skip to content

Commit

Permalink
healthy
Browse files Browse the repository at this point in the history
  • Loading branch information
hunter-bera committed Feb 2, 2024
1 parent ab5568c commit 5381bc9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
6 changes: 6 additions & 0 deletions client/eth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
type Client interface {
DialContext(ctx context.Context, rawurl string) error
Close() error
Health() bool
Reader
Writer
}
Expand Down Expand Up @@ -87,6 +88,11 @@ func (c *ExtendedEthClient) Close() error {
return nil
}

func (c *ExtendedEthClient) Health() bool {
_, err := c.ChainID(context.TODO())
return err == nil
}

// ==================================================================
// Client Usage Methods
// ==================================================================
Expand Down
18 changes: 11 additions & 7 deletions client/eth/client_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ var (
ErrClientNotFound = errors.New("client not found")
)

// ChainProvider is an interface that groups the Reader, Writer, and ConnectionPool interfaces.
type ChainProvider interface {
Reader
Writer
ConnectionPool
}

// ChainProviderImpl is an implementation of the ChainProvider interface.
type ChainProviderImpl struct {
ConnectionPool
Expand Down Expand Up @@ -234,3 +227,14 @@ func (c *ChainProviderImpl) TxPoolContent(ctx context.Context) (
}
return nil, ErrClientNotFound
}

func (c *ChainProviderImpl) Health() bool {
httpOk, wsOk := false, false
if client, ok := c.GetHTTP(); ok {
httpOk = client.Healthy()
}
if client, ok := c.GetWS(); ok {
wsOk = client.Healthy()
}
return httpOk && wsOk
}
11 changes: 8 additions & 3 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ type CancellableContext interface {

type Context struct {
context.Context
chain eth.Client
logger log.Logger
db ethdb.KeyValueStore
chain eth.Client
logger log.Logger
db ethdb.KeyValueStore
connPool eth.ConnectionPool
}

// UnwrapContext unwraps the sdk context.
Expand Down Expand Up @@ -60,3 +61,7 @@ func (c *Context) Logger() log.Logger {
func (c *Context) DB() ethdb.KeyValueStore {
return c.db
}

func (c *Context) ConnectionPool() eth.ConnectionPool {
return c.connPool
}

0 comments on commit 5381bc9

Please sign in to comment.