@@ -2267,42 +2267,9 @@ where
22672267 myself. stop ( None ) ;
22682268 }
22692269 ChannelEvent :: ClosingTransactionConfirmed ( tx_hash, force, close_by_us) => {
2270- match state. state {
2271- ChannelState :: ShuttingDown ( flags)
2272- if flags. contains ( ShuttingDownFlags :: WAITING_COMMITMENT_CONFIRMATION ) => { }
2273- ChannelState :: ChannelReady if force && !close_by_us => { }
2274- _ => {
2275- return Err ( ProcessingChannelError :: InvalidState ( format ! (
2276- "Expecting commitment transaction confirmed event in unexpected state {:?} force {force} close_by_us {close_by_us}" , & state. state)
2277- ) ) ;
2278- }
2279- } ;
2280-
2281- let closed_state = if force {
2282- debug ! ( "Channel closed with uncooperative close" ) ;
2283- if close_by_us {
2284- ChannelState :: Closed ( CloseFlags :: UNCOOPERATIVE_LOCAL )
2285- } else {
2286- ChannelState :: Closed ( CloseFlags :: UNCOOPERATIVE_REMOTE )
2287- }
2288- } else {
2289- debug ! ( "Channel closed with cooperative close" ) ;
2290- ChannelState :: Closed ( CloseFlags :: COOPERATIVE )
2291- } ;
2292- state. update_state ( closed_state) ;
2293- state. shutdown_transaction_hash . replace ( tx_hash) ;
2294- // Broadcast the channel update message which disables the channel.
2295- if state. is_public ( ) {
2296- let update = state. generate_disabled_channel_update ( ) . await ;
2297-
2298- self . network
2299- . send_message ( NetworkActorMessage :: new_command (
2300- NetworkActorCommand :: BroadcastMessages ( vec ! [
2301- BroadcastMessageWithTimestamp :: ChannelUpdate ( update) ,
2302- ] ) ,
2303- ) )
2304- . expect ( ASSUME_NETWORK_ACTOR_ALIVE ) ;
2305- }
2270+ state
2271+ . update_close_transaction_confirmed ( tx_hash, force, close_by_us)
2272+ . await ?;
23062273 debug_event ! ( self . network, "ChannelClosed" ) ;
23072274 myself. stop ( Some ( "ChannelClosed" . to_string ( ) ) ) ;
23082275 }
@@ -7966,6 +7933,51 @@ impl ChannelActorState {
79667933 }
79677934 }
79687935
7936+ pub ( crate ) async fn update_close_transaction_confirmed (
7937+ & mut self ,
7938+ tx_hash : H256 ,
7939+ force : bool ,
7940+ close_by_us : bool ,
7941+ ) -> Result < ( ) , ProcessingChannelError > {
7942+ match self . state {
7943+ ChannelState :: ShuttingDown ( flags)
7944+ if flags. contains ( ShuttingDownFlags :: WAITING_COMMITMENT_CONFIRMATION ) => { }
7945+ ChannelState :: ChannelReady if force && !close_by_us => { }
7946+ _ => {
7947+ return Err ( ProcessingChannelError :: InvalidState ( format ! (
7948+ "Expecting commitment transaction confirmed event in unexpected state {:?} force {force} close_by_us {close_by_us}" , & self . state)
7949+ ) ) ;
7950+ }
7951+ } ;
7952+
7953+ let closed_state = if force {
7954+ debug ! ( "Channel closed with uncooperative close" ) ;
7955+ if close_by_us {
7956+ ChannelState :: Closed ( CloseFlags :: UNCOOPERATIVE_LOCAL )
7957+ } else {
7958+ ChannelState :: Closed ( CloseFlags :: UNCOOPERATIVE_REMOTE )
7959+ }
7960+ } else {
7961+ debug ! ( "Channel closed with cooperative close" ) ;
7962+ ChannelState :: Closed ( CloseFlags :: COOPERATIVE )
7963+ } ;
7964+ self . update_state ( closed_state) ;
7965+ self . shutdown_transaction_hash . replace ( tx_hash) ;
7966+ // Broadcast the channel update message which disables the channel.
7967+ if self . is_public ( ) {
7968+ let update = self . generate_disabled_channel_update ( ) . await ;
7969+
7970+ self . network ( )
7971+ . send_message ( NetworkActorMessage :: new_command (
7972+ NetworkActorCommand :: BroadcastMessages ( vec ! [
7973+ BroadcastMessageWithTimestamp :: ChannelUpdate ( update) ,
7974+ ] ) ,
7975+ ) )
7976+ . expect ( ASSUME_NETWORK_ACTOR_ALIVE ) ;
7977+ }
7978+ Ok ( ( ) )
7979+ }
7980+
79697981 fn can_abort_funding_on_timeout ( & self ) -> bool {
79707982 // Can abort funding on timeout if the channel is not ready and we have
79717983 // not signed the funding tx yet.
0 commit comments