Skip to content

fix(#383,#386): reduce cancel_release ledger footprint and add checked ops in cancel_refund - #422

Merged
godamongstmen897 merged 1 commit into
Goldii-locks:mainfrom
Sarietgold:fix/issues-383-386-admin-override-storage-checked-ops
Aug 29, 2026
Merged

fix(#383,#386): reduce cancel_release ledger footprint and add checked ops in cancel_refund#422
godamongstmen897 merged 1 commit into
Goldii-locks:mainfrom
Sarietgold:fix/issues-383-386-admin-override-storage-checked-ops

Conversation

@Sarietgold

@Sarietgold Sarietgold commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR resolves two issues in a single branch:


Issue #383 — Reduce ledger storage footprint of admin_override_cancel_release

Change: Removed the redundant store_milestone_released(&env, index) temporary-storage write from the milestone loop inside admin_override_cancel_release.

Rationale: The MilestoneReleased(index) temporary key is a hot-read optimisation designed specifically for the normal approve_milestone code path. In the admin cancel-override flow it is redundant because the persistent Milestone(index) entry already carries status = Released. Removing it reduces distinct ledger storage keys written per invocation by N.


Issue #386 — Replace unchecked arithmetic in admin_override_cancel_refund

Change: Added explicit non-negativity guard block around checked_sub on milestone.amount and milestone.released_amount.

Rationale: Prevents any malformed entry with a negative field value (e.g. i128::MIN) from producing a positive remaining that slips through filters and inflates refund totals.


Tests (admin_override_cancel_tests.rs) — 14 new tests


Closes #383
Closes #386
Closes #384
Closes #388

…footprint and add checked ops in cancel_refund

Issue Goldii-locks#383 - admin_override_cancel_release storage footprint
- Remove the redundant store_milestone_released() temporary-storage write
  from the milestone loop inside admin_override_cancel_release.
- The temporary MilestoneReleased(index) flag is a hot-read optimisation
  for the approve_milestone code path; it is not needed in the admin
  cancel-override path because the persistent Milestone entry already
  carries status=Released.
- This reduces distinct ledger keys written per call by N (one per
  updated milestone), lowering both compute cost and storage rent burden.

Issue Goldii-locks#386 - admin_override_cancel_refund checked arithmetic
- Add explicit non-negativity guards on milestone.amount and
  milestone.released_amount before the checked_sub call.
- A malformed on-chain entry with a negative field (e.g. i128::MIN)
  previously could pass through the remaining > 0 filter with a
  nonsensical value; now it is caught early and returns
  Error::InvalidAmount instead of causing a wrap or silent corruption.
- All arithmetic (checked_sub, checked_add) already existed; the guard
  block tightens the contract so every exit path is provably safe.

Tests (admin_override_cancel_tests.rs)
- Happy-path release: verifies tokens transferred, milestones Released,
  CancelLock cleared, and MilestoneReleased temporary flag absent (Goldii-locks#383).
- Skip-terminal release: milestones already Released are skipped and no
  temporary flag is written for the remaining ones (Goldii-locks#383).
- Happy-path refund: verifies tokens transferred, milestones Refunded,
  CancelLock cleared, and YieldAccrued reset (Goldii-locks#386).
- Skip-terminal refund: terminal milestones excluded from total (Goldii-locks#386).
- All-terminal refund: returns Error::InvalidAmount, not panic (Goldii-locks#386).
- Unauthorized / InvalidStatus guards verified for both functions.
- Minimum-amount (1 stroop) and multi-milestone sum tests (Goldii-locks#386).
@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@Sarietgold 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

@godamongstmen897
godamongstmen897 merged commit a41aa5d into Goldii-locks:main Aug 29, 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

2 participants