@@ -1529,9 +1529,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
15291529 ( claimable_outpoints, Some ( ( htlc_txid, outputs) ) )
15301530 }
15311531
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 ) > ) {
15331533 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 ( ) ) ;
15351534
15361535 let redeemscript = chan_utils:: get_revokeable_redeemscript ( & holder_tx. revocation_key , self . on_holder_tx_csv , & holder_tx. delayed_payment_key ) ;
15371536 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> {
15501549 } else { None } ,
15511550 amount : htlc. amount_msat ,
15521551 } } ) ;
1553- watch_outputs. push ( ( transaction_output_index, commitment_tx. output [ transaction_output_index as usize ] . clone ( ) ) ) ;
15541552 }
15551553 }
15561554
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
15581566 }
15591567
15601568 /// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
@@ -1589,10 +1597,10 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
15891597 }
15901598
15911599 macro_rules! append_onchain_update {
1592- ( $updates: expr) => {
1600+ ( $updates: expr, $to_watch : expr ) => {
15931601 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 ) ;
15961604 }
15971605 }
15981606
@@ -1602,14 +1610,16 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
16021610 if self . current_holder_commitment_tx . txid == commitment_txid {
16031611 is_holder_tx = true ;
16041612 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) ;
16071616 } else if let & Some ( ref holder_tx) = & self . prev_holder_signed_commitment_tx {
16081617 if holder_tx. txid == commitment_txid {
16091618 is_holder_tx = true ;
16101619 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) ;
16131623 }
16141624 }
16151625
@@ -1777,7 +1787,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17771787 self . pending_monitor_events . push ( MonitorEvent :: CommitmentTxBroadcasted ( self . funding_info . 0 ) ) ;
17781788 if let Some ( commitment_tx) = self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) {
17791789 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) ;
17811792 if !new_outputs. is_empty ( ) {
17821793 watch_outputs. push ( ( self . current_holder_commitment_tx . txid . clone ( ) , new_outputs) ) ;
17831794 }
0 commit comments