@@ -18,6 +18,7 @@ use bitcoin::transaction::Version;
18
18
19
19
use crate :: chain:: channelmonitor:: LATENCY_GRACE_PERIOD_BLOCKS ;
20
20
use crate :: chain:: ChannelMonitorUpdateStatus ;
21
+ use crate :: chain:: transaction:: OutPoint ;
21
22
use crate :: events:: bump_transaction:: WalletSource ;
22
23
use crate :: events:: { ClosureReason , Event , MessageSendEvent , MessageSendEventsProvider } ;
23
24
use crate :: ln:: chan_utils:: ClosingTransaction ;
@@ -963,65 +964,65 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
963
964
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
964
965
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
965
966
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 ) ;
967
968
968
969
// Avoid extra channel ready message upon reestablish later
969
970
send_payment ( & nodes[ 0 ] , & vec ! [ & nodes[ 1 ] ] [ ..] , 8_000_000 ) ;
970
971
971
- expect_channel_shutdown_state ! ( nodes[ 0 ] , chan_1 . 2 , ChannelShutdownState :: NotShuttingDown ) ;
972
+ expect_channel_shutdown_state ! ( nodes[ 0 ] , chan_id , ChannelShutdownState :: NotShuttingDown ) ;
972
973
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 ( ) ;
974
975
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 ) ;
977
978
978
979
let node_0_shutdown = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendShutdown , nodes[ 1 ] . node. get_our_node_id( ) ) ;
979
980
nodes[ 1 ] . node . handle_shutdown ( nodes[ 0 ] . node . get_our_node_id ( ) , & node_0_shutdown) ;
980
981
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 ) ;
983
984
984
985
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 ) ;
986
987
nodes[ 0 ] . node . handle_shutdown ( nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_shutdown) ;
987
988
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 ) ;
990
991
991
992
let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
992
993
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 ) ;
994
995
nodes[ 0 ] . node . signer_unblocked ( None ) ;
995
996
996
997
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 ) ;
998
999
nodes[ 1 ] . node . handle_closing_signed ( nodes[ 0 ] . node . get_our_node_id ( ) , & node_0_closing_signed) ;
999
1000
1000
1001
let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
1001
1002
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 ) ;
1003
1004
nodes[ 1 ] . node . signer_unblocked ( None ) ;
1004
1005
1005
1006
let node_1_closing_signed = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendClosingSigned , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1006
1007
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 ) ;
1008
1009
nodes[ 0 ] . node . handle_closing_signed ( nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_closing_signed) ;
1009
1010
let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
1010
1011
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 ) ;
1012
1013
1013
1014
if extra_closing_signed {
1014
1015
let node_1_closing_signed_2_bad = {
1015
1016
let mut node_1_closing_signed_2 = node_1_closing_signed. clone ( ) ;
1016
1017
let holder_script = nodes[ 0 ] . keys_manager . get_shutdown_scriptpubkey ( ) . unwrap ( ) ;
1017
1018
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 } ;
1019
1020
let closing_tx_2 = ClosingTransaction :: new ( 50000 , 0 , holder_script. into ( ) ,
1020
1021
counterparty_script. into ( ) , funding_outpoint) ;
1021
1022
1022
1023
let per_peer_state = nodes[ 1 ] . node . per_peer_state . read ( ) . unwrap ( ) ;
1023
1024
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 ( ) ;
1025
1026
1026
1027
let signer = chan. get_mut_signer ( ) . as_mut_ecdsa ( ) . unwrap ( ) ;
1027
1028
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) {
1090
1091
check_closed_event ! ( nodes[ 0 ] , 1 , ClosureReason :: LocallyInitiatedCooperativeClosure , [ nodes[ 1 ] . node. get_our_node_id( ) ] , 100000 ) ;
1091
1092
check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: CounterpartyInitiatedCooperativeClosure , [ nodes[ 0 ] . node. get_our_node_id( ) ] , 100000 ) ;
1092
1093
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( ) ) ;
1093
1098
}
0 commit comments