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

Cleanup old retention window and upgrade history-retention-window #277

Merged
merged 2 commits into from
Aug 30, 2024
Merged
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
9 changes: 0 additions & 9 deletions cmd/soroban-rpc/internal/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type Config struct {
CoreRequestTimeout time.Duration
DefaultEventsLimit uint
DefaultTransactionsLimit uint
EventLedgerRetentionWindow uint32
FriendbotURL string
HistoryArchiveURLs []string
HistoryArchiveUserAgent string
Expand All @@ -42,7 +41,6 @@ type Config struct {
PreflightEnableDebug bool
SQLiteDBPath string
HistoryRetentionWindow uint32
TransactionLedgerRetentionWindow uint32
SorobanFeeStatsLedgerRetentionWindow uint32
ClassicFeeStatsLedgerRetentionWindow uint32
RequestBacklogGlobalQueueLimit uint
Expand Down Expand Up @@ -115,13 +113,6 @@ func (cfg *Config) SetValues(lookupEnv func(string) (string, bool)) error {
}
}

// Set to the maximum as a compromise until we deprecate the transaction/event flags
cfg.HistoryRetentionWindow = max(
cfg.HistoryRetentionWindow,
cfg.EventLedgerRetentionWindow,
cfg.TransactionLedgerRetentionWindow,
)

return nil
}

Expand Down
28 changes: 3 additions & 25 deletions cmd/soroban-rpc/internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,32 +218,10 @@ func (cfg *Config) options() Options {
Name: "history-retention-window",
Usage: fmt.Sprintf(
"configures history retention window for transactions and events, expressed in number of ledgers,"+
" the default value is %d which corresponds to about 24 hours of history",
OneDayOfLedgers),
" the default value is %d which corresponds to about 7 days of history",
SevenDayOfLedgers),
ConfigKey: &cfg.HistoryRetentionWindow,
DefaultValue: uint32(OneDayOfLedgers),
Validate: positive,
},
// TODO: remove
{
Name: "event-retention-window",
Usage: fmt.Sprintf(
"(Deprecated, overidden by history-retention-window) configures the event retention window expressed in number of ledgers,"+
" the default value is %d which corresponds to about 24 hours of history",
OneDayOfLedgers),
ConfigKey: &cfg.EventLedgerRetentionWindow,
DefaultValue: uint32(OneDayOfLedgers),
Validate: positive,
},
// TODO: remove
{
Name: "transaction-retention-window",
Usage: fmt.Sprintf(
"(Deprecated, overidden by history-retention-window) configures the transaction retention window expressed in number of ledgers,"+
" the default value is %d which corresponds to about 24 hours of history",
OneDayOfLedgers),
ConfigKey: &cfg.TransactionLedgerRetentionWindow,
DefaultValue: uint32(OneDayOfLedgers),
DefaultValue: uint32(SevenDayOfLedgers),
Validate: positive,
},
{
Expand Down
6 changes: 3 additions & 3 deletions cmd/soroban-rpc/internal/config/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func TestBasicTomlWriting(t *testing.T) {
// comment when outputting multi-line comments, which go-toml does *not* do
// by default.
assert.Contains(t, out,
`# (Deprecated, overidden by history-retention-window) configures the event
# retention window expressed in number of ledgers, the default value is 17280
# which corresponds to about 24 hours of history`)
`# configures history retention window for transactions and events, expressed in
# number of ledgers, the default value is 120960 which corresponds to about 7
# days of history`)
}

func TestRoundTrip(t *testing.T) {
Expand Down
54 changes: 27 additions & 27 deletions cmd/soroban-rpc/internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ type ReadWriterMetrics struct {
}

type readWriter struct {
log *log.Entry
db *DB
maxBatchSize int
ledgerRetentionWindow uint32
passphrase string
log *log.Entry
db *DB
maxBatchSize int
historyRetentionWindow uint32
passphrase string

metrics ReadWriterMetrics
}
Expand All @@ -181,7 +181,7 @@ func NewReadWriter(
db *DB,
daemon interfaces.Daemon,
maxBatchSize int,
ledgerRetentionWindow uint32,
historyRetentionWindow uint32,
networkPassphrase string,
) ReadWriter {
// a metric for measuring latency of transaction store operations
Expand All @@ -203,11 +203,11 @@ func NewReadWriter(
daemon.MetricsRegistry().MustRegister(txDurationMetric, txCountMetric)

return &readWriter{
log: log,
db: db,
maxBatchSize: maxBatchSize,
ledgerRetentionWindow: ledgerRetentionWindow,
passphrase: networkPassphrase,
log: log,
db: db,
maxBatchSize: maxBatchSize,
historyRetentionWindow: historyRetentionWindow,
passphrase: networkPassphrase,
metrics: ReadWriterMetrics{
TxIngestDuration: txDurationMetric.With(prometheus.Labels{"operation": "ingest"}),
TxCount: txCountMetric,
Expand All @@ -234,10 +234,10 @@ func (rw *readWriter) NewTx(ctx context.Context) (WriteTx, error) {
_, err := db.ExecRaw(ctx, "PRAGMA wal_checkpoint(TRUNCATE)")
return err
},
tx: txSession,
stmtCache: stmtCache,
ledgerRetentionWindow: rw.ledgerRetentionWindow,
ledgerWriter: ledgerWriter{stmtCache: stmtCache},
tx: txSession,
stmtCache: stmtCache,
historyRetentionWindow: rw.historyRetentionWindow,
ledgerWriter: ledgerWriter{stmtCache: stmtCache},
ledgerEntryWriter: ledgerEntryWriter{
stmtCache: stmtCache,
buffer: xdr.NewEncodingBuffer(),
Expand Down Expand Up @@ -266,15 +266,15 @@ func (rw *readWriter) NewTx(ctx context.Context) (WriteTx, error) {
}

type writeTx struct {
globalCache *dbCache
postCommit func() error
tx db.SessionInterface
stmtCache *sq.StmtCache
ledgerEntryWriter ledgerEntryWriter
ledgerWriter ledgerWriter
txWriter transactionHandler
eventWriter eventHandler
ledgerRetentionWindow uint32
globalCache *dbCache
postCommit func() error
tx db.SessionInterface
stmtCache *sq.StmtCache
ledgerEntryWriter ledgerEntryWriter
ledgerWriter ledgerWriter
txWriter transactionHandler
eventWriter eventHandler
historyRetentionWindow uint32
}

func (w writeTx) LedgerEntryWriter() LedgerEntryWriter {
Expand All @@ -298,14 +298,14 @@ func (w writeTx) Commit(ledgerSeq uint32) error {
return err
}

if err := w.ledgerWriter.trimLedgers(ledgerSeq, w.ledgerRetentionWindow); err != nil {
if err := w.ledgerWriter.trimLedgers(ledgerSeq, w.historyRetentionWindow); err != nil {
return err
}
if err := w.txWriter.trimTransactions(ledgerSeq, w.ledgerRetentionWindow); err != nil {
if err := w.txWriter.trimTransactions(ledgerSeq, w.historyRetentionWindow); err != nil {
return err
}

if err := w.eventWriter.trimEvents(ledgerSeq, w.ledgerRetentionWindow); err != nil {
if err := w.eventWriter.trimEvents(ledgerSeq, w.historyRetentionWindow); err != nil {
return err
}

Expand Down
Loading