Skip to content

Commit

Permalink
Fix state override (#66)
Browse files Browse the repository at this point in the history
* fix: state override

* chore: refactor

* fix: AttributeError
  • Loading branch information
BobTheBuidler authored Apr 24, 2023
1 parent 71e79b2 commit 7e39ca8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
29 changes: 16 additions & 13 deletions dank_mids/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,22 @@ def reduce_batch_size(self, num_calls: int) -> None:
main_logger.warning(f'Multicall batch size reduced from {old_step} to {new_step}. The failed batch had {num_calls} calls.')

def _start_exception_daemon_if_stopped(self) -> None:
if not self._daemon_running:
fut = asyncio.ensure_future(self._exception_daemon())
def done_callback(fut: asyncio.Future) -> None:
"""Notifies the controller in the event of daemon shutdown or failure."""
self._daemon_running = False
if not fut.exception():
try:
self._futs.remove(fut)
except ValueError as e:
if str(e) != "list.remove(x): x not in list":
raise
fut.add_done_callback(done_callback)
self._futs.append(fut)
if self._daemon_running:
return

def done_callback(fut: asyncio.Future) -> None:
"""Notifies the controller in the event of daemon shutdown or failure."""
self._daemon_running = False
if not fut.exception():
try:
self._futs.remove(fut)
except ValueError as e:
if str(e) != "list.remove(x): x not in list":
raise

fut = asyncio.ensure_future(self._exception_daemon())
fut.add_done_callback(done_callback)
self._futs.append(fut)

async def _exception_daemon(self) -> None:
if self._daemon_running:
Expand Down
6 changes: 2 additions & 4 deletions dank_mids/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ def bisect(self) -> Generator[List[_Request], None, None]:
"""Destroys this reuest."""
yield self.chunk0
yield self.chunk1
# We no longer need these references to the calls, the new batch calls will have them.
del self.calls

@property
def chunk0(self) -> List[_Request]:
Expand Down Expand Up @@ -358,7 +356,7 @@ def target(self) -> ChecksumAddress:
@property
def params(self) -> JsonrpcParams:
params = [{'to': self.target, 'data': f'0x{self.calldata}'}, self.block]
if self.worker.state_override_not_supported:
if self.worker.state_override_supported:
params.append({self.target: {'code': OVERRIDE_CODE}})
return params

Expand Down Expand Up @@ -532,7 +530,7 @@ async def set_response(self, response: Union[List[RPCResponse], Exception]) -> N
else:
await await_all(
# NOTE: For some rpc methods, the result will be a dict we can't hash during the gather.
call.set_response(AttributeDict(result["result"], wakeup_main_loop=False) if isinstance(result["result"], dict) else result["result"]) # type: ignore
call.set_response(AttributeDict(result["result"]) if isinstance(result["result"], dict) else result["result"], wakeup_main_loop=False) # type: ignore
for call, result in zip(self.calls, response)
)
self.set_done()
Expand Down
2 changes: 1 addition & 1 deletion dank_mids/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, controller: "DankMiddlewareController") -> None:
self.multicall_uid: UIDGenerator = UIDGenerator()
self.request_uid: UIDGenerator = UIDGenerator()
self.jsonrpc_batch_uid: UIDGenerator = UIDGenerator()
self.state_override_not_supported: bool = _config.GANACHE_FORK or self.controller.chain_id == 100 # Gnosis Chain does not support state override.
self.state_override_supported: bool = not _config.GANACHE_FORK and self.controller.chain_id != 100 # Gnosis Chain does not support state override.
self.event_loop = asyncio.new_event_loop()
self.worker_thread = threading.Thread(target=self.start)
self.worker_thread.start()
Expand Down

0 comments on commit 7e39ca8

Please sign in to comment.