Skip to content

getFeeStats: rebuild fee windows on restart #888

Description

@karthikiyer56

What

How — raw bytes through the view path (changed from the earlier plan)

# pseudocode; real types are query.ReadView / xdr.LedgerCloseMetaView
view = registry.NewReadView()          # frozen range + handle set; defer view.Release()
latest = lastCommittedLedger           # the hot loop resumes at latest + 1
start  = max(latest - window + 1, view.OldestLedger())
if start > latest:
    return                             # fresh start / short history: no-op, not an error

for entry in view.ScanLedgers(start, latest):
    lcm   = LedgerCloseMetaView(entry.Bytes)
    parts = ingest.ExtractLedgerTxParts(lcm)   # the one walk
    fees  = ingest.FeesFromTxParts(parts)      # fees only; events never computed
    # seq + close time read off the view header; append to BOTH windows,
    # each trimming to its own retention
    windows.AppendLedgerFees(seq, closeTime, fees)
  • entry.Bytes is borrowed (it aliases the reader's scratch buffer, overwritten on the next step) — fine here: fees are folded within the loop body and only plain uint64 slices are retained.
  • The replay range spanning a chunk boundary is the common case, not an edge case (any restart within the first window ledgers of a chunk). ScanLedgers does the split and per-chunk clip; ≤1000 ledgers means at most 2 chunks, so routing failures surface before any ledger is emitted.

Ordering — the double-count hazard

Scope notes (carried over, still true)

  • Clamp to what exists: on a fresh start OldestLedger() can exceed latest by one, so a short history must be a no-op, not an error.
  • No config-time window-vs-retention guard needed (v1 has one): windows are capped at 1,000 ledgers (limits.MaxFeeStatsRetentionWindow) and v2's smallest retention is one chunk = 10,000 ledgers, so the guard can never fire.

Dependency change

Sizing

  • ~80–120 lines in 1 file, ~6 tests (unchanged estimate).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions