diff --git a/cmd/soroban-rpc/internal/daemon/daemon.go b/cmd/soroban-rpc/internal/daemon/daemon.go index 9707b309..44cf75fa 100644 --- a/cmd/soroban-rpc/internal/daemon/daemon.go +++ b/cmd/soroban-rpc/internal/daemon/daemon.go @@ -361,10 +361,12 @@ func (d *Daemon) mustInitializeStorage(cfg *config.Config) *feewindow.FeeWindows // means the final range is only the fee stat analysis range. // feeStatsRange, err := db.GetMigrationLedgerRange(readTxMetaCtx, d.db, maxFeeRetentionWindow) + dataMigrations.Append(feeWindows.AsMigration(feeStatsRange)) if err != nil { d.logger.WithError(err).Fatal("could not get ledger range for fee stats") } - ledgerSeqRange := dataMigrations.ApplicableRange().Merge(feeStatsRange) + + ledgerSeqRange := dataMigrations.ApplicableRange() // // 5. Apply migration for events & transactions, and perform fee stat analysis. @@ -389,12 +391,6 @@ func (d *Daemon) mustInitializeStorage(cfg *config.Config) *feewindow.FeeWindows Debug("Still initializing in-memory store") } - if feeStatsRange.IsLedgerIncluded(currentSeq) { // skip irrelevant ledgers - if err = feeWindows.IngestFees(txMeta); err != nil { - d.logger.WithError(err).Fatal("could not initialize fee stats") - } - } - if err := dataMigrations.Apply(readTxMetaCtx, txMeta); err != nil { d.logger.WithError(err).Fatal("could not apply migration for ledger ", currentSeq) } diff --git a/cmd/soroban-rpc/internal/feewindow/feewindow.go b/cmd/soroban-rpc/internal/feewindow/feewindow.go index 5b8cc50a..d914558a 100644 --- a/cmd/soroban-rpc/internal/feewindow/feewindow.go +++ b/cmd/soroban-rpc/internal/feewindow/feewindow.go @@ -2,6 +2,7 @@ package feewindow import ( + "context" "errors" "io" "slices" @@ -194,3 +195,34 @@ func (fw *FeeWindows) IngestFees(meta xdr.LedgerCloseMeta) error { } return nil } + +func (fw *FeeWindows) AsMigration(seqRange db.LedgerSeqRange) db.Migration { + return &feeWindowMigration{ + firstLedger: seqRange.First, + lastLedger: seqRange.Last, + windows: fw, + } +} + +type feeWindowMigration struct { + firstLedger uint32 + lastLedger uint32 + windows *FeeWindows +} + +func (fw *feeWindowMigration) ApplicableRange() db.LedgerSeqRange { + return db.LedgerSeqRange{ + First: fw.firstLedger, + Last: fw.lastLedger, + } +} + +func (fw *feeWindowMigration) Apply(_ context.Context, meta xdr.LedgerCloseMeta) error { + return fw.windows.IngestFees(meta) +} + +func (fw *feeWindowMigration) Commit(_ context.Context) error { + return nil // no-op +} + +var _ db.Migration = &feeWindowMigration{}