Description
resolve_market and distribute_payouts iterate over per-user stakes and emit several events. As markets grow we risk exceeding Soroban's per-transaction CPU-instruction budget. We need a measured budget guard that aborts gracefully with a typed error before the host runs out of resources.
Requirements and Context
- Read the current instruction budget via
env.budget().cpu_instruction_cost() style calls at well-defined checkpoints
- Add a
BudgetGuard helper in gas.rs that records pre/post-call cost and short-circuits with Error::OperationWouldExceedBudget if remaining < configured threshold
- Wire the guard into
MarketResolutionManager::resolve_market and the distribute_payouts loop in lib.rs
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested Execution
- Fork the repo and create a branch
git checkout -b feat/cpu-instruction-budget-guard
- Implement changes
contracts/predictify-hybrid/src/gas.rs
contracts/predictify-hybrid/src/resolution.rs
contracts/predictify-hybrid/src/lib.rs (call sites)
contracts/predictify-hybrid/src/err.rs (new OperationWouldExceedBudget variant)
- Test and commit
cargo test -p predictify-hybrid budget_guard -- --nocapture
- Cover edge cases: tiny budget, huge winner set, single winner
- Include test output and notes in the PR
Example commit message
feat: enforce per-transaction CPU-instruction budget guard in resolution path
Acceptance Criteria
Guidelines
- Validate auth and storage TTL assumptions remain intact when aborting mid-payout
- Minimum 95% coverage of new branches
- Clear documentation and inline comments
- Timeframe: 96 hours
Description
resolve_marketanddistribute_payoutsiterate over per-user stakes and emit several events. As markets grow we risk exceeding Soroban's per-transaction CPU-instruction budget. We need a measured budget guard that aborts gracefully with a typed error before the host runs out of resources.Requirements and Context
env.budget().cpu_instruction_cost()style calls at well-defined checkpointsBudgetGuardhelper ingas.rsthat records pre/post-call cost and short-circuits withError::OperationWouldExceedBudgetif remaining < configured thresholdMarketResolutionManager::resolve_marketand thedistribute_payoutsloop inlib.rsSuggested Execution
contracts/predictify-hybrid/src/gas.rscontracts/predictify-hybrid/src/resolution.rscontracts/predictify-hybrid/src/lib.rs(call sites)contracts/predictify-hybrid/src/err.rs(newOperationWouldExceedBudgetvariant)cargo test -p predictify-hybrid budget_guard -- --nocaptureExample commit message
Acceptance Criteria
BudgetGuarddocumented with///rustdoc and used at >= 3 hot-path call sitesevents::ErrorLoggedEventfor client visibilityunwrap()onResultfrom budget queriesGuidelines