From b1461f05d05a0b9cf056a9604032468064ca1a05 Mon Sep 17 00:00:00 2001 From: Daniela Brozzoni Date: Fri, 6 Oct 2023 16:29:21 +0200 Subject: [PATCH] fix(wallet_esplora): missing_heights uses the... ...graph update Fixes #1151. When wallet_esplora_* was used to sync a wallet containing a transaction confirmed some time ago (more than 10-15 blocks ago), the transaction would be stuck in an "unconfirmed" state forever. At the first scan time, `update_local_chain` would just fetch the last 10 to 15 blocks (depending on the server used), and `tx_graph.missing_heights` wouldn't return the tx's confirmation block as it was called on the original, non-updated tx_graph. So, after the first scan, we would have a transaction in memory with an anchor that doesn't exist in our local_chain, and try_get_chain_position would return unconfirmed. When scanning again, missing_heights would find the missing anchor, but `update_local_chain` wouldn't include it as it's older than ASSUME_FINAL_DEPTH. The missing block would be downloaded every time, but never included in the local_chain, and the transaction would remain unconfirmed forever. Here we call missing_heights on the updated graph, so that it can correctly return the anchor height, and `update_local_chain` can fetch it and include it in the chain. --- example-crates/wallet_esplora_async/src/main.rs | 2 +- example-crates/wallet_esplora_blocking/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example-crates/wallet_esplora_async/src/main.rs b/example-crates/wallet_esplora_async/src/main.rs index c7a729af6..ff1bbfb6d 100644 --- a/example-crates/wallet_esplora_async/src/main.rs +++ b/example-crates/wallet_esplora_async/src/main.rs @@ -56,7 +56,7 @@ async fn main() -> Result<(), Box> { let (update_graph, last_active_indices) = client .scan_txs_with_keychains(keychain_spks, None, None, STOP_GAP, PARALLEL_REQUESTS) .await?; - let missing_heights = wallet.tx_graph().missing_heights(wallet.local_chain()); + let missing_heights = update_graph.missing_heights(wallet.local_chain()); let chain_update = client.update_local_chain(prev_tip, missing_heights).await?; let update = Update { last_active_indices, diff --git a/example-crates/wallet_esplora_blocking/src/main.rs b/example-crates/wallet_esplora_blocking/src/main.rs index a93a449c8..71554b0a8 100644 --- a/example-crates/wallet_esplora_blocking/src/main.rs +++ b/example-crates/wallet_esplora_blocking/src/main.rs @@ -55,7 +55,7 @@ fn main() -> Result<(), Box> { let (update_graph, last_active_indices) = client.scan_txs_with_keychains(keychain_spks, None, None, STOP_GAP, PARALLEL_REQUESTS)?; - let missing_heights = wallet.tx_graph().missing_heights(wallet.local_chain()); + let missing_heights = update_graph.missing_heights(wallet.local_chain()); let chain_update = client.update_local_chain(prev_tip, missing_heights)?; let update = Update { last_active_indices,