Skip to content

Feat/match queue - #1161

Merged
chinweobtagaz merged 12 commits into
OpenKnight-Foundation:mainfrom
codesailor4:feat/MatchQueue
Aug 28, 2026
Merged

Feat/match queue#1161
chinweobtagaz merged 12 commits into
OpenKnight-Foundation:mainfrom
codesailor4:feat/MatchQueue

Conversation

@codesailor4

Copy link
Copy Markdown
Contributor

Summary of Changes

1. Updated Data Models (models.rs)

  • Renamed MatchType to QueueType with three distinct queue types:
    • CasualUnrated: For casual games that never modify ratings
    • RatedFree: For rated games without staking
    • RatedStaked { token: String, amount: u64 }: For crypto-staked rated games
    • Private: Kept for private matches
  • Added StakeInfo struct to track token, amount, and escrow signature for staked matches
  • Updated all structs to use queue_type instead of match_type and added stake_info field
  • Redis key isolation: Each queue type has its own unique Redis key, with staked queues having keys that include token and amount for tier isolation

closes #1015

2. New API Endpoints (routes.rs)

  • Removed the generic /join endpoint and replaced with three specific endpoints:
    • POST /matchmaking/join-casual: For casual unrated matches
    • POST /matchmaking/join-rated-free: For free rated matches
    • POST /matchmaking/join-rated-staked: For staked rated matches (requires token, amount, and escrow signature)
  • Each endpoint creates the appropriate MatchRequest with the correct queue type and validates required fields

3. Matchmaking Service Improvements (service.rs)

  • Added escrow verification: verify_escrow_signature method that would call Soroban RPC in production to validate on-chain deposits
  • Queue-specific match finding:
    • find_casual_unrated_match: Only matches players from the casual queue
    • find_rated_free_match: Only matches players from the rated free queue
    • find_rated_staked_match: Only matches players from the exact same token/amount tier and verifies both have valid escrow signatures
  • Strict queue isolation: Lua scripts in Redis ensure players are only matched with others in the exact same queue type and stake tier
  • Updated all queue operations: cancel_request, get_queue_status, and expand_elo_ranges now work with all new queue types

closes #1039

4. Key Requirements Met

  • Casual games never modify ratings: CasualUnrated queue is completely isolated, and the matchmaking system never touches Elo for these matches
  • Staked matches require verified escrow: Both players must provide valid escrow signatures before a match can be created
  • Clean API endpoints: Three separate endpoints for joining each queue type
  • Strict pairing restrictions: Players can only be matched with others in the same queue type and stake tier
  • Redis queue isolation: Each queue type has its own Redis key, preventing cross-queue matching

closes #1016

5. Next Steps for Production

  1. Implement the actual Soroban RPC call in verify_escrow_signature to validate on-chain deposits
  2. Add proper tracking of active staked queues for better cancellation and status checking
  3. Implement rating update logic that only modifies Elo/Glicko for RatedFree and RatedStaked matches
  4. Add comprehensive unit and integration tests to verify cross-queue isolation
  5. Add cleanup logic for expired staked queue entries to refund players if matches aren't found

The implementation successfully separates the previously shared queue parameters into distinct, isolated queues that meet all the requirements, preventing accidental stake deductions or rating modifications for casual players.

closes #1017

@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@codesailor4 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! 🚀

Learn more about application limits

@chinweobtagaz
chinweobtagaz merged commit c4801bc into OpenKnight-Foundation:main Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants