From 5f56b894832d06e485aae130319cdb717aa0dbd9 Mon Sep 17 00:00:00 2001 From: Ross Savage Date: Wed, 19 Jun 2024 09:48:26 +0200 Subject: [PATCH] wollet: workaround subscriptions not persisting with reconnects --- lwk_wollet/src/clients/electrum_client.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lwk_wollet/src/clients/electrum_client.rs b/lwk_wollet/src/clients/electrum_client.rs index c85a6538..551d06fa 100644 --- a/lwk_wollet/src/clients/electrum_client.rs +++ b/lwk_wollet/src/clients/electrum_client.rs @@ -118,9 +118,21 @@ impl super::BlockchainBackend for ElectrumClient { popped_header = Some(header) } - if let Some(popped_header) = popped_header { - let tip: BlockHeader = elements_deserialize(&popped_header.header)?; - self.tip = tip; + match popped_header { + Some(header) => { + let tip: BlockHeader = elements_deserialize(&header.header)?; + self.tip = tip; + } + None => { + // https://github.com/bitcoindevkit/rust-electrum-client/issues/124 + // It might be that the client has reconnected and subscriptions don't persist + // across connections. Calling `client.ping()` won't help here because the + // successful retry will prevent us knowing about the reconnect. + if let Ok(header) = self.client.block_headers_subscribe_raw() { + let tip: BlockHeader = elements_deserialize(&header.header)?; + self.tip = tip; + } + } } Ok(self.tip.clone())