Description
When report_revenue is called with override_existing=true for a period_id that has no prior persisted report, the override flag is effectively ignored and the call falls through to initial-report handling. This conflates "correct an existing period" with "create a new period" and can mask off-chain bugs. Make override_existing=true require an existing report, returning a typed error otherwise.
Requirements and context
- Must be secure, tested, and documented
- Should be efficient and easy to review
- Relevant code:
src/lib.rs (report_revenue match on reports.get(period_id))
- The override path must still emit
rev_ovrd and apply net delta to total_revenue without incrementing report_count
Suggested execution
- Fork the repo and create a branch
git checkout -b feat/override-requires-existing-period
- Implement changes
- In the
None arm, branch on override_existing and return a clear error (e.g. InvalidPeriodId or new variant)
- Preserve existing initial-report behavior when
override_existing=false
- Update README
report_revenue semantics
- Validate security and correctness assumptions
Test and commit
- Run tests
- Cover edge cases
- override on new period, override on existing, initial then override, event_only mode
- Include test output and security notes
Example commit message
feat: require existing period for report_revenue override_existing
Guidelines
- Minimum 95 percent test coverage
- Clear documentation
- Timeframe: 96 hours
Description
When
report_revenueis called withoverride_existing=truefor aperiod_idthat has no prior persisted report, the override flag is effectively ignored and the call falls through to initial-report handling. This conflates "correct an existing period" with "create a new period" and can mask off-chain bugs. Makeoverride_existing=truerequire an existing report, returning a typed error otherwise.Requirements and context
src/lib.rs(report_revenuematch onreports.get(period_id))rev_ovrdand apply net delta tototal_revenuewithout incrementingreport_countSuggested execution
git checkout -b feat/override-requires-existing-periodNonearm, branch onoverride_existingand return a clear error (e.g.InvalidPeriodIdor new variant)override_existing=falsereport_revenuesemanticsTest and commit
cargo testExample commit message
feat: require existing period for report_revenue override_existingGuidelines