@@ -2178,17 +2178,28 @@ impl<Signer: Sign> Channel<Signer> {
2178
2178
} else if non_shutdown_state == ( ChannelState :: FundingSent as u32 | ChannelState :: OurFundingLocked as u32 ) {
2179
2179
self . channel_state = ChannelState :: ChannelFunded as u32 | ( self . channel_state & MULTI_STATE_FLAGS ) ;
2180
2180
self . update_time_counter += 1 ;
2181
- } else if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) != 0 &&
2182
- // Note that funding_signed/funding_created will have decremented both by 1!
2183
- self . cur_holder_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 &&
2184
- self . cur_counterparty_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 ) ||
2185
- // If we reconnected before sending our funding locked they may still resend theirs:
2186
- ( self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: TheirFundingLocked as u32 ) ==
2187
- ( ChannelState :: FundingSent as u32 | ChannelState :: TheirFundingLocked as u32 ) ) {
2188
- if self . counterparty_cur_commitment_point != Some ( msg. next_per_commitment_point ) {
2181
+ } else if self . channel_state & ( ChannelState :: ChannelFunded as u32 ) != 0 ||
2182
+ // If we reconnected before sending our funding locked they may still resend theirs:
2183
+ ( self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: TheirFundingLocked as u32 ) ==
2184
+ ( ChannelState :: FundingSent as u32 | ChannelState :: TheirFundingLocked as u32 ) )
2185
+ {
2186
+ // They probably disconnected/reconnected and re-sent the funding_locked, which is
2187
+ // required, or we're getting a fresh SCID alias.
2188
+ let expected_point =
2189
+ if self . cur_counterparty_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 {
2190
+ // If they haven't ever sent an updated point, the point they send should match
2191
+ // the current one.
2192
+ self . counterparty_cur_commitment_point
2193
+ } else {
2194
+ // If they have sent updated points, funding_locked is always supposed to match
2195
+ // their "first" point, which we re-derive here.
2196
+ self . commitment_secrets . get_secret ( INITIAL_COMMITMENT_NUMBER - 1 )
2197
+ . map ( |secret| SecretKey :: from_slice ( & secret) . ok ( ) ) . flatten ( )
2198
+ . map ( |sk| PublicKey :: from_secret_key ( & self . secp_ctx , & sk) )
2199
+ } ;
2200
+ if expected_point != Some ( msg. next_per_commitment_point ) {
2189
2201
return Err ( ChannelError :: Close ( "Peer sent a reconnect funding_locked with a different point" . to_owned ( ) ) ) ;
2190
2202
}
2191
- // They probably disconnected/reconnected and re-sent the funding_locked, which is required
2192
2203
return Ok ( None ) ;
2193
2204
} else {
2194
2205
return Err ( ChannelError :: Close ( "Peer sent a funding_locked at a strange time" . to_owned ( ) ) ) ;
@@ -4482,7 +4493,8 @@ impl<Signer: Sign> Channel<Signer> {
4482
4493
if need_commitment_update {
4483
4494
if self . channel_state & ( ChannelState :: MonitorUpdateFailed as u32 ) == 0 {
4484
4495
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == 0 {
4485
- let next_per_commitment_point = self . holder_signer . get_per_commitment_point ( self . cur_holder_commitment_transaction_number , & self . secp_ctx ) ;
4496
+ let next_per_commitment_point =
4497
+ self . holder_signer . get_per_commitment_point ( INITIAL_COMMITMENT_NUMBER - 1 , & self . secp_ctx ) ;
4486
4498
return Some ( msgs:: FundingLocked {
4487
4499
channel_id : self . channel_id ,
4488
4500
next_per_commitment_point,
0 commit comments