0xSpaceShard / starknet-devnet

A local testnet for Starknet
https://0xspaceshard.github.io/starknet-devnet/
MIT License
211 stars 77 forks source link

Change default port #26

Closed janek26 closed 2 years ago

janek26 commented 2 years ago

Hey guys,

great work! While integrating this with Argent X we notices port 5000 is often already in use and the devnet doesn't check that and starts anyways (but doesn't work) After a quick google search it seems like port 5000 is often used by the system on MacOS

would it be possible to change the default port to something less used?

Cheers, Janek

FabijanC commented 2 years ago

Can you use the --port option (as documented here)? E.g.

starknet-devnet --port 5001

or

starknet-devnet -p 5001

Or is it just a matter of convenience?

janek26 commented 2 years ago

I do use it personally. But while integrating with ArgentX we also needed to set some default port for localhost we want the network to be on, and I just feel like 5000 is too often used (many devs use macOS). In that case the developer would need to spin up the local dev testate with the -p port option AND also change the port inside ArgentX. I think choosing a less frequently used port could resolve this

FabijanC commented 2 years ago

@janek26 I don't understand. Does your program run starknet-devnet in the background?

JorikSchellekens commented 2 years ago

@FabijanC Macos has a system service called ControlCe that uses port 5000 but the devnet doesn't error out properly when it uses that port. I don't know how this works - it looks like it's running fine but only handles a subset of the requests. It would be nice if the default port wasn't one used by Macos and that it would fail gracefully in this condition. For now just moving the port would save a lot of frustration, it took me a while to realise what was going on.

FabijanC commented 2 years ago

@JorikSchellekens I agree that this should be done. The fact is, this is the only breaking change in the project backlog, and I don't want to release v0.2.0 just to change the default port. So, it should either be argued why the port change is sufficient for a new major version, or suggest another breaking change :smiley: .

JorikSchellekens commented 2 years ago

@FabijanC Considering that starknet-devnet doesn't work on a major os without any clear error messages as to why I'd say 0.1.0 is already broken.

JorikSchellekens commented 2 years ago

I've opened some prs for it which could wait until another breaking change comes along. More importantly perhaps starknet-devnet should check the port is free and fail early, I can look into that later.

FabijanC commented 2 years ago

@ccarnino You said you'd like to be pinged on MacOS issues, did you also experience this issue with an occupied port? I'm asking because I'm not sure if all mac users are experiencing this. E.g. the CI/CD pipeline starknet-hardhat-plugin includes some integration tests that run Devnet on a mac virtual machine, and it works fine with the default settings.

clacladev commented 2 years ago

I personally have not experienced this problem, unless I was trying to run another devnet in another terminal by mistake.

@JorikSchellekens @janek26 what kind of issues or how do you realise that devnet is failing behind the scenes because of this issue?

JorikSchellekens commented 2 years ago

@ccarnino this is a monterey specific issue https://developer.apple.com/forums/thread/682332

JorikSchellekens commented 2 years ago

None of the tests on https://github.com/Shard-Labs/starknet-hardhat-example would run. The following is the result of running the tests:

 yarn test                                                                                                                             [7d3h10m] ✖ ✹ ✭
yarn run v1.22.17
$ npx hardhat --network localhost test
Starknet plugin using dockerized environment (shardlabs/cairo-cli:0.7.1)
Using network devnet at http://localhost:5000

  Starknet
Started deployment
HardhatPluginError: Got ClientConnectorError
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 986, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 962, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 949, in create_connection
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 473, in sock_connect
    return await fut
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 503, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 5000)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/services/external_api/base_client.py", line 112, in _send_request
    method=send_method, url=url, data=data
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 1138, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 536, in _request
    req, traces=traces, timeout=real_timeout
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 1187, in _create_direct_connection
    client_error=client_error,
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host localhost:5000 ssl:default [Connect call failed ('127.0.0.1', 5000)]
Error: ClientConnectorError: Cannot connect to host localhost:5000 ssl:default [Connect call failed ('127.0.0.1', 5000)]

    at /Users/jorik/dev/nethermind/starknet-hardhat-example/node_modules/@shardlabs/starknet-hardhat-plugin/src/types.ts:110:15
    at Generator.next (<anonymous>)
    at fulfilled (/Users/jorik/dev/nethermind/starknet-hardhat-example/node_modules/@shardlabs/starknet-hardhat-plugin/dist/types.js:24:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
Retrying transaction status check...
HardhatPluginError: Got ClientConnectorError
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 986, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 962, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 949, in create_connection
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 473, in sock_connect
    return await fut
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 503, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 5000)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/services/external_api/base_client.py", line 112, in _send_request
    method=send_method, url=url, data=data
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 1138, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 536, in _request
    req, traces=traces, timeout=real_timeout
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 1187, in _create_direct_connection
    client_error=client_error,
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host localhost:5000 ssl:default [Connect call failed ('127.0.0.1', 5000)]
Error: ClientConnectorError: Cannot connect to host localhost:5000 ssl:default [Connect call failed ('127.0.0.1', 5000)]

    at /Users/jorik/dev/nethermind/starknet-hardhat-example/node_modules/@shardlabs/starknet-hardhat-plugin/src/types.ts:110:15
    at Generator.next (<anonymous>)
    at fulfilled (/Users/jorik/dev/nethermind/starknet-hardhat-example/node_modules/@shardlabs/starknet-hardhat-plugin/dist/types.js:24:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
Retrying transaction status check...

Meanwhile the server reports a single successful post:

starknet-devnet                                                                                                                                [2h32m]
 * Running on http://localhost:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [10/Mar/2022 16:07:51] "POST /gateway/add_transaction HTTP/1.1" 200 -
clacladev commented 2 years ago

I am on Monterey too. And I have the Airplay Receiver option On. I am running starknet-devnet from console, not from docker.

And no my test don't throw that error.

clacladev commented 2 years ago

Try to use python 3.9. I had problems with 3.7

clacladev commented 2 years ago

This is the guide I use to startup my dev environment https://github.com/ccarnino/starknet-hardhat-typescript-example

janek26 commented 2 years ago

me and my colleagues at argent had this issue aswell. thanks for pushing on it @JorikSchellekens

FabijanC commented 2 years ago

More importantly perhaps starknet-devnet should check the port is free and fail early, I can look into that later.

@JorikSchellekens Update us when you can, from what I've seen this should be fairly simple in Python with resources being a part of the standard library.