@@ -405,9 +405,9 @@ pub(super) struct Channel<Signer: Sign> {
405
405
counterparty_forwarding_info : Option < CounterpartyForwardingInfo > ,
406
406
407
407
pub ( crate ) channel_transaction_parameters : ChannelTransactionParameters ,
408
+ funding_transaction : Option < Transaction > ,
408
409
409
410
counterparty_cur_commitment_point : Option < PublicKey > ,
410
-
411
411
counterparty_prev_commitment_point : Option < PublicKey > ,
412
412
counterparty_node_id : PublicKey ,
413
413
@@ -595,8 +595,9 @@ impl<Signer: Sign> Channel<Signer> {
595
595
counterparty_parameters : None ,
596
596
funding_outpoint : None
597
597
} ,
598
- counterparty_cur_commitment_point : None ,
598
+ funding_transaction : None ,
599
599
600
+ counterparty_cur_commitment_point : None ,
600
601
counterparty_prev_commitment_point : None ,
601
602
counterparty_node_id,
602
603
@@ -836,8 +837,9 @@ impl<Signer: Sign> Channel<Signer> {
836
837
} ) ,
837
838
funding_outpoint : None
838
839
} ,
839
- counterparty_cur_commitment_point : Some ( msg . first_per_commitment_point ) ,
840
+ funding_transaction : None ,
840
841
842
+ counterparty_cur_commitment_point : Some ( msg. first_per_commitment_point ) ,
841
843
counterparty_prev_commitment_point : None ,
842
844
counterparty_node_id,
843
845
@@ -1600,7 +1602,7 @@ impl<Signer: Sign> Channel<Signer> {
1600
1602
1601
1603
/// Handles a funding_signed message from the remote end.
1602
1604
/// If this call is successful, broadcast the funding transaction (and not before!)
1603
- pub fn funding_signed < L : Deref > ( & mut self , msg : & msgs:: FundingSigned , last_block_hash : BlockHash , logger : & L ) -> Result < ChannelMonitor < Signer > , ChannelError > where L :: Target : Logger {
1605
+ pub fn funding_signed < L : Deref > ( & mut self , msg : & msgs:: FundingSigned , last_block_hash : BlockHash , logger : & L ) -> Result < ( ChannelMonitor < Signer > , Transaction ) , ChannelError > where L :: Target : Logger {
1604
1606
if !self . is_outbound ( ) {
1605
1607
return Err ( ChannelError :: Close ( "Received funding_signed for an inbound channel?" . to_owned ( ) ) ) ;
1606
1608
}
@@ -1662,7 +1664,7 @@ impl<Signer: Sign> Channel<Signer> {
1662
1664
self . cur_holder_commitment_transaction_number -= 1 ;
1663
1665
self . cur_counterparty_commitment_transaction_number -= 1 ;
1664
1666
1665
- Ok ( channel_monitor)
1667
+ Ok ( ( channel_monitor, self . funding_transaction . as_ref ( ) . cloned ( ) . unwrap ( ) ) )
1666
1668
}
1667
1669
1668
1670
pub fn funding_locked ( & mut self , msg : & msgs:: FundingLocked ) -> Result < ( ) , ChannelError > {
@@ -2763,20 +2765,21 @@ impl<Signer: Sign> Channel<Signer> {
2763
2765
/// Indicates that the latest ChannelMonitor update has been committed by the client
2764
2766
/// successfully and we should restore normal operation. Returns messages which should be sent
2765
2767
/// to the remote side.
2766
- pub fn monitor_updating_restored < L : Deref > ( & mut self , logger : & L ) -> ( Option < msgs:: RevokeAndACK > , Option < msgs:: CommitmentUpdate > , RAACommitmentOrder , Vec < ( PendingHTLCInfo , u64 ) > , Vec < ( HTLCSource , PaymentHash , HTLCFailReason ) > , bool , Option < msgs:: FundingLocked > ) where L :: Target : Logger {
2768
+ pub fn monitor_updating_restored < L : Deref > ( & mut self , logger : & L ) -> ( Option < msgs:: RevokeAndACK > , Option < msgs:: CommitmentUpdate > , RAACommitmentOrder , Vec < ( PendingHTLCInfo , u64 ) > , Vec < ( HTLCSource , PaymentHash , HTLCFailReason ) > , Option < Transaction > , Option < msgs:: FundingLocked > ) where L :: Target : Logger {
2767
2769
assert_eq ! ( self . channel_state & ChannelState :: MonitorUpdateFailed as u32 , ChannelState :: MonitorUpdateFailed as u32 ) ;
2768
2770
self . channel_state &= !( ChannelState :: MonitorUpdateFailed as u32 ) ;
2769
2771
2770
- let needs_broadcast_safe = self . channel_state & ( ChannelState :: FundingSent as u32 ) != 0 && self . is_outbound ( ) ;
2772
+ let funding_broadcastable = if self . channel_state & ( ChannelState :: FundingSent as u32 ) != 0 && self . is_outbound ( ) {
2773
+ self . funding_transaction . take ( )
2774
+ } else { None } ;
2771
2775
2772
- // Because we will never generate a FundingBroadcastSafe event when we're in
2773
- // MonitorUpdateFailed, if we assume the user only broadcast the funding transaction when
2774
- // they received the FundingBroadcastSafe event, we can only ever hit
2775
- // monitor_pending_funding_locked when we're an inbound channel which failed to persist the
2776
- // monitor on funding_created, and we even got the funding transaction confirmed before the
2777
- // monitor was persisted.
2776
+ // We will never broadcast the funding transaction when we're in MonitorUpdateFailed (and
2777
+ // we assume the user never directly broadcasts the funding transaction and waits for us to
2778
+ // do it). Thus, we can only ever hit monitor_pending_funding_locked when we're an inbound
2779
+ // channel which failed to persist the monitor on funding_created, and we got the funding
2780
+ // transaction confirmed before the monitor was persisted.
2778
2781
let funding_locked = if self . monitor_pending_funding_locked {
2779
- assert ! ( !self . is_outbound( ) , "Funding transaction broadcast without FundingBroadcastSafe !" ) ;
2782
+ assert ! ( !self . is_outbound( ) , "Funding transaction broadcast by the local client before it should have - LDK didn't do it !" ) ;
2780
2783
self . monitor_pending_funding_locked = false ;
2781
2784
let next_per_commitment_point = self . holder_signer . get_per_commitment_point ( self . cur_holder_commitment_transaction_number , & self . secp_ctx ) ;
2782
2785
Some ( msgs:: FundingLocked {
@@ -2793,7 +2796,7 @@ impl<Signer: Sign> Channel<Signer> {
2793
2796
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) != 0 {
2794
2797
self . monitor_pending_revoke_and_ack = false ;
2795
2798
self . monitor_pending_commitment_signed = false ;
2796
- return ( None , None , RAACommitmentOrder :: RevokeAndACKFirst , forwards, failures, needs_broadcast_safe , funding_locked) ;
2799
+ return ( None , None , RAACommitmentOrder :: RevokeAndACKFirst , forwards, failures, funding_broadcastable , funding_locked) ;
2797
2800
}
2798
2801
2799
2802
let raa = if self . monitor_pending_revoke_and_ack {
@@ -2807,11 +2810,11 @@ impl<Signer: Sign> Channel<Signer> {
2807
2810
self . monitor_pending_commitment_signed = false ;
2808
2811
let order = self . resend_order . clone ( ) ;
2809
2812
log_trace ! ( logger, "Restored monitor updating resulting in {}{} commitment update and {} RAA, with {} first" ,
2810
- if needs_broadcast_safe { "a funding broadcast safe , " } else { "" } ,
2813
+ if funding_broadcastable . is_some ( ) { "a funding broadcastable , " } else { "" } ,
2811
2814
if commitment_update. is_some( ) { "a" } else { "no" } ,
2812
2815
if raa. is_some( ) { "an" } else { "no" } ,
2813
2816
match order { RAACommitmentOrder :: CommitmentFirst => "commitment" , RAACommitmentOrder :: RevokeAndACKFirst => "RAA" } ) ;
2814
- ( raa, commitment_update, order, forwards, failures, needs_broadcast_safe , funding_locked)
2817
+ ( raa, commitment_update, order, forwards, failures, funding_broadcastable , funding_locked)
2815
2818
}
2816
2819
2817
2820
pub fn update_fee < F : Deref > ( & mut self , fee_estimator : & F , msg : & msgs:: UpdateFee ) -> Result < ( ) , ChannelError >
@@ -3764,7 +3767,7 @@ impl<Signer: Sign> Channel<Signer> {
3764
3767
/// Note that channel_id changes during this call!
3765
3768
/// Do NOT broadcast the funding transaction until after a successful funding_signed call!
3766
3769
/// If an Err is returned, it is a ChannelError::Close.
3767
- pub fn get_outbound_funding_created < L : Deref > ( & mut self , funding_txo : OutPoint , logger : & L ) -> Result < msgs:: FundingCreated , ChannelError > where L :: Target : Logger {
3770
+ pub fn get_outbound_funding_created < L : Deref > ( & mut self , funding_transaction : Transaction , funding_txo : OutPoint , logger : & L ) -> Result < msgs:: FundingCreated , ChannelError > where L :: Target : Logger {
3768
3771
if !self . is_outbound ( ) {
3769
3772
panic ! ( "Tried to create outbound funding_created message on an inbound channel!" ) ;
3770
3773
}
@@ -3795,6 +3798,7 @@ impl<Signer: Sign> Channel<Signer> {
3795
3798
3796
3799
self . channel_state = ChannelState :: FundingCreated as u32 ;
3797
3800
self . channel_id = funding_txo. to_channel_id ( ) ;
3801
+ self . funding_transaction = Some ( funding_transaction) ;
3798
3802
3799
3803
Ok ( msgs:: FundingCreated {
3800
3804
temporary_channel_id,
@@ -4519,8 +4523,9 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
4519
4523
}
4520
4524
4521
4525
self . channel_transaction_parameters . write ( writer) ?;
4522
- self . counterparty_cur_commitment_point . write ( writer) ?;
4526
+ self . funding_transaction . write ( writer) ?;
4523
4527
4528
+ self . counterparty_cur_commitment_point . write ( writer) ?;
4524
4529
self . counterparty_prev_commitment_point . write ( writer) ?;
4525
4530
self . counterparty_node_id . write ( writer) ?;
4526
4531
@@ -4689,6 +4694,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4689
4694
} ;
4690
4695
4691
4696
let channel_parameters = Readable :: read ( reader) ?;
4697
+ let funding_transaction = Readable :: read ( reader) ?;
4698
+
4692
4699
let counterparty_cur_commitment_point = Readable :: read ( reader) ?;
4693
4700
4694
4701
let counterparty_prev_commitment_point = Readable :: read ( reader) ?;
@@ -4761,8 +4768,9 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4761
4768
counterparty_forwarding_info,
4762
4769
4763
4770
channel_transaction_parameters : channel_parameters,
4764
- counterparty_cur_commitment_point ,
4771
+ funding_transaction ,
4765
4772
4773
+ counterparty_cur_commitment_point,
4766
4774
counterparty_prev_commitment_point,
4767
4775
counterparty_node_id,
4768
4776
@@ -5030,7 +5038,7 @@ mod tests {
5030
5038
value: 10000000 , script_pubkey: output_script. clone( ) ,
5031
5039
} ] } ;
5032
5040
let funding_outpoint = OutPoint { txid : tx. txid ( ) , index : 0 } ;
5033
- let funding_created_msg = node_a_chan. get_outbound_funding_created ( funding_outpoint, & & logger) . unwrap ( ) ;
5041
+ let funding_created_msg = node_a_chan. get_outbound_funding_created ( tx . clone ( ) , funding_outpoint, & & logger) . unwrap ( ) ;
5034
5042
let ( funding_signed_msg, _) = node_b_chan. funding_created ( & funding_created_msg, last_block_hash, & & logger) . unwrap ( ) ;
5035
5043
5036
5044
// Node B --> Node A: funding signed
0 commit comments