Skip to content

Commit 730c62c

Browse files
committed
Add rescan logic to ChainMonitor::block_connected
Electrum clients will only provide transaction data for outputs that have been explicitly registered. Hence, upon registering new outputs, recursively register any outputs to watch contained within dependent transactions from the same block.
1 parent 3cc1b63 commit 730c62c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@ where C::Target: chain::Filter,
100100
if let Some(ref chain_source) = self.chain_source {
101101
for (txid, outputs) in txn_outputs.drain(..) {
102102
for (idx, output) in outputs.iter() {
103-
chain_source.register_output(&OutPoint { txid, index: *idx as u16 }, &output.script_pubkey);
103+
// Register any new outputs with the chain source for filtering and recurse
104+
// if it indicates that there are dependent transactions within the block
105+
// that had not been previously included in txdata.
106+
let outpoint = OutPoint { txid, index: *idx as u16 };
107+
if let Some(txdata) = chain_source.register_output(&outpoint, &output.script_pubkey) {
108+
let txdata: Vec<_> = txdata.iter().map(|(index, tx)| (*index, tx)).collect();
109+
self.block_connected(header, &txdata, height);
110+
}
104111
}
105112
}
106113
}

0 commit comments

Comments
 (0)