Skip to content

Implement lazy storage initialisation to reduce per-invoice rent cost #433

Description

@Kingsman-99

Description

Every invoice currently initialises all storage keys (payment map, contributor count, etc.) at creation, incurring rent for entries that may never be used. This issue converts those entries to lazily-initialised storage using env.storage().has() checks before reads, deferring rent until first write.

Technical Context

Audit all create_invoice storage writes in lib.rs and identify entries that are only populated after the first pay_invoice call (e.g. payment_map_key, contributor_count_key, payer_window_key). Replace unconditional writes with lazy get_or_default helpers. Update read paths to handle the absent case. Measure storage slot reduction using a test that compares slot counts before and after.

Acceptance Criteria

  • create_invoice writes only the minimum required storage entries (invoice struct, status key)
  • All lazily-initialised entries are correctly handled when absent (return default, not panic)
  • A test asserts the number of storage entries written per create_invoice is ≤ N (document N)
  • All existing payment and release flows continue to pass without regression
  • cargo test --test integration runs without error on the refactored storage model
  • All CI checks (cargo test, cargo clippy, cargo fmt) pass and the branch has no merge conflicts

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programcomplexity: highComplex feature requiring deep knowledge - 200 ptsstorageStorage layout and TTL optimisation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions