Skip to content

Restore fast delegated roll result handling - #124

Merged
sporicle merged 1 commit into
mainfrom
fix/fast-correlated-roll
Jul 28, 2026
Merged

Restore fast delegated roll result handling#124
sporicle merged 1 commit into
mainfrom
fix/fast-correlated-roll

Conversation

@sporicle

@sporicle sporicle commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What changed

  • Complete ordinary delegated rolls directly from the processed player-account subscription when rollnum advances after the signed request.
  • Keep sync reads, polling, stale slots, warm-up updates, and unchanged counters from completing a user roll.
  • Avoid per-roll log and signature WebSocket subscriptions on the ordinary single-in-flight hot path.
  • Retain seed-correlated callback logs and transaction-history reconciliation for ambiguous cases, including saturated counters and unresolved prior seeds.
  • Add focused tests for normal, stale, warm-up, saturated, and generation-mismatch behavior.

Why

The current frontend makes callback logs primary and performs an additional account RPC before resolving the UI. That preserves correlation correctness but adds avoidable client-side latency after the player account has already changed. The older frontend reacted immediately to account notifications, but accepted any update and could associate stale or unrelated callbacks with the pending roll.

This restores the direct account-subscription path when an advancing rollnum proves a new result, while preserving correlated fallbacks where account state alone is ambiguous.

Impact

Ordinary delegated rolls resolve on the first valid account notification without extra live WebSocket subscriptions or an additional account fetch. Onchain VRF scheduling latency remains unchanged.

Validation

  • npm run test:roll-result (7 tests)
  • npx tsc --noEmit
  • npm run build

Summary by CodeRabbit

  • Bug Fixes

    • Improved delegated dice-roll completion detection for ambiguous account updates.
    • Added more reliable handling of callback confirmations, transaction signatures, roll numbers, and client seeds.
    • Prevented stale or unrelated updates from incorrectly completing a roll.
  • Tests

    • Added coverage for roll correlation and completion scenarios, including saturated counters and mismatched generations.
  • Chores

    • Added a dedicated command for running roll-result tests.

@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
binary-prediction-demo Ready Ready Preview, Comment Jul 28, 2026 8:58am
counter-session-keys Ready Ready Preview, Comment Jul 28, 2026 8:58am
er-rolldice Ready Ready Preview, Comment Jul 28, 2026 8:58am
magicblock-counter-example Ready Ready Preview, Comment Jul 28, 2026 8:58am
magicblock-engine-examples Ready Ready Preview, Comment Jul 28, 2026 8:58am
magicblock-rewards-dashboard Ready Ready Preview, Comment Jul 28, 2026 8:58am
rps-example Ready Ready Preview, Comment Jul 28, 2026 8:58am
spl-tokens Ready Ready Preview, Comment Jul 28, 2026 8:58am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 62518534-4a1e-4081-a2a1-cc99c1f50d95

📥 Commits

Reviewing files that changed from the base of the PR and between a2cd230 and 6cec5c7.

📒 Files selected for processing (5)
  • roll-dice/anchor/app/app/delegated/page.tsx
  • roll-dice/anchor/app/lib/roll-result.test.ts
  • roll-dice/anchor/app/lib/roll-result.ts
  • roll-dice/anchor/app/package.json
  • roll-dice/anchor/app/tsconfig.json

Walkthrough

The delegated dice roll flow now centralizes completion and live-correlation decisions in shared helpers, tracks pending roll context, conditionally subscribes to callback logs, and adds focused unit-test coverage.

Changes

Delegated roll reconciliation

Layer / File(s) Summary
Correlation predicates and validation
roll-dice/anchor/app/lib/roll-result.ts, roll-dice/anchor/app/lib/roll-result.test.ts, roll-dice/anchor/app/package.json, roll-dice/anchor/app/tsconfig.json
Adds shared source types and predicates for live correlation and roll completion, with tests and a dedicated test script.
Account-change completion reconciliation
roll-dice/anchor/app/app/delegated/page.tsx
Tracks pending roll number and client seed context, then uses shouldCompleteRoll to reconcile account updates and clear completed-roll state.
Conditional callback correlation
roll-dice/anchor/app/app/delegated/page.tsx
Uses requiresLiveRollCorrelation to gate log subscriptions and conditionally records request slots or transaction signatures for reconciliation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/fast-correlated-roll

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant