@@ -409,9 +409,9 @@ pub(super) struct Channel<Signer: Sign> {
409
409
counterparty_forwarding_info : Option < CounterpartyForwardingInfo > ,
410
410
411
411
pub ( crate ) channel_transaction_parameters : ChannelTransactionParameters ,
412
+ funding_transaction : Option < Transaction > ,
412
413
413
414
counterparty_cur_commitment_point : Option < PublicKey > ,
414
-
415
415
counterparty_prev_commitment_point : Option < PublicKey > ,
416
416
counterparty_node_id : PublicKey ,
417
417
@@ -603,8 +603,9 @@ impl<Signer: Sign> Channel<Signer> {
603
603
counterparty_parameters : None ,
604
604
funding_outpoint : None
605
605
} ,
606
- counterparty_cur_commitment_point : None ,
606
+ funding_transaction : None ,
607
607
608
+ counterparty_cur_commitment_point : None ,
608
609
counterparty_prev_commitment_point : None ,
609
610
counterparty_node_id,
610
611
@@ -844,8 +845,9 @@ impl<Signer: Sign> Channel<Signer> {
844
845
} ) ,
845
846
funding_outpoint : None
846
847
} ,
847
- counterparty_cur_commitment_point : Some ( msg . first_per_commitment_point ) ,
848
+ funding_transaction : None ,
848
849
850
+ counterparty_cur_commitment_point : Some ( msg. first_per_commitment_point ) ,
849
851
counterparty_prev_commitment_point : None ,
850
852
counterparty_node_id,
851
853
@@ -1608,7 +1610,7 @@ impl<Signer: Sign> Channel<Signer> {
1608
1610
1609
1611
/// Handles a funding_signed message from the remote end.
1610
1612
/// If this call is successful, broadcast the funding transaction (and not before!)
1611
- 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 {
1613
+ 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 {
1612
1614
if !self . is_outbound ( ) {
1613
1615
return Err ( ChannelError :: Close ( "Received funding_signed for an inbound channel?" . to_owned ( ) ) ) ;
1614
1616
}
@@ -1670,7 +1672,7 @@ impl<Signer: Sign> Channel<Signer> {
1670
1672
self . cur_holder_commitment_transaction_number -= 1 ;
1671
1673
self . cur_counterparty_commitment_transaction_number -= 1 ;
1672
1674
1673
- Ok ( channel_monitor)
1675
+ Ok ( ( channel_monitor, self . funding_transaction . as_ref ( ) . cloned ( ) . unwrap ( ) ) )
1674
1676
}
1675
1677
1676
1678
pub fn funding_locked ( & mut self , msg : & msgs:: FundingLocked ) -> Result < ( ) , ChannelError > {
@@ -2771,20 +2773,21 @@ impl<Signer: Sign> Channel<Signer> {
2771
2773
/// Indicates that the latest ChannelMonitor update has been committed by the client
2772
2774
/// successfully and we should restore normal operation. Returns messages which should be sent
2773
2775
/// to the remote side.
2774
- 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 {
2776
+ 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 {
2775
2777
assert_eq ! ( self . channel_state & ChannelState :: MonitorUpdateFailed as u32 , ChannelState :: MonitorUpdateFailed as u32 ) ;
2776
2778
self . channel_state &= !( ChannelState :: MonitorUpdateFailed as u32 ) ;
2777
2779
2778
- let needs_broadcast_safe = self . channel_state & ( ChannelState :: FundingSent as u32 ) != 0 && self . is_outbound ( ) ;
2780
+ let funding_broadcastable = if self . channel_state & ( ChannelState :: FundingSent as u32 ) != 0 && self . is_outbound ( ) {
2781
+ self . funding_transaction . take ( )
2782
+ } else { None } ;
2779
2783
2780
- // Because we will never generate a FundingBroadcastSafe event when we're in
2781
- // MonitorUpdateFailed, if we assume the user only broadcast the funding transaction when
2782
- // they received the FundingBroadcastSafe event, we can only ever hit
2783
- // monitor_pending_funding_locked when we're an inbound channel which failed to persist the
2784
- // monitor on funding_created, and we even got the funding transaction confirmed before the
2785
- // monitor was persisted.
2784
+ // We will never broadcast the funding transaction when we're in MonitorUpdateFailed (and
2785
+ // we assume the user never directly broadcasts the funding transaction and waits for us to
2786
+ // do it). Thus, we can only ever hit monitor_pending_funding_locked when we're an inbound
2787
+ // channel which failed to persist the monitor on funding_created, and we got the funding
2788
+ // transaction confirmed before the monitor was persisted.
2786
2789
let funding_locked = if self . monitor_pending_funding_locked {
2787
- assert ! ( !self . is_outbound( ) , "Funding transaction broadcast without FundingBroadcastSafe !" ) ;
2790
+ assert ! ( !self . is_outbound( ) , "Funding transaction broadcast by the local client before it should have - LDK didn't do it !" ) ;
2788
2791
self . monitor_pending_funding_locked = false ;
2789
2792
let next_per_commitment_point = self . holder_signer . get_per_commitment_point ( self . cur_holder_commitment_transaction_number , & self . secp_ctx ) ;
2790
2793
Some ( msgs:: FundingLocked {
@@ -2801,7 +2804,7 @@ impl<Signer: Sign> Channel<Signer> {
2801
2804
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) != 0 {
2802
2805
self . monitor_pending_revoke_and_ack = false ;
2803
2806
self . monitor_pending_commitment_signed = false ;
2804
- return ( None , None , RAACommitmentOrder :: RevokeAndACKFirst , forwards, failures, needs_broadcast_safe , funding_locked) ;
2807
+ return ( None , None , RAACommitmentOrder :: RevokeAndACKFirst , forwards, failures, funding_broadcastable , funding_locked) ;
2805
2808
}
2806
2809
2807
2810
let raa = if self . monitor_pending_revoke_and_ack {
@@ -2815,11 +2818,11 @@ impl<Signer: Sign> Channel<Signer> {
2815
2818
self . monitor_pending_commitment_signed = false ;
2816
2819
let order = self . resend_order . clone ( ) ;
2817
2820
log_trace ! ( logger, "Restored monitor updating resulting in {}{} commitment update and {} RAA, with {} first" ,
2818
- if needs_broadcast_safe { "a funding broadcast safe , " } else { "" } ,
2821
+ if funding_broadcastable . is_some ( ) { "a funding broadcastable , " } else { "" } ,
2819
2822
if commitment_update. is_some( ) { "a" } else { "no" } ,
2820
2823
if raa. is_some( ) { "an" } else { "no" } ,
2821
2824
match order { RAACommitmentOrder :: CommitmentFirst => "commitment" , RAACommitmentOrder :: RevokeAndACKFirst => "RAA" } ) ;
2822
- ( raa, commitment_update, order, forwards, failures, needs_broadcast_safe , funding_locked)
2825
+ ( raa, commitment_update, order, forwards, failures, funding_broadcastable , funding_locked)
2823
2826
}
2824
2827
2825
2828
pub fn update_fee < F : Deref > ( & mut self , fee_estimator : & F , msg : & msgs:: UpdateFee ) -> Result < ( ) , ChannelError >
@@ -3734,7 +3737,7 @@ impl<Signer: Sign> Channel<Signer> {
3734
3737
/// Note that channel_id changes during this call!
3735
3738
/// Do NOT broadcast the funding transaction until after a successful funding_signed call!
3736
3739
/// If an Err is returned, it is a ChannelError::Close.
3737
- pub fn get_outbound_funding_created < L : Deref > ( & mut self , funding_txo : OutPoint , logger : & L ) -> Result < msgs:: FundingCreated , ChannelError > where L :: Target : Logger {
3740
+ 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 {
3738
3741
if !self . is_outbound ( ) {
3739
3742
panic ! ( "Tried to create outbound funding_created message on an inbound channel!" ) ;
3740
3743
}
@@ -3765,6 +3768,7 @@ impl<Signer: Sign> Channel<Signer> {
3765
3768
3766
3769
self . channel_state = ChannelState :: FundingCreated as u32 ;
3767
3770
self . channel_id = funding_txo. to_channel_id ( ) ;
3771
+ self . funding_transaction = Some ( funding_transaction) ;
3768
3772
3769
3773
Ok ( msgs:: FundingCreated {
3770
3774
temporary_channel_id,
@@ -4489,8 +4493,9 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
4489
4493
}
4490
4494
4491
4495
self . channel_transaction_parameters . write ( writer) ?;
4492
- self . counterparty_cur_commitment_point . write ( writer) ?;
4496
+ self . funding_transaction . write ( writer) ?;
4493
4497
4498
+ self . counterparty_cur_commitment_point . write ( writer) ?;
4494
4499
self . counterparty_prev_commitment_point . write ( writer) ?;
4495
4500
self . counterparty_node_id . write ( writer) ?;
4496
4501
@@ -4659,6 +4664,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4659
4664
} ;
4660
4665
4661
4666
let channel_parameters = Readable :: read ( reader) ?;
4667
+ let funding_transaction = Readable :: read ( reader) ?;
4668
+
4662
4669
let counterparty_cur_commitment_point = Readable :: read ( reader) ?;
4663
4670
4664
4671
let counterparty_prev_commitment_point = Readable :: read ( reader) ?;
@@ -4731,8 +4738,9 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4731
4738
counterparty_forwarding_info,
4732
4739
4733
4740
channel_transaction_parameters : channel_parameters,
4734
- counterparty_cur_commitment_point ,
4741
+ funding_transaction ,
4735
4742
4743
+ counterparty_cur_commitment_point,
4736
4744
counterparty_prev_commitment_point,
4737
4745
counterparty_node_id,
4738
4746
@@ -5000,7 +5008,7 @@ mod tests {
5000
5008
value: 10000000 , script_pubkey: output_script. clone( ) ,
5001
5009
} ] } ;
5002
5010
let funding_outpoint = OutPoint { txid : tx. txid ( ) , index : 0 } ;
5003
- let funding_created_msg = node_a_chan. get_outbound_funding_created ( funding_outpoint, & & logger) . unwrap ( ) ;
5011
+ let funding_created_msg = node_a_chan. get_outbound_funding_created ( tx . clone ( ) , funding_outpoint, & & logger) . unwrap ( ) ;
5004
5012
let ( funding_signed_msg, _) = node_b_chan. funding_created ( & funding_created_msg, last_block_hash, & & logger) . unwrap ( ) ;
5005
5013
5006
5014
// Node B --> Node A: funding signed
0 commit comments