Skip to content

feat: document default API overlap and ordering#779

Merged
Baskarayelu merged 4 commits intoQuickLendX:mainfrom
Marvy247:feature/default-handler-overlap
Apr 1, 2026
Merged

feat: document default API overlap and ordering#779
Baskarayelu merged 4 commits intoQuickLendX:mainfrom
Marvy247:feature/default-handler-overlap

Conversation

@Marvy247
Copy link
Copy Markdown
Contributor

Summary

Clarifies when each default API applies, closes the grace-period bypass in handle_default, and proves no double-accounting when both entry points are reachable.

Root cause

handle_default called do_handle_default directly, skipping the grace-period time check that mark_invoice_defaulted enforces. An admin could use it to default a funded invoice before its grace window elapsed.

Changes

  • lib.rshandle_default now calls do_mark_invoice_defaulted(&env, &invoice_id, None) instead of do_handle_default directly. Both entry points now share the same time guard and converge on the same internal helper, so state is written exactly once.

  • test_default.rs — 5 new overlap/ordering tests:

    • test_handle_default_respects_grace_period — grace-period bypass is closed
    • test_handle_default_succeeds_after_grace_period — succeeds once grace elapsed
    • test_no_double_accounting_handle_default_then_mark_defaulted
    • test_no_double_accounting_mark_defaulted_then_handle_default
    • test_both_paths_produce_identical_state — identical final state from both paths
  • docs/contracts/defaults.md — Removed duplicate content, added API ordering table, no-double-accounting guarantee, and ordering invariant diagram.

Security notes

  • No new attack surface; this is a tightening of an existing admin-only operation.
  • The grace-period bypass is now structurally impossible: both public entry points go through do_mark_invoice_defaulted.

Closes #732

- handle_default now routes through do_mark_invoice_defaulted (grace=None)
  instead of do_handle_default directly, closing the grace-period bypass
- Both entry points converge on the same internal helper so state is
  written exactly once regardless of which path is taken first
- Add 5 overlap/ordering tests in test_default.rs:
    test_handle_default_respects_grace_period
    test_handle_default_succeeds_after_grace_period
    test_no_double_accounting_handle_default_then_mark_defaulted
    test_no_double_accounting_mark_defaulted_then_handle_default
    test_both_paths_produce_identical_state
- Rewrite docs/contracts/defaults.md: remove duplicate content, add
  API ordering table, no-double-accounting guarantee, and ordering
  invariant diagram

Closes QuickLendX#732
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 30, 2026

@Marvy247 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Baskarayelu Baskarayelu merged commit b2c8cef into QuickLendX:main Apr 1, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

handle_default versus mark_invoice_defaulted ordering and overlap

2 participants