Skip to content

feat: implement granular pause per operation#338

Closed
anumukul wants to merge 178 commits intoJagadeeshftw:masterfrom
anumukul:feat/granular-pause-per-operation
Closed

feat: implement granular pause per operation#338
anumukul wants to merge 178 commits intoJagadeeshftw:masterfrom
anumukul:feat/granular-pause-per-operation

Conversation

@anumukul
Copy link

@anumukul anumukul commented Jan 30, 2026

Granular Per-Operation Pause

Closes #312

What this does

Adds the ability to pause individual operations instead of the entire contract. Previously, calling pause() would block everything - locks, releases, and refunds all at once. Now you can selectively pause just what you need.

For example, if there's a bug in the lock logic, you can pause only locks while still allowing contributors to receive their payouts.

Changes

Bounty Escrow:

  • New PauseConfig struct replaces the old boolean pause flag
  • Added set_pause_lock(), set_pause_release(), set_pause_refund()
  • Each operation now checks its own pause flag
  • New error codes: LockPaused (21), ReleasePaused (22), RefundPaused (23)

Program Escrow:

  • Same pattern with lock_paused, payout_paused, schedule_paused
  • Error codes: LockPaused (4), PayoutPaused (5), SchedulePaused (6)

Backward compatibility

The old pause() and unpause() functions still work - they just set/clear all three flags at once. is_paused() returns true only when everything is paused.

Test coverage

Scenario Bounty Program
Only lock paused
Only release/payout paused
Only refund/schedule paused
Multiple operations paused
Global pause still works
Partial unpause after global

53 tests total, all passing.

How to test

cd contracts/bounty_escrow/contracts/escrow && cargo test --lib pause_tests
cd contracts/program-escrow && cargo test --lib pause_tests

Henry3029 and others added 30 commits January 23, 2026 10:07
- Add comprehensive event schema documentation (EVENT_SCHEMA.md)
  * Define event structures for all contracts
  * Document event versioning strategy
  * Provide indexing strategies and retention policies
  * Include monitoring hooks and filtering examples

- Implement event indexing infrastructure (internal/events/indexing.go)
  * EventIndexer for efficient event querying
  * Support for time-series, entity-based, and composite queries
  * Event aggregation capabilities
  * Event statistics and unindexed event tracking

- Implement event monitoring system (internal/events/monitoring.go)
  * EventMonitor for real-time event listening
  * AnomalyDetector for detecting unusual patterns
  * Alert generation and handling
  * EventFilter and EventAggregator utilities

- Implement advanced event filtering (internal/events/filtering.go)
  * FilterBuilder with fluent API
  * AdvancedEventFilter with operators (eq, ne, gt, gte, lt, lte, contains, in)
  * EventFilterStatistics for analytics
  * EventFilterExporter for JSON/CSV export

- Create database migration (migrations/000025_contract_events_indexing.up.sql)
  * contract_events table with comprehensive indexing
  * event_alerts table for monitoring alerts
  * event_metrics table for performance tracking
  * event_replay_log table for event replay capability
  * Materialized views for daily statistics
  * Database functions for cleanup and queries

- Add event indexing strategy guide (EVENT_INDEXING_STRATEGY.md)
  * Architecture overview and data flow
  * Database schema documentation
  * Indexing strategies (time-series, entity, composite, JSONB, materialized views)
  * Query patterns and monitoring hooks
  * Performance optimization techniques
  * Event retention policy

- Add event versioning documentation (contracts/EVENT_VERSIONING.md)
  * Semantic versioning scheme (MAJOR.MINOR.PATCH)
  * Version evolution rules and migration strategies
  * Deprecation timeline and best practices
  * Indexer compatibility patterns
  * Version roadmap

- Add implementation guide (EVENT_INDEXING_README.md)
  * Component overview and architecture
  * Usage examples for all major features
  * API integration patterns
  * Monitoring dashboard metrics
  * Performance tuning guide
  * Troubleshooting section

Key Features:
- Efficient off-chain event indexing with multiple strategies
- Real-time event monitoring and anomaly detection
- Comprehensive event schema with backward compatibility
- Event versioning for smooth schema evolution
- Advanced filtering and aggregation capabilities
- Performance metrics and SLA tracking
- Event retention policies for compliance
- Monitoring alerts and dashboards

Closes #[event-indexing-issue]
… Soroban contracts

- Add error classification system (transient, permanent, partial)
- Implement exponential backoff with jitter for retry logic
- Add circuit breaker pattern to prevent cascading failures
- Support partial success in batch operations with detailed tracking
- Implement error state persistence and monitoring
- Add comprehensive event emission for all error scenarios
- Create 20 passing unit tests covering all error recovery scenarios
- Integrate error recovery into program-escrow contract

This implementation significantly improves platform reliability by:
- Automatically retrying transient failures (network timeouts, rate limits)
- Preventing permanent error retries (insufficient funds, invalid addresses)
- Allowing batch operations to partially succeed instead of all-or-nothing
- Tracking failed batch items for targeted retry
- Implementing circuit breakers to prevent system overload
- Providing detailed error events for monitoring and debugging

All tests passing (36/36)
- Create comprehensive SDK for Grainlify contracts
- TypeScript bindings from contract ABIs
- Client classes for Core and Escrow contracts
- Examples for all workflows: lock funds, release funds, batch payouts, query escrow
- Error handling utilities
- Complete documentation and usage guide
- Remove node_modules directory from contracts/sdk
- Add node_modules/ to root .gitignore to prevent future commits
…tracts

- Added ContractPaused error (code 11) to bounty escrow
- Added IsPaused state to contract storage (DataKey enum)
- Implemented pause() and unpause() functions (admin-only)
- Implemented emergency_withdraw() for critical fund recovery (paused state only)
- Added pause checks to all state-changing functions:
  - lock_funds, release_funds, refund
  - batch_lock_funds, batch_release_funds
- Added pause events: ContractPaused, ContractUnpaused, EmergencyWithdrawal
- Applied same pause functionality to program-escrow contract
- Added pause guards to lock_program_funds, batch_payout, single_payout
- Added pause guards to create_program_release_schedule and release_prog_schedule_automatic
- Implemented is_paused() helper function for querying pause state
- Added comprehensive pause tests:
  - test_pause_functionality: validates pause/unpause and blocked operations
  - test_emergency_withdraw: validates fund recovery during pause
- All operations blocked when paused (fail-fast design)
- Read-only functions unaffected by pause state

Security features:
- Least privilege: only admins can pause/unpause or withdraw
- Fail-closed design: paused contracts reject state-changing operations
- Auditability: all sensitive actions emit events
- State persistence: pause state survives upgrades
- Idempotent operations: pause/unpause can be called multiple times safely
- Fixed duplicate error code 11: moved BatchSizeMismatch to code 18
- ContractPaused now uses code 11 (was duplicated)
- Changed IsPaused storage from instance to persistent storage for better persistence
- Added 2 pause-specific tests: test_pause_functionality and test_emergency_withdraw
- Fixed test assertions to work with Soroban SDK's no_std environment

Test Results:
- Bounty Escrow: 50/50 passing (42 existing + 2 pause tests + 6 other tests)
- All pause functionality working correctly:
  - pause() and unpause() functions properly toggle pause state
  - Pause state persists across function calls
  - is_paused() correctly reports pause status
  - emergency_withdraw() callable when paused
@Jagadeeshftw
Copy link
Owner

@anumukul

@Jagadeeshftw Jagadeeshftw requested review from Jagadeeshftw and removed request for Jagadeeshftw January 31, 2026 12:42
Tola-byte and others added 4 commits January 31, 2026 14:19
…-utilities

feat: add contract testing utilities and helpers
- Add PauseConfig struct with lock_paused, release_paused, refund_paused flags (bounty-escrow)
- Add PauseConfig struct with lock_paused, payout_paused, schedule_paused flags (program-escrow)
- Add set_pause_lock(), set_pause_release(), set_pause_refund() functions (bounty-escrow)
- Add set_pause_lock(), set_pause_payout(), set_pause_schedule() functions (program-escrow)
- Add get_pause_config() and individual is_*_paused() view functions
- Update lock_funds, release_funds, refund to check operation-specific flags (bounty-escrow)
- Update lock_program_funds, single_payout, batch_payout, create_program_release_schedule to check operation-specific flags (program-escrow)
- Add OperationPauseChanged event for granular pause state changes (bounty-escrow)
- Add LockPaused (21), ReleasePaused (22), RefundPaused (23) error codes (bounty-escrow)
- Add LockPaused (4), PayoutPaused (5), SchedulePaused (6) error codes (program-escrow)
- Maintain backward compatibility: pause()/unpause() set all flags
- Add comprehensive test coverage for pause matrix combinations (53 tests total)
- Merged granular pause functionality with upstream features
- Integrated reentrancy guards with pause checks
- Fixed duplicate struct/function definitions
- Updated error codes to avoid conflicts
- Added missing pause internal helper functions
- Fixed field name mismatches (auth_key vs authorized_payout_key)
- Both contracts now compile successfully
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.

Implement Granular Pause (Per-Operation)

Comments