Skip to content

Commit 115ab6d

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 115ab6d

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

lightning-transaction-sync/src/electrum.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,17 +336,29 @@ where
336336
script_history.iter().filter(|h| h.tx_hash == **txid);
337337
if let Some(history) = filtered_history.next() {
338338
let prob_conf_height = history.height as u32;
339+
if prob_conf_height <= 0 {
340+
// Skip if it's a an unconfirmed entry.
341+
continue;
342+
}
339343
let confirmed_tx = self.get_confirmed_tx(tx, prob_conf_height)?;
340344
confirmed_txs.push(confirmed_tx);
341345
}
342-
debug_assert!(filtered_history.next().is_none());
346+
if filtered_history.next().is_some() {
347+
log_error!(
348+
self.logger,
349+
"Failed due to server returning multiple history entries for Tx {}.",
350+
txid
351+
);
352+
return Err(InternalError::Failed);
353+
}
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

lightning/src/ln/script.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ mod shutdown_script_tests {
310310
#[cfg(simple_close)]
311311
#[test]
312312
fn generates_op_return_from_data() {
313-
let data = [6; 6];
313+
let data = [4; 4];
314314
let op_return_script = ScriptBuf::new_op_return(&data);
315315
let shutdown_script = ShutdownScript::new_op_return(&data).unwrap();
316316
assert!(shutdown_script.is_compatible(&simple_close_features()));

0 commit comments

Comments
 (0)