@@ -306,6 +306,8 @@ pub(super) struct Channel<ChanSigner: ChannelKeys> {
306
306
307
307
last_sent_closing_fee : Option < ( u64 , u64 , Signature ) > , // (feerate, fee, our_sig)
308
308
309
+ funding_txo : Option < OutPoint > ,
310
+
309
311
/// The hash of the block in which the funding transaction reached our CONF_TARGET. We use this
310
312
/// to detect unconfirmation after a serialize-unserialize roundtrip where we may not see a full
311
313
/// series of block_connected/block_disconnected calls. Obviously this is not a guarantee as we
@@ -501,6 +503,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
501
503
502
504
last_sent_closing_fee : None ,
503
505
506
+ funding_txo : None ,
504
507
funding_tx_confirmed_in : None ,
505
508
short_channel_id : None ,
506
509
last_block_connected : Default :: default ( ) ,
@@ -721,6 +724,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
721
724
722
725
last_sent_closing_fee : None ,
723
726
727
+ funding_txo : None ,
724
728
funding_tx_confirmed_in : None ,
725
729
short_channel_id : None ,
726
730
last_block_connected : Default :: default ( ) ,
@@ -817,7 +821,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
817
821
let txins = {
818
822
let mut ins: Vec < TxIn > = Vec :: new ( ) ;
819
823
ins. push ( TxIn {
820
- previous_output : self . channel_monitor . get_funding_txo ( ) . unwrap ( ) . into_bitcoin_outpoint ( ) ,
824
+ previous_output : self . funding_txo . unwrap ( ) . into_bitcoin_outpoint ( ) ,
821
825
script_sig : Script :: new ( ) ,
822
826
sequence : ( ( 0x80 as u32 ) << 8 * 3 ) | ( ( obscured_commitment_transaction_number >> 3 * 8 ) as u32 ) ,
823
827
witness : Vec :: new ( ) ,
@@ -1036,7 +1040,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1036
1040
let txins = {
1037
1041
let mut ins: Vec < TxIn > = Vec :: new ( ) ;
1038
1042
ins. push ( TxIn {
1039
- previous_output : self . channel_monitor . get_funding_txo ( ) . unwrap ( ) . into_bitcoin_outpoint ( ) ,
1043
+ previous_output : self . funding_txo . unwrap ( ) . into_bitcoin_outpoint ( ) ,
1040
1044
script_sig : Script :: new ( ) ,
1041
1045
sequence : 0xffffffff ,
1042
1046
witness : Vec :: new ( ) ,
@@ -1464,17 +1468,19 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1464
1468
}
1465
1469
1466
1470
let funding_txo = OutPoint :: new ( msg. funding_txid , msg. funding_output_index ) ;
1467
- let funding_txo_script = self . get_funding_redeemscript ( ) . to_v0_p2wsh ( ) ;
1468
- self . channel_monitor . set_funding_info ( ( funding_txo, funding_txo_script) ) ;
1471
+ self . funding_txo = Some ( funding_txo. clone ( ) ) ;
1469
1472
1470
1473
let ( remote_initial_commitment_tx, local_initial_commitment_tx, our_signature, local_keys) = match self . funding_created_signature ( & msg. signature ) {
1471
1474
Ok ( res) => res,
1472
1475
Err ( e) => {
1473
- self . channel_monitor . unset_funding_info ( ) ;
1476
+ self . funding_txo = None ;
1474
1477
return Err ( e) ;
1475
1478
}
1476
1479
} ;
1477
1480
1481
+ let funding_txo_script = self . get_funding_redeemscript ( ) . to_v0_p2wsh ( ) ;
1482
+ self . channel_monitor . set_funding_info ( ( funding_txo, funding_txo_script) ) ;
1483
+
1478
1484
// Now that we're past error-generating stuff, update our local state:
1479
1485
1480
1486
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 ( ) ) ;
@@ -2829,7 +2835,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2829
2835
/// Returns the funding_txo we either got from our peer, or were given by
2830
2836
/// get_outbound_funding_created.
2831
2837
pub fn get_funding_txo ( & self ) -> Option < OutPoint > {
2832
- self . channel_monitor . get_funding_txo ( )
2838
+ self . funding_txo
2833
2839
}
2834
2840
2835
2841
/// Allowed in any state (including after shutdown)
@@ -3021,8 +3027,8 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3021
3027
}
3022
3028
if non_shutdown_state & !( ChannelState :: TheirFundingLocked as u32 ) == ChannelState :: FundingSent as u32 {
3023
3029
for ( ref tx, index_in_block) in txn_matched. iter ( ) . zip ( indexes_of_txn_matched) {
3024
- if tx. txid ( ) == self . channel_monitor . get_funding_txo ( ) . unwrap ( ) . txid {
3025
- let txo_idx = self . channel_monitor . get_funding_txo ( ) . unwrap ( ) . index as usize ;
3030
+ if tx. txid ( ) == self . funding_txo . unwrap ( ) . txid {
3031
+ let txo_idx = self . funding_txo . unwrap ( ) . index as usize ;
3026
3032
if txo_idx >= tx. output . len ( ) || tx. output [ txo_idx] . script_pubkey != self . get_funding_redeemscript ( ) . to_v0_p2wsh ( ) ||
3027
3033
tx. output [ txo_idx] . value != self . channel_value_satoshis {
3028
3034
if self . channel_outbound {
@@ -3225,18 +3231,18 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3225
3231
panic ! ( "Should not have advanced channel commitment tx numbers prior to funding_created" ) ;
3226
3232
}
3227
3233
3228
- let funding_txo_script = self . get_funding_redeemscript ( ) . to_v0_p2wsh ( ) ;
3229
- self . channel_monitor . set_funding_info ( ( funding_txo, funding_txo_script) ) ;
3230
-
3234
+ self . funding_txo = Some ( funding_txo. clone ( ) ) ;
3231
3235
let ( our_signature, commitment_tx) = match self . get_outbound_funding_created_signature ( ) {
3232
3236
Ok ( res) => res,
3233
3237
Err ( e) => {
3234
3238
log_error ! ( self , "Got bad signatures: {:?}!" , e) ;
3235
- self . channel_monitor . unset_funding_info ( ) ;
3239
+ self . funding_txo = None ;
3236
3240
return Err ( e) ;
3237
3241
}
3238
3242
} ;
3239
3243
3244
+ let funding_txo_script = self . get_funding_redeemscript ( ) . to_v0_p2wsh ( ) ;
3245
+ self . channel_monitor . set_funding_info ( ( funding_txo, funding_txo_script) ) ;
3240
3246
let temporary_channel_id = self . channel_id ;
3241
3247
3242
3248
// Now that we're past error-generating stuff, update our local state:
@@ -3828,6 +3834,7 @@ impl<ChanSigner: ChannelKeys + Writeable> Writeable for Channel<ChanSigner> {
3828
3834
None => 0u8 . write ( writer) ?,
3829
3835
}
3830
3836
3837
+ write_option ! ( self . funding_txo) ;
3831
3838
write_option ! ( self . funding_tx_confirmed_in) ;
3832
3839
write_option ! ( self . short_channel_id) ;
3833
3840
@@ -3980,6 +3987,7 @@ impl<R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>> ReadableArgs<R,
3980
3987
_ => return Err ( DecodeError :: InvalidValue ) ,
3981
3988
} ;
3982
3989
3990
+ let funding_txo = Readable :: read ( reader) ?;
3983
3991
let funding_tx_confirmed_in = Readable :: read ( reader) ?;
3984
3992
let short_channel_id = Readable :: read ( reader) ?;
3985
3993
@@ -4056,6 +4064,7 @@ impl<R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>> ReadableArgs<R,
4056
4064
4057
4065
last_sent_closing_fee,
4058
4066
4067
+ funding_txo,
4059
4068
funding_tx_confirmed_in,
4060
4069
short_channel_id,
4061
4070
last_block_connected,
@@ -4196,7 +4205,7 @@ mod tests {
4196
4205
chan. our_dust_limit_satoshis = 546 ;
4197
4206
4198
4207
let funding_info = OutPoint :: new ( Sha256dHash :: from_hex ( "8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be" ) . unwrap ( ) , 0 ) ;
4199
- chan. channel_monitor . set_funding_info ( ( funding_info , Script :: new ( ) ) ) ;
4208
+ chan. funding_txo = Some ( funding_info ) ;
4200
4209
4201
4210
let their_pubkeys = ChannelPublicKeys {
4202
4211
funding_pubkey : public_from_secret_hex ( & secp_ctx, "1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e13" ) ,
0 commit comments