Concurrent VRF Requests: Keep Results Attached to the Right Job
Design concurrent D20DAO VRF consumers on Arc and Robinhood Chain. Associate callbacks with simulation jobs and preserve each result through recovery.
Two jobs need two result records
A simulation application opens randomness requests for independent jobs A and B. Both are pending. If B's callback is processed first, its word must be stored for B while A remains pending. A single latest-request field or shared result slot makes that association fragile.
Design for this interleaving rather than assuming submission-order delivery. D20DAO's coordinator fulfills requests by ID and sends that ID with the callback. This guide proposes the application records and checks needed to keep concurrent jobs independent; it does not report a completed consumer implementation.
Give each simulation an application identity
Assign a stable job ID before opening its request. Record the simulation version, input commitment, selected mapping and who may start the job. Enforce one active randomness request for that operation in the consumer, including when a user repeats the start action.
Keep jobs A and B distinct even when they use identical parameters. A completed job must retain its original result. If the user deliberately starts a new simulation, give it a new operation identity instead of rewriting an earlier job's request association.
Associate jobs and request IDs explicitly
When the requesting call succeeds, retain the coordinator's returned request ID with the job. Keep the reverse association too, so a callback's ID resolves to exactly one operation. Each job needs its own pending state and eventual accepted word.
For records outside a single consumer deployment, include chain ID, coordinator and consumer address with the request ID. Request numbers from different networks or coordinators must not collide in an application database. Recover the association from the original transaction and request event when a browser loses its local state.
Authenticate first, then resolve the operation
D20VRFConsumer checks that the callback caller is its configured coordinator. The application still needs to look up the callback's request ID, verify that it belongs to the expected job and validate that job's current state. The base consumer does not maintain your simulation registry.
Store the word in the resolved job's record. Never assign it to whichever job the interface currently displays. Define handling for unknown and already-recorded IDs so neither can trigger another application action. Keep simulation execution and other expensive work outside this bounded callback.
Store independently, execute by explicit rules
With B resolved and A still waiting, the interface should show those separate states. A global loading flag or shared current-result field cannot represent them accurately. Let the simulation worker read B's stored word and record whether B's application action has already run.
If jobs later contribute to a shared report, define that report's ordering and completion conditions separately. Callback arrival should not silently decide how outputs are combined. Reprocessing a worker task must not execute a completed job twice, even though reading its retained randomness again is harmless.
Recover one job without replacing another
Proof acceptance and callback delivery are separate. If A's proof was accepted but its callback failed, retryCallback delivers A's same stored word. Keep A's request association intact; B's record needs no reset. A delivery retry must not become permission to request a preferred replacement outcome.
If A expires without an accepted proof, follow its documented refund terms and the simulation's previously defined failure policy. An unavailable RPC leaves the application uncertain; it does not establish expiry. Review administrative reset paths as well as user controls so a privileged action cannot silently swap an active request or overwrite a known result.
Keep each job's evidence together
Retain the job's original input commitment, request arguments, network and contract identities, transaction references and final state. Link its result to that exact request's Explorer evidence. A valid proof for B cannot justify the value stored for A.
Independent verification also checks canonical receipts, request context and the historical implementation and configuration. The application association remains its own invariant: a proof establishes its recorded randomness, while the consumer must preserve which simulation receives it.
Plan tests around interleavings
Use these acceptance cases when implementing the concurrent consumer:
- Open A and B, process B's callback first, and confirm that only B receives its word.
- Process A afterward and preserve both job records and their original input commitments.
- Repeat a start action while its job is pending without creating another active request.
- Exercise unauthorized callers, unknown IDs and duplicate processing without advancing another job.
- Fail A's callback, recover its same word, and keep B's completed state unchanged.
- Retry a completed worker task without applying the simulation action a second time.