@@ -1438,6 +1438,24 @@ pub(crate) async fn close_channel(
14381438 Err ( _) => return Err ( APIError :: InvalidPubkey ) ,
14391439 } ;
14401440
1441+ if let Some ( chan_details) = unlocked_state
1442+ . channel_manager
1443+ . list_channels ( )
1444+ . iter ( )
1445+ . find ( |c| c. channel_id == requested_cid)
1446+ {
1447+ match chan_details. channel_shutdown_state {
1448+ Some ( ChannelShutdownState :: NotShuttingDown ) => { }
1449+ _ => {
1450+ return Err ( APIError :: CannotCloseChannel ( s ! (
1451+ "Channel is already being closed"
1452+ ) ) )
1453+ }
1454+ }
1455+ } else {
1456+ return Err ( APIError :: UnknownChannelId ) ;
1457+ }
1458+
14411459 if payload. force {
14421460 match unlocked_state
14431461 . channel_manager
@@ -1447,15 +1465,25 @@ pub(crate) async fn close_channel(
14471465 "Manually force-closed" . to_string ( ) ,
14481466 ) {
14491467 Ok ( ( ) ) => tracing:: info!( "EVENT: initiating channel force-close" ) ,
1450- Err ( e) => return Err ( APIError :: FailedClosingChannel ( format ! ( "{e:?}" ) ) ) ,
1468+ Err ( e) => match e {
1469+ LDKAPIError :: APIMisuseError { err } => {
1470+ return Err ( APIError :: FailedClosingChannel ( err) )
1471+ }
1472+ _ => return Err ( APIError :: CannotCloseChannel ( format ! ( "{e:?}" ) ) ) ,
1473+ } ,
14511474 }
14521475 } else {
14531476 match unlocked_state
14541477 . channel_manager
14551478 . close_channel ( & requested_cid, & peer_pubkey)
14561479 {
14571480 Ok ( ( ) ) => tracing:: info!( "EVENT: initiating channel close" ) ,
1458- Err ( e) => return Err ( APIError :: FailedClosingChannel ( format ! ( "{e:?}" ) ) ) ,
1481+ Err ( e) => match e {
1482+ LDKAPIError :: APIMisuseError { err } => {
1483+ return Err ( APIError :: FailedClosingChannel ( err) )
1484+ }
1485+ _ => return Err ( APIError :: CannotCloseChannel ( format ! ( "{e:?}" ) ) ) ,
1486+ } ,
14591487 }
14601488 }
14611489
0 commit comments