Implement on-chain notification expiration (Closes #128)#157
Open
giftexceed wants to merge 2 commits into
Open
Implement on-chain notification expiration (Closes #128)#157giftexceed wants to merge 2 commits into
giftexceed wants to merge 2 commits into
Conversation
Adds configurable-duration expiration for notifications stored on-chain: - schedule_notification(id, creator, ttl_seconds): stores a notification with created_at + expires_at; rejects zero/overflowing durations and duplicate ids; emits NotificationScheduled. - is_notification_expired / get_notification: query a notification's validity and details (inclusive expiry boundary). - expire_notification(id): permissionless finalization of an elapsed notification — reaps storage and emits NotificationExpired; rejects a not-yet-elapsed one. - cancel_notification now treats an expired tracked notification as invalid (NotificationExpired) and reaps a valid one on cancellation, while still accepting untracked ids for backward compatibility. New errors: NotificationExpired, InvalidExpirationDuration, NotificationNotExpired. New type ScheduledNotification. New events NotificationScheduled and NotificationExpired (category Notification), following the existing trailing category/priority topic convention. Adds 15 contract tests covering scheduling, the expiry boundary, event shapes, expired-notification invalidity, duration validation, pause gating, and cancellation. This change also repairs the contract crate, which did not compile on main: prior merges around the notification-priority-levels work left duplicated enum definitions, struct fields, imports, and test functions in events.rs, autoshare_logic.rs and notification_test.rs. These are resolved to the coherent Low/Medium/High/Critical priority scheme so the crate builds and the full suite (119 tests) passes.
Collaborator
|
please fix CI and resolve conflicts |
…xpiration-128 # Conflicts: # contract/contracts/hello-world/src/autoshare_logic.rs # contract/contracts/hello-world/src/tests/notification_test.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements configurable-duration notification expiration for notifications stored on-chain (issue #128).
Feature
schedule_notification(id, creator, ttl_seconds)— stores aScheduledNotification { id, creator, created_at, expires_at }whereexpires_at = created_at + ttl_seconds. Rejects a zero or overflowing duration (InvalidExpirationDuration) and a duplicate id (AlreadyExists); emitsNotificationScheduled.get_notification(id)/is_notification_expired(id)— read a notification's details / validity. The expiry boundary is inclusive (expired oncenow >= expires_at).expire_notification(id)— permissionless finalization of an elapsed notification (e.g. by an off-chain keeper): reaps storage and emitsNotificationExpired. A not-yet-elapsed notification is rejected withNotificationNotExpired.cancel_notification(id, caller)— now treats an expired tracked notification as invalid (NotificationExpired) and reaps a valid one on cancellation, while still accepting untracked ids for backward compatibility.New
ScheduledNotificationtype; new errorsNotificationExpired,InvalidExpirationDuration,NotificationNotExpired; new eventsNotificationScheduled/NotificationExpired(categoryNotification), following the existing trailing category/priority topic convention.Tests
15 new contract tests in
tests/expiration_test.rscover: storage of created/expiry timestamps, the expiry boundary (before / at / after),NotificationScheduledandNotificationExpiredevent shapes (topics + data), expired notifications being uncancellable, finalized expiry reaping storage, duration validation, duplicate/unknown handling, pause gating, and cancellation (valid, expired, untracked, paused).Heads-up: this PR also repairs a broken
mainThe contract crate did not compile on
main. Prior merges around the notification-priority-levels work were resolved by keeping both sides of each conflict, leaving duplicated enum definitions, struct fields, imports, and test functions inevents.rs,autoshare_logic.rs, andnotification_test.rs(e.g. twoNotificationPriorityenums; 18priorityfields where 9 were expected; duplicatedpriority_oftest helpers and malformedassert_eq!calls).Making #128's tests pass required restoring a compiling crate. I resolved the duplications to the coherent
Low/Medium/High/Criticalpriority scheme (recovered from the last clean commit,33c5764), re-added theScheduledNotificationCancelledevent/handler cleanly, and alignedAutoShareDetails.priorityto the same scheme.Verification
Closes #128