@@ -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,11 +2773,13 @@ 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
2784
// Because we will never generate a FundingBroadcastSafe event when we're in
2781
2785
// MonitorUpdateFailed, if we assume the user only broadcast the funding transaction when
@@ -2801,7 +2805,7 @@ impl<Signer: Sign> Channel<Signer> {
2801
2805
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) != 0 {
2802
2806
self . monitor_pending_revoke_and_ack = false ;
2803
2807
self . monitor_pending_commitment_signed = false ;
2804
- return ( None , None , RAACommitmentOrder :: RevokeAndACKFirst , forwards, failures, needs_broadcast_safe , funding_locked) ;
2808
+ return ( None , None , RAACommitmentOrder :: RevokeAndACKFirst , forwards, failures, funding_broadcastable , funding_locked) ;
2805
2809
}
2806
2810
2807
2811
let raa = if self . monitor_pending_revoke_and_ack {
@@ -2815,11 +2819,11 @@ impl<Signer: Sign> Channel<Signer> {
2815
2819
self . monitor_pending_commitment_signed = false ;
2816
2820
let order = self . resend_order . clone ( ) ;
2817
2821
log_trace ! ( logger, "Restored monitor updating resulting in {}{} commitment update and {} RAA, with {} first" ,
2818
- if needs_broadcast_safe { "a funding broadcast safe, " } else { "" } ,
2822
+ if funding_broadcastable . is_some ( ) { "a funding broadcast safe, " } else { "" } ,
2819
2823
if commitment_update. is_some( ) { "a" } else { "no" } ,
2820
2824
if raa. is_some( ) { "an" } else { "no" } ,
2821
2825
match order { RAACommitmentOrder :: CommitmentFirst => "commitment" , RAACommitmentOrder :: RevokeAndACKFirst => "RAA" } ) ;
2822
- ( raa, commitment_update, order, forwards, failures, needs_broadcast_safe , funding_locked)
2826
+ ( raa, commitment_update, order, forwards, failures, funding_broadcastable , funding_locked)
2823
2827
}
2824
2828
2825
2829
pub fn update_fee < F : Deref > ( & mut self , fee_estimator : & F , msg : & msgs:: UpdateFee ) -> Result < ( ) , ChannelError >
@@ -3734,7 +3738,7 @@ impl<Signer: Sign> Channel<Signer> {
3734
3738
/// Note that channel_id changes during this call!
3735
3739
/// Do NOT broadcast the funding transaction until after a successful funding_signed call!
3736
3740
/// 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 {
3741
+ 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
3742
if !self . is_outbound ( ) {
3739
3743
panic ! ( "Tried to create outbound funding_created message on an inbound channel!" ) ;
3740
3744
}
@@ -3765,6 +3769,7 @@ impl<Signer: Sign> Channel<Signer> {
3765
3769
3766
3770
self . channel_state = ChannelState :: FundingCreated as u32 ;
3767
3771
self . channel_id = funding_txo. to_channel_id ( ) ;
3772
+ self . funding_transaction = Some ( funding_transaction) ;
3768
3773
3769
3774
Ok ( msgs:: FundingCreated {
3770
3775
temporary_channel_id,
@@ -4489,8 +4494,9 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
4489
4494
}
4490
4495
4491
4496
self . channel_transaction_parameters . write ( writer) ?;
4492
- self . counterparty_cur_commitment_point . write ( writer) ?;
4497
+ self . funding_transaction . write ( writer) ?;
4493
4498
4499
+ self . counterparty_cur_commitment_point . write ( writer) ?;
4494
4500
self . counterparty_prev_commitment_point . write ( writer) ?;
4495
4501
self . counterparty_node_id . write ( writer) ?;
4496
4502
@@ -4659,6 +4665,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4659
4665
} ;
4660
4666
4661
4667
let channel_parameters = Readable :: read ( reader) ?;
4668
+ let funding_transaction = Readable :: read ( reader) ?;
4669
+
4662
4670
let counterparty_cur_commitment_point = Readable :: read ( reader) ?;
4663
4671
4664
4672
let counterparty_prev_commitment_point = Readable :: read ( reader) ?;
@@ -4731,8 +4739,9 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4731
4739
counterparty_forwarding_info,
4732
4740
4733
4741
channel_transaction_parameters : channel_parameters,
4734
- counterparty_cur_commitment_point ,
4742
+ funding_transaction ,
4735
4743
4744
+ counterparty_cur_commitment_point,
4736
4745
counterparty_prev_commitment_point,
4737
4746
counterparty_node_id,
4738
4747
@@ -5000,7 +5009,7 @@ mod tests {
5000
5009
value: 10000000 , script_pubkey: output_script. clone( ) ,
5001
5010
} ] } ;
5002
5011
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 ( ) ;
5012
+ let funding_created_msg = node_a_chan. get_outbound_funding_created ( tx . clone ( ) , funding_outpoint, & & logger) . unwrap ( ) ;
5004
5013
let ( funding_signed_msg, _) = node_b_chan. funding_created ( & funding_created_msg, last_block_hash, & & logger) . unwrap ( ) ;
5005
5014
5006
5015
// Node B --> Node A: funding signed
0 commit comments