Skip to content

feat(ttl): state-specific TTL thresholds for escrow contracts - #1384

Open
ogbemercyada-sketch wants to merge 2 commits into
Talenttrust:mainfrom
ogbemercyada-sketch:feat/state-specific-ttl-1348
Open

feat(ttl): state-specific TTL thresholds for escrow contracts#1384
ogbemercyada-sketch wants to merge 2 commits into
Talenttrust:mainfrom
ogbemercyada-sketch:feat/state-specific-ttl-1348

Conversation

@ogbemercyada-sketch

Copy link
Copy Markdown
Contributor

Active obligations can silently disappear when persistent entries are not extended as the lifecycle progresses. This implements a tiered TTL policy that matches contract lifetime to actual lifecycle state:

Active (Created/PartiallyFunded/Funded): 60 d, bump threshold 15 d
Disputed: 75 d, bump threshold 20 d
Closed (Completed/Cancelled/Refunded): 30 d, bump threshold 7 d

Changes:

  • ttl.rs: add ACTIVE/DISPUTED/CLOSED _CONTRACT_TTL_LEDGERS and _BUMP_THRESHOLD constants; add ttl_for_status(status)->(threshold, extend_to), extend_contract_ttl_for_status, extend_milestone_ttl_for_status, extend_contract_and_milestones_ttl_for_status helpers; update module doc.
  • create_contract.rs: use extend_contract_and_milestones_ttl_for_status with ContractStatus::Created so new records receive 60-day windows.
  • deposit.rs: use state-aware TTL bump after Funded/PartiallyFunded transition instead of flat extend_contract_ttl.
  • lib.rs: replace flat extend_contract_ttl calls at cancel_contract, release_milestone (single+batch), raise_dispute, resolve_dispute, and refund_unreleased_milestones with state-aware counterparts.
  • test/ttl_lifecycle.rs: full edge-case coverage for new_record, active_record, disputed_record, near_expiry, expired_record, TTL constant ordering, and ttl_for_status correctness.
  • test/mod.rs: register ttl_lifecycle module.

Security note: TTL is bumped only on meaningful writes (state transitions, deposits, releases, refunds, cancellations, dispute operations). Read-only entrypoints do not bump TTL, preventing indefinite TTL extension via reads.

Closes #1348

Active obligations can silently disappear when persistent entries are not
extended as the lifecycle progresses. This implements a tiered TTL policy
that matches contract lifetime to actual lifecycle state:

  Active (Created/PartiallyFunded/Funded): 60 d, bump threshold 15 d
  Disputed:                                75 d, bump threshold 20 d
  Closed (Completed/Cancelled/Refunded):   30 d, bump threshold  7 d

Changes:
- ttl.rs: add ACTIVE/DISPUTED/CLOSED _CONTRACT_TTL_LEDGERS and
  _BUMP_THRESHOLD constants; add ttl_for_status(status)->(threshold,
  extend_to), extend_contract_ttl_for_status, extend_milestone_ttl_for_status,
  extend_contract_and_milestones_ttl_for_status helpers; update module doc.
- create_contract.rs: use extend_contract_and_milestones_ttl_for_status
  with ContractStatus::Created so new records receive 60-day windows.
- deposit.rs: use state-aware TTL bump after Funded/PartiallyFunded
  transition instead of flat extend_contract_ttl.
- lib.rs: replace flat extend_contract_ttl calls at cancel_contract,
  release_milestone (single+batch), raise_dispute, resolve_dispute, and
  refund_unreleased_milestones with state-aware counterparts.
- test/ttl_lifecycle.rs: full edge-case coverage for new_record,
  active_record, disputed_record, near_expiry, expired_record, TTL
  constant ordering, and ttl_for_status correctness.
- test/mod.rs: register ttl_lifecycle module.

Security note: TTL is bumped only on meaningful writes (state transitions,
deposits, releases, refunds, cancellations, dispute operations). Read-only
entrypoints do not bump TTL, preventing indefinite TTL extension via reads.

Closes Talenttrust#1348
@drips-wave

drips-wave Bot commented Sep 1, 2026

Copy link
Copy Markdown

@ogbemercyada-sketch 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

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.

Bump TTL for active milestone and dispute records

1 participant