-
Notifications
You must be signed in to change notification settings - Fork 15
feat: implement contract pausability (circuit breaker) #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Bosun-Josh121
merged 6 commits into
LightForgeHub:main
from
KevinMB0220:feat/contract-pausability
Feb 26, 2026
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3689703
style: apply cargo fmt formatting
KevinMB0220 7c73ace
feat: add IsPaused storage key and ContractPaused error variant
KevinMB0220 6ffc8ca
feat: add contract_paused event emitter
KevinMB0220 c9513fb
feat: implement pause/unpause admin functions and pause guards
KevinMB0220 8cb6616
test: add circuit breaker pausability tests
KevinMB0220 d69571d
merge: resolve conflicts between pausability and expert-rate features
KevinMB0220 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,4 +11,5 @@ pub enum VaultError { | |
| BookingNotPending = 5, | ||
| InvalidAmount = 6, | ||
| ReclaimTooEarly = 7, | ||
| } | ||
| ContractPaused = 8, | ||
| } | ||
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pause/unpauseshould guard against redundant state transitions.Calling
pause()when the contract is already paused silently succeeds and emits a spuriouspaused=trueevent;unpause()when already unpaused does the same. This creates misleading audit trails for indexers and monitoring tools and gives callers no signal that the call was a no-op.Consider returning an error (or at minimum skipping the event) when the requested state matches the current state:
🛡️ Proposed fix for idempotency guards
pub fn pause(env: &Env) -> Result<(), VaultError> { let admin = storage::get_admin(env).ok_or(VaultError::NotInitialized)?; admin.require_auth(); + if storage::is_paused(env) { + return Err(VaultError::ContractPaused); // already paused + } storage::set_paused(env, true); events::contract_paused(env, true); Ok(()) } pub fn unpause(env: &Env) -> Result<(), VaultError> { let admin = storage::get_admin(env).ok_or(VaultError::NotInitialized)?; admin.require_auth(); + if !storage::is_paused(env) { + return Err(VaultError::NotInitialized); // reuse or add a dedicated NotPaused variant + } storage::set_paused(env, false); events::contract_paused(env, false); Ok(()) }Alternatively, add a dedicated
VaultError::NotPaused = 9variant for clarity instead of reusingNotInitialized.🤖 Prompt for AI Agents