Skip to content

Commit

Permalink
fix: remove middlewares from sync_w3 for use in subprocess (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored May 19, 2022
1 parent 93daf6b commit 1616f30
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dank_mids/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

instances: List["DankMiddlewareController"] = []

def reattempt_call_and_return_exception(target: str, calldata: bytes, block: str, web3: Web3) -> Exception:
def reattempt_call_and_return_exception(target: str, calldata: bytes, block: str, w3: Web3) -> Exception:
""" NOTE: This runs synchronously in a subprocess in order to bypass Dank Middleware without blocking the event loop. """
try:
return web3.eth.call({"to": target, "data": calldata}, block)
return w3.eth.call({"to": target, "data": calldata}, block)
except Exception as e:
return e

Expand All @@ -47,6 +47,7 @@ def __init__(self, w3: Web3) -> None:
self.sync_w3 = Web3(provider = HTTPProvider(self.w3.provider.endpoint_uri))
# Can't pickle middlewares to send to process executor
self.sync_w3.middleware_onion.clear()
self.sync_w3.provider.middlewares = tuple()
self.DO_NOT_BATCH = set()
self.pending_calls = defaultdict(dict)
self.completed_calls = defaultdict(dict)
Expand Down Expand Up @@ -246,6 +247,7 @@ async def _setup(self) -> None:
return
self._initializing = True
print('Dank Middleware initializing... Strap on your rocket boots...')
# NOTE use sync w3 here to prevent timeout issues with abusive scripts.
chain_id = self.sync_w3.eth.chain_id
MULTICALL = multicall.constants.MULTICALL_ADDRESSES.get(chain_id,None)
self.MULTICALL2 = multicall.constants.MULTICALL2_ADDRESSES.get(chain_id,None)
Expand Down

0 comments on commit 1616f30

Please sign in to comment.