@@ -303,6 +303,8 @@ pub(super) struct Channel<ChanSigner: ChannelKeys> {
303
303
304
304
last_sent_closing_fee : Option < ( u64 , u64 , Signature ) > , // (feerate, fee, our_sig)
305
305
306
+ funding_txo : Option < OutPoint > ,
307
+
306
308
/// The hash of the block in which the funding transaction reached our CONF_TARGET. We use this
307
309
/// to detect unconfirmation after a serialize-unserialize roundtrip where we may not see a full
308
310
/// series of block_connected/block_disconnected calls. Obviously this is not a guarantee as we
@@ -498,6 +500,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
498
500
499
501
last_sent_closing_fee : None ,
500
502
503
+ funding_txo : None ,
501
504
funding_tx_confirmed_in : None ,
502
505
short_channel_id : None ,
503
506
last_block_connected : Default :: default ( ) ,
@@ -718,6 +721,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
718
721
719
722
last_sent_closing_fee : None ,
720
723
724
+ funding_txo : None ,
721
725
funding_tx_confirmed_in : None ,
722
726
short_channel_id : None ,
723
727
last_block_connected : Default :: default ( ) ,
@@ -814,7 +818,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
814
818
let txins = {
815
819
let mut ins: Vec < TxIn > = Vec :: new ( ) ;
816
820
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 ( ) ,
818
822
script_sig : Script :: new ( ) ,
819
823
sequence : ( ( 0x80 as u32 ) << 8 * 3 ) | ( ( obscured_commitment_transaction_number >> 3 * 8 ) as u32 ) ,
820
824
witness : Vec :: new ( ) ,
@@ -1033,7 +1037,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1033
1037
let txins = {
1034
1038
let mut ins: Vec < TxIn > = Vec :: new ( ) ;
1035
1039
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 ( ) ,
1037
1041
script_sig : Script :: new ( ) ,
1038
1042
sequence : 0xffffffff ,
1039
1043
witness : Vec :: new ( ) ,
@@ -1461,17 +1465,19 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1461
1465
}
1462
1466
1463
1467
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 ( ) ) ;
1466
1469
1467
1470
let ( remote_initial_commitment_tx, local_initial_commitment_tx, our_signature, local_keys) = match self . funding_created_signature ( & msg. signature ) {
1468
1471
Ok ( res) => res,
1469
1472
Err ( e) => {
1470
- self . channel_monitor . unset_funding_info ( ) ;
1473
+ self . funding_txo = None ;
1471
1474
return Err ( e) ;
1472
1475
}
1473
1476
} ;
1474
1477
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
+
1475
1481
// Now that we're past error-generating stuff, update our local state:
1476
1482
1477
1483
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> {
2825
2831
/// Returns the funding_txo we either got from our peer, or were given by
2826
2832
/// get_outbound_funding_created.
2827
2833
pub fn get_funding_txo ( & self ) -> Option < OutPoint > {
2828
- self . channel_monitor . get_funding_txo ( )
2834
+ self . funding_txo
2829
2835
}
2830
2836
2831
2837
/// Allowed in any state (including after shutdown)
@@ -3005,8 +3011,8 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3005
3011
}
3006
3012
if non_shutdown_state & !( ChannelState :: TheirFundingLocked as u32 ) == ChannelState :: FundingSent as u32 {
3007
3013
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 ;
3010
3016
if txo_idx >= tx. output . len ( ) || tx. output [ txo_idx] . script_pubkey != self . get_funding_redeemscript ( ) . to_v0_p2wsh ( ) ||
3011
3017
tx. output [ txo_idx] . value != self . channel_value_satoshis {
3012
3018
if self . channel_outbound {
@@ -3209,18 +3215,18 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3209
3215
panic ! ( "Should not have advanced channel commitment tx numbers prior to funding_created" ) ;
3210
3216
}
3211
3217
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 ( ) ) ;
3215
3219
let ( our_signature, commitment_tx) = match self . get_outbound_funding_created_signature ( ) {
3216
3220
Ok ( res) => res,
3217
3221
Err ( e) => {
3218
3222
log_error ! ( self , "Got bad signatures: {:?}!" , e) ;
3219
- self . channel_monitor . unset_funding_info ( ) ;
3223
+ self . funding_txo = None ;
3220
3224
return Err ( e) ;
3221
3225
}
3222
3226
} ;
3223
3227
3228
+ let funding_txo_script = self . get_funding_redeemscript ( ) . to_v0_p2wsh ( ) ;
3229
+ self . channel_monitor . set_funding_info ( ( funding_txo, funding_txo_script) ) ;
3224
3230
let temporary_channel_id = self . channel_id ;
3225
3231
3226
3232
// Now that we're past error-generating stuff, update our local state:
@@ -3815,6 +3821,7 @@ impl<ChanSigner: ChannelKeys + Writeable> Writeable for Channel<ChanSigner> {
3815
3821
None => 0u8 . write ( writer) ?,
3816
3822
}
3817
3823
3824
+ write_option ! ( self . funding_txo) ;
3818
3825
write_option ! ( self . funding_tx_confirmed_in) ;
3819
3826
write_option ! ( self . short_channel_id) ;
3820
3827
@@ -3967,6 +3974,7 @@ impl<R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>> ReadableArgs<R,
3967
3974
_ => return Err ( DecodeError :: InvalidValue ) ,
3968
3975
} ;
3969
3976
3977
+ let funding_txo = Readable :: read ( reader) ?;
3970
3978
let funding_tx_confirmed_in = Readable :: read ( reader) ?;
3971
3979
let short_channel_id = Readable :: read ( reader) ?;
3972
3980
@@ -4043,6 +4051,7 @@ impl<R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>> ReadableArgs<R,
4043
4051
4044
4052
last_sent_closing_fee,
4045
4053
4054
+ funding_txo,
4046
4055
funding_tx_confirmed_in,
4047
4056
short_channel_id,
4048
4057
last_block_connected,
@@ -4183,7 +4192,7 @@ mod tests {
4183
4192
chan. our_dust_limit_satoshis = 546 ;
4184
4193
4185
4194
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 ) ;
4187
4196
4188
4197
let their_pubkeys = ChannelPublicKeys {
4189
4198
funding_pubkey : public_from_secret_hex ( & secp_ctx, "1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e13" ) ,
0 commit comments