@@ -2188,17 +2188,28 @@ impl<Signer: Sign> Channel<Signer> {
2188
2188
} else if non_shutdown_state == ( ChannelState :: FundingSent as u32 | ChannelState :: OurFundingLocked as u32 ) {
2189
2189
self . channel_state = ChannelState :: ChannelFunded as u32 | ( self . channel_state & MULTI_STATE_FLAGS ) ;
2190
2190
self . update_time_counter += 1 ;
2191
- } else if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) != 0 &&
2192
- // Note that funding_signed/funding_created will have decremented both by 1!
2193
- self . cur_holder_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 &&
2194
- self . cur_counterparty_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 ) ||
2195
- // If we reconnected before sending our funding locked they may still resend theirs:
2196
- ( self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: TheirFundingLocked as u32 ) ==
2197
- ( ChannelState :: FundingSent as u32 | ChannelState :: TheirFundingLocked as u32 ) ) {
2198
- if self . counterparty_cur_commitment_point != Some ( msg. next_per_commitment_point ) {
2191
+ } else if self . channel_state & ( ChannelState :: ChannelFunded as u32 ) != 0 ||
2192
+ // If we reconnected before sending our funding locked they may still resend theirs:
2193
+ ( self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: TheirFundingLocked as u32 ) ==
2194
+ ( ChannelState :: FundingSent as u32 | ChannelState :: TheirFundingLocked as u32 ) )
2195
+ {
2196
+ // They probably disconnected/reconnected and re-sent the funding_locked, which is
2197
+ // required, or they're sending a fresh SCID alias.
2198
+ let expected_point =
2199
+ if self . cur_counterparty_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 {
2200
+ // If they haven't ever sent an updated point, the point they send should match
2201
+ // the current one.
2202
+ self . counterparty_cur_commitment_point
2203
+ } else {
2204
+ // If they have sent updated points, funding_locked is always supposed to match
2205
+ // their "first" point, which we re-derive here.
2206
+ Some ( PublicKey :: from_secret_key ( & self . secp_ctx , & SecretKey :: from_slice (
2207
+ & self . commitment_secrets . get_secret ( INITIAL_COMMITMENT_NUMBER - 1 ) . expect ( "We should have all prev secrets available" )
2208
+ ) . expect ( "We already advanced, so previous secret keys should have been validated already" ) ) )
2209
+ } ;
2210
+ if expected_point != Some ( msg. next_per_commitment_point ) {
2199
2211
return Err ( ChannelError :: Close ( "Peer sent a reconnect funding_locked with a different point" . to_owned ( ) ) ) ;
2200
2212
}
2201
- // They probably disconnected/reconnected and re-sent the funding_locked, which is required
2202
2213
return Ok ( None ) ;
2203
2214
} else {
2204
2215
return Err ( ChannelError :: Close ( "Peer sent a funding_locked at a strange time" . to_owned ( ) ) ) ;
@@ -4238,7 +4249,7 @@ impl<Signer: Sign> Channel<Signer> {
4238
4249
self . outbound_scid_alias
4239
4250
}
4240
4251
/// Only allowed immediately after deserialization if get_outbound_scid_alias returns 0,
4241
- /// indicating we were written by an old LDK which did not set outbound SCID aliases.
4252
+ /// indicating we were written by LDK prior to 0.0.106 which did not set outbound SCID aliases.
4242
4253
pub fn set_outbound_scid_alias ( & mut self , outbound_scid_alias : u64 ) {
4243
4254
assert_eq ! ( self . outbound_scid_alias, 0 ) ;
4244
4255
self . outbound_scid_alias = outbound_scid_alias;
@@ -4492,7 +4503,8 @@ impl<Signer: Sign> Channel<Signer> {
4492
4503
if need_commitment_update {
4493
4504
if self . channel_state & ( ChannelState :: MonitorUpdateFailed as u32 ) == 0 {
4494
4505
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == 0 {
4495
- let next_per_commitment_point = self . holder_signer . get_per_commitment_point ( self . cur_holder_commitment_transaction_number , & self . secp_ctx ) ;
4506
+ let next_per_commitment_point =
4507
+ self . holder_signer . get_per_commitment_point ( INITIAL_COMMITMENT_NUMBER - 1 , & self . secp_ctx ) ;
4496
4508
return Some ( msgs:: FundingLocked {
4497
4509
channel_id : self . channel_id ,
4498
4510
next_per_commitment_point,
0 commit comments