Skip to content

Commit

Permalink
Add common retention window for events and transactions.
Browse files Browse the repository at this point in the history
  • Loading branch information
psheth9 committed Jan 16, 2024
1 parent 7ee51fa commit ea0412f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/soroban-rpc/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Config struct {
PreflightEnableDebug bool
SQLiteDBPath string
TransactionLedgerRetentionWindow uint32
LedgerRetentionWindow uint32
RequestBacklogGlobalQueueLimit uint
RequestBacklogGetHealthQueueLimit uint
RequestBacklogGetEventsQueueLimit uint
Expand Down
10 changes: 10 additions & 0 deletions cmd/soroban-rpc/internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-rpc/internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions cmd/soroban-rpc/internal/test/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ea0412f

Please sign in to comment.