Repository navigation
Conversation
A batch reply carries `id: null` when the server could not read the id of an item, and the order of the replies is not tied to the order of the requests. The transport sorted the replies by id with `a.id - b.id` and handed them out by index, so a `null` id took part in the comparison as zero and moved the other replies to the wrong requests. Each request now gets its id before the batch goes out, and the replies are placed back by id. A reply whose id matches no request in the batch cannot be attributed, so it fills the first request that has no reply of its own. The tests cover a null id at the end, at the start and in the middle of the batch. Closes wevm#5561
🦋 Changeset detectedLatest commit: dd760d0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@lx3133584 is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
|
Thank you @lx3133584 for the fix and the clear write-up! I've folded your commit (a63e11c) into #5594, which supersedes this PR and fixes #5561. On top of it, a reply that carries a batch request's id now goes only to that request (a duplicate reply could fill another request here). Matching uses a Set and a Map, a request with no reply gets an error, and there's a changeset. Closing this in favor of #5594. |
A batch reply carries
id: nullwhen the server could not read the id of an item (JSON-RPC 2.0), and the order of the replies is not tied to the order of the requests. The transport sorted the replies by id witha.id - b.id, where anullid takes part in the comparison as zero, so that reply moved the others and each request could receive a neighbour's result.The reply array is now matched to the requests by id rather than by position: every request gets its id before the batch goes out, and each reply is placed at the position of the request that asked for it. A reply whose id matches no request in the batch cannot be attributed, so it fills the first request that has no reply of its own.
Before, the three calls came back as
["0x1", "InvalidRequestRpcError", "0x2"]; they now come back as["0x1", "0x2", "InvalidRequestRpcError"], which is what the server actually sent for the first two requests.Tests
Three cases added for a null id at the end, at the start, and in the middle of the batch. On the current code the first one fails with the mismatch above; the other two pass before and after, and guard the attribution rules for the positions the old comparator happened to get right.
http.test.ts -t "null"— 3 passedhttp.test.ts -t "batch"— 17 passedcreateBatchScheduler.test.ts— 9 passedhttp.test.ts— 43 passed, 4 failed (default,behavior: dedupe,behavior: raw,errors: rpc error). Those four open a real RPC connection and fail the same way onmainin this environment (no route to the public endpoints); the failure set is unchanged by this change.tsc --noEmitandbiome checkclean.