Skip to content

refactor: formalize strict feature flag (ex relaxed) - #902

Merged
scarmuega merged 3 commits into
mainfrom
dolos-strict
Feb 16, 2026
Merged

refactor: formalize strict feature flag (ex relaxed)#902
scarmuega merged 3 commits into
mainfrom
dolos-strict

Conversation

@scarmuega

@scarmuega scarmuega commented Feb 16, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

Release Notes

  • Refactor

    • Replaced "relaxed" feature flag with "strict" mode for improved arithmetic overflow handling
    • Removed unchecked convenience methods from epoch management API
    • Unified arithmetic operations across modules for consistency
  • Chores

    • Updated dependencies to support enhanced validation framework

@coderabbitai

coderabbitai Bot commented Feb 16, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR renames the feature flag from relaxed to strict and inverts arithmetic overflow handling behavior. Direct arithmetic operations are replaced with add! and sub! macros throughout the codebase (checked with panic in strict mode, saturating otherwise). Unchecked public methods are removed from EpochValue, and strict-mode assertions are conditionally compiled around epoch and state validations.

Changes

Cohort / File(s) Summary
Feature Flag Rename & Macro Behavior Inversion
Cargo.toml, crates/cardano/Cargo.toml, crates/cardano/src/math_macros.rs
Renames relaxed feature to strict in default and explicit feature lists. Inverts overflow behavior: strict mode uses checked_add/checked_sub with panic on overflow; non-strict uses saturating_add/saturating_sub.
Macro-Based Arithmetic Replacement
crates/cardano/src/ewrap/enactment.rs, crates/cardano/src/ewrap/rewards.rs, crates/cardano/src/pots.rs, crates/cardano/src/roll/accounts.rs
Replaces direct arithmetic (+=, -=) with add! and sub! macro calls for controlled overflow handling across stake rewards, pot updates, and account balances.
Conditional Assertions & API Removal
crates/cardano/src/model.rs, crates/cardano/src/ewrap/wrapup.rs, crates/cardano/src/rewards/mod.rs
Removes public unchecked methods (schedule_unchecked, live_mut_unchecked, reset_unchecked, replace_unchecked, transition_unchecked). Adds #[cfg(feature = "strict")] guards around epoch and state validations.
Epoch State Management
crates/cardano/src/roll/epochs.rs
Adds epoch field to EpochStatsUpdate struct; updates epoch state retrieval from live_mut_unchecked() to explicit live_mut(self.epoch) call; revises BlockVisitor to track epoch parameter explicitly.
Test Dependencies
crates/testing/Cargo.toml
Adds workspace dependencies for dolos-fjall and itertools.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 Overflow checked with rigor now,
No unchecked paths allowed, oh wow!
Strict and sane, the macros say,
Safer arithmetic all the way! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing the 'relaxed' feature flag with a 'strict' feature flag across the codebase and formalizing its usage patterns.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dolos-strict

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/cardano/src/roll/accounts.rs (1)

90-107: ⚠️ Potential issue | 🟡 Minor

Pre-existing: ControlledAmountDec::undo ignores is_pointer flag.

The undo path always adds back to utxo_sum (Line 106), but the apply path (Lines 95-99) conditionally subtracts from either utxo_sum_at_pointer_addresses or utxo_sum depending on self.is_pointer. If the original decrement targeted a pointer address, the undo will incorrectly credit utxo_sum instead of utxo_sum_at_pointer_addresses.

This is pre-existing (not introduced by this PR's macro change), but since the lines are in the changed surface, flagging for awareness.

Suggested fix
     fn undo(&self, entity: &mut Option<AccountState>) {
         let entity = entity.as_mut().expect("existing account");
 
         let stake = entity.stake.unwrap_live_mut();
-        stake.utxo_sum = add!(stake.utxo_sum, self.amount);
+        if self.is_pointer {
+            stake.utxo_sum_at_pointer_addresses = add!(stake.utxo_sum_at_pointer_addresses, self.amount);
+        } else {
+            stake.utxo_sum = add!(stake.utxo_sum, self.amount);
+        }
     }
🧹 Nitpick comments (2)
crates/testing/Cargo.toml (1)

10-10: Unrelated additions bundled with the feature-flag rename.

Adding dolos-fjall and itertools dependencies appears unrelated to the relaxedstrict refactor. Consider splitting these into a separate commit or PR for cleaner history if they serve a different purpose.

Also applies to: 19-19

crates/cardano/src/pots.rs (1)

52-75: Consider applying add!/sub! to query methods for full strict-mode coverage.

Methods like stake_deposits(), obligations(), max_supply(), and circulating() still use direct +/-/* operators. If the intent of strict mode is to surface any arithmetic anomaly (e.g., corrupted pot values causing overflow during reads), these would also benefit from the macros. Not urgent since these are read-only, but worth considering for completeness.

@scarmuega
scarmuega merged commit e51c910 into main Feb 16, 2026
9 of 10 checks passed
@scarmuega
scarmuega deleted the dolos-strict branch February 16, 2026 10:46
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.

1 participant