eth-brownie / brownie

A Python-based development and testing framework for smart contracts targeting the Ethereum Virtual Machine.
https://eth-brownie.readthedocs.io
MIT License
2.65k stars 553 forks source link

websockets 9.1 connection issue #1617

Open sandybradley opened 2 years ago

sandybradley commented 2 years ago

Environment information

What was wrong?

Using a websocket connection does not work on latest brownie.

Config

SUCCESS: Network 'Mainnet (Infura)' has been modified
  └─Mainnet (Infura)
    ├─id: mainnet
    ├─chainid: 1
    ├─explorer: https://api.etherscan.io/api
    ├─host: wss://eth-mainnet.g.alchemy.com/v2/...
    └─multicall2: 0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696
brownie console --network mainnet                                                                                                            1 ↵

Brownie v1.19.1 - Python development framework for Ethereum

  File "brownie/_cli/__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/console.py", line 58, in main
    network.connect(CONFIG.argv["network"])
  File "brownie/network/main.py", line 55, in connect
    p._load_deployments()
  File "brownie/project/main.py", line 384, in _load_deployments
    contract = Contract.from_abi(  # type: ignore
  File "brownie/network/contract.py", line 969, in from_abi
    _DeployedContractBase.__init__(self, address, owner, None)
  File "brownie/network/contract.py", line 706, in __init__
    self.bytecode = web3.eth.get_code(address).hex()[2:]
  File "web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "web3/manager.py", line 197, in request_blocking
    response = self._make_request(method, params)
  File "web3/manager.py", line 150, in _make_request
    return request_func(method, params)
  File "web3/middleware/formatting.py", line 94, in middleware
    response = make_request(method, params)
  File "web3/middleware/gas_price_strategy.py", line 90, in middleware
    return make_request(method, params)
  File "web3/middleware/formatting.py", line 94, in middleware
    response = make_request(method, params)
  File "web3/middleware/attrdict.py", line 33, in middleware
    response = make_request(method, params)
  File "web3/middleware/formatting.py", line 94, in middleware
    response = make_request(method, params)
  File "web3/middleware/formatting.py", line 94, in middleware
    response = make_request(method, params)
  File "web3/middleware/formatting.py", line 94, in middleware
    response = make_request(method, params)
  File "web3/middleware/buffered_gas_estimate.py", line 40, in middleware
    return make_request(method, params)
  File "web3/providers/websocket.py", line 144, in make_request
    return future.result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 446, in result
    return self.__get_result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 391, in __get_result
    raise self._exception
  File "web3/providers/websocket.py", line 124, in coro_make_request
    async with self.conn as conn:
  File "web3/providers/websocket.py", line 72, in __aenter__
    self.ws = await connect(
  File "websockets/legacy/client.py", line 622, in __await_impl__
    transport, protocol = await self._create_connection()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1089, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1107, in _create_connection_transport
    protocol = protocol_factory()
  File "websockets/legacy/client.py", line 160, in __init__
    super().__init__(**kwargs)
  File "websockets/legacy/protocol.py", line 154, in __init__
    self._drain_lock = asyncio.Lock(
  File "/usr/lib/python3.10/asyncio/locks.py", line 78, in __init__
    super().__init__(loop=loop)
  File "/usr/lib/python3.10/asyncio/mixins.py", line 17, in __init__
    raise TypeError(

TypeError: As of 3.10, the *loop* parameter was removed from Lock() since it is no longer necessary

How can it be fixed?

Upgrade websockets dependency to 10.3

sandybradley commented 2 years ago

Apparently web3.py has the dependency issue.

The conflict is caused by:
    The user requested websockets==10.3
    web3 5.31.0 depends on websockets<10 and >=9.1The conflict is caused by:
    The user requested websockets==10.3
    web3 5.31.0 depends on websockets<10 and >=9.1
sandybradley commented 2 years ago

Web3.py has fixed this in their latest beta version

sandybradley commented 2 years ago

Patched a working version here: https://github.com/sandybradley/brownie