@@ -2071,6 +2071,9 @@ impl Channel {
2071
2071
self . channel_state = ChannelState :: ShutdownComplete as u32 ;
2072
2072
return outbound_drops;
2073
2073
}
2074
+ // Upon reconnect we have to start the closing_signed dance over, but shutdown messages
2075
+ // will be retransmitted.
2076
+ self . last_sent_closing_fee = None ;
2074
2077
2075
2078
let mut inbound_drop_count = 0 ;
2076
2079
self . pending_inbound_htlcs . retain ( |htlc| {
@@ -2261,7 +2264,7 @@ impl Channel {
2261
2264
2262
2265
/// May panic if some calls other than message-handling calls (which will all Err immediately)
2263
2266
/// have been called between remove_uncommitted_htlcs_and_mark_paused and this call.
2264
- pub fn channel_reestablish ( & mut self , msg : & msgs:: ChannelReestablish ) -> Result < ( Option < msgs:: FundingLocked > , Option < msgs:: RevokeAndACK > , Option < msgs:: CommitmentUpdate > , Option < ChannelMonitor > , RAACommitmentOrder ) , ChannelError > {
2267
+ pub fn channel_reestablish ( & mut self , msg : & msgs:: ChannelReestablish ) -> Result < ( Option < msgs:: FundingLocked > , Option < msgs:: RevokeAndACK > , Option < msgs:: CommitmentUpdate > , Option < ChannelMonitor > , RAACommitmentOrder , Option < msgs :: Shutdown > ) , ChannelError > {
2265
2268
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == 0 {
2266
2269
// While BOLT 2 doesn't indicate explicitly we should error this channel here, it
2267
2270
// almost certainly indicates we are going to end up out-of-sync in some way, so we
@@ -2277,9 +2280,16 @@ impl Channel {
2277
2280
// remaining cases either succeed or ErrorMessage-fail).
2278
2281
self . channel_state &= !( ChannelState :: PeerDisconnected as u32 ) ;
2279
2282
2283
+ let shutdown_msg = if self . channel_state & ( ChannelState :: LocalShutdownSent as u32 ) != 0 {
2284
+ Some ( msgs:: Shutdown {
2285
+ channel_id : self . channel_id ,
2286
+ scriptpubkey : self . get_closing_scriptpubkey ( ) ,
2287
+ } )
2288
+ } else { None } ;
2289
+
2280
2290
if self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: OurFundingLocked as u32 ) == ChannelState :: FundingSent as u32 {
2281
2291
// Short circuit the whole handler as there is nothing we can resend them
2282
- return Ok ( ( None , None , None , None , RAACommitmentOrder :: CommitmentFirst ) ) ;
2292
+ return Ok ( ( None , None , None , None , RAACommitmentOrder :: CommitmentFirst , shutdown_msg ) ) ;
2283
2293
}
2284
2294
2285
2295
if msg. next_local_commitment_number == 0 || msg. next_remote_commitment_number == 0 {
@@ -2292,7 +2302,7 @@ impl Channel {
2292
2302
return Ok ( ( Some ( msgs:: FundingLocked {
2293
2303
channel_id : self . channel_id ( ) ,
2294
2304
next_per_commitment_point : next_per_commitment_point,
2295
- } ) , None , None , None , RAACommitmentOrder :: CommitmentFirst ) ) ;
2305
+ } ) , None , None , None , RAACommitmentOrder :: CommitmentFirst , shutdown_msg ) ) ;
2296
2306
}
2297
2307
2298
2308
let required_revoke = if msg. next_remote_commitment_number == INITIAL_COMMITMENT_NUMBER - self . cur_local_commitment_transaction_number {
@@ -2355,11 +2365,11 @@ impl Channel {
2355
2365
panic ! ( "Got non-channel-failing result from free_holding_cell_htlcs" ) ;
2356
2366
}
2357
2367
} ,
2358
- Ok ( Some ( ( commitment_update, channel_monitor) ) ) => return Ok ( ( resend_funding_locked, required_revoke, Some ( commitment_update) , Some ( channel_monitor) , order) ) ,
2359
- Ok ( None ) => return Ok ( ( resend_funding_locked, required_revoke, None , None , order) ) ,
2368
+ Ok ( Some ( ( commitment_update, channel_monitor) ) ) => return Ok ( ( resend_funding_locked, required_revoke, Some ( commitment_update) , Some ( channel_monitor) , order, shutdown_msg ) ) ,
2369
+ Ok ( None ) => return Ok ( ( resend_funding_locked, required_revoke, None , None , order, shutdown_msg ) ) ,
2360
2370
}
2361
2371
} else {
2362
- return Ok ( ( resend_funding_locked, required_revoke, None , None , order) ) ;
2372
+ return Ok ( ( resend_funding_locked, required_revoke, None , None , order, shutdown_msg ) ) ;
2363
2373
}
2364
2374
} else if msg. next_local_commitment_number == our_next_remote_commitment_number - 1 {
2365
2375
if required_revoke. is_some ( ) {
@@ -2373,10 +2383,10 @@ impl Channel {
2373
2383
2374
2384
if self . channel_state & ( ChannelState :: MonitorUpdateFailed as u32 ) != 0 {
2375
2385
self . monitor_pending_commitment_signed = true ;
2376
- return Ok ( ( resend_funding_locked, None , None , None , order) ) ;
2386
+ return Ok ( ( resend_funding_locked, None , None , None , order, shutdown_msg ) ) ;
2377
2387
}
2378
2388
2379
- return Ok ( ( resend_funding_locked, required_revoke, Some ( self . get_last_commitment_update ( ) ) , None , order) ) ;
2389
+ return Ok ( ( resend_funding_locked, required_revoke, Some ( self . get_last_commitment_update ( ) ) , None , order, shutdown_msg ) ) ;
2380
2390
} else {
2381
2391
return Err ( ChannelError :: Close ( "Peer attempted to reestablish channel with a very old remote commitment transaction" ) ) ;
2382
2392
}
@@ -2424,9 +2434,6 @@ impl Channel {
2424
2434
return Err ( ChannelError :: Close ( "Got shutdown with remote pending HTLCs" ) ) ;
2425
2435
}
2426
2436
}
2427
- if ( self . channel_state & ChannelState :: RemoteShutdownSent as u32 ) == ChannelState :: RemoteShutdownSent as u32 {
2428
- return Err ( ChannelError :: Ignore ( "Remote peer sent duplicate shutdown message" ) ) ;
2429
- }
2430
2437
assert_eq ! ( self . channel_state & ChannelState :: ShutdownComplete as u32 , 0 ) ;
2431
2438
2432
2439
// BOLT 2 says we must only send a scriptpubkey of certain standard forms, which are up to
0 commit comments