Skip to content

Commit

Permalink
Expose the maximum ledger retention window
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Apr 11, 2024
1 parent e9dda73 commit 2ba5720
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion cmd/soroban-rpc/internal/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ func NewJSONRPCHandler(cfg *config.Config, params HandlerParams) Handler {

// Get the largest history window
var ledgerRangeGetter methods.LedgerRangeGetter = params.EventStore
var retentionWindow = cfg.EventLedgerRetentionWindow
if cfg.TransactionLedgerRetentionWindow > cfg.EventLedgerRetentionWindow {
retentionWindow = cfg.TransactionLedgerRetentionWindow
ledgerRangeGetter = params.TransactionStore
}

Expand All @@ -150,7 +152,7 @@ func NewJSONRPCHandler(cfg *config.Config, params HandlerParams) Handler {
}{
{
methodName: "getHealth",
underlyingHandler: methods.NewHealthCheck(ledgerRangeGetter, cfg.MaxHealthyLedgerLatency),
underlyingHandler: methods.NewHealthCheck(retentionWindow, ledgerRangeGetter, cfg.MaxHealthyLedgerLatency),
longName: "get_health",
queueLimit: cfg.RequestBacklogGetHealthQueueLimit,
requestDurationLimit: cfg.MaxGetHealthExecutionDuration,
Expand Down
16 changes: 9 additions & 7 deletions cmd/soroban-rpc/internal/methods/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ import (
)

type HealthCheckResult struct {
Status string `json:"status"`
LatestLedger uint32 `json:"latestLedger"`
OldestLedger uint32 `json:"oldestLedger"`
Status string `json:"status"`
LatestLedger uint32 `json:"latestLedger"`
OldestLedger uint32 `json:"oldestLedger"`
LedgerRetentionWindow uint32 `json:"ledgerRetentionWindow"`
}

type LedgerRangeGetter interface {
GetLedgerRange() ledgerbucketwindow.LedgerRange
}

// NewHealthCheck returns a health check json rpc handler
func NewHealthCheck(ledgerRangeGetter LedgerRangeGetter, maxHealthyLedgerLatency time.Duration) jrpc2.Handler {
func NewHealthCheck(retentionWindow uint32, ledgerRangeGetter LedgerRangeGetter, maxHealthyLedgerLatency time.Duration) jrpc2.Handler {
return handler.New(func(ctx context.Context) (HealthCheckResult, error) {
ledgerRange := ledgerRangeGetter.GetLedgerRange()
if ledgerRange.LastLedger.Sequence < 1 {
Expand All @@ -43,9 +44,10 @@ func NewHealthCheck(ledgerRangeGetter LedgerRangeGetter, maxHealthyLedgerLatency
}
}
result := HealthCheckResult{
Status: "healthy",
LatestLedger: ledgerRange.LastLedger.Sequence,
OldestLedger: ledgerRange.FirstLedger.Sequence,
Status: "healthy",
LatestLedger: ledgerRange.LastLedger.Sequence,
OldestLedger: ledgerRange.FirstLedger.Sequence,
LedgerRetentionWindow: retentionWindow,
}
return result, nil
})
Expand Down
2 changes: 2 additions & 0 deletions cmd/soroban-rpc/internal/test/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/creachadair/jrpc2/jhttp"
"github.com/stretchr/testify/assert"

"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/ledgerbucketwindow"
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/methods"
)

Expand All @@ -22,6 +23,7 @@ func TestHealth(t *testing.T) {
t.Fatalf("rpc call failed: %v", err)
}
assert.Equal(t, "healthy", result.Status)
assert.Equal(t, uint32(ledgerbucketwindow.DefaultEventLedgerRetentionWindow), result.LedgerRetentionWindow)
assert.Greater(t, result.OldestLedger, uint32(0))
assert.Greater(t, result.LatestLedger, uint32(0))
assert.GreaterOrEqual(t, result.LatestLedger, result.OldestLedger)
Expand Down

0 comments on commit 2ba5720

Please sign in to comment.