Skip to content

Expose negotiated protocol version#213

Open
tnull wants to merge 2 commits into
bitcoindevkit:masterfrom
tnull:2026-06-expose-protocol-version
Open

Expose negotiated protocol version#213
tnull wants to merge 2 commits into
bitcoindevkit:masterfrom
tnull:2026-06-expose-protocol-version

Conversation

@tnull

@tnull tnull commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

The v1.6 upgrade negotiated and stored the server protocol version during connection setup, but omitted the documented public API for reading it.

Add protocol_version() so callers can reuse the negotiated value. Only fall back to server.version when no cached version exists.

@oleonardolima oleonardolima left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK f78ed74

Overall it looks good! I pushed a commit fixing the CI, though.

@caarloshenriq caarloshenriq left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK fadedd9

I wrote this example to validate:

use electrum_client::{Client, Config, ElectrumApi, Socks5Config};
use std::env;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let url = env::args().nth(1).expect("uso: cargo run --example test_protocol_version -- <url> [socks5_addr]");
    let proxy = env::args().nth(2);

    let config = Config::builder()
        .validate_domain(false)
        .socks5(proxy.map(Socks5Config::new))
        .build();

    let client = Client::from_config(&url, config)?;
    println!("{} -> protocol_version = {}", url, client.protocol_version()?);

    let features = client.server_features()?;
    println!("server_features = {:#?}", features);

    Ok(())
}

and tested using these electrum url's

➜  rust-electrum-client git:(pr-213) - cargo run --example test_protocol_version -- "ssl://testnet.aranguren.org:51002"
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/examples/test_protocol_version 'ssl://testnet.aranguren.org:51002'`
ssl://testnet.aranguren.org:51002 -> protocol_version = 1.6
server_features = ServerFeaturesRes {
    server_version: "Fulcrum 2.1.1",
    genesis_hash: [
        0,
        0,
        0,
        0,
        9,
        51,
        234,
        1,
        173,
        14,
        233,
        132,
        32,
        151,
        121,
        186,
        174,
        195,
        206,
        217,
        15,
        163,
        244,
        8,
        113,
        149,
        38,
        248,
        215,
        127,
        73,
        67,
    ],
    protocol_min: "1.4",
    protocol_max: "1.6",
    hash_function: Some(
        "sha256",
    ),
    pruning: None,
}
➜  rust-electrum-client git:(pr-213) - cargo run --example test_protocol_version -- "tcp://blackie.c3-soft.com:57005"
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.22s
     Running `target/debug/examples/test_protocol_version 'tcp://blackie.c3-soft.com:57005'`
tcp://blackie.c3-soft.com:57005 -> protocol_version = 1.6
server_features = ServerFeaturesRes {
    server_version: "Fulcrum 2.1.1",
    genesis_hash: [
        0,
        0,
        0,
        0,
        9,
        51,
        234,
        1,
        173,
        14,
        233,
        132,
        32,
        151,
        121,
        186,
        174,
        195,
        206,
        217,
        15,
        163,
        244,
        8,
        113,
        149,
        38,
        248,
        215,
        127,
        73,
        67,
    ],
    protocol_min: "1.4",
    protocol_max: "1.6",
    hash_function: Some(
        "sha256",
    ),
    pruning: None,
}
➜  rust-electrum-client git:(pr-213) - cargo run --example test_protocol_version -- "ssl://blackie.c3-soft.com:62002"
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/examples/test_protocol_version 'ssl://blackie.c3-soft.com:62002'`
ssl://blackie.c3-soft.com:62002 -> protocol_version = 1.6
server_features = ServerFeaturesRes {
    server_version: "Fulcrum 2.1.1",
    genesis_hash: [
        0,
        0,
        0,
        0,
        29,
        212,
        16,
        196,
        154,
        120,
        134,
        104,
        206,
        38,
        117,
        23,
        24,
        204,
        121,
        116,
        116,
        211,
        21,
        42,
        95,
        192,
        115,
        221,
        68,
        253,
        159,
        123,
    ],
    protocol_min: "1.4",
    protocol_max: "1.6",
    hash_function: Some(
        "sha256",
    ),
    pruning: None,
}

➜  rust-electrum-client git:(pr-213) - cargo run --example test_protocol_version -- "tcp://5dfr3ossuq3kxyc4zsgwqarh37yzlp7b6jc2j7h2gjq6jp7d7zg6fnid.onion:62001" "127.0.0.1:9050"
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.26s
     Running `target/debug/examples/test_protocol_version 'tcp://5dfr3ossuq3kxyc4zsgwqarh37yzlp7b6jc2j7h2gjq6jp7d7zg6fnid.onion:62001' '127.0.0.1:9050'`
tcp://5dfr3ossuq3kxyc4zsgwqarh37yzlp7b6jc2j7h2gjq6jp7d7zg6fnid.onion:62001 -> protocol_version = 1.6
server_features = ServerFeaturesRes {
    server_version: "Fulcrum 2.1.0",
    genesis_hash: [
        0,
        0,
        0,
        0,
        29,
        212,
        16,
        196,
        154,
        120,
        134,
        104,
        206,
        38,
        117,
        23,
        24,
        204,
        121,
        116,
        116,
        211,
        21,
        42,
        95,
        192,
        115,
        221,
        68,
        253,
        159,
        123,
    ],
    protocol_min: "1.4",
    protocol_max: "1.6",
    hash_function: Some(
        "sha256",
    ),
    pruning: None,
}

oleonardolima and others added 2 commits July 22, 2026 15:44
The v1.6 upgrade negotiated and stored the server protocol
version during connection setup, but omitted the documented
public API for reading it.

Add protocol_version() so callers can reuse the negotiated value.
Only fall back to server.version when no cached version exists.

Co-Authored-By: HAL 9000
@oleonardolima
oleonardolima force-pushed the 2026-06-expose-protocol-version branch from f78ed74 to 522ffc1 Compare July 22, 2026 18:56
@oleonardolima

Copy link
Copy Markdown
Collaborator

@caarloshenriq did you manage to test it against a server that didn't support v1.6 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

3 participants