@@ -969,7 +969,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
969969
970970 let key_derivation_params = keys. key_derivation_params ( ) ;
971971 let holder_revocation_basepoint = keys. pubkeys ( ) . revocation_basepoint ;
972- let mut onchain_tx_handler = OnchainTxHandler :: new ( destination_script. clone ( ) , keys, channel_parameters. clone ( ) ) ;
973972
974973 let secp_ctx = Secp256k1 :: new ( ) ;
975974
@@ -991,7 +990,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
991990 } ;
992991 ( holder_commitment_tx, trusted_tx. commitment_number ( ) )
993992 } ;
994- onchain_tx_handler. provide_latest_holder_tx ( initial_holder_commitment_tx) ;
993+
994+ let onchain_tx_handler =
995+ OnchainTxHandler :: new ( destination_script. clone ( ) , keys, channel_parameters. clone ( ) , initial_holder_commitment_tx) ;
995996
996997 let mut outputs_to_watch = HashMap :: new ( ) ;
997998 outputs_to_watch. insert ( funding_info. 0 . txid , vec ! [ ( funding_info. 0 . index as u32 , funding_info. 1 . clone( ) ) ] ) ;
@@ -1725,28 +1726,26 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17251726 pub fn get_latest_holder_commitment_txn < L : Deref > ( & mut self , logger : & L ) -> Vec < Transaction > where L :: Target : Logger {
17261727 log_trace ! ( logger, "Getting signed latest holder commitment transaction!" ) ;
17271728 self . holder_tx_signed = true ;
1728- if let Some ( commitment_tx) = self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) {
1729- let txid = commitment_tx. txid ( ) ;
1730- let mut res = vec ! [ commitment_tx] ;
1731- for htlc in self . current_holder_commitment_tx . htlc_outputs . iter ( ) {
1732- if let Some ( vout) = htlc. 0 . transaction_output_index {
1733- let preimage = if !htlc. 0 . offered {
1734- if let Some ( preimage) = self . payment_preimages . get ( & htlc. 0 . payment_hash ) { Some ( preimage. clone ( ) ) } else {
1735- // We can't build an HTLC-Success transaction without the preimage
1736- continue ;
1737- }
1738- } else { None } ;
1739- if let Some ( htlc_tx) = self . onchain_tx_handler . get_fully_signed_htlc_tx (
1740- & :: bitcoin:: OutPoint { txid, vout } , & preimage) {
1741- res. push ( htlc_tx) ;
1729+ let commitment_tx = self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) ;
1730+ let txid = commitment_tx. txid ( ) ;
1731+ let mut res = vec ! [ commitment_tx] ;
1732+ for htlc in self . current_holder_commitment_tx . htlc_outputs . iter ( ) {
1733+ if let Some ( vout) = htlc. 0 . transaction_output_index {
1734+ let preimage = if !htlc. 0 . offered {
1735+ if let Some ( preimage) = self . payment_preimages . get ( & htlc. 0 . payment_hash ) { Some ( preimage. clone ( ) ) } else {
1736+ // We can't build an HTLC-Success transaction without the preimage
1737+ continue ;
17421738 }
1739+ } else { None } ;
1740+ if let Some ( htlc_tx) = self . onchain_tx_handler . get_fully_signed_htlc_tx (
1741+ & :: bitcoin:: OutPoint { txid, vout } , & preimage) {
1742+ res. push ( htlc_tx) ;
17431743 }
17441744 }
1745- // We throw away the generated waiting_first_conf data as we aren't (yet) confirmed and we don't actually know what the caller wants to do.
1746- // The data will be re-generated and tracked in check_spend_holder_transaction if we get a confirmation.
1747- return res
17481745 }
1749- Vec :: new ( )
1746+ // We throw away the generated waiting_first_conf data as we aren't (yet) confirmed and we don't actually know what the caller wants to do.
1747+ // The data will be re-generated and tracked in check_spend_holder_transaction if we get a confirmation.
1748+ return res;
17501749 }
17511750
17521751 /// Unsafe test-only version of get_latest_holder_commitment_txn used by our test framework
@@ -1755,26 +1754,24 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17551754 #[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
17561755 pub fn unsafe_get_latest_holder_commitment_txn < L : Deref > ( & mut self , logger : & L ) -> Vec < Transaction > where L :: Target : Logger {
17571756 log_trace ! ( logger, "Getting signed copy of latest holder commitment transaction!" ) ;
1758- if let Some ( commitment_tx) = self . onchain_tx_handler . get_fully_signed_copy_holder_tx ( & self . funding_redeemscript ) {
1759- let txid = commitment_tx. txid ( ) ;
1760- let mut res = vec ! [ commitment_tx] ;
1761- for htlc in self . current_holder_commitment_tx . htlc_outputs . iter ( ) {
1762- if let Some ( vout) = htlc. 0 . transaction_output_index {
1763- let preimage = if !htlc. 0 . offered {
1764- if let Some ( preimage) = self . payment_preimages . get ( & htlc. 0 . payment_hash ) { Some ( preimage. clone ( ) ) } else {
1765- // We can't build an HTLC-Success transaction without the preimage
1766- continue ;
1767- }
1768- } else { None } ;
1769- if let Some ( htlc_tx) = self . onchain_tx_handler . unsafe_get_fully_signed_htlc_tx (
1770- & :: bitcoin:: OutPoint { txid, vout } , & preimage) {
1771- res. push ( htlc_tx) ;
1757+ let commitment_tx = self . onchain_tx_handler . get_fully_signed_copy_holder_tx ( & self . funding_redeemscript ) ;
1758+ let txid = commitment_tx. txid ( ) ;
1759+ let mut res = vec ! [ commitment_tx] ;
1760+ for htlc in self . current_holder_commitment_tx . htlc_outputs . iter ( ) {
1761+ if let Some ( vout) = htlc. 0 . transaction_output_index {
1762+ let preimage = if !htlc. 0 . offered {
1763+ if let Some ( preimage) = self . payment_preimages . get ( & htlc. 0 . payment_hash ) { Some ( preimage. clone ( ) ) } else {
1764+ // We can't build an HTLC-Success transaction without the preimage
1765+ continue ;
17721766 }
1767+ } else { None } ;
1768+ if let Some ( htlc_tx) = self . onchain_tx_handler . unsafe_get_fully_signed_htlc_tx (
1769+ & :: bitcoin:: OutPoint { txid, vout } , & preimage) {
1770+ res. push ( htlc_tx) ;
17731771 }
17741772 }
1775- return res
17761773 }
1777- Vec :: new ( )
1774+ return res
17781775 }
17791776
17801777 /// Processes transactions in a newly connected block, which may result in any of the following:
@@ -1853,15 +1850,14 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
18531850 }
18541851 if should_broadcast {
18551852 self . pending_monitor_events . push ( MonitorEvent :: CommitmentTxBroadcasted ( self . funding_info . 0 ) ) ;
1856- if let Some ( commitment_tx) = self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) {
1857- self . holder_tx_signed = true ;
1858- let ( mut new_outpoints, _) = self . get_broadcasted_holder_claims ( & self . current_holder_commitment_tx ) ;
1859- let new_outputs = self . get_broadcasted_holder_watch_outputs ( & self . current_holder_commitment_tx , & commitment_tx) ;
1860- if !new_outputs. is_empty ( ) {
1861- watch_outputs. push ( ( self . current_holder_commitment_tx . txid . clone ( ) , new_outputs) ) ;
1862- }
1863- claimable_outpoints. append ( & mut new_outpoints) ;
1864- }
1853+ let commitment_tx = self . onchain_tx_handler . get_fully_signed_holder_tx ( & self . funding_redeemscript ) ;
1854+ self . holder_tx_signed = true ;
1855+ let ( mut new_outpoints, _) = self . get_broadcasted_holder_claims ( & self . current_holder_commitment_tx ) ;
1856+ let new_outputs = self . get_broadcasted_holder_watch_outputs ( & self . current_holder_commitment_tx , & commitment_tx) ;
1857+ if !new_outputs. is_empty ( ) {
1858+ watch_outputs. push ( ( self . current_holder_commitment_tx . txid . clone ( ) , new_outputs) ) ;
1859+ }
1860+ claimable_outpoints. append ( & mut new_outpoints) ;
18651861 }
18661862 if let Some ( events) = self . onchain_events_waiting_threshold_conf . remove ( & height) {
18671863 for ev in events {
0 commit comments