Skip to content

fix(distribute): mount orphaned pause module, unify StorageKey::Pause… - #1356

Open
Ahmad12developer wants to merge 1 commit into
CalloraOrg:mainfrom
Ahmad12developer:fix/issue-1175-mount-distribute-pause
Open

Ahmad12developer wants to merge 1 commit into
CalloraOrg:mainfrom
Ahmad12developer:fix/issue-1175-mount-distribute-pause

Conversation

@Ahmad12developer

@Ahmad12developer Ahmad12developer commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #1175

Problem

contracts/distribute/src/pause.rs was not declared in lib.rs, leaving it orphaned as dead code. Furthermore, it used limits::StorageKey::Paused, while the live contract in lib.rs stored the pause flag under raw Symbol("paused"). These two incompatible storage layouts created a latent desynchronization bug where wiring the module would read/write different on-ledger storage slots.

Changes

  • contracts/distribute/src/limits.rs:
    • Add StorageKey enum with the canonical Paused variant.
  • contracts/distribute/src/pause.rs:
    • Implement pause primitives: is_paused, set_paused, require_not_paused, pause, and resume.
    • Wire reads and writes strictly to canonical StorageKey::Paused.
    • Transparent on-the-fly migration: if StorageKey::Paused is absent and legacy Symbol("paused") exists, migrate the boolean value to StorageKey::Paused and prune the legacy symbol key.
    • Ensure set_paused unconditionally purges any legacy Symbol("paused") key so only one pause key exists.
    • Comprehensive unit tests validating canonical key usage, symbol key pruning, lazy migration, idempotency, and circuit-breaker gating.
  • contracts/distribute/src/lib.rs:
    • Declare pub mod pause; so no undeclared .rs files remain in distribute/src.
    • Re-export pub use limits::StorageKey; and provide CalloraDistribute type alias.
    • Remove dead string constant PAUSED_KEY.
    • Wire init, pause, unpause, get_paused, and distribution guards through the pause module.
    • Expose is_paused view entrypoint alongside get_paused.
    • Make require_admin pub(crate) for module reuse.
  • contracts/distribute/src/test.rs & test_ttl.rs:
    • Add pause_and_unpause_use_single_storage_key_paused ensuring single key invariant.
    • Add legacy_symbol_key_migration_via_client verifying end-to-end lazy migration and event equivalence.
    • Fix type assertion in batch_distribute_total_overflow_returns_typed_error.
    • Fix test auth in ttl_instances_are_isolated.
  • contracts/distribute/tests/auth_snap.rs:
    • Add is_paused check in read_only_views_do_not_require_auth.
    • Add pause_and_unpause_single_key_invariant integration test.

Acceptance Criteria

  • Only one pause storage key exists (StorageKey::Paused)
  • No undeclared .rs files remain in distribute/src
  • Pause tests pass against the chosen key
  • Pause/unpause emit the same events regardless of which key is chosen

Validation

  • cargo test -p callora-distribute pause -> 19 passed; 0 failed
  • cargo test -p callora-distribute -> 87 passed; 0 failed

@drips-wave

drips-wave Bot commented Sep 30, 2026

Copy link
Copy Markdown

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

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

Thanks for the contribution! We reviewed this PR while merging the open queue and couldn't merge it yet. Here's what needs fixing:

  • This distribute refactor now conflicts in about 32 places with six later changes on main.
  • It needs re-implementing on top of the current distribute contract rather than a mechanical conflict fix.

This branch also has merge conflicts with main. Please update it with the latest main, resolve the conflicts, fix the points above, and push — then we can merge it.

@Ahmad12developer
Ahmad12developer force-pushed the fix/issue-1175-mount-distribute-pause branch from 0ba9b75 to 928e102 Compare October 15, 2026 15:07
CalloraOrg#1175)

Problem
-------
distribute/src/pause.rs was not declared in lib.rs, leaving it orphaned
as dead code. Additionally, it referenced CalloraDistribute and used
limits::StorageKey::Paused, while Distribute in lib.rs stored the pause flag
under bare Symbol("paused"). These two incompatible storage keys created a latent
desynchronization bug where wiring the module would read a different key than the
contract writes.

Changes
-------
* contracts/distribute/src/limits.rs:
  - Add StorageKey enum with the canonical Paused variant.

* contracts/distribute/src/pause.rs:
  - Implement pause primitives (is_paused, set_paused, require_not_paused, pause, resume).
  - Wire reads and writes strictly to canonical StorageKey::Paused.
  - Implement transparent on-the-fly migration: if StorageKey::Paused is absent and
    legacy Symbol("paused") exists, migrate the boolean value to StorageKey::Paused
    and prune the legacy symbol key.
  - Ensure set_paused unconditionally purges any legacy Symbol("paused") key.
  - Add unit tests validating canonical key usage, symbol key pruning, lazy migration,
    idempotency, and circuit-breaker gating.

* contracts/distribute/src/lib.rs:
  - Declare pub mod pause; so no undeclared .rs files remain in distribute/src.
  - Re-export pub use limits::StorageKey; and provide CalloraDistribute type alias.
  - Remove dead string constant PAUSED_KEY.
  - Update init, pause, unpause, get_paused, and distribution guards to use
    pause::set_paused, pause::is_paused, and pause::require_not_paused.
  - Expose is_paused view entrypoint alongside get_paused.
  - Make require_admin pub(crate) for internal module reuse.

* contracts/distribute/src/test.rs & test_ttl.rs:
  - Add pause_and_unpause_use_single_storage_key_paused ensuring single key invariant.
  - Add legacy_symbol_key_migration_via_client verifying end-to-end lazy migration and event equivalence.
  - Fix type assertion in batch_distribute_total_overflow_returns_typed_error.
  - Fix test auth in ttl_instances_are_isolated.

* contracts/distribute/tests/auth_snap.rs:
  - Add is_paused check in read_only_views_do_not_require_auth.
  - Add pause_and_unpause_single_key_invariant integration test.

Acceptance Criteria Addressed
-----------------------------
[x] Only one pause storage key exists (StorageKey::Paused)
[x] No undeclared .rs files remain in distribute/src
[x] Pause tests pass against the chosen key
[x] Pause/unpause emit the same events regardless of which key is chosen

Validation: cargo test -p callora-distribute pause (19/19 passed)
Full suite: cargo test -p callora-distribute (87/87 passed)

Closes CalloraOrg#1175
@Ahmad12developer
Ahmad12developer force-pushed the fix/issue-1175-mount-distribute-pause branch from 928e102 to 4cd6531 Compare October 16, 2026 20:02
@Ahmad12developer

Copy link
Copy Markdown
Contributor Author

@greatest0fallt1me Thank you for the feedback!

I have completely re-implemented the distribute pause refactor on top of the latest main (2730f2d4):

  • Conflict Resolution & Native Re-implementation: Cleanly rebased and integrated on top of the latest distribute contract changes (including require_admin_auth on init from feat(distribute): require admin auth on init #1355).
  • Mounted Pause Module: Fully mounted contracts/distribute/src/pause.rs into callora-distribute.
  • Unified StorageKey::Paused: Single canonical enum key for pause/unpause state across the module and contract entrypoints, complete with legacy Symbol-key migration and isolation tests.
  • Verification & Tests:
    • All 87 tests in callora-distribute passing cleanly (72 unit tests + 15 auth snap integration tests).
    • Contract WASM compiles cleanly (33.6 KiB, well within the 102.4 KiB budget).
    • Distribute event shape check conforms 100% with EVENT_TOPICS.md (15/15 constructors snapshot-tested and documented).
    • Formatted with rustfmt and passing Clippy with zero warnings.

Ready for review! 🚀

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.

Delete or mount the orphaned distribute pause module

2 participants