Skip to content

Commit 9f3970e

Browse files
committed
ElectrumSyncClient: Skip unconfirmed get_history entries
Electrum's `blockchain.scripthash.get_history` will return the *confirmed* history for any scripthash, but will then also append any matching entries from the mempool, with respective `height` fields set to 0 or -1 (depending on whether all inputs are confirmed or not). Unfortunately we previously only included a filter for confirmed `get_history` entries in the watched output case, and forgot to add such a check also when checking for watched transactions. This would have us treat the entry as confirmed, then failing on the `get_merkle` step which of course couldn't prove block inclusion. Here we simply fix this omission and skip entries that are still unconfirmed (e.g., unconfirmed funding transactions from 0conf channels). Signed-off-by: Elias Rohrer <dev@tnull.de>
1 parent feef6a4 commit 9f3970e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lightning-transaction-sync/src/electrum.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,31 @@ where
334334
}
335335
let mut filtered_history =
336336
script_history.iter().filter(|h| h.tx_hash == **txid);
337+
if filtered_history.len() > 1 {
338+
log_error!(
339+
self.logger,
340+
"Failed due server returning multiple history entries for Tx {}.",
341+
txid
342+
);
343+
return Err(InternalError::Failed);
344+
}
337345
if let Some(history) = filtered_history.next() {
338346
let prob_conf_height = history.height as u32;
347+
if prob_conf_height <= 0 {
348+
// Skip if it's a an unconfirmed entry.
349+
continue;
350+
}
339351
let confirmed_tx = self.get_confirmed_tx(tx, prob_conf_height)?;
340352
confirmed_txs.push(confirmed_tx);
341353
}
342-
debug_assert!(filtered_history.next().is_none());
343354
}
344355

345356
for (watched_output, script_history) in
346357
sync_state.watched_outputs.values().zip(output_results)
347358
{
348359
for possible_output_spend in script_history {
349360
if possible_output_spend.height <= 0 {
361+
// Skip if it's a an unconfirmed entry.
350362
continue;
351363
}
352364

0 commit comments

Comments
 (0)