lbryio / lbry-sdk

The LBRY SDK for building decentralized, censorship resistant, monetized, digital content apps.
https://lbry.com
MIT License
7.2k stars 483 forks source link

Using wrong part of the result to check compatible version #3738

Open ben221199 opened 1 month ago

ben221199 commented 1 month ago

Dear,

When analyzing the code and writing my own hub, I struggled with the server.version method. In LBRY a request of server.version looks like {"method":"server.version","id":58,"jsonrpc":"2.0","params":["0.113.0","0.113.0"]} and a response looks like {"jsonrpc":"2.0","result":["0.107.0","0.113.0"],"id":47}. At first glance, it doesn't look compatible with the server.version of Electrum, but it is.

First the request. Electrum defines server.version(client_name, protocol_version), where client_name is the name of the client and protocol_version is the supported version or range of supported versions of the client. When looking at the code at https://github.com/lbryio/hub/blob/ebcc6e508660f72fe11d308ae4031971b5fbf782/hub/herald/session.py#L1688, this is indeed the case. The LBRY request is fully compatible with the Electrum request, so it is also possible to send a request like {"method":"server.version","id":58,"jsonrpc":"2.0","params":["LBRY Desktop 1.0.0","0.113.0"]} or {"method":"server.version","id":58,"jsonrpc":"2.0","params":["LBRY Desktop 1.0.0",["0.113.0","0.113.0"]]}.

Then the response. Electrum defines it as returning [server_software_version, protocol_version], where server_software_version is the name of server and protocol_version is the chosen protocol version by the server to communicate with. Looking at https://github.com/lbryio/hub/blob/ebcc6e508660f72fe11d308ae4031971b5fbf782/hub/herald/session.py#L1695 and https://github.com/lbryio/hub/blob/ebcc6e508660f72fe11d308ae4031971b5fbf782/hub/herald/session.py#L1723, it indeed returns 2 variables.

Now we take a look at the following code: https://github.com/lbryio/lbry-sdk/blob/eb5da9511e162ef1080cb34af2ee087383cfa94a/lbry/wallet/network.py#L106

Note the response[0]. Why does this client code check for the first variable? The protocol information is in the second variable. I assume that response[1] is the right solution.


Also, some logging (note line 106):

2024-05-21 21:34:42,756 ERROR    lbry.wallet.network:219: wallet server connection loop crashed
Traceback (most recent call last):
  File "lbry\wallet\network.py", line 216, in loop_task_done_callback
  File "lbry\wallet\network.py", line 321, in network_loop
  File "lbry\wallet\network.py", line 304, in connect_to_fastest
  File "lbry\wallet\network.py", line 106, in ensure_server_version
  File "lbry\wallet\network.py", line 106, in <genexpr>
ValueError: invalid literal for int() with base 10: 'LBRYum Hub 1'