diff --git a/cmd/soroban-rpc/internal/jsonrpc.go b/cmd/soroban-rpc/internal/jsonrpc.go index 688e9331..b0ceb372 100644 --- a/cmd/soroban-rpc/internal/jsonrpc.go +++ b/cmd/soroban-rpc/internal/jsonrpc.go @@ -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 } @@ -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, diff --git a/cmd/soroban-rpc/internal/methods/health.go b/cmd/soroban-rpc/internal/methods/health.go index 7aabe707..b8f684af 100644 --- a/cmd/soroban-rpc/internal/methods/health.go +++ b/cmd/soroban-rpc/internal/methods/health.go @@ -12,9 +12,10 @@ 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 { @@ -22,7 +23,7 @@ type LedgerRangeGetter interface { } // 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 { @@ -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 }) diff --git a/cmd/soroban-rpc/internal/test/health_test.go b/cmd/soroban-rpc/internal/test/health_test.go index 3f39c62c..75e097d4 100644 --- a/cmd/soroban-rpc/internal/test/health_test.go +++ b/cmd/soroban-rpc/internal/test/health_test.go @@ -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" ) @@ -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)