feat(contract): enforce min_score_to_earn gate in record_payment#191
feat(contract): enforce min_score_to_earn gate in record_payment#191leocagli wants to merge 1 commit into
Conversation
Closes Stellar-Ecosystem#140 SpendingPolicy.min_score_to_earn was stored and displayed in the UI but never checked — agents below the threshold earned score at the same rate as qualified agents, making the field cosmetic. Semantic: 'agents below min_score_to_earn do not gain SCORE_SUCCESS from successful payments; payment stats (total_payments, successful_payments, volume) are still recorded so credit history remains accurate.' Changes: - Added apply_score_success(current, min_score_to_earn) helper that encapsulates the gate logic: returns current score unchanged when below the threshold, or (current + SCORE_SUCCESS).min(MAX_SCORE) when at or above - Moved SpendingPolicy load to before the score update in record_payment so the gate can be applied without a second storage read - Added is_new_day helper (replaces the inline DAY_LEDGERS check reused from the policy section) for clarity and reuse - Added doc comment on SpendingPolicy.min_score_to_earn explaining the semantic - Added #[cfg(test)] module with 8 tests: 6 for apply_score_success (no gate, below gate, at gate, above gate, cap, at-max) and 2 boundary tests for is_new_day
|
Warning Review limit reached
More reviews will be available in 3 seconds. Learn how PR review limits work. To continue reviewing without waiting, enable usage-based billing in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Fixes #140
Problem
SpendingPolicy.min_score_to_earnwas stored on-chain, displayed inSpendingPolicy.tsxas "Min Score to Earn", and settable viaupdate_policy— but never enforced. Agents below the threshold gainedSCORE_SUCCESSfrom every successful payment at the same rate as qualified agents, making the field purely cosmetic.Chosen Semantic
This is the "earn-gate" interpretation: existing agents can still use services; they just cannot improve their score until they qualify. (The alternative — blocking spending entirely — would be a breaking change to
check_spending_allowed.)Changes
contract/agents/src/lib.rsNew helpers:
record_payment: movedSpendingPolicyload to before the score update somin_score_to_earncan be read without a second storage hit. Score now goes throughapply_score_success(agent.score, min_score).Doc comment added to
min_score_to_earnfield explaining the semantic.#[cfg(test)]module with 8 tests:apply_score_success(no gate, below gate, at gate, above gate, near-cap, at-max)is_new_day🤖 Generated with Claude Code