bitcoindevkit / rust-electrum-client

Bitcoin Electrum client library. Supports plaintext, TLS and Onion servers.
MIT License
78 stars 63 forks source link

New header notification seems to not be received #113

Closed RCasatta closed 1 year ago

RCasatta commented 1 year ago

New header notification seems to not be received,

in absence of a regtest env, I tried this long-running test. Even after a new block is found on mainnet, the block_headers_pop always return None even though the message should be handled by https://github.com/bitcoindevkit/rust-electrum-client/blob/20493aa475719d0ea7364e86b121117bf32bc5cf/src/raw_client.rs#L651

    #[test]
    #[ignore]
    fn test_block_headers_subscribe_pop_long() {
        let client = RawClient::new(get_test_server(), None).unwrap();
        let start = client.block_headers_subscribe().unwrap();
        println!("{start:?}");

        loop {
            let resp = client.block_headers_pop();
            println!("{resp:?}");
            std::thread::sleep(std::time::Duration::from_secs(60));
        }
    }

I tested with default electrum server and with export TEST_ELECTRUM_SERVER=electrum.bitaroo.net:50001

RCasatta commented 1 year ago

On a deeper inspection, the connection is dropped after a while if anything is sent over the wire (blockstream endpoint cut after one minute).

By adding a ping and a lower sleeping period the notification is sent.

I am not sure if there is a way for the pop logic to error in case the connection isn't alive