@@ -1687,7 +1687,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1687
1687
( claimable_outpoints, Some ( ( htlc_txid, tx. output . clone ( ) ) ) )
1688
1688
}
1689
1689
1690
- fn broadcast_by_local_state ( & self , local_tx : & LocalSignedTx ) -> ( Vec < Transaction > , Vec < TxOut > , Option < ( Script , SecretKey , Script ) > ) {
1690
+ fn broadcast_by_local_state ( & self , commitment_tx : & Transaction , local_tx : & LocalSignedTx ) -> ( Vec < Transaction > , Vec < TxOut > , Option < ( Script , SecretKey , Script ) > ) {
1691
1691
let mut res = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1692
1692
let mut watch_outputs = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1693
1693
@@ -1730,7 +1730,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1730
1730
res. push ( htlc_success_tx) ;
1731
1731
}
1732
1732
}
1733
- watch_outputs. push ( local_tx . tx . without_valid_witness ( ) . output [ transaction_output_index as usize ] . clone ( ) ) ;
1733
+ watch_outputs. push ( commitment_tx . output [ transaction_output_index as usize ] . clone ( ) ) ;
1734
1734
} else { panic ! ( "Should have sigs for non-dust local tx outputs!" ) }
1735
1735
}
1736
1736
}
@@ -1784,16 +1784,15 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1784
1784
if local_tx. txid == commitment_txid {
1785
1785
is_local_tx = true ;
1786
1786
log_trace ! ( self , "Got latest local commitment tx broadcast, searching for available HTLCs to claim" ) ;
1787
- let mut res = self . broadcast_by_local_state ( local_tx) ;
1787
+ let mut res = self . broadcast_by_local_state ( tx , local_tx) ;
1788
1788
append_onchain_update ! ( res) ;
1789
1789
}
1790
1790
}
1791
1791
if let & Some ( ref local_tx) = & self . prev_local_signed_commitment_tx {
1792
1792
if local_tx. txid == commitment_txid {
1793
1793
is_local_tx = true ;
1794
1794
log_trace ! ( self , "Got previous local commitment tx broadcast, searching for available HTLCs to claim" ) ;
1795
- assert ! ( local_tx. tx. has_local_sig( ) ) ;
1796
- let mut res = self . broadcast_by_local_state ( local_tx) ;
1795
+ let mut res = self . broadcast_by_local_state ( tx, local_tx) ;
1797
1796
append_onchain_update ! ( res) ;
1798
1797
}
1799
1798
}
@@ -1832,22 +1831,35 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1832
1831
/// out-of-band the other node operator to coordinate with him if option is available to you.
1833
1832
/// In any-case, choice is up to the user.
1834
1833
pub fn get_latest_local_commitment_txn ( & mut self ) -> Vec < Transaction > {
1835
- // TODO: We should likely move all of the logic in here into OnChainTxHandler and unify it
1836
- // to ensure add_local_sig is only ever called once no matter what. This likely includes
1837
- // tracking state and panic!()ing if we get an update after force-closure/local-tx signing.
1838
1834
log_trace ! ( self , "Getting signed latest local commitment transaction!" ) ;
1839
- if let & mut Some ( ref mut local_tx) = & mut self . current_local_signed_commitment_tx {
1840
- self . onchain_detection . keys . sign_local_commitment ( & mut local_tx. tx , self . funding_redeemscript . as_ref ( ) . unwrap ( ) , self . channel_value_satoshis . unwrap ( ) , & self . secp_ctx ) ;
1835
+ if let Some ( commitment_tx) = self . onchain_tx_handler . get_fully_signed_local_tx ( self . channel_value_satoshis . unwrap ( ) ) {
1836
+ let mut res = vec ! [ commitment_tx] ;
1837
+ if let & Some ( ref local_tx) = & self . current_local_signed_commitment_tx {
1838
+ let mut htlc_txn = self . broadcast_by_local_state ( res. get ( 0 ) . unwrap ( ) , local_tx) . 0 ;
1839
+ res. append ( & mut htlc_txn) ;
1840
+ // 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.
1841
+ // The data will be re-generated and tracked in check_spend_local_transaction if we get a confirmation.
1842
+ }
1843
+ return res
1841
1844
}
1842
- if let & Some ( ref local_tx) = & self . current_local_signed_commitment_tx {
1843
- let mut res = vec ! [ local_tx. tx. with_valid_witness( ) . clone( ) ] ;
1844
- res. append ( & mut self . broadcast_by_local_state ( local_tx) . 0 ) ;
1845
- // 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.
1846
- // The data will be re-generated and tracked in check_spend_local_transaction if we get a confirmation.
1847
- res
1848
- } else {
1849
- Vec :: new ( )
1845
+ Vec :: new ( )
1846
+ }
1847
+
1848
+ /// Unsafe test-only version of get_latest_local_commitment_txn used by our test framework
1849
+ /// to bypass LocalCommitmentTransaction state update lockdown after signature and generate
1850
+ /// revoked commitment transaction.
1851
+ #[ cfg( test) ]
1852
+ pub fn unsafe_get_latest_local_commitment_txn ( & mut self ) -> Vec < Transaction > {
1853
+ log_trace ! ( self , "Getting signed copy of latest local commitment transaction!" ) ;
1854
+ if let Some ( commitment_tx) = self . onchain_tx_handler . get_fully_signed_copy_local_tx ( self . channel_value_satoshis . unwrap ( ) ) {
1855
+ let mut res = vec ! [ commitment_tx] ;
1856
+ if let & Some ( ref local_tx) = & self . current_local_signed_commitment_tx {
1857
+ let mut htlc_txn = self . broadcast_by_local_state ( res. get ( 0 ) . unwrap ( ) , local_tx) . 0 ;
1858
+ res. append ( & mut htlc_txn) ;
1859
+ }
1860
+ return res
1850
1861
}
1862
+ Vec :: new ( )
1851
1863
}
1852
1864
1853
1865
/// Called by SimpleManyChannelMonitor::block_connected, which implements
@@ -1922,13 +1934,15 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1922
1934
}
1923
1935
if let Some ( ref cur_local_tx) = self . current_local_signed_commitment_tx {
1924
1936
if should_broadcast {
1925
- let ( txs, new_outputs, _) = self . broadcast_by_local_state ( & cur_local_tx) ;
1926
- if !new_outputs. is_empty ( ) {
1927
- watch_outputs. push ( ( cur_local_tx. txid . clone ( ) , new_outputs) ) ;
1928
- }
1929
- for tx in txs {
1930
- log_trace ! ( self , "Broadcast onchain {}" , log_tx!( tx) ) ;
1931
- broadcaster. broadcast_transaction ( & tx) ;
1937
+ if let Some ( commitment_tx) = self . onchain_tx_handler . get_fully_signed_local_tx ( self . channel_value_satoshis . unwrap ( ) ) {
1938
+ let ( txs, new_outputs, _) = self . broadcast_by_local_state ( & commitment_tx, cur_local_tx) ;
1939
+ if !new_outputs. is_empty ( ) {
1940
+ watch_outputs. push ( ( cur_local_tx. txid . clone ( ) , new_outputs) ) ;
1941
+ }
1942
+ for tx in txs {
1943
+ log_trace ! ( self , "Broadcast onchain {}" , log_tx!( tx) ) ;
1944
+ broadcaster. broadcast_transaction ( & tx) ;
1945
+ }
1932
1946
}
1933
1947
}
1934
1948
}
@@ -2401,7 +2415,8 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2401
2415
2402
2416
LocalSignedTx {
2403
2417
txid: tx. txid( ) ,
2404
- tx, revocation_key, a_htlc_key, b_htlc_key, delayed_payment_key, per_commitment_point, feerate_per_kw,
2418
+ tx,
2419
+ revocation_key, a_htlc_key, b_htlc_key, delayed_payment_key, per_commitment_point, feerate_per_kw,
2405
2420
htlc_outputs: htlcs
2406
2421
}
2407
2422
}
0 commit comments