Skip to content

Commit

Permalink
fix: json batch ordering on chainstack and tenderly (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Nov 3, 2023
1 parent f4c5975 commit 9a75cc7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion dank_mids/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,19 @@ def should_retry(self, e: Exception) -> bool:
@set_done
async def spoof_response(self, response: List[RawResponse]) -> None:
# This means we got results. That doesn't mean they're good, but we got 'em.
for r in await asyncio.gather(*[call.spoof_response(raw) for call, raw in zip(self.calls, response)], return_exceptions=True):

if "tenderly" or "chainstack" in self.controller.endpoint:
# NOTE: these providers don't always return batch results in the correct ordering
# NOTE: is it maybe because they
calls = sorted(self.calls, key=lambda call: call.uid)
for i, (call, raw) in enumerate(zip(calls, response)):
# TODO: make sure this doesn't ever raise and then delete it
decoded = raw.decode()
assert call.uid == decoded.id, (i, call, decoded, response, [[call.uid for call in calls], [raw.decode() for raw in response]])
else:
calls = self.calls

for r in await asyncio.gather(*[call.spoof_response(raw) for call, raw in zip(calls, response)], return_exceptions=True):
# NOTE: By doing this with the exceptions we allow any successful calls to get their results sooner
# without being interrupted by the first exc in the gather and having to wait for the bisect and retry process
# TODO: stop retrying ones that succeed, that's wasteful
Expand Down

0 comments on commit 9a75cc7

Please sign in to comment.