feat: add half-life refill mode to RateLimiter and governance vote salt#795
Open
CodeNinjaStephen wants to merge 2 commits into
Conversation
Issue Predictify-org#660 — Half-life rate-limiter token replenishment • Add RefillMode enum { Linear, HalfLife(u64) } to rate_limiter.rs • RateLimitConfig gains refill_mode field (default: Linear, backwards compatible) • HalfLife mode: consumed tokens halve every half_life_seconds via integer right-shift (no floats, no overflow, asymptotically approaches capacity) • New RateLimiterError::InvalidHalfLife = 10 for zero or out-of-window values • validate_rate_limit_configuration rejects half_life=0 or half_life>time_window • check_limit_with_config and halflife_available added for mode-aware checks • get_rate_limit_status reports correct remaining for both modes • All existing RateLimitConfig literals updated with refill_mode: Linear • New: src/tests/rate_limiter_halflife_tests.rs (15 tests) - capacity enforcement, 1 half-life refill, full saturation (32+ shifts) - no overflow past capacity, monotone recovery, independent user/market buckets - validation (zero, >window rejected; valid passes), static-time no-refill - capacity-1 edge case, Linear→HalfLife config switch via update Issue Predictify-org#668 — Governance proposal salt for vote-replay prevention • GovernanceProposal gains salt: BytesN<32> field • Salt generated at creation via env.prng().gen() — never block timestamp • GovernanceContract::vote() now requires salt: BytesN<32> parameter; rejects with GovernanceError::SaltMismatch when it does not match stored salt • New GovernanceContract::get_proposal_salt() view function • GovernanceError::SaltMismatch added • governance_tests.rs: BytesN import, vote helper auto-fetches correct salt, get_salt/vote_with_salt helpers added to fixture • 7 new salt tests: stored+retrievable, distinct per proposal, correct vote passes, wrong salt rejected, replay prevention across resubmitted proposals, ProposalNotFound for missing proposal, fixture helper works end-to-end Pre-existing fix: market_id_generator.rs — add missing closing brace for impl MarketIdGenerator (unclosed delimiter; unrelated to these features)
|
@CodeNinjaStephen Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #660 — Half-life rate-limiter token replenishment • Add RefillMode enum { Linear, HalfLife(u64) } to rate_limiter.rs • RateLimitConfig gains refill_mode field (default: Linear, backwards compatible) • HalfLife mode: consumed tokens halve every half_life_seconds via integer
right-shift (no floats, no overflow, asymptotically approaches capacity)
• New RateLimiterError::InvalidHalfLife = 10 for zero or out-of-window values • validate_rate_limit_configuration rejects half_life=0 or half_life>time_window • check_limit_with_config and halflife_available added for mode-aware checks • get_rate_limit_status reports correct remaining for both modes • All existing RateLimitConfig literals updated with refill_mode: Linear • New: src/tests/rate_limiter_halflife_tests.rs (15 tests)
Issue #668 — Governance proposal salt for vote-replay prevention • GovernanceProposal gains salt: BytesN<32> field
• Salt generated at creation via env.prng().gen() — never block timestamp • GovernanceContract::vote() now requires salt: BytesN<32> parameter;
rejects with GovernanceError::SaltMismatch when it does not match stored salt
• New GovernanceContract::get_proposal_salt() view function • GovernanceError::SaltMismatch added
• governance_tests.rs: BytesN import, vote helper auto-fetches correct salt,
get_salt/vote_with_salt helpers added to fixture
• 7 new salt tests: stored+retrievable, distinct per proposal, correct vote
passes, wrong salt rejected, replay prevention across resubmitted proposals,
ProposalNotFound for missing proposal, fixture helper works end-to-end
Pre-existing fix: market_id_generator.rs — add missing closing brace for impl MarketIdGenerator (unclosed delimiter; unrelated to these features)
Pull Request Description
📋 Basic Information
Type of Change
Please select the type of change this PR introduces:
Related Issues
Closes #(issue number)
Fixes #(issue number)
Related to #(issue number)
Priority Level
📝 Detailed Description
What does this PR do?
Why is this change needed?
How was this tested?
Alternative Solutions Considered
🏗️ Smart Contract Specific
Contract Changes
Please check all that apply:
Oracle Integration
Market Resolution Logic
Security Considerations
🧪 Testing
Test Coverage
Test Results
Manual Testing Steps
📚 Documentation
Documentation Updates
Breaking Changes
Breaking Changes:
Migration Guide:
🔍 Code Quality
Code Review Checklist
Performance Impact
Security Review
🚀 Deployment & Integration
Deployment Notes
Integration Points
📊 Impact Assessment
User Impact
Business Impact
✅ Final Checklist
Pre-Submission
Review Readiness
📸 Screenshots (if applicable)
🔗 Additional Resources
💬 Notes for Reviewers
Please pay special attention to:
Questions for reviewers:
Thank you for your contribution to Predictify! 🚀
closes #660
closes #668