rust-electrum-client icon indicating copy to clipboard operation
rust-electrum-client copied to clipboard

[Feature] Version negotiation

Open Beanow opened this issue 4 years ago • 1 comments

Trying to connect to a BTG server at tcp://electrumx-eu.bitcoingold.org:50001 I found the server is rather old.

{"jsonrpc": "2.0", "method": "server.features", "params": [], "id": 2}
{"jsonrpc": "2.0", "result": {"hosts": {"electrumx-eu.bitcoingold.org": {"tcp_port": 50001, "ssl_port": 50002}}, "pruning": null, "server_version": "ElectrumX 1.8.12", "protocol_min": "1.2", "protocol_max": "1.4", "genesis_hash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", "hash_function": "sha256"}, "id": 2}

Because of this, it defaults to Electrum protocol 1.2 which isn't compatible with this client. We can negotiate version 1.4 though, as per https://electrumx.readthedocs.io/en/latest/protocol-basics.html#version-negotiation

{"jsonrpc": "2.0", "method": "server.version", "params": {"client_name": "telnet", "protocol_version": "1.4"}, "id": 5}
{"jsonrpc": "2.0", "result": ["ElectrumX 1.8.12", "1.4"], "id": 5}

Not only would this fix issues with the old server, it also future proofs the client for servers in the wild that may default to newer protocol versions than are supported. Plus it can give specific error messages when there's a compatibility issue.

Beanow avatar Sep 28 '21 13:09 Beanow

Update, BTG specifically is unlikely to work without changes to the bitcoin crate, as they've substantially changed the block header format. That said, it may still be an interesting forward compatibility feature.

Beanow avatar Sep 28 '21 15:09 Beanow