rollkit / rollkit

A modular framework for rollups, with an ABCI-compatible client interface.
Apache License 2.0
337 stars 160 forks source link

Tendermint WebSocket not allowed by Upgrader.CheckOrigin #742

Closed nodebreaker0-0 closed 1 year ago

nodebreaker0-0 commented 1 year ago

version: https://github.com/nodebreaker0-0/crescent/blob/crescent-sdk-rollmint-v0.0.0/go.mod#L348

A bug was detected while trying to send a transaction through a web socket.

web-log : WebSocket connection to 'wss://cel-cre.crescent.network:26657/websocket' failed: Error sign TX Error: hex string contains invalid characters

node-log : 12:10PM ERR failed to update to WebSocket connection error="websocket: request origin not allowed by Upgrader.CheckOrigin"

It's not happening in the standard tender mint, is there a solution?

jcstein commented 1 year ago

I'm experiencing something similar, with the same error

i’m working on connecting a gm rollup to a frontend, but running into an error with cors permissions on websockets for the RPC (26657). i did some research on what is required to enable wss connections from anywhere, and before starting the chain, i now am modifying cors_allowed_origins = [] to cors_allowed_origins = ["*"] in .gm/config/config.toml

Reproduction

Here are the steps to reproduce:

  1. https://github.com/rollkit/gm clone this
  2. run a blockspacerace light node that is funded and has gateway flags to enable submitting PFBs
  3. run the rollup from the repo above using bash init-local.sh in the root of the gm directory
    • as a sanity check, open the ~/.gm/config/config.toml and verify that the [rpc] section has changed cors_allowed_origins = [] to cors_allowed_origins = ["*"]
  4. go to https://rollkit-frontend.vercel.app/multi-chain and search for “my gm rollup”
  5. click connect wallet
  6. accept the chain info
    • NOTE: I have confirmed with the Cosmology team that there is a check being performed on the RPCs either given by chain-registry or by the config I have set up for this custom rollup, and if the check fails (i.e. if WSS is not accessible) it will suggest endpoints from a public directory called cosmos.directory
      # example of connection data in keplr
      {
      "rpc": "https://rpc.cosmos.directory/gmrollup",
      "rest": "https://rest.cosmos.directory/gmrollup",
      "chainId": "gm",
      "chainName": "my gm rollup",
      ...
  7. go to Keplr > settings > endpoints > and manually add http://127.0.0.1:26657/ as RPC and http://127.0.0.1:1317/ for LCD
  8. this is where i hit the error:
    • on the Rollkit gm node: 5:12PM ERR failed to update to WebSocket connection error="websocket: request origin not allowed by Upgrader.CheckOrigin"
    • and on Keplr:

debugging

I worked with @tuxcanfly on this testing out a few things to isolate the issue:

  1. we removed the part of the script that changes cors_allowed_origins = [] to cors_allowed_origins = ["*"], and saw the same behavior
  2. we tried adding a tendermint flag for --rpc.cors_allowed_origins, this is not in the Rollkit node's CLI menu, so it failed to start chain, which is expected
  3. we tried cors_allowed_origins = ["localhost"] and saw the same error
  4. we tried cors_allowed_origins = ["0.0.0.0"] and saw the same error
  5. using websocat (brew install websocat) and running websocat ws://127.0.0.1:26657/websocket, the connection opened. then, sending { "jsonrpc": "2.0", "method": "subscribe", "params": ["tm.event='NewBlock'"], "id": 1 } resulted in {"jsonrpc":"2.0","error":{"code":-32600,"message":"json: cannot unmarshal string into Go value of type json.subscribeArgs","data":["tm.event='NewBlock'"]},"id":1}
  6. In keplr, we used these domains, but all had the same result: http://127.0.0.1:26657, http://localhost:26657, and http://0.0.0.0:26657
  7. used the --rpc.unsafe flag in the init-local.sh script on the rollkit start command, same result

i’m not getting an error for the API endpoint (port 1317). i enabled it using --api.enable --api.enabled-unsafe-cors, so I think that this is working properly

Related issues

Keplr issue & why we need websockets:

3 WS related issues here: https://github.com/rollkit/rollkit/issues/448

Tendermint issue: https://github.com/tendermint/tendermint/issues/9316

It looks like the following may be related to fixes for the REST API (but not for the RPC, which is the issue we are facing now)

jcstein commented 1 year ago

More debugging

Video: https://www.loom.com/share/ab6e87f5ef224c74a864881dbed37b01

  1. using this branch made by @tuxcanfly https://github.com/rollkit/rollkit/tree/tux/websocket-cors
  2. I updated my fork of cosmos-sdk https://github.com/jcstein/cosmos-sdk/tree/release/v0.46.x-rollkit
  3. and made a new branch of the gm repository i am testing with https://github.com/rollkit/gm/tree/test-cors

good news, i don't get the same error

not so great news, we have a new one 😈 3:41PM ERR failed to read next WebSocket message error="websocket: close 1005 (no status)" and on keplr it says: Failed to get response /cosmos/base/tendermint/v1beta1/node_info from lcd endpoint

If i curl the endpoint:

curl -X GET "http://localhost:1317/cosmos/base/tendermint/v1beta1/node_info" -H  "accept: application/json"
{
  "code": 12,
  "message": "unknown service cosmos.base.tendermint.v1beta1.Service",
  "details": [
  ]
}

I see the following on my logs on rollkit node:

4:04PM DBG served RPC HTTP response duration=0 method=GET module=api-server remoteAddr=127.0.0.1:56878 status=501 url={"ForceQuery":false,"Fragment":"","Host":"","OmitHost":false,"Opaque":"","Path":"/cosmos/base/tendermint/v1beta1/node_info","RawFragment":"","RawPath":"","RawQuery":"","Scheme":"","User":null}

4:05PM DBG served RPC HTTP response duration=0 method=GET module=api-server remoteAddr=[::1]:56914 status=501 url={"ForceQuery":false,"Fragment":"","Host":"","OmitHost":false,"Opaque":"","Path":"/[object Module]","RawFragment":"","RawPath":"/[object%20Module]","RawQuery":"","Scheme":"","User":null}

When I try to use the frontend at http://localhost:1317 to test the endpoint, i see the same details/errors:

image

nodebreaker0-0 commented 1 year ago

@jcstein @tuxcanfly Thanks guys, We've already seen the just pre-forking that part for quick app adoption! https://github.com/nodebreaker0-0/rollkit/tree/v0.7.3-wsorg

jcstein commented 1 year ago

gm @nodebreaker0-0 - were you able to bypass the Failed to get response /cosmos/base/tendermint/v1beta1/node_info from lcd endpoint or 3:41PM ERR failed to read next WebSocket message error="websocket: close 1005 (no status)" errors?

nodebreaker0-0 commented 1 year ago

@jcstein gm bro, hmm... It all is well,

this is the SovereignChain product endpoint using the rollkit below. Try what you're trying to do!

wss://cel-cre.crescent.network:26657/websocket

https://cel-cre.crescent.network:1317/cosmos/base/tendermint/v1beta1/node_info

If this succeeds, see the code below, please note that if the code deviates much from the SDK standards, the probability of errors will increase.

https://github.com/nodebreaker0-0/rollkit/tree/v0.7.4-ws-main

Your configuration may be incorrect,

config.toml cors_allowed_origins = ["*", ] experimental_close_on_slow_client = false

jcstein commented 1 year ago

thanks @nodebreaker0-0!

i do have in my config.toml: cors_allowed_origins = ["*"] and experimental_close_on_slow_client = false

jcstein commented 1 year ago

cc @nashqueue

tuxcanfly commented 1 year ago

Tested and was be fixed by #864 @nodebreaker0-0

websocat ws://127.0.0.1:26657/websocket

{ "jsonrpc": "2.0", "method": "subscribe", "id": 7, "params": { "query": "tm.event='NewBlock'" } } {"jsonrpc":"2.0","result":{},"id":7}

There is still unknown service cosmos.base.tendermint.v1beta1.Service which is the same as #944 so let's follow up there.