@@ -457,9 +457,10 @@ pub(super) struct Channel<Signer: Sign> {
457457 funding_tx_confirmed_in : Option < BlockHash > ,
458458 funding_tx_confirmation_height : u32 ,
459459 short_channel_id : Option < u64 > ,
460- /// If this channel was created in recent software, this will be set to the height at which
461- /// channel creation was intiated. This is used to close if funding is never broadcasted.
462- channel_creation_height : Option < u32 > ,
460+ /// Either the height at which this channel was created or the height at which it was last
461+ /// serialized by older software.
462+ /// We use this to close if funding is never broadcasted.
463+ channel_creation_height : u32 ,
463464
464465 counterparty_dust_limit_satoshis : u64 ,
465466 #[ cfg( test) ]
@@ -715,7 +716,7 @@ impl<Signer: Sign> Channel<Signer> {
715716 funding_tx_confirmed_in : None ,
716717 funding_tx_confirmation_height : 0 ,
717718 short_channel_id : None ,
718- channel_creation_height : Some ( current_chain_heigt) ,
719+ channel_creation_height : current_chain_heigt,
719720
720721 feerate_per_kw : feerate,
721722 counterparty_dust_limit_satoshis : 0 ,
@@ -982,7 +983,7 @@ impl<Signer: Sign> Channel<Signer> {
982983 funding_tx_confirmed_in : None ,
983984 funding_tx_confirmation_height : 0 ,
984985 short_channel_id : None ,
985- channel_creation_height : Some ( current_chain_heigt) ,
986+ channel_creation_height : current_chain_heigt,
986987
987988 feerate_per_kw : msg. feerate_per_kw ,
988989 channel_value_satoshis : msg. funding_satoshis ,
@@ -4148,18 +4149,16 @@ impl<Signer: Sign> Channel<Signer> {
41484149 data : format ! ( "Funding transaction was un-confirmed. Locked at {} confs, now have {} confs." , self . minimum_depth. unwrap( ) , funding_tx_confirmations) ,
41494150 } ) ;
41504151 }
4151- } else if let Some ( creation_height) = self . channel_creation_height {
4152- if !self . is_outbound ( ) && self . funding_tx_confirmed_in . is_none ( ) &&
4153- creation_height + FUNDING_CONF_DEADLINE_BLOCKS <= height {
4154- log_info ! ( logger, "Closing channel {} due to funding timeout" , log_bytes!( self . channel_id) ) ;
4155- // If funding_tx_confirmed_in is unset, the channel must not be active
4156- assert ! ( non_shutdown_state <= ChannelState :: ChannelFunded as u32 ) ;
4157- assert_eq ! ( non_shutdown_state & ChannelState :: OurFundingLocked as u32 , 0 ) ;
4158- return Err ( msgs:: ErrorMessage {
4159- channel_id : self . channel_id ( ) ,
4160- data : format ! ( "Funding transaction failed to confirm in {} blocks" , FUNDING_CONF_DEADLINE_BLOCKS ) ,
4161- } ) ;
4162- }
4152+ } else if !self . is_outbound ( ) && self . funding_tx_confirmed_in . is_none ( ) &&
4153+ self . channel_creation_height + FUNDING_CONF_DEADLINE_BLOCKS <= height {
4154+ log_info ! ( logger, "Closing channel {} due to funding timeout" , log_bytes!( self . channel_id) ) ;
4155+ // If funding_tx_confirmed_in is unset, the channel must not be active
4156+ assert ! ( non_shutdown_state <= ChannelState :: ChannelFunded as u32 ) ;
4157+ assert_eq ! ( non_shutdown_state & ChannelState :: OurFundingLocked as u32 , 0 ) ;
4158+ return Err ( msgs:: ErrorMessage {
4159+ channel_id : self . channel_id ( ) ,
4160+ data : format ! ( "Funding transaction failed to confirm within {} blocks" , FUNDING_CONF_DEADLINE_BLOCKS ) ,
4161+ } ) ;
41634162 }
41644163
41654164 Ok ( ( None , timed_out_htlcs) )
@@ -5188,17 +5187,18 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
51885187 ( 5 , self . config, required) ,
51895188 ( 7 , self . shutdown_scriptpubkey, option) ,
51905189 ( 9 , self . target_closing_feerate_sats_per_kw, option) ,
5191- ( 11 , self . channel_creation_height, option ) ,
5190+ ( 11 , self . channel_creation_height, required ) ,
51925191 } ) ;
51935192
51945193 Ok ( ( ) )
51955194 }
51965195}
51975196
51985197const MAX_ALLOC_SIZE : usize = 64 * 1024 ;
5199- impl < ' a , Signer : Sign , K : Deref > ReadableArgs < & ' a K > for Channel < Signer >
5198+ impl < ' a , Signer : Sign , K : Deref > ReadableArgs < ( & ' a K , u32 ) > for Channel < Signer >
52005199 where K :: Target : KeysInterface < Signer = Signer > {
5201- fn read < R : io:: Read > ( reader : & mut R , keys_source : & ' a K ) -> Result < Self , DecodeError > {
5200+ fn read < R : io:: Read > ( reader : & mut R , args : ( & ' a K , u32 ) ) -> Result < Self , DecodeError > {
5201+ let ( keys_source, serialized_height) = args;
52025202 let ver = read_ver_prefix ! ( reader, SERIALIZATION_VERSION ) ;
52035203
52045204 let user_id = Readable :: read ( reader) ?;
@@ -5422,7 +5422,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
54225422
54235423 let mut announcement_sigs = None ;
54245424 let mut target_closing_feerate_sats_per_kw = None ;
5425- let mut channel_creation_height = None ;
5425+ let mut channel_creation_height = Some ( serialized_height ) ;
54265426 read_tlv_fields ! ( reader, {
54275427 ( 0 , announcement_sigs, option) ,
54285428 ( 1 , minimum_depth, option) ,
@@ -5487,7 +5487,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
54875487 funding_tx_confirmed_in,
54885488 funding_tx_confirmation_height,
54895489 short_channel_id,
5490- channel_creation_height,
5490+ channel_creation_height : channel_creation_height . unwrap ( ) ,
54915491
54925492 counterparty_dust_limit_satoshis,
54935493 holder_dust_limit_satoshis,
0 commit comments