feat: implement match pause and resume for extended games (#952)#1021
Merged
famvilianity-eng merged 2 commits intoJul 1, 2026
Merged
Conversation
…ckMate#952) - Add Paused state to MatchState enum - Add paused_ledger and total_pause_duration fields to Match struct - Implement pause_match() - either player can pause an active match - Implement resume_match() - either player can resume a paused match - Update expire_match() to exclude pause duration from timeout calculation - Add SnapshotReason::Paused and SnapshotReason::Resumed variants - Add comprehensive tests for pause/resume cycle - Add error variants: MatchNotPaused, MatchAlreadyPaused, InvalidPauseState
|
@Killerjunior 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.
Implement Match Pause and Resume for Extended Games (#952)
Summary
This PR implements pause and resume functionality for chess matches to support extended games (simuls, blindfold matches) that may span multiple days. The escrow contract now allows either player to pause an active match without losing stake or state, and the timeout calculation excludes pause duration to prevent unfair expiration of long matches.
Related Issue
Closes #952 - Implement Match Pause and Resume for Extended Games
What Changed
Contracts
Pausedstate toMatchStateenum incontracts/escrow/src/types.rspaused_ledger: Option<u32>field toMatchstruct to track pause start timetotal_pause_duration: u32field toMatchstruct to accumulate pause time across multiple cyclespause_match(env, match_id, caller)- allows either player to pause an active matchresume_match(env, match_id, caller)- allows either player to resume a paused matchexpire_match()to exclude pause duration from timeout calculation usingtotal_pause_durationSnapshotReason::PausedandSnapshotReason::Resumedvariants for balance snapshot trackingTests
contracts/escrow/src/tests/lifecycle.rs:test_pause_active_match_sets_paused_state- verifies state transition and paused_ledger recordingtest_resume_paused_match_sets_active_state- verifies state transition back to Activetest_pause_accumulates_total_pause_duration- verifies pause duration tracking across multiple cyclestest_pause_fails_on_non_active_match- validates state requirementstest_resume_fails_on_non_paused_match- validates state requirementstest_unauthorized_player_cannot_pause- authorization checkstest_unauthorized_player_cannot_resume- authorization checkstest_pause_resume_cycle_preserves_escrow_balance- fund conservationtest_submit_result_fails_on_paused_match- prevents result submission while pausedtest_deposit_fails_on_paused_match- prevents deposits while pausedtest_multiple_pause_resume_cycles- tests multiple pause/resume cyclestest_pause_resume_with_snapshots- verifies balance snapshot recordingErrors
MatchNotPaused = 22- error when attempting to resume a non-paused matchMatchAlreadyPaused = 23- error when attempting to pause an already paused matchInvalidPauseState = 24- error when attempting to pause a non-active matchEvents / API / Storage
(match, paused)- emitted when a match is paused(match, resumed)- emitted when a match is resumedVerification
Note: Tests could not be run locally due to missing Visual Studio C++ build tools (link.exe not found). However, the implementation follows the existing codebase patterns and includes comprehensive test coverage.
The following verification steps should be performed:
cargo test -p escrow- runs all escrow contract tests including new pause/resume testscargo test -p oracle- ensures oracle integration still workscargo fmt- code formattingcargo clippy- lintingChecklist
Notes
Design Decisions
expire_match()excludes pause duration; active match operations (deposit, submit_result) remain blocked while pausedStorage Impact
Risks & Considerations
Follow-up Tasks