feat: Add Collision-Resistant Market ID Generation System#191
Merged
greatest0fallt1me merged 1 commit intoOct 7, 2025
Merged
Conversation
Contributor
|
LGTM! @pushkarm029 |
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.
Pull Request Description
📋 Basic Information
Type of Change
Please select the type of change this PR introduces:
Related Issues
Closes #54
Priority Level
📝 Detailed Description
What does this PR do?
This PR implements a collision-resistant market ID generation system that replaces the simple counter-based approach with a robust, multi-factor unique ID generator. The new system ensures guaranteed uniqueness across all admins and time periods using per-admin counters and cryptographic hashing.
Key Changes:
MarketIdGeneratormodule with comprehensive ID generation logicWhy is this change needed?
The previous market ID generation used a simple global counter (
market_1,market_2, etc.), which had several critical issues:This implementation solves all these issues while maintaining backward compatibility.
How was this tested?
create_market()functionAlternative Solutions Considered
The chosen approach (hash + per-admin counter) provides optimal balance of uniqueness, scalability, and information density.
🏗️ 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
mkt_{hash}_{counter}market_Nformat validation still works📚 Documentation
Documentation Updates
Breaking Changes
Breaking Changes:
market_{N}tomkt_{hash}_{counter}for new marketsMigration Guide:
This is backward compatible - existing markets retain their
market_NIDs and continue to work. Only new markets created after this update will use the new format. No migration required.🔍 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)
N/A - Backend smart contract change with no UI component
🔗 Additional Resources
market_id_generator.rsmkt_{6_hex_chars}_{counter}💬 Notes for Reviewers
Please pay special attention to:
create_market()logicQuestions for reviewers:
🎯 Implementation Highlights
New Files
contracts/predictify-hybrid/src/market_id_generator.rs(218 lines)MarketIdGeneratorstruct with static methodsMarketIdComponentsfor parsingMarketIdRegistryEntryfor registry trackingModified Files
contracts/predictify-hybrid/src/lib.rsmarket_id_generatormodule importcreate_market()to useMarketIdGenerator::generate_market_id()Functions Implemented
generate_market_id(admin: Address)→ Symbolvalidate_market_id_format(market_id: Symbol)→ boolcheck_market_id_collision(market_id: Symbol)→ boolparse_market_id_components(market_id: Symbol)→ MarketIdComponentsis_market_id_valid(market_id: Symbol)→ boolget_market_id_registry(start: u32, limit: u32)→ Vecget_admin_markets(admin: Address)→ VecStorage Schema
Thank you for your contribution to Predictify! 🚀