Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Websocket not working #379

Open
m-bo-one opened this issue Jun 3, 2022 · 6 comments
Open

Websocket not working #379

m-bo-one opened this issue Jun 3, 2022 · 6 comments
Assignees
Labels
help wanted Extra attention is needed v1

Comments

@m-bo-one
Copy link

m-bo-one commented Jun 3, 2022

when I am trying to connect blockscout exporer with wss://godwoken-testnet-v1.ckbapp.dev/ws url (https://github.com/nervosnetwork/godwoken-info/tree/main/testnet_v1_1#godwoken-web3-rpc), explorer, I am getting

2022-06-02T16:46:55.156 [info] TLS :client: In state :wait_cert_cr at ssl_handshake.erl:1971 generated CLIENT ALERT: Fatal - Certificate Expired

If I remove wss, just ws without tls, blockscout just hang. I also verified, that through websocat I am getting an error

websocat wss://godwoken-testnet-v1.ckbapp.dev/ws
websocat: WebSocketError: Received unexpected status code (405 Method Not Allowed)
websocat: error running
@e00dan
Copy link
Contributor

e00dan commented Jun 3, 2022

I have tried to reproduce the issue and I can't connect to WebSocket provider as well:
image

Full code:

const Web3 = require('web3');

/**
 * BEFORE USING THIS SCRIPT MAKE SURE TO REPLACE:
 * - <YOUR_CONTRACT_ABI>
 * - <YOUR_CONTRACT_ADDRESS>
 * - CONTRACT_ADDRESS variable value
 * - YOUR_READ_FUNCTION_NAME method name
 * - YOUR_WRITE_FUNCTION_NAME method name
 */

const ACCOUNT_PRIVATE_KEY = '0xd9066ff9f753a1898709b568119055660a77d9aae4d7a4ad677b8fb3d2a571e5'; // Replace this with your Ethereum private key with funds on Layer 2.
const CONTRACT_ABI = [
    {
      "inputs": [],
      "stateMutability": "payable",
      "type": "constructor"
    },
    {
      "inputs": [],
      "name": "get",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "stateMutability": "view",
      "type": "function"
    },
    {
      "inputs": [
        {
          "internalType": "uint256",
          "name": "x",
          "type": "uint256"
        }
      ],
      "name": "set",
      "outputs": [],
      "stateMutability": "payable",
      "type": "function"
    }
  ]; // this should be an Array []
const CONTRACT_ADDRESS = '0xd4A8b3018f0c79f6BD3375C89a5Db47ca11A1C35';

const web3 = new Web3('wss://godwoken-testnet-v1.ckbapp.dev/ws');

const account = web3.eth.accounts.wallet.add(ACCOUNT_PRIVATE_KEY);

async function readCall() {
    const contract = new web3.eth.Contract(CONTRACT_ABI, CONTRACT_ADDRESS);

    const callResult = await contract.methods.get().call({
        from: account.address
    });

    console.log(`Read call result: ${callResult}`);
}

async function writeCall() {
    const contract = new web3.eth.Contract(CONTRACT_ABI, CONTRACT_ADDRESS);

    const tx = contract.methods.set(333).send(
        {
            from: account.address,
            gas: 6000000
        }
    );

    tx.on('transactionHash', hash => console.log(`Write call transaction hash: ${hash}`));

    const receipt = await tx;

    console.log('Write call transaction receipt: ', receipt);
}

(async () => {
    const balance = BigInt(await web3.eth.getBalance(account.address));

    if (balance === 0n) {
        console.log(`Insufficient balance. Can't issue a smart contract call. Please deposit funds to your Ethereum address: ${account.address}`);
        return;
    }

    console.log('Calling contract...');

    // Check smart contract state before state change.
    await readCall();

    // Change smart contract state.
    await writeCall();

    // Check smart contract state after state change.
    await readCall();
})();

@RetricSu
Copy link
Contributor

RetricSu commented Jun 6, 2022

@jiangxianliang007 seems the testnet TLS is broken? I check web3 websocket works on local development.

@RetricSu
Copy link
Contributor

RetricSu commented Jun 6, 2022

we have updated the testnet ws configuration, can you check if it works now? @kuzirashi @m-bo-one

@Flouse Flouse added help wanted Extra attention is needed v1 labels Jun 6, 2022
@e00dan
Copy link
Contributor

e00dan commented Jun 6, 2022

we have updated the testnet ws configuration, can you check if it works now? @kuzirashi @m-bo-one

Works for me now

image

@m-bo-one
Copy link
Author

m-bo-one commented Jun 6, 2022

websockat works, however blockscout has the same issue:

2022-06-06T12:48:57.898 [notice] TLS :client: In state :wait_cert_cr at ssl_handshake.erl:2017 generated CLIENT ALERT: Fatal - Handshake Failure
 - {:bad_cert, :hostname_check_failed}

@blckngm
Copy link

blckngm commented Jun 7, 2022

websockat works, however blockscout has the same issue:

2022-06-06T12:48:57.898 [notice] TLS :client: In state :wait_cert_cr at ssl_handshake.erl:2017 generated CLIENT ALERT: Fatal - Handshake Failure
 - {:bad_cert, :hostname_check_failed}

Could be caused by this OTP problem described here:

By default OTP does not permit wildcards in SAN extensions, unless you opt-in using {customize_hostname_check, [{match_fun, public_key:pkix_verify_hostname_match_fun(https)}]}

(or, to be precise, by default it recognises wildcards only in Subject CN, and only when no SAN extension is present)

From: benoitc/hackney#624 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed v1
Projects
None yet
Development

No branches or pull requests

5 participants