@@ -303,6 +303,8 @@ pub(super) struct Channel<ChanSigner: ChannelKeys> {
303303
304304 last_sent_closing_fee : Option < ( u64 , u64 , Signature ) > , // (feerate, fee, our_sig)
305305
306+ funding_txo : Option < OutPoint > ,
307+
306308 /// The hash of the block in which the funding transaction reached our CONF_TARGET. We use this
307309 /// to detect unconfirmation after a serialize-unserialize roundtrip where we may not see a full
308310 /// series of block_connected/block_disconnected calls. Obviously this is not a guarantee as we
@@ -498,6 +500,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
498500
499501 last_sent_closing_fee : None ,
500502
503+ funding_txo : None ,
501504 funding_tx_confirmed_in : None ,
502505 short_channel_id : None ,
503506 last_block_connected : Default :: default ( ) ,
@@ -718,6 +721,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
718721
719722 last_sent_closing_fee : None ,
720723
724+ funding_txo : None ,
721725 funding_tx_confirmed_in : None ,
722726 short_channel_id : None ,
723727 last_block_connected : Default :: default ( ) ,
@@ -814,7 +818,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
814818 let txins = {
815819 let mut ins: Vec < TxIn > = Vec :: new ( ) ;
816820 ins. push ( TxIn {
817- previous_output : self . channel_monitor . get_funding_txo ( ) . unwrap ( ) . into_bitcoin_outpoint ( ) ,
821+ previous_output : self . funding_txo . unwrap ( ) . into_bitcoin_outpoint ( ) ,
818822 script_sig : Script :: new ( ) ,
819823 sequence : ( ( 0x80 as u32 ) << 8 * 3 ) | ( ( obscured_commitment_transaction_number >> 3 * 8 ) as u32 ) ,
820824 witness : Vec :: new ( ) ,
@@ -1033,7 +1037,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
10331037 let txins = {
10341038 let mut ins: Vec < TxIn > = Vec :: new ( ) ;
10351039 ins. push ( TxIn {
1036- previous_output : self . channel_monitor . get_funding_txo ( ) . unwrap ( ) . into_bitcoin_outpoint ( ) ,
1040+ previous_output : self . funding_txo . unwrap ( ) . into_bitcoin_outpoint ( ) ,
10371041 script_sig : Script :: new ( ) ,
10381042 sequence : 0xffffffff ,
10391043 witness : Vec :: new ( ) ,
@@ -1461,17 +1465,19 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
14611465 }
14621466
14631467 let funding_txo = OutPoint :: new ( msg. funding_txid , msg. funding_output_index ) ;
1464- let funding_txo_script = self . get_funding_redeemscript ( ) . to_v0_p2wsh ( ) ;
1465- self . channel_monitor . set_funding_info ( ( funding_txo, funding_txo_script) ) ;
1468+ self . funding_txo = Some ( funding_txo. clone ( ) ) ;
14661469
14671470 let ( remote_initial_commitment_tx, local_initial_commitment_tx, our_signature, local_keys) = match self . funding_created_signature ( & msg. signature ) {
14681471 Ok ( res) => res,
14691472 Err ( e) => {
1470- self . channel_monitor . unset_funding_info ( ) ;
1473+ self . funding_txo = None ;
14711474 return Err ( e) ;
14721475 }
14731476 } ;
14741477
1478+ let funding_txo_script = self . get_funding_redeemscript ( ) . to_v0_p2wsh ( ) ;
1479+ self . channel_monitor . set_funding_info ( ( funding_txo, funding_txo_script) ) ;
1480+
14751481 // Now that we're past error-generating stuff, update our local state:
14761482
14771483 self . channel_monitor . provide_latest_remote_commitment_tx_info ( & remote_initial_commitment_tx, Vec :: new ( ) , self . cur_remote_commitment_transaction_number , self . their_cur_commitment_point . unwrap ( ) ) ;
@@ -2825,7 +2831,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
28252831 /// Returns the funding_txo we either got from our peer, or were given by
28262832 /// get_outbound_funding_created.
28272833 pub fn get_funding_txo ( & self ) -> Option < OutPoint > {
2828- self . channel_monitor . get_funding_txo ( )
2834+ self . funding_txo
28292835 }
28302836
28312837 /// Allowed in any state (including after shutdown)
@@ -3005,8 +3011,8 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
30053011 }
30063012 if non_shutdown_state & !( ChannelState :: TheirFundingLocked as u32 ) == ChannelState :: FundingSent as u32 {
30073013 for ( ref tx, index_in_block) in txn_matched. iter ( ) . zip ( indexes_of_txn_matched) {
3008- if tx. txid ( ) == self . channel_monitor . get_funding_txo ( ) . unwrap ( ) . txid {
3009- let txo_idx = self . channel_monitor . get_funding_txo ( ) . unwrap ( ) . index as usize ;
3014+ if tx. txid ( ) == self . funding_txo . unwrap ( ) . txid {
3015+ let txo_idx = self . funding_txo . unwrap ( ) . index as usize ;
30103016 if txo_idx >= tx. output . len ( ) || tx. output [ txo_idx] . script_pubkey != self . get_funding_redeemscript ( ) . to_v0_p2wsh ( ) ||
30113017 tx. output [ txo_idx] . value != self . channel_value_satoshis {
30123018 if self . channel_outbound {
@@ -3209,18 +3215,18 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
32093215 panic ! ( "Should not have advanced channel commitment tx numbers prior to funding_created" ) ;
32103216 }
32113217
3212- let funding_txo_script = self . get_funding_redeemscript ( ) . to_v0_p2wsh ( ) ;
3213- self . channel_monitor . set_funding_info ( ( funding_txo, funding_txo_script) ) ;
3214-
3218+ self . funding_txo = Some ( funding_txo. clone ( ) ) ;
32153219 let ( our_signature, commitment_tx) = match self . get_outbound_funding_created_signature ( ) {
32163220 Ok ( res) => res,
32173221 Err ( e) => {
32183222 log_error ! ( self , "Got bad signatures: {:?}!" , e) ;
3219- self . channel_monitor . unset_funding_info ( ) ;
3223+ self . funding_txo = None ;
32203224 return Err ( e) ;
32213225 }
32223226 } ;
32233227
3228+ let funding_txo_script = self . get_funding_redeemscript ( ) . to_v0_p2wsh ( ) ;
3229+ self . channel_monitor . set_funding_info ( ( funding_txo, funding_txo_script) ) ;
32243230 let temporary_channel_id = self . channel_id ;
32253231
32263232 // Now that we're past error-generating stuff, update our local state:
@@ -3815,6 +3821,7 @@ impl<ChanSigner: ChannelKeys + Writeable> Writeable for Channel<ChanSigner> {
38153821 None => 0u8 . write ( writer) ?,
38163822 }
38173823
3824+ write_option ! ( self . funding_txo) ;
38183825 write_option ! ( self . funding_tx_confirmed_in) ;
38193826 write_option ! ( self . short_channel_id) ;
38203827
@@ -3967,6 +3974,7 @@ impl<R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>> ReadableArgs<R,
39673974 _ => return Err ( DecodeError :: InvalidValue ) ,
39683975 } ;
39693976
3977+ let funding_txo = Readable :: read ( reader) ?;
39703978 let funding_tx_confirmed_in = Readable :: read ( reader) ?;
39713979 let short_channel_id = Readable :: read ( reader) ?;
39723980
@@ -4043,6 +4051,7 @@ impl<R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>> ReadableArgs<R,
40434051
40444052 last_sent_closing_fee,
40454053
4054+ funding_txo,
40464055 funding_tx_confirmed_in,
40474056 short_channel_id,
40484057 last_block_connected,
@@ -4183,7 +4192,7 @@ mod tests {
41834192 chan. our_dust_limit_satoshis = 546 ;
41844193
41854194 let funding_info = OutPoint :: new ( Sha256dHash :: from_hex ( "8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be" ) . unwrap ( ) , 0 ) ;
4186- chan. channel_monitor . set_funding_info ( ( funding_info , Script :: new ( ) ) ) ;
4195+ chan. funding_txo = Some ( funding_info ) ;
41874196
41884197 let their_pubkeys = ChannelPublicKeys {
41894198 funding_pubkey : public_from_secret_hex ( & secp_ctx, "1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e13" ) ,
0 commit comments