@@ -258,7 +258,7 @@ impl MsgHandleErrInternal {
258
258
} ,
259
259
} ,
260
260
} ,
261
- chan_id : Some ( channel_id ) ,
261
+ chan_id : None ,
262
262
shutdown_finish : None ,
263
263
}
264
264
}
@@ -837,7 +837,7 @@ macro_rules! handle_error {
837
837
} ) ;
838
838
}
839
839
if let Some ( channel_id) = chan_id {
840
- $self. pending_events. lock( ) . unwrap( ) . push( events:: Event :: ChannelClosed { channel_id, err : ClosureReason :: ProcessingError { err: err. err. clone( ) } } ) ;
840
+ $self. pending_events. lock( ) . unwrap( ) . push( events:: Event :: ChannelClosed { channel_id, reason : ClosureReason :: ProcessingError { err: err. err. clone( ) } } ) ;
841
841
}
842
842
}
843
843
@@ -1447,6 +1447,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1447
1447
}
1448
1448
}
1449
1449
1450
+ /// `peer_node_id` should be set when we receive a message from a peer, but not set when the user closes, which will be re-exposed as the `ChannelClosed`
1451
+ /// reason.
1450
1452
fn force_close_channel_with_peer ( & self , channel_id : & [ u8 ; 32 ] , peer_node_id : Option < & PublicKey > , peer_msg : Option < & String > ) -> Result < PublicKey , APIError > {
1451
1453
let mut chan = {
1452
1454
let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
@@ -1463,12 +1465,10 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1463
1465
let mut pending_events_lock = self . pending_events . lock ( ) . unwrap ( ) ;
1464
1466
if peer_node_id. is_some ( ) {
1465
1467
if let Some ( peer_msg) = peer_msg {
1466
- pending_events_lock. push ( events:: Event :: ChannelClosed { channel_id : * channel_id, err : ClosureReason :: CounterpartyForceClosed { peer_msg : Some ( peer_msg. to_string ( ) ) } } ) ;
1467
- } else {
1468
- pending_events_lock. push ( events:: Event :: ChannelClosed { channel_id : * channel_id, err : ClosureReason :: CounterpartyForceClosed { peer_msg : None } } ) ;
1468
+ pending_events_lock. push ( events:: Event :: ChannelClosed { channel_id : * channel_id, reason : ClosureReason :: CounterpartyForceClosed { peer_msg : peer_msg. to_string ( ) } } ) ;
1469
1469
}
1470
1470
} else {
1471
- pending_events_lock. push ( events:: Event :: ChannelClosed { channel_id : * channel_id, err : ClosureReason :: HolderForceClosed } ) ;
1471
+ pending_events_lock. push ( events:: Event :: ChannelClosed { channel_id : * channel_id, reason : ClosureReason :: HolderForceClosed } ) ;
1472
1472
}
1473
1473
chan. remove_entry ( ) . 1
1474
1474
} else {
@@ -2435,7 +2435,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2435
2435
if let Some ( short_id) = channel. get_short_channel_id ( ) {
2436
2436
channel_state. short_to_id . remove ( & short_id) ;
2437
2437
}
2438
- // ChannelClosed event is generated by handle_errors for us.
2438
+ // ChannelClosed event is generated by handle_error for us.
2439
2439
Err ( MsgHandleErrInternal :: from_finish_shutdown ( msg, channel_id, channel. force_shutdown ( true ) , self . get_channel_update_for_broadcast ( & channel) . ok ( ) ) )
2440
2440
} ,
2441
2441
ChannelError :: CloseDelayBroadcast ( _) => { panic ! ( "Wait is only generated on receipt of channel_reestablish, which is handled by try_chan_entry, we don't bother to support it here" ) ; }
@@ -3565,8 +3565,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3565
3565
msg : update
3566
3566
} ) ;
3567
3567
}
3568
- //TODO: split between CounterpartyInitiated/LocallyInitiated
3569
- self . pending_events . lock ( ) . unwrap ( ) . push ( events:: Event :: ChannelClosed { channel_id : msg. channel_id , err : ClosureReason :: CooperativeClosure } ) ;
3568
+ self . pending_events . lock ( ) . unwrap ( ) . push ( events:: Event :: ChannelClosed { channel_id : msg. channel_id , reason : ClosureReason :: CooperativeClosure } ) ;
3570
3569
}
3571
3570
Ok ( ( ) )
3572
3571
}
@@ -3978,7 +3977,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3978
3977
msg : update
3979
3978
} ) ;
3980
3979
}
3981
- self . pending_events . lock ( ) . unwrap ( ) . push ( events:: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , err : ClosureReason :: CommitmentTxBroadcasted } ) ;
3980
+ self . pending_events . lock ( ) . unwrap ( ) . push ( events:: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , reason : ClosureReason :: CommitmentTxBroadcasted } ) ;
3982
3981
pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
3983
3982
node_id : chan. get_counterparty_node_id ( ) ,
3984
3983
action : msgs:: ErrorAction :: SendErrorMessage {
@@ -4514,7 +4513,7 @@ where
4514
4513
msg : update
4515
4514
} ) ;
4516
4515
}
4517
- self . pending_events . lock ( ) . unwrap ( ) . push ( events:: Event :: ChannelClosed { channel_id : channel. channel_id ( ) , err : ClosureReason :: CommitmentTxBroadcasted } ) ;
4516
+ self . pending_events . lock ( ) . unwrap ( ) . push ( events:: Event :: ChannelClosed { channel_id : channel. channel_id ( ) , reason : ClosureReason :: CommitmentTxBroadcasted } ) ;
4518
4517
pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
4519
4518
node_id : channel. get_counterparty_node_id ( ) ,
4520
4519
action : msgs:: ErrorAction :: SendErrorMessage { msg : e } ,
@@ -4705,7 +4704,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
4705
4704
msg : update
4706
4705
} ) ;
4707
4706
}
4708
- self . pending_events . lock ( ) . unwrap ( ) . push ( events:: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , err : ClosureReason :: DisconnectedPeer } ) ;
4707
+ self . pending_events . lock ( ) . unwrap ( ) . push ( events:: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , reason : ClosureReason :: DisconnectedPeer } ) ;
4709
4708
false
4710
4709
} else {
4711
4710
true
@@ -4720,7 +4719,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
4720
4719
if let Some ( short_id) = chan. get_short_channel_id ( ) {
4721
4720
short_to_id. remove ( & short_id) ;
4722
4721
}
4723
- self . pending_events . lock ( ) . unwrap ( ) . push ( events:: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , err : ClosureReason :: DisconnectedPeer } ) ;
4722
+ self . pending_events . lock ( ) . unwrap ( ) . push ( events:: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , reason : ClosureReason :: DisconnectedPeer } ) ;
4724
4723
return false ;
4725
4724
} else {
4726
4725
no_channels_remain = false ;
@@ -5679,10 +5678,8 @@ mod tests {
5679
5678
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
5680
5679
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
5681
5680
commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , payment_event. commitment_msg, false ) ;
5682
- let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
5683
- expect_pending_htlcs_forwardable ! ( nodes[ 1 ] , events) ;
5684
- let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
5685
- expect_pending_htlcs_forwardable ! ( nodes[ 1 ] , events) ;
5681
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
5682
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
5686
5683
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
5687
5684
let updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
5688
5685
assert ! ( updates. update_add_htlcs. is_empty( ) ) ;
@@ -5747,7 +5744,7 @@ mod tests {
5747
5744
5748
5745
#[ test]
5749
5746
fn test_keysend_dup_payment_hash ( ) {
5750
- return true ;
5747
+ return ;
5751
5748
5752
5749
// (1): Test that a keysend payment with a duplicate payment hash to an existing pending
5753
5750
// outbound regular payment fails as expected.
@@ -5816,10 +5813,8 @@ mod tests {
5816
5813
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
5817
5814
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
5818
5815
commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , payment_event. commitment_msg, false ) ;
5819
- let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
5820
- expect_pending_htlcs_forwardable ! ( nodes[ 1 ] , events) ;
5821
- let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
5822
- expect_pending_htlcs_forwardable ! ( nodes[ 1 ] , events) ;
5816
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
5817
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
5823
5818
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
5824
5819
let updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
5825
5820
assert ! ( updates. update_add_htlcs. is_empty( ) ) ;
0 commit comments