@@ -969,7 +969,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
969
969
970
970
let key_derivation_params = keys. key_derivation_params ( ) ;
971
971
let holder_revocation_basepoint = keys. pubkeys ( ) . revocation_basepoint ;
972
- let mut onchain_tx_handler = OnchainTxHandler :: new ( destination_script. clone ( ) , keys, channel_parameters. clone ( ) ) ;
973
972
974
973
let secp_ctx = Secp256k1 :: new ( ) ;
975
974
@@ -991,7 +990,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
991
990
} ;
992
991
( holder_commitment_tx, trusted_tx. commitment_number ( ) )
993
992
} ;
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) ;
995
996
996
997
let mut outputs_to_watch = HashMap :: new ( ) ;
997
998
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> {
1725
1726
pub fn get_latest_holder_commitment_txn < L : Deref > ( & mut self , logger : & L ) -> Vec < Transaction > where L :: Target : Logger {
1726
1727
log_trace ! ( logger, "Getting signed latest holder commitment transaction!" ) ;
1727
1728
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 ;
1742
1738
}
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) ;
1743
1743
}
1744
1744
}
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
1748
1745
}
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;
1750
1749
}
1751
1750
1752
1751
/// Unsafe test-only version of get_latest_holder_commitment_txn used by our test framework
@@ -1755,26 +1754,24 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1755
1754
#[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
1756
1755
pub fn unsafe_get_latest_holder_commitment_txn < L : Deref > ( & mut self , logger : & L ) -> Vec < Transaction > where L :: Target : Logger {
1757
1756
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 ;
1772
1766
}
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) ;
1773
1771
}
1774
1772
}
1775
- return res
1776
1773
}
1777
- Vec :: new ( )
1774
+ return res
1778
1775
}
1779
1776
1780
1777
/// Processes transactions in a newly connected block, which may result in any of the following:
@@ -1853,15 +1850,14 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1853
1850
}
1854
1851
if should_broadcast {
1855
1852
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) ;
1865
1861
}
1866
1862
if let Some ( events) = self . onchain_events_waiting_threshold_conf . remove ( & height) {
1867
1863
for ev in events {
0 commit comments