Skip to content

feat: define atomicity semantics for batch_add_to_goals#381

Open
abbakargarba wants to merge 10 commits intoRemitwise-Org:mainfrom
abbakargarba:feature/savings-batch-atomicity-rules
Open

feat: define atomicity semantics for batch_add_to_goals#381
abbakargarba wants to merge 10 commits intoRemitwise-Org:mainfrom
abbakargarba:feature/savings-batch-atomicity-rules

Conversation

@abbakargarba
Copy link
Copy Markdown
Contributor

closes issue #261

Overview

This PR implements atomic batch funding operations for the savings_goals contract, ensuring all-or-nothing semantics to prevent inconsistent partial updates.

Changes Made

Core Implementation (savings_goals/src/lib.rs)

  • Rewrote batch_add_to_goals() with 6-phase atomic processing:

    1. Comprehensive upfront validation
    2. BatchStarted event emission
    3. In-memory processing with overflow checks
    4. Atomic storage commit
    5. Individual FundsAdded/GoalCompleted events
    6. BatchCompleted event emission
  • New Error Types:

    • BatchTooLarge: Enforces 50-goal limit
    • BatchValidationFailed: Invalid data/authorization
    • BatchProcessingFailed: Processing errors
  • New Event Types:

    • BatchStartedEvent: Processing initiation
    • BatchCompletedEvent: Successful completion
    • BatchFailedEvent: Failure notification

Security & Reliability

  • All-or-nothing semantics: Either all contributions succeed or none do
  • Upfront validation: Prevents partial state corruption
  • Overflow protection: Guards against integer overflow
  • Authorization checks: Verifies caller owns all goals
  • Size limits: Prevents gas exhaustion attacks

Comprehensive Testing (savings_goals/src/test.rs)

Added 8 new test functions covering:

  • Successful batch operations with goal completions
  • Validation failure scenarios (atomic rollback)
  • Batch size limit enforcement
  • Empty batch handling
  • Invalid amount validation
  • Overflow protection
  • Event emission verification
  • Goal completion event emission

Documentation Updated (savings_goals/README.md)

  • Added "Batch Atomicity" section with guarantees
  • API reference for batch_add_to_goals
  • ContributionItem data structure documentation
  • Usage examples for batch operations
  • Security considerations for atomicity

Testing

Run tests with: cargo test -p savings_goals

Note: Tests are comprehensive but couldn't be executed due to workspace dependency conflicts. Code follows established patterns and is ready for validation.

Checklist

  • Atomicity guarantees implemented
  • Comprehensive validation added
  • Event emission for audit trails
  • Extensive test coverage written
  • Documentation updated with NatSpec-style comments
  • Security considerations addressed
  • Batch size limits enforced

abbakargarba and others added 6 commits March 24, 2026 13:12
- Implement batch_add_to_goals with all-or-nothing atomicity
- Add comprehensive validation upfront to prevent partial failures
- Include overflow protection and authorization checks
- Emit structured events for batch start/completion/failure
- Add extensive test coverage for edge cases and security
- Update documentation with NatSpec-style comments
- Enforce batch size limits to prevent gas exhaustion
- Update all crates to use soroban-sdk 21.1.1 for consistency
- Resolve ed25519-dalek dependency conflicts causing CI failures
- Ensure uniform SDK version across remitwise-common and all contracts
- Add Debug derive to SavingsGoalsError
- Fix symbol lengths for batch events (batch_str, batch_end, batch_err)
- Fix match arm syntax with braces
- Update test assertions to use new symbol names
- Fix type casting for batch size validation
- Fix duplicate function signature in insurance crate
- Prefix unused variable with underscore
@Baskarayelu
Copy link
Copy Markdown
Contributor

Please resolve the conflicts

@abbakargarba
Copy link
Copy Markdown
Contributor Author

this build error is heart breaking, whats going on bro😅

@Baskarayelu
Copy link
Copy Markdown
Contributor

@abbakargarba Please resolve the conflicts

@abbakargarba
Copy link
Copy Markdown
Contributor Author

@abbakargarba Please resolve the conflicts

conflict resolved🌊

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.

2 participants