Skip to content

Commit 98d964c

Browse files
author
Antoine Riard
committed
Track outputs from local commitment tx
Aims to detect onchain resolution of channel Modifiy in consequence test_txn_broadcast to still pass channel_monitor_network test
1 parent b14baa0 commit 98d964c

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5229,7 +5229,7 @@ mod tests {
52295229
false
52305230
} else { true }
52315231
});
5232-
assert_eq!(res.len(), 2);
5232+
assert!(res.len() >= 2);
52335233
}
52345234

52355235
assert!(node_txn.is_empty());

src/ln/channelmonitor.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,16 +1294,16 @@ impl ChannelMonitor {
12941294
/// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
12951295
/// revoked using data in local_claimable_outpoints.
12961296
/// Should not be used if check_spend_revoked_transaction succeeds.
1297-
fn check_spend_local_transaction(&self, tx: &Transaction, _height: u32) -> (Vec<Transaction>, Vec<SpendableOutputDescriptor>) {
1297+
fn check_spend_local_transaction(&self, tx: &Transaction, _height: u32) -> ((Vec<Transaction>, Vec<SpendableOutputDescriptor>), (Sha256dHash, Vec<TxOut>)) {
12981298
let commitment_txid = tx.txid();
12991299
if let &Some(ref local_tx) = &self.current_local_signed_commitment_tx {
13001300
if local_tx.txid == commitment_txid {
13011301
match self.key_storage {
13021302
KeyStorage::PrivMode { revocation_base_key: _, htlc_base_key: _, ref delayed_payment_base_key, prev_latest_per_commitment_point: _, ref latest_per_commitment_point } => {
1303-
return self.broadcast_by_local_state(local_tx, latest_per_commitment_point, &Some(*delayed_payment_base_key));
1303+
return (self.broadcast_by_local_state(local_tx, latest_per_commitment_point, &Some(*delayed_payment_base_key)), (commitment_txid, tx.output.clone()));
13041304
},
13051305
KeyStorage::SigsMode { .. } => {
1306-
return self.broadcast_by_local_state(local_tx, &None, &None);
1306+
return (self.broadcast_by_local_state(local_tx, &None, &None), (commitment_txid, tx.output.clone()));
13071307
}
13081308
}
13091309
}
@@ -1312,15 +1312,15 @@ impl ChannelMonitor {
13121312
if local_tx.txid == commitment_txid {
13131313
match self.key_storage {
13141314
KeyStorage::PrivMode { revocation_base_key: _, htlc_base_key: _, ref delayed_payment_base_key, ref prev_latest_per_commitment_point, .. } => {
1315-
return self.broadcast_by_local_state(local_tx, prev_latest_per_commitment_point, &Some(*delayed_payment_base_key));
1315+
return (self.broadcast_by_local_state(local_tx, prev_latest_per_commitment_point, &Some(*delayed_payment_base_key)), (commitment_txid, tx.output.clone()));
13161316
},
13171317
KeyStorage::SigsMode { .. } => {
1318-
return self.broadcast_by_local_state(local_tx, &None, &None);
1318+
return (self.broadcast_by_local_state(local_tx, &None, &None), (commitment_txid, tx.output.clone()));
13191319
}
13201320
}
13211321
}
13221322
}
1323-
(Vec::new(), Vec::new())
1323+
((Vec::new(), Vec::new()), (commitment_txid, Vec::new()))
13241324
}
13251325

13261326
/// Used by ChannelManager deserialization to broadcast the latest local state if it's copy of
@@ -1359,9 +1359,12 @@ impl ChannelMonitor {
13591359
watch_outputs.push(new_outputs);
13601360
}
13611361
if txn.is_empty() {
1362-
let (remote_txn, mut outputs) = self.check_spend_local_transaction(tx, height);
1363-
spendable_outputs.append(&mut outputs);
1364-
txn = remote_txn;
1362+
let (mut local_data, new_outputs) = self.check_spend_local_transaction(tx, height);
1363+
spendable_outputs.append(&mut local_data.1);
1364+
txn = local_data.0;
1365+
if !new_outputs.1.is_empty() {
1366+
watch_outputs.push(new_outputs);
1367+
}
13651368
}
13661369
} else {
13671370
if let Some(&(commitment_number, _)) = self.remote_commitment_txn_on_chain.get(&prevout.txid) {

0 commit comments

Comments
 (0)