Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Websocket] - Websocket returns binary code instead of Json. #2226

Closed
2 tasks done
maestroi opened this issue Feb 16, 2024 · 7 comments · Fixed by #2269
Closed
2 tasks done

[Websocket] - Websocket returns binary code instead of Json. #2226

maestroi opened this issue Feb 16, 2024 · 7 comments · Fixed by #2269
Assignees

Comments

@maestroi
Copy link
Contributor

New issue checklist

General information

  • Library version(s): 0.20 +
  • Browser version(s): -
  • Devices/Simulators/Machine affected: -
  • Reproducible in the testnet? (Yes/No): Yes
  • Related issues: -

Bug report

Expected behavior

Connecting with websocket and send a subscribe for block giving back Json blobs.

Actual behavior

If you connect to websocket with something like postman and send a subscribe message you get Json in binary format back.

Steps to reproduce

Connect:
wss://rpc-testnet.nimiqcloud.com/ws

{
"jsonrpc": "2.0",
"id": 1,
"method": "subscribeForHeadBlock",
"params": [true]
}

Crash log? Screenshots? Videos? Sample project?

00000000: 7B 22 6A 73 6F 6E 72 70 63 22 3A 22 32 2E 30 22 {"jsonrpc":"2.0"
00000010: 2C 22 6D 65 74 68 6F 64 22 3A 22 73 75 62 73 63 ,"method":"subsc
00000020: 72 69 62 65 46 6F 72 48 65 61 64 42 6C 6F 63 6B ribeForHeadBlock
00000030: 22 2C 22 70 61 72 61 6D 73 22 3A 7B 22 73 75 62 ","params":{"sub
00000040: 73 63 72 69 70 74 69 6F 6E 22 3A 31 32 35 32 2C scription":1252,
00000050: 22 72 65 73 75 6C 74 22 3A 7B 22 64 61 74 61 22 "result":{"data"
00000060: 3A 7B 22 68 61 73 68 22 3A 22 38 35 61 64 31 36 :{"hash":"85ad16
00000070: 35 37 34 62 30 33 35 38 38 66 65 34 61 36 61 38 574b03588fe4a6a8
00000080: 37 33 30 38 32 61 30 62 64 64 61 31 65 64 36 63 73082a0bdda1ed6c
00000090: 38 64 63 63 34 33 32 63 35 64 35 62 31 36 34 31 8dcc432c5d5b1641
000000a0: 62 61 39 65 62 61 33 63 37 30 22 2C 22 73 69 7A ba9eba3c70","siz
000000b0: 65 22 3A 33 33 38 2C 22 62 61 74 63 68 22 3A 33 e":338,"batch":3
000000c0: 35 2C 22 65 70 6F 63 68 22 3A 31 2C 22 6E 65 74 5,"epoch":1,"net
000000d0: 77 6F 72 6B 22 3A 22 54 65 73 74 41 6C 62 61 74 work":"TestAlbat
000000e0: 72 6F 73 73 22 2C 22 76 65 72 73 69 6F 6E 22 3A ross","version":
000000f0: 31 2C 22 6E 75 6D 62 65 72 22 3A 31 36 33 33 37 1,"number":16337
00000100: 36 31 36 2C 22 74 69 6D 65 73 74 61 6D 70 22 3A 616,"timestamp":
00000110: 31 37 30 38 31 31 38 34 32 34 35 33 32 2C 22 70 1708118424532,"p
00000120: 61 72 65 6E 74 48 61 73 68 22 3A 22 30 63 66 63 arentHash":"0cfc
00000130: 36 62 37 39 62 61 31 37 64 63 34 36 65 39 33 32 6b79ba17dc46e932
00000140: 39 39 65 33 65 34 33 37 35 39 64 64 33 37 66 30 99e3e43759dd37f0
00000150: 63 39 33 30 35 37 64 65 66 62 36 64 39 63 38 62 c93057defb6d9c8b
00000160: 66 32 64 65 65 65 39 66 65 31 65 33 22 2C 22 73 f2deee9fe1e3","s
00000170: 65 65 64 22 3A 22 30 32 62 62 35 33 34 39 35 38 eed":"02bb534958
00000180: 66 63 63 31 37 64 32 37 66 35 34 31 33 65 66 37 fcc17d27f5413ef7
00000190: 39 65 39 66 62 62 34 63 31 33 31 65 66 63 39 66 9e9fbb4c131efc9f
000001a0: 37 38 66 65 35 32 31 38 35 62 37 38 36 34 31 33 78fe52185b786413
000001b0: 64 63 31 62 65 35 65 36 65 31 62 33 32 66 62 65 dc1be5e6e1b32fbe
000001c0: 32 31 62 32 66 30 62 63 31 31 61 32 31 39 64 66 21b2f0bc11a219df
000001d0: 65 39 39 62 65 35 32 62 31 66 62 30 64 64 65 65 e99be52b1fb0ddee
000001e0: 30 36 38 65 62 35 31 63 37 65 38 62 31 31 66 61 068eb51c7e8b11fa
000001f0: 32 34 37 32 30 65 66 63 32 39 33 31 34 62 35 30 24720efc29314b50
00000200: 31 63 31 32 36 62 36 63 36 65 31 39 30 33 37 30 1c126b6c6e190370
00000210: 63 65 64 38 32 37 31 37 37 35 63 39 35 32 38 31 ced8271775c95281
00000220: 35 61 39 62 32 37 66 39 64 63 35 66 37 31 30 32 5a9b27f9dc5f7102
00000230: 30 35 34 32 30 61 22 2C 22 65 78 74 72 61 44 61 05420a","extraDa
00000240: 74 61 22 3A 22 22 2C 22 73 74 61 74 65 48 61 73 ta":"","stateHas
00000250: 68 22 3A 22 66 39 65 39 66 36 36 37 66 34 30 39 h":"f9e9f667f409
00000260: 31 65 65 36 61 32 62 32 66 36 36 65 65 31 62 34 1ee6a2b2f66ee1b4
00000270: 62 31 65 32 62 65 31 31 35 31 38 31 65 65 34 38 b1e2be115181ee48
00000280: 38 35 39 66 36 66 38 36 61 64 35 35 61 64 32 66 859f6f86ad55ad2f
00000290: 34 66 39 37 22 2C 22 62 6F 64 79 48 61 73 68 22 4f97","bodyHash"
000002a0: 3A 22 37 37 34 66 39 30 31 38 62 34 62 32 63 64 :"774f9018b4b2cd
000002b0: 63 30 38 66 38 39 32 38 65 38 39 62 30 64 39 36 c08f8928e89b0d96
000002c0: 33 61 63 33 38 38 65 35 33 37 62 30 30 33 34 39 3ac388e537b00349
000002d0: 32 63 36 39 61 61 66 65 65 61 62 39 37 36 65 35 2c69aafeeab976e5
000002e0: 35 33 22 2C 22 68 69 73 74 6F 72 79 48 61 73 68 53","historyHash
000002f0: 22 3A 22 62 35 39 65 38 33 32 31 31 33 31 38 61 ":"b59e83211318a
00000300: 37 64 31 31 64 62 35 35 36 39 33 61 61 61 66 66 7d11db55693aaaff
00000310: 64 61 36 39 34 61 38 31 61 35 66 36 34 66 30 30 da694a81a5f64f00
00000320: 34 36 34 39 62 38 33 61 31 36 39 61 65 61 33 33 4649b83a169aea33
00000330: 63 39 34 22 2C 22 74 72 61 6E 73 61 63 74 69 6F c94","transactio
00000340: 6E 73 22 3A 5B 5D 2C 22 74 79 70 65 22 3A 22 6D ns":[],"type":"m
00000350: 69 63 72 6F 22 2C 22 70 72 6F 64 75 63 65 72 22 icro","producer"
00000360: 3A 7B 22 73 6C 6F 74 4E 75 6D 62 65 72 22 3A 36 :{"slotNumber":6
00000370: 32 2C 22 76 61 6C 69 64 61 74 6F 72 22 3A 22 4E 2,"validator":"N
00000380: 51 39 34 20 35 38 52 38 20 59 44 52 35 20 30 35 Q94.58R8.YDR5.05
00000390: 45 58 20 4A 54 41 34 20 33 37 4A 55 20 4E 31 45 EX.JTA4.37JU.N1E
000003a0: 4B 20 36 52 33 51 20 4D 39 43 35 22 2C 22 70 75 K.6R3Q.M9C5","pu
000003b0: 62 6C 69 63 4B 65 79 22 3A 22 32 35 31 35 34 34 blicKey":"251544
000003c0: 33 65 32 39 39 35 66 66 62 65 30 62 66 63 30 30 3e2995ffbe0bfc00
000003d0: 65 33 65 34 63 38 63 36 65 64 62 64 39 65 39 35 e3e4c8c6edbd9e95
000003e0: 31 32 31 62 31 62 35 33 34 65 37 66 35 65 34 63 121b1b534e7f5e4c
000003f0: 35 65 63 61 62 38 65 32 35 61 34 32 64 38 66 31 5ecab8e25a42d8f1
00000400: 64 38 33 35 63 30 39 35 65 33 38 61 32 38 63 64 d835c095e38a28cd
00000410: 33 31 32 35 62 35 35 35 63 38 36 39 36 61 34 36 3125b555c8696a46
00000420: 64 32 34 37 31 35 33 32 39 31 38 65 31 30 63 35 d2471532918e10c5
00000430: 36 30 31 33 66 61 62 64 66 38 33 30 31 65 33 34 6013fabdf8301e34
00000440: 61 34 37 62 32 36 33 65 66 37 35 65 34 64 32 63 a47b263ef75e4d2c
00000450: 36 33 61 66 66 38 33 61 32 33 36 30 32 65 61 35 63aff83a23602ea5
00000460: 32 35 66 30 39 62 33 34 62 38 65 30 34 36 61 31 25f09b34b8e046a1
00000470: 62 32 66 61 38 65 30 30 61 37 38 62 65 34 63 64 b2fa8e00a78be4cd
00000480: 63 63 32 32 32 30 34 36 39 34 37 63 30 62 36 34 cc222046947c0b64
00000490: 38 35 66 39 32 39 32 34 30 62 33 32 39 31 30 38 85f929240b329108
000004a0: 62 30 66 37 64 65 63 63 62 33 37 62 35 33 66 65 b0f7deccb37b53fe
000004b0: 39 32 32 39 61 35 63 63 63 35 36 35 34 65 61 30 9229a5ccc5654ea0
000004c0: 61 35 61 36 31 36 37 30 33 34 62 33 64 38 33 32 a5a6167034b3d832
000004d0: 35 66 39 32 64 36 30 30 66 61 30 62 66 37 31 31 5f92d600fa0bf711
000004e0: 66 66 39 64 31 39 38 36 62 66 38 61 63 37 62 34 ff9d1986bf8ac7b4
000004f0: 63 38 63 63 38 64 62 64 64 33 30 32 38 30 33 61 c8cc8dbdd302803a
00000500: 38 31 36 35 32 34 36 34 36 65 66 63 31 30 32 34 816524646efc1024
00000510: 37 34 35 38 39 32 31 35 33 61 65 62 31 37 66 32 745892153aeb17f2
00000520: 65 63 66 65 39 62 30 30 38 33 65 35 36 31 31 64 ecfe9b0083e5611d
00000530: 39 63 31 65 30 31 36 61 35 65 37 32 66 38 35 32 9c1e016a5e72f852
00000540: 34 63 35 37 36 63 65 38 34 65 63 66 63 62 66 63 4c576ce84ecfcbfc
00000550: 30 32 35 62 31 35 38 34 37 37 34 64 35 34 35 34 025b1584774d5454
00000560: 32 35 34 65 62 65 63 36 61 32 63 33 64 30 61 33 254ebec6a2c3d0a3
00000570: 63 36 34 36 34 32 61 37 33 35 65 64 64 64 34 30 c64642a735eddd40
00000580: 65 36 33 39 61 64 39 36 65 31 35 33 65 66 64 33 e639ad96e153efd3
00000590: 30 66 37 62 62 39 61 30 32 37 64 33 66 65 37 38 0f7bb9a027d3fe78
000005a0: 61 37 33 63 37 62 66 64 66 38 61 61 38 35 64 34 a73c7bfdf8aa85d4
000005b0: 64 65 36 35 63 64 33 64 32 39 38 39 31 36 61 30 de65cd3d298916a0
000005c0: 30 31 35 30 37 30 34 64 62 35 30 31 37 64 31 65 0150704db5017d1e
000005d0: 32 35 32 39 65 62 66 61 35 31 32 32 65 39 38 39 2529ebfa5122e989
000005e0: 63 64 30 31 63 36 31 65 36 62 32 61 37 38 31 35 cd01c61e6b2a7815
000005f0: 30 36 38 30 22 7D 2C 22 65 71 75 69 76 6F 63 61 0680"},"equivoca
00000600: 74 69 6F 6E 50 72 6F 6F 66 73 22 3A 5B 5D 2C 22 tionProofs":[],"
00000610: 6A 75 73 74 69 66 69 63 61 74 69 6F 6E 22 3A 7B justification":{
00000620: 22 6D 69 63 72 6F 22 3A 22 65 32 39 39 35 32 61 "micro":"e29952a
00000630: 37 62 32 63 34 38 34 33 37 30 63 66 33 31 31 37 7b2c484370cf3117
00000640: 36 32 36 61 64 39 65 33 38 35 30 62 38 31 35 61 626ad9e3850b815a
00000650: 62 31 31 63 30 30 39 36 66 36 66 65 35 63 65 62 b11c0096f6fe5ceb
00000660: 38 65 38 65 34 31 64 36 37 33 64 64 64 30 62 38 8e8e41d673ddd0b8
00000670: 61 38 30 36 31 37 36 63 37 36 36 62 63 38 33 35 a806176c766bc835
00000680: 37 38 32 64 36 64 66 30 32 30 64 36 66 30 62 39 782d6df020d6f0b9
00000690: 64 62 31 65 63 63 36 33 62 63 34 34 38 35 62 62 db1ecc63bc4485bb
000006a0: 38 63 33 65 64 32 39 30 64 22 7D 7D 2C 22 6D 65 8c3ed290d"}},"me
000006b0: 74 61 64 61 74 61 22 3A 6E 75 6C 6C 7D 7D 7D tadata":null}}}

Question or Feature Request

Add layer to convert to Json blobs.

@hrxi
Copy link
Contributor

hrxi commented Feb 19, 2024

The hexdump looks like it contains correct JSON. What's needed here? Some type hint for the client to not display the hexdump?

@maestroi
Copy link
Contributor Author

Yeah it is valid json, but indeed, its read by default as binary instead of json, so some type of type hint

@sisou
Copy link
Member

sisou commented Feb 20, 2024

I think the issue stems from the fact that the albatross node RPC always responds in binary, although it accepts text-based request messages just fine. Usually a server responds in the same type as what the client sends. So if client sends text, should respond with text. If client sends binary, should reply in binary.

@hrxi
Copy link
Contributor

hrxi commented Feb 20, 2024

Can you give the command that leads to the output you posted @maestroi?

@jsdanielh jsdanielh self-assigned this Feb 20, 2024
@jsdanielh
Copy link
Member

I think the issue stems from the fact that the albatross node RPC always responds in binary, although it accepts text-based request messages just fine. Usually a server responds in the same type as what the client sends. So if client sends text, should respond with text. If client sends binary, should reply in binary.

Yeah, this is the case. Will take a look

@jsdanielh
Copy link
Member

I have a draft for addressing this in nimiq/jsonrpc#20. It's not tested yet

@maestroi
Copy link
Contributor Author

maestroi commented Feb 22, 2024

I used postman to connect, from otherprotocols seems to force just json response:

wss://rpc-testnet.nimiqcloud.com/ws

{
"jsonrpc": "2.0",
"id": 1,
"method": "subscribeForHeadBlock",
"params": [true]
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants