Skip to content

Commit f738fae

Browse files
committed
Update status readyness check
1 parent 8cba743 commit f738fae

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

client/client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ type Client interface {
2323
// and wait for it to be committed to the chain
2424
SendTransactionCommit(tx *std.Tx) (*coreTypes.ResultBroadcastTxCommit, error)
2525

26-
// Ping calls the simplest element on the implementation that is able
27-
// to tell if it is still alive. If there is any problem, it returns an error.
28-
Ping() error
26+
// Status fetches the node's latest status
27+
Status() (*coreTypes.ResultStatus, error)
2928
}

client/http/http.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ func (c *Client) SendTransactionCommit(tx *std.Tx) (*coreTypes.ResultBroadcastTx
6363
return c.client.BroadcastTxCommit(context.Background(), aminoTx)
6464
}
6565

66-
func (c *Client) Ping() error {
67-
_, err := c.client.Health(context.Background())
68-
69-
return err
66+
func (c *Client) Status() (*coreTypes.ResultStatus, error) {
67+
return c.client.Status(context.Background(), nil)
7068
}

handler.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ func (f *Faucet) healthcheckHandler(_ http.ResponseWriter, r *http.Request) {
223223

224224
// readycheckHandler is the default ready check handler for the faucet
225225
func (f *Faucet) readycheckHandler(w http.ResponseWriter, r *http.Request) {
226-
err := f.client.Ping()
226+
// Grab the node's status
227+
status, err := f.client.Status()
227228
if err != nil {
228229
render.JSON(w, r, &response{
229230
Message: fmt.Sprintf("node not ready: %s", err.Error()),
@@ -240,7 +241,8 @@ func (f *Faucet) readycheckHandler(w http.ResponseWriter, r *http.Request) {
240241
render.JSON(w, r, &response{
241242
Message: "node is ready",
242243
Info: map[string]any{
243-
"time": time.Now().String(),
244+
"height": status.SyncInfo.LatestBlockHeight,
245+
"time": time.Now().String(),
244246
},
245247
})
246248
}

mock_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ type (
137137
getAccountDelegate func(crypto.Address) (std.Account, error)
138138
sendTransactionSyncDelegate func(tx *std.Tx) (*coreTypes.ResultBroadcastTx, error)
139139
sendTransactionCommitDelegate func(tx *std.Tx) (*coreTypes.ResultBroadcastTxCommit, error)
140-
pingDelegate func() error
140+
statusDelegate func() (*coreTypes.ResultStatus, error)
141141
)
142142

143143
type mockClient struct {
144144
getAccountFn getAccountDelegate
145145
sendTransactionSyncFn sendTransactionSyncDelegate
146146
sendTransactionCommitFn sendTransactionCommitDelegate
147-
pingFn pingDelegate
147+
statusFn statusDelegate
148148
}
149149

150150
func (m *mockClient) GetAccount(address crypto.Address) (std.Account, error) {
@@ -171,12 +171,12 @@ func (m *mockClient) SendTransactionCommit(tx *std.Tx) (*coreTypes.ResultBroadca
171171
return nil, nil
172172
}
173173

174-
func (m *mockClient) Ping() error {
175-
if m.pingFn != nil {
176-
return m.pingFn()
174+
func (m *mockClient) Status() (*coreTypes.ResultStatus, error) {
175+
if m.statusFn != nil {
176+
return m.statusFn()
177177
}
178178

179-
return nil
179+
return nil, nil
180180
}
181181

182182
type (

0 commit comments

Comments
 (0)