Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soroban-rpc: Add common retention window for events and transactions. #1169

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading