@@ -1529,9 +1529,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1529
1529
( claimable_outpoints, Some ( ( htlc_txid, outputs) ) )
1530
1530
}
1531
1531
1532
- fn broadcast_by_holder_state ( & self , commitment_tx : & Transaction , holder_tx : & HolderSignedTx ) -> ( Vec < ClaimRequest > , Vec < ( u32 , TxOut ) > , Option < ( Script , PublicKey , PublicKey ) > ) {
1532
+ fn get_broadcasted_holder_claims ( & self , holder_tx : & HolderSignedTx ) -> ( Vec < ClaimRequest > , Option < ( Script , PublicKey , PublicKey ) > ) {
1533
1533
let mut claim_requests = Vec :: with_capacity ( holder_tx. htlc_outputs . len ( ) ) ;
1534
- let mut watch_outputs = Vec :: with_capacity ( holder_tx. htlc_outputs . len ( ) ) ;
1535
1534
1536
1535
let redeemscript = chan_utils:: get_revokeable_redeemscript ( & holder_tx. revocation_key , self . on_holder_tx_csv , & holder_tx. delayed_payment_key ) ;
1537
1536
let broadcasted_holder_revokable_script = Some ( ( redeemscript. to_v0_p2wsh ( ) , holder_tx. per_commitment_point . clone ( ) , holder_tx. revocation_key . clone ( ) ) ) ;
@@ -1550,11 +1549,20 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1550
1549
} else { None } ,
1551
1550
amount : htlc. amount_msat ,
1552
1551
} } ) ;
1553
- watch_outputs. push ( ( transaction_output_index, commitment_tx. output [ transaction_output_index as usize ] . clone ( ) ) ) ;
1554
1552
}
1555
1553
}
1556
1554
1557
- ( claim_requests, watch_outputs, broadcasted_holder_revokable_script)
1555
+ ( claim_requests, broadcasted_holder_revokable_script)
1556
+ }
1557
+
1558
+ fn get_broadcasted_holder_watch_outputs ( & self , holder_tx : & HolderSignedTx , commitment_tx : & Transaction ) -> Vec < ( u32 , TxOut ) > {
1559
+ let mut watch_outputs = Vec :: with_capacity ( holder_tx. htlc_outputs . len ( ) ) ;
1560
+ for & ( ref htlc, _, _) in holder_tx. htlc_outputs . iter ( ) {
1561
+ if let Some ( transaction_output_index) = htlc. transaction_output_index {
1562
+ watch_outputs. push ( ( transaction_output_index, commitment_tx. output [ transaction_output_index as usize ] . clone ( ) ) ) ;
1563
+ }
1564
+ }
1565
+ watch_outputs
1558
1566
}
1559
1567
1560
1568
/// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
@@ -1589,10 +1597,10 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1589
1597
}
1590
1598
1591
1599
macro_rules! append_onchain_update {
1592
- ( $updates: expr) => {
1600
+ ( $updates: expr, $to_watch : expr ) => {
1593
1601
claim_requests = $updates. 0 ;
1594
- watch_outputs . append ( & mut $updates. 1 ) ;
1595
- self . broadcasted_holder_revokable_script = $updates . 2 ;
1602
+ self . broadcasted_holder_revokable_script = $updates. 1 ;
1603
+ watch_outputs . append ( & mut $to_watch ) ;
1596
1604
}
1597
1605
}
1598
1606
@@ -1602,14 +1610,16 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1602
1610
if self . current_holder_commitment_tx . txid == commitment_txid {
1603
1611
is_holder_tx = true ;
1604
1612
log_trace ! ( logger, "Got latest holder commitment tx broadcast, searching for available HTLCs to claim" ) ;
1605
- let mut res = self . broadcast_by_holder_state ( tx, & self . current_holder_commitment_tx ) ;
1606
- append_onchain_update ! ( res) ;
1613
+ let res = self . get_broadcasted_holder_claims ( & self . current_holder_commitment_tx ) ;
1614
+ let mut to_watch = self . get_broadcasted_holder_watch_outputs ( & self . current_holder_commitment_tx , tx) ;
1615
+ append_onchain_update ! ( res, to_watch) ;
1607
1616
} else if let & Some ( ref holder_tx) = & self . prev_holder_signed_commitment_tx {
1608
1617
if holder_tx. txid == commitment_txid {
1609
1618
is_holder_tx = true ;
1610
1619
log_trace ! ( logger, "Got previous holder commitment tx broadcast, searching for available HTLCs to claim" ) ;
1611
- let mut res = self . broadcast_by_holder_state ( tx, holder_tx) ;
1612
- append_onchain_update ! ( res) ;
1620
+ let res = self . get_broadcasted_holder_claims ( holder_tx) ;
1621
+ let mut to_watch = self . get_broadcasted_holder_watch_outputs ( holder_tx, tx) ;
1622
+ append_onchain_update ! ( res, to_watch) ;
1613
1623
}
1614
1624
}
1615
1625
@@ -1777,7 +1787,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1777
1787
self . pending_monitor_events . push ( MonitorEvent :: CommitmentTxBroadcasted ( self . funding_info . 0 ) ) ;
1778
1788
if let Some ( commitment_tx) = self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) {
1779
1789
self . holder_tx_signed = true ;
1780
- let ( mut new_outpoints, new_outputs, _) = self . broadcast_by_holder_state ( & commitment_tx, & self . current_holder_commitment_tx ) ;
1790
+ let ( mut new_outpoints, _) = self . get_broadcasted_holder_claims ( & self . current_holder_commitment_tx ) ;
1791
+ let new_outputs = self . get_broadcasted_holder_watch_outputs ( & self . current_holder_commitment_tx , & commitment_tx) ;
1781
1792
if !new_outputs. is_empty ( ) {
1782
1793
watch_outputs. push ( ( self . current_holder_commitment_tx . txid . clone ( ) , new_outputs) ) ;
1783
1794
}
0 commit comments