hyperledger / besu

An enterprise-grade Java-based, Apache 2.0 licensed Ethereum client https://wiki.hyperledger.org/display/besu
https://www.hyperledger.org/projects/besu
Apache License 2.0
1.5k stars 822 forks source link

Event Listener Error: connection not open on send() #1237

Open ARR552 opened 4 years ago

ARR552 commented 4 years ago

Hello, I'm trying to read events in real time (Not past events). The docker compose is:

bootnode: build: context: besu/. args: BESU_VERSION: ${BESU_VERSION} image: sample-network/besu:${BESU_VERSION} environment:

  • BESU_PUBLIC_KEY_DIRECTORY=${BESU_PUBLIC_KEY_DIRECTORY} entrypoint: /opt/besu/bootnode_start.sh command: &base_options [ "--config-file=/config/config.toml", "--genesis-file=/config/genesis.json", "--node-private-key-file=/opt/besu/keys/key", "--min-gas-price=0", "--rpc-ws-enabled", "--rpc-http-api=WEB3,ETH,NET,EEA,ADMIN,${SAMPLE_POA_API-ibft}", "--rpc-ws-api=WEB3,ETH,NET,EEA,ADMIN,${SAMPLE_POA_API-ibft}"] volumes:
  • public-keys:${BESU_PUBLIC_KEY_DIRECTORY}
  • ./config/besu/config.toml:/config/config.toml
  • ./config/besu/${SAMPLE_POA_NAME-ibft2}Genesis.json:/config/genesis.json
  • ./config/besu/networkFiles/bootnode/keys:/opt/besu/keys

The config.toml has this content:

logging="INFO" data-path="/opt/besu/data" host-whitelist=["*"]

rpc-http-enabled=true rpc-http-host="0.0.0.0" rpc-http-port=8545 rpc-http-cors-origins=["*"]

rpc-ws-enabled=true rpc-ws-host="0.0.0.0" rpc-ws-port=8546 rpc-ws-api=["WEB3","ETH","NET","EEA","ADMIN"] rpc-ws-authentication-enabled=false

graphql-http-enabled=true graphql-http-host="0.0.0.0" graphql-http-port=8547 graphql-http-cors-origins=["*"]

metrics-enabled=true metrics-host="0.0.0.0" metrics-port=9545

The script that i am using to read events:

const Web3 = require('web3'); var web3 = new Web3('ws://localhost:8546') const abi = [{ "anonymous": false, "inputs": [{ "indexed": false, "internalType": "address", "name": "sender", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "eventValue", "type": "event" }, { "inputs": [{ "internalType": "uint256", "name": "_val", "type": "uint256" }], "name": "launchEvent", "outputs": [], "stateMutability": "nonpayable", "type": "function" }]; const contractAddress = "0xBe0B0f08A599F07699E98A9D001084e97b9a900A";

var contractsInstance = new web3.eth.Contract(abi, contractAddress); contractsInstance.events.allEvents({ address: contractAddress, fromBlock: 0 }, function (error, event) { console.log(event); }) .on('data', function (event) { console.log(event); }) .on('changed', function (event) { }) .on('error', console.error);

When I run the script I get the following error all the time:

node ReadEvent.js null Error: connection not open on send() at Object.ConnectionError (/home/rr/Documentos/git/events/node_modules/web3-core-helpers/src/errors.js:72:23) at Object.ConnectionNotOpenError (/home/rr/Documentos/git/events/node_modules/web3-core-helpers/src/errors.js:51:21) at /home/rr/Documentos/git/events/node_modules/web3-providers-ws/src/index.js:183:37 at Map.forEach () at WebsocketProvider._onClose (/home/rr/Documentos/git/events/node_modules/web3-providers-ws/src/index.js:182:27) at W3CWebSocket._dispatchEvent [as dispatchEvent] (/home/rr/Documentos/git/events/node_modules/yaeti/lib/EventTarget.js:115:12) at W3CWebSocket.onConnectFailed (/home/rr/Documentos/git/events/node_modules/websocket/lib/W3CWebSocket.js:219:14) at WebSocketClient. (/home/rr/Documentos/git/events/node_modules/websocket/lib/W3CWebSocket.js:59:25) at WebSocketClient.emit (events.js:315:20) at ClientRequest.handleRequestError (/home/rr/Documentos/git/events/node_modules/websocket/lib/WebSocketClient.js:227:14) at ClientRequest.emit (events.js:315:20) at Socket.socketErrorListener (_http_client.js:426:9) at Socket.emit (events.js:315:20) at emitErrorNT (internal/streams/destroy.js:92:8) at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) at processTicksAndRejections (internal/process/task_queues.js:84:21) { code: 1006, reason: 'connection failed' } false Error: connection not open on send() at Object.ConnectionError (/home/rr/Documentos/git/events/node_modules/web3-core-helpers/src/errors.js:72:23) at Object.ConnectionNotOpenError (/home/rr/Documentos/git/events/node_modules/web3-core-helpers/src/errors.js:51:21) at /home/rr/Documentos/git/events/node_modules/web3-providers-ws/src/index.js:183:37 at Map.forEach () at WebsocketProvider._onClose (/home/rr/Documentos/git/events/node_modules/web3-providers-ws/src/index.js:182:27) at W3CWebSocket._dispatchEvent [as dispatchEvent] (/home/rr/Documentos/git/events/node_modules/yaeti/lib/EventTarget.js:115:12) at W3CWebSocket.onConnectFailed (/home/rr/Documentos/git/events/node_modules/websocket/lib/W3CWebSocket.js:219:14) at WebSocketClient. (/home/rr/Documentos/git/events/node_modules/websocket/lib/W3CWebSocket.js:59:25) at WebSocketClient.emit (events.js:315:20) at ClientRequest.handleRequestError (/home/rr/Documentos/git/events/node_modules/websocket/lib/WebSocketClient.js:227:14) at ClientRequest.emit (events.js:315:20) at Socket.socketErrorListener (_http_client.js:426:9) at Socket.emit (events.js:315:20) at emitErrorNT (internal/streams/destroy.js:92:8) at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) at processTicksAndRejections (internal/process/task_queues.js:84:21) { code: 1006, reason: 'connection failed' }

I able to recover the events in ganache but I don't know what I'm doing wrong.

¿Any idea?

Thank you

"web3": "^1.2.11" Besu: latest version

shemnon commented 4 years ago

First, what version of Besu are you using?

You are querying all events from block zero and we are timing out getting all the events.

fromBlock: 0 Change that to a more current block, or leave the option out.

Finally, what network is being connected to?

ARR552 commented 4 years ago

Hey @shemnon I'm using besu/v1.5.0/linux-x86_64/oracle_openjdk-java-11 (docker version) I'm getting the same error removing fromBlock: 0. What do you mean when you ask to which network i am connected to?

MadelineMurray commented 4 years ago

@ARR552 - are you connected to a public network (eg, mainnet, rinkeby, etc) or to a private network?

shemnon commented 4 years ago

Can you change the fromBlock: to a block number closer to the chainhead?

ARR552 commented 4 years ago

@MadelineMurray I am connected to a private network. However the same code in ganache is working. @shemnon I try with block 9000 (the chain has only 9500 blocks for now) but i get the same error.

shemnon commented 4 years ago

It must be something other than too many logs. We will need to reproduce this in-house. How loaded is the chain with data? Is the contract you are calling open source?

ARR552 commented 4 years ago

pragma solidity ^0.6.11;

contract eventContract {

event eventValue(address sender, uint amount); // Event

function launchEvent(uint _val) public {
    emit eventValue(msg.sender, _val); // Triggering event
}

} Only this SmartContract is deployed on the besu network. Maybe it is a configuration problem, I don't know.