@@ -1873,6 +1873,7 @@ impl ChannelManager {
1873
1873
}
1874
1874
1875
1875
fn internal_closing_signed ( & self , their_node_id : & PublicKey , msg : & msgs:: ClosingSigned ) -> Result < ( ) , MsgHandleErrInternal > {
1876
+ let mut spendable_output = Vec :: with_capacity ( 1 ) ;
1876
1877
let ( tx, chan_option) = {
1877
1878
let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
1878
1879
let channel_state = channel_state_lock. borrow_parts ( ) ;
@@ -1882,13 +1883,16 @@ impl ChannelManager {
1882
1883
//TODO: here and below MsgHandleErrInternal, #153 case
1883
1884
return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Got a message for a channel from the wrong node!" , msg. channel_id ) ) ;
1884
1885
}
1885
- let ( closing_signed, tx) = chan_entry. get_mut ( ) . closing_signed ( & * self . fee_estimator , & msg) . map_err ( |e| MsgHandleErrInternal :: from_maybe_close ( e) ) ?;
1886
+ let ( closing_signed, spendable_outp , tx) = chan_entry. get_mut ( ) . closing_signed ( & * self . fee_estimator , & msg) . map_err ( |e| MsgHandleErrInternal :: from_maybe_close ( e) ) ?;
1886
1887
if let Some ( msg) = closing_signed {
1887
1888
channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendClosingSigned {
1888
1889
node_id : their_node_id. clone ( ) ,
1889
1890
msg,
1890
1891
} ) ;
1891
1892
}
1893
+ if let Some ( spendable_outp) = spendable_outp {
1894
+ spendable_output. push ( spendable_outp) ;
1895
+ }
1892
1896
if tx. is_some ( ) {
1893
1897
// We're done with this channel, we've got a signed closing transaction and
1894
1898
// will send the closing_signed back to the remote peer upon return. This
@@ -1904,6 +1908,9 @@ impl ChannelManager {
1904
1908
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" , msg. channel_id ) )
1905
1909
}
1906
1910
} ;
1911
+ if spendable_output. len ( ) > 0 {
1912
+ self . pending_events . lock ( ) . unwrap ( ) . push ( events:: Event :: SpendableOutputs { outputs : spendable_output } ) ;
1913
+ }
1907
1914
if let Some ( broadcast_tx) = tx {
1908
1915
self . tx_broadcaster . broadcast_transaction ( & broadcast_tx) ;
1909
1916
}
@@ -3672,6 +3679,23 @@ mod tests {
3672
3679
}
3673
3680
}
3674
3681
3682
+ macro_rules! check_closing_output {
3683
+ ( $node: expr) => {
3684
+ let events = $node. get_and_clear_pending_events( ) ;
3685
+ if events. len( ) > 0 {
3686
+ match events[ 0 ] {
3687
+ Event :: SpendableOutputs { ref outputs } => {
3688
+ match outputs[ 0 ] {
3689
+ SpendableOutputDescriptor :: StaticOutput { .. } => { } ,
3690
+ _ => panic!( "Unexpected event" ) ,
3691
+ }
3692
+ }
3693
+ _ => panic!( "Unexpected event" ) ,
3694
+ }
3695
+ }
3696
+ }
3697
+ }
3698
+
3675
3699
fn close_channel ( outbound_node : & Node , inbound_node : & Node , channel_id : & [ u8 ; 32 ] , funding_tx : Transaction , close_inbound_first : bool ) -> ( msgs:: ChannelUpdate , msgs:: ChannelUpdate ) {
3676
3700
let ( node_a, broadcaster_a, struct_a) = if close_inbound_first { ( & inbound_node. node , & inbound_node. tx_broadcaster , inbound_node) } else { ( & outbound_node. node , & outbound_node. tx_broadcaster , outbound_node) } ;
3677
3701
let ( node_b, broadcaster_b) = if close_inbound_first { ( & outbound_node. node , & outbound_node. tx_broadcaster ) } else { ( & inbound_node. node , & inbound_node. tx_broadcaster ) } ;
@@ -4571,6 +4595,9 @@ mod tests {
4571
4595
send_payment ( & nodes[ 1 ] , & vec ! ( & nodes[ 0 ] ) [ ..] , 800000 ) ;
4572
4596
send_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 800000 ) ;
4573
4597
close_channel ( & nodes[ 0 ] , & nodes[ 1 ] , & chan. 2 , chan. 3 , true ) ;
4598
+
4599
+ check_closing_output ! ( nodes[ 0 ] . node) ;
4600
+ check_closing_output ! ( nodes[ 1 ] . node) ;
4574
4601
}
4575
4602
4576
4603
#[ test]
@@ -4679,6 +4706,9 @@ mod tests {
4679
4706
assert_eq ! ( get_feerate!( nodes[ 0 ] ) , feerate + 30 ) ;
4680
4707
assert_eq ! ( get_feerate!( nodes[ 1 ] ) , feerate + 30 ) ;
4681
4708
close_channel ( & nodes[ 0 ] , & nodes[ 1 ] , & chan. 2 , chan. 3 , true ) ;
4709
+
4710
+ check_closing_output ! ( nodes[ 0 ] . node) ;
4711
+ check_closing_output ! ( nodes[ 1 ] . node) ;
4682
4712
}
4683
4713
4684
4714
#[ test]
@@ -4705,6 +4735,9 @@ mod tests {
4705
4735
4706
4736
assert ! ( nodes[ 0 ] . node. list_channels( ) . is_empty( ) ) ;
4707
4737
assert ! ( nodes[ 1 ] . node. list_channels( ) . is_empty( ) ) ;
4738
+
4739
+ check_closing_output ! ( nodes[ 0 ] . node) ;
4740
+ check_closing_output ! ( nodes[ 1 ] . node) ;
4708
4741
}
4709
4742
4710
4743
#[ test]
@@ -4777,6 +4810,10 @@ mod tests {
4777
4810
close_channel ( & nodes[ 1 ] , & nodes[ 2 ] , & chan_2. 2 , chan_2. 3 , true ) ;
4778
4811
assert ! ( nodes[ 1 ] . node. list_channels( ) . is_empty( ) ) ;
4779
4812
assert ! ( nodes[ 2 ] . node. list_channels( ) . is_empty( ) ) ;
4813
+
4814
+ check_closing_output ! ( nodes[ 0 ] . node) ;
4815
+ check_closing_output ! ( nodes[ 1 ] . node) ;
4816
+ check_closing_output ! ( nodes[ 2 ] . node) ;
4780
4817
}
4781
4818
4782
4819
#[ test]
@@ -4843,6 +4880,10 @@ mod tests {
4843
4880
close_channel ( & nodes[ 1 ] , & nodes[ 2 ] , & chan_2. 2 , chan_2. 3 , true ) ;
4844
4881
assert ! ( nodes[ 1 ] . node. list_channels( ) . is_empty( ) ) ;
4845
4882
assert ! ( nodes[ 2 ] . node. list_channels( ) . is_empty( ) ) ;
4883
+
4884
+ check_closing_output ! ( nodes[ 0 ] . node) ;
4885
+ check_closing_output ! ( nodes[ 1 ] . node) ;
4886
+ check_closing_output ! ( nodes[ 2 ] . node) ;
4846
4887
}
4847
4888
4848
4889
#[ test]
@@ -4889,6 +4930,9 @@ mod tests {
4889
4930
nodes[ 0 ] . node . handle_closing_signed ( & nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_closing_signed. unwrap ( ) ) . unwrap ( ) ;
4890
4931
let ( _, node_0_none) = get_closing_signed_broadcast ! ( nodes[ 0 ] . node, nodes[ 1 ] . node. get_our_node_id( ) ) ;
4891
4932
assert ! ( node_0_none. is_none( ) ) ;
4933
+
4934
+ check_closing_output ! ( nodes[ 0 ] . node) ;
4935
+ check_closing_output ! ( nodes[ 1 ] . node) ;
4892
4936
}
4893
4937
4894
4938
fn do_test_shutdown_rebroadcast ( recv_count : u8 ) {
@@ -5041,6 +5085,10 @@ mod tests {
5041
5085
close_channel ( & nodes[ 1 ] , & nodes[ 2 ] , & chan_2. 2 , chan_2. 3 , true ) ;
5042
5086
assert ! ( nodes[ 1 ] . node. list_channels( ) . is_empty( ) ) ;
5043
5087
assert ! ( nodes[ 2 ] . node. list_channels( ) . is_empty( ) ) ;
5088
+
5089
+ check_closing_output ! ( nodes[ 0 ] . node) ;
5090
+ check_closing_output ! ( nodes[ 1 ] . node) ;
5091
+ check_closing_output ! ( nodes[ 2 ] . node) ;
5044
5092
}
5045
5093
5046
5094
#[ test]
@@ -5160,6 +5208,11 @@ mod tests {
5160
5208
close_channel ( & nodes[ 2 ] , & nodes[ 3 ] , & chan_3. 2 , chan_3. 3 , true ) ;
5161
5209
close_channel ( & nodes[ 1 ] , & nodes[ 3 ] , & chan_4. 2 , chan_4. 3 , false ) ;
5162
5210
close_channel ( & nodes[ 1 ] , & nodes[ 3 ] , & chan_5. 2 , chan_5. 3 , false ) ;
5211
+
5212
+ check_closing_output ! ( nodes[ 0 ] . node) ;
5213
+ check_closing_output ! ( nodes[ 1 ] . node) ;
5214
+ check_closing_output ! ( nodes[ 2 ] . node) ;
5215
+ check_closing_output ! ( nodes[ 3 ] . node) ;
5163
5216
}
5164
5217
5165
5218
#[ test]
0 commit comments