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