Skip to content

Commit debb3ab

Browse files
author
Antoine Riard
committed
Move SpendableOutputDescriptor for closing tx in is_mine
1 parent 4558bc6 commit debb3ab

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

lightning/src/ln/channelmonitor.rs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,31 +1873,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
18731873
(local_txn, (commitment_txid, watch_outputs))
18741874
}
18751875

1876-
/// Generate a spendable output event when closing_transaction get registered onchain.
1877-
fn check_spend_closing_transaction(&self, tx: &Transaction) -> Option<SpendableOutputDescriptor> {
1878-
if tx.input[0].sequence == 0xFFFFFFFF && !tx.input[0].witness.is_empty() && tx.input[0].witness.last().unwrap().len() == 71 {
1879-
match self.key_storage {
1880-
Storage::Local { ref shutdown_pubkey, .. } => {
1881-
let our_channel_close_key_hash = Hash160::hash(&shutdown_pubkey.serialize());
1882-
let shutdown_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script();
1883-
for (idx, output) in tx.output.iter().enumerate() {
1884-
if shutdown_script == output.script_pubkey {
1885-
return Some(SpendableOutputDescriptor::StaticOutput {
1886-
outpoint: BitcoinOutPoint { txid: tx.txid(), vout: idx as u32 },
1887-
output: output.clone(),
1888-
});
1889-
}
1890-
}
1891-
}
1892-
Storage::Watchtower { .. } => {
1893-
//TODO: we need to ensure an offline client will generate the event when it
1894-
// comes back online after only the watchtower saw the transaction
1895-
}
1896-
}
1897-
}
1898-
None
1899-
}
1900-
19011876
/// Used by ChannelManager deserialization to broadcast the latest local state if its copy of
19021877
/// the Channel was out-of-date. You may use it to get a broadcastable local toxic tx in case of
19031878
/// fallen-behind, i.e when receiving a channel_reestablish with a proof that our remote side knows
@@ -1988,11 +1963,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
19881963
}
19891964
claimable_outpoints.append(&mut new_outpoints);
19901965
}
1991-
if !funding_txo.is_none() && claimable_outpoints.is_empty() {
1992-
if let Some(spendable_output) = self.check_spend_closing_transaction(&tx) {
1993-
spendable_outputs.push(spendable_output);
1994-
}
1995-
}
19961966
} else {
19971967
if let Some(&(commitment_number, _)) = self.remote_commitment_txn_on_chain.get(&prevout.txid) {
19981968
let (mut new_outpoints, new_outputs_option) = self.check_spend_remote_htlc(&tx, commitment_number, height);
@@ -2323,6 +2293,20 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
23232293
output: outp.clone(),
23242294
});
23252295
}
2296+
} else {
2297+
match self.key_storage {
2298+
Storage::Local { ref shutdown_pubkey, .. } => {
2299+
let our_channel_close_key_hash = Hash160::hash(&shutdown_pubkey.serialize());
2300+
let shutdown_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script();
2301+
if shutdown_script == outp.script_pubkey {
2302+
return Some(SpendableOutputDescriptor::StaticOutput {
2303+
outpoint: BitcoinOutPoint { txid: tx.txid(), vout: i as u32 },
2304+
output: outp.clone(),
2305+
});
2306+
}
2307+
},
2308+
_ => {}
2309+
}
23262310
}
23272311
}
23282312
None

0 commit comments

Comments
 (0)