diff --git a/cmd/soroban-rpc/internal/config/config.go b/cmd/soroban-rpc/internal/config/config.go index 1f89ab2b5..5827c1c33 100644 --- a/cmd/soroban-rpc/internal/config/config.go +++ b/cmd/soroban-rpc/internal/config/config.go @@ -39,6 +39,7 @@ type Config struct { PreflightEnableDebug bool SQLiteDBPath string TransactionLedgerRetentionWindow uint32 + LedgerRetentionWindow uint32 RequestBacklogGlobalQueueLimit uint RequestBacklogGetHealthQueueLimit uint RequestBacklogGetEventsQueueLimit uint diff --git a/cmd/soroban-rpc/internal/config/options.go b/cmd/soroban-rpc/internal/config/options.go index cecfb2e7d..f3c308944 100644 --- a/cmd/soroban-rpc/internal/config/options.go +++ b/cmd/soroban-rpc/internal/config/options.go @@ -225,6 +225,16 @@ func (cfg *Config) options() ConfigOptions { DefaultValue: uint32(1440), Validate: positive, }, + + { + Name: "ledger-retention-window", + Usage: "configures the common retention window for events and transactions expressed in number of ledgers," + + " the default value is 17280 which corresponds to about 24 hours of history", + ConfigKey: &cfg.LedgerRetentionWindow, + DefaultValue: uint32(ledgerbucketwindow.DefaultLedgerRetentionWindow), + Validate: positive, + }, + { Name: "max-events-limit", Usage: "Maximum amount of events allowed in a single getEvents response", diff --git a/cmd/soroban-rpc/internal/daemon/daemon.go b/cmd/soroban-rpc/internal/daemon/daemon.go index 63afb9a71..f233ad655 100644 --- a/cmd/soroban-rpc/internal/daemon/daemon.go +++ b/cmd/soroban-rpc/internal/daemon/daemon.go @@ -175,12 +175,12 @@ func MustNew(cfg *config.Config) *Daemon { eventStore := events.NewMemoryStore( daemon, cfg.NetworkPassphrase, - cfg.EventLedgerRetentionWindow, + cfg.LedgerRetentionWindow, ) transactionStore := transactions.NewMemoryStore( daemon, cfg.NetworkPassphrase, - cfg.TransactionLedgerRetentionWindow, + cfg.LedgerRetentionWindow, ) // initialize the stores using what was on the DB diff --git a/cmd/soroban-rpc/internal/ledgerbucketwindow/ledgerbucketwindow.go b/cmd/soroban-rpc/internal/ledgerbucketwindow/ledgerbucketwindow.go index 0d447e716..62fe45789 100644 --- a/cmd/soroban-rpc/internal/ledgerbucketwindow/ledgerbucketwindow.go +++ b/cmd/soroban-rpc/internal/ledgerbucketwindow/ledgerbucketwindow.go @@ -24,10 +24,14 @@ type LedgerBucket[T any] struct { // an incoming event in memory. The value was calculated to align with (roughly) 24 hours window. const DefaultEventLedgerRetentionWindow = 17280 +// DefaultLedgerRetentionWindow represents default number of ledgers we would like to keep for events and transactions. +// The value was calculated to align with (roughly) 24 hours window. +const DefaultLedgerRetentionWindow = 17280 + // NewLedgerBucketWindow creates a new LedgerBucketWindow func NewLedgerBucketWindow[T any](retentionWindow uint32) *LedgerBucketWindow[T] { if retentionWindow == 0 { - retentionWindow = DefaultEventLedgerRetentionWindow + retentionWindow = DefaultLedgerRetentionWindow } return &LedgerBucketWindow[T]{ buckets: make([]LedgerBucket[T], 0, retentionWindow), diff --git a/cmd/soroban-rpc/internal/test/integration.go b/cmd/soroban-rpc/internal/test/integration.go index ea918d13d..3c12d7095 100644 --- a/cmd/soroban-rpc/internal/test/integration.go +++ b/cmd/soroban-rpc/internal/test/integration.go @@ -143,6 +143,7 @@ func (i *Test) launchDaemon(coreBinaryPath string) { config.SQLiteDBPath = path.Join(i.t.TempDir(), "soroban_rpc.sqlite") config.IngestionTimeout = 10 * time.Minute config.EventLedgerRetentionWindow = ledgerbucketwindow.DefaultEventLedgerRetentionWindow + config.LedgerRetentionWindow = ledgerbucketwindow.DefaultLedgerRetentionWindow config.CheckpointFrequency = checkpointFrequency config.MaxHealthyLedgerLatency = time.Second * 10 config.PreflightEnableDebug = true