Skip to content

Add invoice payment event replay for indexer recovery #232

Description

@Kingsman-99

Label: complexity: high
Points: 200

Description

If an off-chain indexer misses events (downtime, RPC issues), there's no on-chain way to "replay" historical state for a given invoice beyond manually re-fetching the audit log, which doesn't carry full payment amounts/structured data.

Technical Context

Involves lib.rsreplay_invoice_events(env, invoice_id), re-emitting invoice_created, each historical payment_received (from invoice.payments), and the current status event (invoice_released/invoice_refunded if applicable) in sequence, allowing an indexer to resync by calling this once and rebuilding state from the replayed event stream.

Acceptance Criteria

  • Re-emits one payment_received-equivalent event per entry in invoice.payments, in original order
  • Re-emits the terminal status event matching current invoice.status if not still Pending
  • Replayed events are clearly tagged (e.g. a replay: true topic marker) so indexers can distinguish them from live events and avoid double-counting
  • Pure read+emit — no state mutation, callable by anyone
  • Test verifies the exact sequence and count of replayed events matches the invoice's actual payment history
  • All existing cargo tests pass
  • cargo clippy passes with zero warnings

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity: highComplex feature requiring deep knowledge - 200 pts

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions