Skip to content

Commit

Permalink
fix: fixed bug where health event from settlement layer were ignored (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
omritoptix authored Jun 29, 2023
1 parent 6c190da commit 73a177d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions .go-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.19.10
2 changes: 1 addition & 1 deletion rpc/middleware/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestStatusMiddleware(t *testing.T) {
{
healthy: &sharedtypes.HealthStatus{IsHealthy: false, Error: errors.New("Node Unhealthy")},
expectedStatus: http.StatusServiceUnavailable,
expectedMessage: "Node Unhealthy",
expectedMessage: "node is unhealthy: Node Unhealthy",
},
}

Expand Down
6 changes: 5 additions & 1 deletion rpc/middleware/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package middleware

import (
"errors"
"fmt"
"net/http"

"github.com/dymensionxyz/dymint/rpc/sharedtypes"
Expand Down Expand Up @@ -34,8 +35,11 @@ func status(healthStatus *sharedtypes.HealthStatus, h http.Handler, logger log.L
isHealthy, err := healthStatus.Get()
if !isHealthy {
w.WriteHeader(http.StatusServiceUnavailable)
errorPrefix := "node is unhealthy"
if err == nil {
err = errors.New("node is unhealthy")
err = errors.New(errorPrefix)
} else {
err = fmt.Errorf("%s: %w", errorPrefix, err)
}
_, err := w.Write([]byte(err.Error()))
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions settlement/dymension/dymension.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ WaitForBatchAcceptance:
if err != nil {
d.logger.Error("Failed submitting batch to settlement layer. Emitting unhealthy event",
"startHeight", batch.StartHeight, "endHeight", batch.EndHeight, "error", err)
heatlhEventData := settlement.EventDataSettlementHealthStatus{Healthy: false, Error: err}
heatlhEventData := &settlement.EventDataSettlementHealthStatus{Healthy: false, Error: err}
utils.SubmitEventOrPanic(d.ctx, d.pubsub, heatlhEventData,
map[string][]string{settlement.EventTypeKey: {settlement.EventSettlementHealthStatus}})
// Sleep to allow context cancellation to take effect before retrying
Expand All @@ -232,7 +232,7 @@ WaitForBatchAcceptance:
case <-d.batchAcceptedCh:
d.logger.Debug("Batch accepted by settlement layer. Emitting healthy event",
"startHeight", batch.StartHeight, "endHeight", batch.EndHeight)
heatlhEventData := settlement.EventDataSettlementHealthStatus{Healthy: true}
heatlhEventData := &settlement.EventDataSettlementHealthStatus{Healthy: true}
utils.SubmitEventOrPanic(d.ctx, d.pubsub, heatlhEventData,
map[string][]string{settlement.EventTypeKey: {settlement.EventSettlementHealthStatus}})
return
Expand All @@ -250,15 +250,15 @@ WaitForBatchAcceptance:
utils.SubmitEventOrPanic(d.ctx, d.pubsub, batchAcceptedEvent,
map[string][]string{settlement.EventTypeKey: {settlement.EventNewSettlementBatchAccepted}})
// Emit health event
heatlhEventData := settlement.EventDataSettlementHealthStatus{Healthy: true}
heatlhEventData := &settlement.EventDataSettlementHealthStatus{Healthy: true}
utils.SubmitEventOrPanic(d.ctx, d.pubsub, heatlhEventData,
map[string][]string{settlement.EventTypeKey: {settlement.EventSettlementHealthStatus}})
return
}
// Batch was not accepted by the settlement layer. Emitting unhealthy event
d.logger.Debug("Batch not accepted by settlement layer. Emitting unhealthy event",
"startHeight", batch.StartHeight, "endHeight", batch.EndHeight)
heatlhEventData := settlement.EventDataSettlementHealthStatus{Healthy: false, Error: settlement.ErrBatchNotAccepted}
heatlhEventData := &settlement.EventDataSettlementHealthStatus{Healthy: false, Error: settlement.ErrBatchNotAccepted}
utils.SubmitEventOrPanic(d.ctx, d.pubsub, heatlhEventData,
map[string][]string{settlement.EventTypeKey: {settlement.EventSettlementHealthStatus}})
// Stop the ticker and restart the loop
Expand Down
2 changes: 1 addition & 1 deletion settlement/dymension/dymension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestPostBatch(t *testing.T) {
select {
case healthEvent := <-HealthSubscription.Out():
t.Logf("got health event: %v", healthEvent)
healthStatusEvent := healthEvent.Data().(settlement.EventDataSettlementHealthStatus)
healthStatusEvent := healthEvent.Data().(*settlement.EventDataSettlementHealthStatus)
assert.Equal(t, c.expectedHealthEventValue, healthStatusEvent.Healthy)
assert.Equal(t, c.expectedError, healthStatusEvent.Error)
wg.Done()
Expand Down

0 comments on commit 73a177d

Please sign in to comment.