@@ -18,6 +18,7 @@ use bitcoin::transaction::Version;
1818
1919use crate :: chain:: channelmonitor:: LATENCY_GRACE_PERIOD_BLOCKS ;
2020use crate :: chain:: ChannelMonitorUpdateStatus ;
21+ use crate :: chain:: transaction:: OutPoint ;
2122use crate :: events:: bump_transaction:: WalletSource ;
2223use crate :: events:: { ClosureReason , Event , MessageSendEvent , MessageSendEventsProvider } ;
2324use crate :: ln:: chan_utils:: ClosingTransaction ;
@@ -963,65 +964,65 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
963964 let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
964965 let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
965966 let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
966- let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
967+ let ( _ , _ , chan_id , funding_tx ) = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
967968
968969 // Avoid extra channel ready message upon reestablish later
969970 send_payment ( & nodes[ 0 ] , & vec ! [ & nodes[ 1 ] ] [ ..] , 8_000_000 ) ;
970971
971- expect_channel_shutdown_state ! ( nodes[ 0 ] , chan_1 . 2 , ChannelShutdownState :: NotShuttingDown ) ;
972+ expect_channel_shutdown_state ! ( nodes[ 0 ] , chan_id , ChannelShutdownState :: NotShuttingDown ) ;
972973
973- nodes[ 0 ] . node . close_channel ( & chan_1 . 2 , & nodes[ 1 ] . node . get_our_node_id ( ) ) . unwrap ( ) ;
974+ nodes[ 0 ] . node . close_channel ( & chan_id , & nodes[ 1 ] . node . get_our_node_id ( ) ) . unwrap ( ) ;
974975
975- expect_channel_shutdown_state ! ( nodes[ 0 ] , chan_1 . 2 , ChannelShutdownState :: ShutdownInitiated ) ;
976- expect_channel_shutdown_state ! ( nodes[ 1 ] , chan_1 . 2 , ChannelShutdownState :: NotShuttingDown ) ;
976+ expect_channel_shutdown_state ! ( nodes[ 0 ] , chan_id , ChannelShutdownState :: ShutdownInitiated ) ;
977+ expect_channel_shutdown_state ! ( nodes[ 1 ] , chan_id , ChannelShutdownState :: NotShuttingDown ) ;
977978
978979 let node_0_shutdown = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendShutdown , nodes[ 1 ] . node. get_our_node_id( ) ) ;
979980 nodes[ 1 ] . node . handle_shutdown ( nodes[ 0 ] . node . get_our_node_id ( ) , & node_0_shutdown) ;
980981
981- expect_channel_shutdown_state ! ( nodes[ 0 ] , chan_1 . 2 , ChannelShutdownState :: ShutdownInitiated ) ;
982- expect_channel_shutdown_state ! ( nodes[ 1 ] , chan_1 . 2 , ChannelShutdownState :: NegotiatingClosingFee ) ;
982+ expect_channel_shutdown_state ! ( nodes[ 0 ] , chan_id , ChannelShutdownState :: ShutdownInitiated ) ;
983+ expect_channel_shutdown_state ! ( nodes[ 1 ] , chan_id , ChannelShutdownState :: NegotiatingClosingFee ) ;
983984
984985 let node_1_shutdown = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendShutdown , nodes[ 0 ] . node. get_our_node_id( ) ) ;
985- nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_1 . 2 , SignerOp :: SignClosingTransaction ) ;
986+ nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id , SignerOp :: SignClosingTransaction ) ;
986987 nodes[ 0 ] . node . handle_shutdown ( nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_shutdown) ;
987988
988- expect_channel_shutdown_state ! ( nodes[ 0 ] , chan_1 . 2 , ChannelShutdownState :: NegotiatingClosingFee ) ;
989- expect_channel_shutdown_state ! ( nodes[ 1 ] , chan_1 . 2 , ChannelShutdownState :: NegotiatingClosingFee ) ;
989+ expect_channel_shutdown_state ! ( nodes[ 0 ] , chan_id , ChannelShutdownState :: NegotiatingClosingFee ) ;
990+ expect_channel_shutdown_state ! ( nodes[ 1 ] , chan_id , ChannelShutdownState :: NegotiatingClosingFee ) ;
990991
991992 let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
992993 assert ! ( events. is_empty( ) , "Expected no events, got {:?}" , events) ;
993- nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_1 . 2 , SignerOp :: SignClosingTransaction ) ;
994+ nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id , SignerOp :: SignClosingTransaction ) ;
994995 nodes[ 0 ] . node . signer_unblocked ( None ) ;
995996
996997 let node_0_closing_signed = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendClosingSigned , nodes[ 1 ] . node. get_our_node_id( ) ) ;
997- nodes[ 1 ] . disable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_1 . 2 , SignerOp :: SignClosingTransaction ) ;
998+ nodes[ 1 ] . disable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_id , SignerOp :: SignClosingTransaction ) ;
998999 nodes[ 1 ] . node . handle_closing_signed ( nodes[ 0 ] . node . get_our_node_id ( ) , & node_0_closing_signed) ;
9991000
10001001 let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
10011002 assert ! ( events. is_empty( ) , "Expected no events, got {:?}" , events) ;
1002- nodes[ 1 ] . enable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_1 . 2 , SignerOp :: SignClosingTransaction ) ;
1003+ nodes[ 1 ] . enable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_id , SignerOp :: SignClosingTransaction ) ;
10031004 nodes[ 1 ] . node . signer_unblocked ( None ) ;
10041005
10051006 let node_1_closing_signed = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendClosingSigned , nodes[ 0 ] . node. get_our_node_id( ) ) ;
10061007
1007- nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_1 . 2 , SignerOp :: SignClosingTransaction ) ;
1008+ nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id , SignerOp :: SignClosingTransaction ) ;
10081009 nodes[ 0 ] . node . handle_closing_signed ( nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_closing_signed) ;
10091010 let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
10101011 assert ! ( events. is_empty( ) , "Expected no events, got {:?}" , events) ;
1011- nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_1 . 2 , SignerOp :: SignClosingTransaction ) ;
1012+ nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id , SignerOp :: SignClosingTransaction ) ;
10121013
10131014 if extra_closing_signed {
10141015 let node_1_closing_signed_2_bad = {
10151016 let mut node_1_closing_signed_2 = node_1_closing_signed. clone ( ) ;
10161017 let holder_script = nodes[ 0 ] . keys_manager . get_shutdown_scriptpubkey ( ) . unwrap ( ) ;
10171018 let counterparty_script = nodes[ 1 ] . keys_manager . get_shutdown_scriptpubkey ( ) . unwrap ( ) ;
1018- let funding_outpoint = bitcoin:: OutPoint { txid : chan_1 . 3 . compute_txid ( ) , vout : 0 } ;
1019+ let funding_outpoint = bitcoin:: OutPoint { txid : funding_tx . compute_txid ( ) , vout : 0 } ;
10191020 let closing_tx_2 = ClosingTransaction :: new ( 50000 , 0 , holder_script. into ( ) ,
10201021 counterparty_script. into ( ) , funding_outpoint) ;
10211022
10221023 let per_peer_state = nodes[ 1 ] . node . per_peer_state . read ( ) . unwrap ( ) ;
10231024 let mut chan_lock = per_peer_state. get ( & nodes[ 0 ] . node . get_our_node_id ( ) ) . unwrap ( ) . lock ( ) . unwrap ( ) ;
1024- let chan = chan_lock. channel_by_id . get_mut ( & chan_1 . 2 ) . map ( |phase| phase. context_mut ( ) ) . unwrap ( ) ;
1025+ let chan = chan_lock. channel_by_id . get_mut ( & chan_id ) . map ( |phase| phase. context_mut ( ) ) . unwrap ( ) ;
10251026
10261027 let signer = chan. get_mut_signer ( ) . as_mut_ecdsa ( ) . unwrap ( ) ;
10271028 let signature = signer. sign_closing_transaction ( & closing_tx_2, & Secp256k1 :: new ( ) ) . unwrap ( ) ;
@@ -1090,4 +1091,8 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
10901091 check_closed_event ! ( nodes[ 0 ] , 1 , ClosureReason :: LocallyInitiatedCooperativeClosure , [ nodes[ 1 ] . node. get_our_node_id( ) ] , 100000 ) ;
10911092 check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: CounterpartyInitiatedCooperativeClosure , [ nodes[ 0 ] . node. get_our_node_id( ) ] , 100000 ) ;
10921093
1094+ // Check that our maps have been updated after async signng channel closure.
1095+ let funding_outpoint = OutPoint { txid : funding_tx. compute_txid ( ) , index : 0 } ;
1096+ assert ! ( nodes[ 0 ] . node( ) . outpoint_to_peer. lock( ) . unwrap( ) . get( & funding_outpoint) . is_none( ) ) ;
1097+ assert ! ( nodes[ 1 ] . node( ) . outpoint_to_peer. lock( ) . unwrap( ) . get( & funding_outpoint) . is_none( ) ) ;
10931098}
0 commit comments