Skip to content

Commit b499290

Browse files
kaloudisclaude
andcommitted
fix: add logging and error tracking to sweep_remote_closed_outputs
Log Esplora query errors instead of silently swallowing them, and log scan progress (scripts checked, errors, UTXOs found) to help diagnose issues when no funds are found. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4a8470a commit b499290

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

src/lib.rs

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,14 @@ impl Node {
18871887

18881888
let chain_source = Arc::clone(&self.chain_source);
18891889

1890+
log_info!(
1891+
self.logger,
1892+
"Scanning {} scripts for counterparty force-closed UTXOs",
1893+
script_to_key.len()
1894+
);
1895+
1896+
let logger = Arc::clone(&self.logger);
1897+
18901898
// Query Esplora for UTXOs matching our scripts
18911899
let found_utxos: Vec<(
18921900
esplora_client::Utxo,
@@ -1895,6 +1903,8 @@ impl Node {
18951903
)> = self.runtime.block_on(async {
18961904
let mut results = Vec::new();
18971905
let scripts: Vec<_> = script_to_key.keys().cloned().collect();
1906+
let mut scanned = 0u64;
1907+
let mut errors = 0u64;
18981908

18991909
// Process in batches of 20 for concurrency
19001910
for chunk in scripts.chunks(20) {
@@ -1909,12 +1919,36 @@ impl Node {
19091919
}
19101920

19111921
while let Some(result) = join_set.join_next().await {
1912-
if let Ok((script, Ok(utxos))) = result {
1913-
for utxo in utxos {
1914-
if let Some(key) = script_to_key.get(&script) {
1915-
results.push((utxo, script.clone(), *key));
1922+
scanned += 1;
1923+
match result {
1924+
Ok((script, Ok(utxos))) => {
1925+
for utxo in utxos {
1926+
if let Some(key) = script_to_key.get(&script) {
1927+
log_info!(
1928+
logger,
1929+
"Found UTXO: txid={} vout={} value={}",
1930+
utxo.txid, utxo.vout, utxo.value
1931+
);
1932+
results.push((utxo, script.clone(), *key));
1933+
}
19161934
}
1917-
}
1935+
},
1936+
Ok((_script, Err(e))) => {
1937+
errors += 1;
1938+
if errors <= 3 {
1939+
log_error!(
1940+
logger,
1941+
"Esplora scripthash query failed: {}",
1942+
e
1943+
);
1944+
}
1945+
},
1946+
Err(e) => {
1947+
errors += 1;
1948+
if errors <= 3 {
1949+
log_error!(logger, "Task join error: {}", e);
1950+
}
1951+
},
19181952
}
19191953
}
19201954

@@ -1923,6 +1957,12 @@ impl Node {
19231957
tokio::time::sleep(Duration::from_secs(sleep_seconds)).await;
19241958
}
19251959
}
1960+
1961+
log_info!(
1962+
logger,
1963+
"Scan complete: checked {} scripts, {} errors, {} UTXOs found",
1964+
scanned, errors, results.len()
1965+
);
19261966
results
19271967
});
19281968

0 commit comments

Comments
 (0)