diff --git a/cmd/soroban-rpc/internal/config/config.go b/cmd/soroban-rpc/internal/config/config.go index b522e424..1bb28321 100644 --- a/cmd/soroban-rpc/internal/config/config.go +++ b/cmd/soroban-rpc/internal/config/config.go @@ -27,6 +27,7 @@ type Config struct { DefaultEventsLimit uint DefaultTransactionsLimit uint EventLedgerRetentionWindow uint32 + HistoryRetentionWindow uint32 FriendbotURL string HistoryArchiveURLs []string HistoryArchiveUserAgent string diff --git a/cmd/soroban-rpc/internal/config/options.go b/cmd/soroban-rpc/internal/config/options.go index 20370012..d2ed8c80 100644 --- a/cmd/soroban-rpc/internal/config/options.go +++ b/cmd/soroban-rpc/internal/config/options.go @@ -209,6 +209,13 @@ func (cfg *Config) options() ConfigOptions { ConfigKey: &cfg.CheckpointFrequency, DefaultValue: uint32(64), }, + { + Name: "history-retention-window", + Usage: fmt.Sprintf("configures the history retention window expressed in number of ledgers,"+ + " the maximum value can be %d which corresponds to about 7 days of history", ledgerbucketwindow.SevenDaysOfLedgers), + ConfigKey: &cfg.HistoryRetentionWindow, + }, + { Name: "event-retention-window", Usage: fmt.Sprintf( @@ -222,9 +229,8 @@ func (cfg *Config) options() ConfigOptions { { Name: "transaction-retention-window", Usage: fmt.Sprintf( - "configures the transaction retention window expressed in number of ledgers,"+ - " the default value is %d which corresponds to about 24 hours of history", - ledgerbucketwindow.OneDayOfLedgers), + "DEPRECATED - The usage of the flag transaction-retention-window has been deprecated. ," + + "RPC now uses history-retention-window by default and this flag will soon be removed in future. "), ConfigKey: &cfg.TransactionLedgerRetentionWindow, DefaultValue: uint32(ledgerbucketwindow.OneDayOfLedgers), Validate: positive, diff --git a/cmd/soroban-rpc/internal/daemon/daemon.go b/cmd/soroban-rpc/internal/daemon/daemon.go index a8f5d2d8..fba5fa4c 100644 --- a/cmd/soroban-rpc/internal/daemon/daemon.go +++ b/cmd/soroban-rpc/internal/daemon/daemon.go @@ -137,6 +137,11 @@ func MustNew(cfg *config.Config) *Daemon { logger.UseJSONFormatter() } + if cfg.TransactionLedgerRetentionWindow > 0 { + logger.Info("DEPRECATION WARNING: transaction-retention-window has been deprecated" + + " Please use history-retention-window instead") + } + logger.WithFields(supportlog.F{ "version": config.Version, "commit": config.CommitHash, @@ -228,14 +233,21 @@ func MustNew(cfg *config.Config) *Daemon { logger.WithError(err).Error("could not run ingestion. Retrying") } - // Take the larger of (event retention, tx retention) and then the smaller - // of (tx retention, default event retention) if event retention wasn't - // specified, for some reason...? - maxRetentionWindow := ordered.Max(cfg.EventLedgerRetentionWindow, cfg.TransactionLedgerRetentionWindow) - if cfg.EventLedgerRetentionWindow <= 0 { - maxRetentionWindow = ordered.Min( - maxRetentionWindow, - ledgerbucketwindow.DefaultEventLedgerRetentionWindow) + var maxRetentionWindow uint32 + + if cfg.HistoryRetentionWindow > 0 { + maxRetentionWindow = cfg.HistoryRetentionWindow + } else { + // TODO: Discard this logic once we fully move from in-memory to on-disk storage + // Take the larger of (event retention, tx retention) and then the smaller + // of (tx retention, default event retention) if event retention wasn't + // specified, for some reason...? + maxRetentionWindow := ordered.Max(cfg.EventLedgerRetentionWindow, cfg.TransactionLedgerRetentionWindow) + if cfg.EventLedgerRetentionWindow <= 0 { + maxRetentionWindow = ordered.Min( + maxRetentionWindow, + ledgerbucketwindow.DefaultEventLedgerRetentionWindow) + } } ingestService := ingest.NewService(ingest.Config{ Logger: logger, diff --git a/cmd/soroban-rpc/internal/jsonrpc.go b/cmd/soroban-rpc/internal/jsonrpc.go index 6529e79b..c7c2698c 100644 --- a/cmd/soroban-rpc/internal/jsonrpc.go +++ b/cmd/soroban-rpc/internal/jsonrpc.go @@ -137,7 +137,13 @@ func NewJSONRPCHandler(cfg *config.Config, params HandlerParams) Handler { // While we transition from in-memory to database-oriented history storage, // the on-disk (transaction) retention window will always be larger than the // in-memory (events) one. - var retentionWindow = cfg.TransactionLedgerRetentionWindow + var retentionWindow uint32 + + if cfg.HistoryRetentionWindow > 0 { + retentionWindow = cfg.HistoryRetentionWindow + } else { + retentionWindow = cfg.TransactionLedgerRetentionWindow + } handlers := []struct { methodName string diff --git a/cmd/soroban-rpc/internal/ledgerbucketwindow/ledgerbucketwindow.go b/cmd/soroban-rpc/internal/ledgerbucketwindow/ledgerbucketwindow.go index ee91427c..f58579fe 100644 --- a/cmd/soroban-rpc/internal/ledgerbucketwindow/ledgerbucketwindow.go +++ b/cmd/soroban-rpc/internal/ledgerbucketwindow/ledgerbucketwindow.go @@ -22,6 +22,7 @@ type LedgerBucket[T any] struct { // OneDayOfLedgers is (roughly) a 24 hour window of ledgers. const OneDayOfLedgers = 17280 +const SevenDaysOfLedgers = 7 * OneDayOfLedgers // DefaultEventLedgerRetentionWindow represents the max number of ledgers we // would like to keep an incoming event in memory.