internet-sicherheit / ethereum-cache-creator

GNU General Public License v3.0
0 stars 0 forks source link

Connect via websocket #43

Closed Mschnuff closed 4 years ago

Mschnuff commented 4 years ago

Work in Progress

First attempt to connect to the bloxberg-network via websocket instead of http. Existing code can be used as a base to work on issue 41. throws WebsocketNotConnectedException (build failure is deliberate) textoutput indicates that the websocket is not open:

[INFO] Running de.internetsicherheit.brl.bloxberg.cache.ethereum.BloxbergClientTests
websocket socket: Socket[addr=core.bloxberg.org/130.183.206.234,port=80,localport=57242]
websocket is open: false
successfully build Web3j object.

I am actually not sure how to proceed from here. I try to read up on this topic a little bit.

kiview commented 4 years ago

Please try the following URLs:

https://websockets.bloxberg.org
wss://websockets.bloxberg.org
Mschnuff commented 4 years ago

running with wss://websockets.bloxberg.org gives following result:

[ERROR] Tests run: 3, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 61.953 s <<< FAILURE! - in de.internetsicherheit.brl.bloxberg.cache.ethereum.BloxbergClientTests
[ERROR] blockNumber  Time elapsed: 60.188 s  <<< ERROR!
java.io.IOException: Request with id 2 timed out

running with ws://websockets.bloxberg.org gives following result:

[INFO] Running BlockDataExtractorTest
websocket socket: Socket[addr=websockets.bloxberg.org/130.183.206.234,port=80,localport=36390]
websocket is open: false
successfully build Web3j object.
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.274 s - in BlockDataExtractorTest
[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   BloxbergClientTests.blockNumber:20 » WebsocketNotConnected

running with https://websockets.bloxberg.org gives following result:

[INFO] Running BlockDataExtractorTest
12:53:59.785 [WebSocketConnectReadThread-41] ERROR org.web3j.protocol.websocket.WebSocketClient - WebSocket connection to https://websockets.bloxberg.org/ failed with error
java.lang.IllegalArgumentException: unknown scheme: https
kiview commented 4 years ago

So the wss://websockets.bloxberg.org is obviously the correct one. Check why timeout happens, or if the API becomes different, potentially asynchronous or something.

Mschnuff commented 4 years ago

I notice java wants to use port 80 or 443 (these are the defaults for ws and wss). chinmay keeps telling me about port 8546. with local parity (ws://localhost:8546 ) I get this result:

[INFO] Running BlockDataExtractorTest
websocket socket: Socket[addr=localhost/127.0.0.1,port=8546,localport=34172]
websocket is open: true
successfully build Web3j object.
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.321 s - in BlockDataExtractorTest
[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   BloxbergClientTests.blockNumber » IO Request with id 2 timed out
[INFO] 
[ERROR] Tests run: 14, Failures: 0, Errors: 1, Skipped: 0

The websocket is open. but there is no data to extract.

kiview commented 4 years ago

Instead of testing against a local empty parity (is it empty or not?), I recommend testing against Ethereum mainnet, which can be done using Infura: https://infura.io/product

I did this for checking the uncles code.

kiview commented 4 years ago

Bloxberg people said, they assume it should run on port 8546.

Mschnuff commented 4 years ago

yeah ok so with infura i get the same errors. requests timing out.

kiview commented 4 years ago

Alright, this gives us some indication that the code is the problem and not the Websocket service from bloxberg.

There are different ways to use WebSockets, blocking or non-blocking, I assume it is related. See these tests from Web3j to get some examples: https://github.com/web3j/web3j/blob/63facc546031c7ea2d9825b3100559ce459c202d/core/src/test/java/org/web3j/protocol/websocket/WebSocketServiceTest.java

Mschnuff commented 4 years ago

ok so that s weird if i add a listener to the websocketclient I do get a message with the version number for both bloxberg and infura. So the websocketclient is responding in some way:

kiview commented 4 years ago

For me this means, Websocket connection works, you now just need to identify the programming model to interact with it correctly from web3j.

Mschnuff commented 4 years ago

Since this is based on an outdated master branch and the commits became increasingly chaotic and unreadable, I opened a new pull request with cleaner code: pull request #46

Mschnuff commented 4 years ago

should we close this? it is confusing to have 2 pull requests open that sound so similar.