@@ -57,7 +57,7 @@ use lightning::ln::functional_test_utils::*;
5757use lightning:: ln:: funding:: { FundingTxInput , SpliceContribution } ;
5858use lightning:: ln:: inbound_payment:: ExpandedKey ;
5959use lightning:: ln:: msgs:: {
60- BaseMessageHandler , ChannelMessageHandler , CommitmentUpdate , Init , MessageSendEvent ,
60+ self , BaseMessageHandler , ChannelMessageHandler , CommitmentUpdate , Init , MessageSendEvent ,
6161 UpdateAddHTLC ,
6262} ;
6363use lightning:: ln:: outbound_payment:: RecipientOnionFields ;
@@ -897,6 +897,18 @@ fn send_mpp_hop_payment(
897897 }
898898}
899899
900+ #[ inline]
901+ fn assert_action_timeout_awaiting_response ( action : & msgs:: ErrorAction ) {
902+ // Since sending/receiving messages may be delayed,
903+ // `timer_tick_occurred` may cause a node to disconnect their
904+ // counterparty if they're expecting a timely response.
905+ assert ! ( matches!(
906+ action,
907+ msgs:: ErrorAction :: DisconnectPeerWithWarning { msg }
908+ if msg. data. contains( "Disconnecting due to timeout awaiting response" )
909+ ) ) ;
910+ }
911+
900912#[ inline]
901913pub fn do_test < Out : Output > ( data : & [ u8 ] , underlying_out : Out , anchors : bool ) {
902914 let out = SearchingOutput :: new ( underlying_out) ;
@@ -1477,8 +1489,12 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
14771489 } ,
14781490 MessageSendEvent :: SendChannelReady { .. } => continue ,
14791491 MessageSendEvent :: SendAnnouncementSignatures { .. } => continue ,
1480- MessageSendEvent :: SendChannelUpdate { ref node_id, ref msg } => {
1481- assert_eq!( msg. contents. channel_flags & 2 , 0 ) ; // The disable bit must never be set!
1492+ MessageSendEvent :: SendChannelUpdate { ref node_id, .. } => {
1493+ if Some ( * node_id) == expect_drop_id { panic!( "peer_disconnected should drop msgs bound for the disconnected peer" ) ; }
1494+ * node_id == a_id
1495+ } ,
1496+ MessageSendEvent :: HandleError { ref action, ref node_id } => {
1497+ assert_action_timeout_awaiting_response( action) ;
14821498 if Some ( * node_id) == expect_drop_id { panic!( "peer_disconnected should drop msgs bound for the disconnected peer" ) ; }
14831499 * node_id == a_id
14841500 } ,
@@ -1691,20 +1707,21 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
16911707 }
16921708 }
16931709 } ,
1710+ MessageSendEvent :: HandleError { ref action, .. } => {
1711+ assert_action_timeout_awaiting_response( action) ;
1712+ } ,
16941713 MessageSendEvent :: SendChannelReady { .. } => {
16951714 // Can be generated as a reestablish response
16961715 } ,
16971716 MessageSendEvent :: SendAnnouncementSignatures { .. } => {
16981717 // Can be generated as a reestablish response
16991718 } ,
1700- MessageSendEvent :: SendChannelUpdate { ref msg, .. } => {
1701- // When we reconnect we will resend a channel_update to make sure our
1702- // counterparty has the latest parameters for receiving payments
1703- // through us. We do, however, check that the message does not include
1704- // the "disabled" bit, as we should never ever have a channel which is
1705- // disabled when we send such an update (or it may indicate channel
1706- // force-close which we should detect as an error).
1707- assert_eq!( msg. contents. channel_flags & 2 , 0 ) ;
1719+ MessageSendEvent :: SendChannelUpdate { .. } => {
1720+ // Can be generated as a reestablish response
1721+ } ,
1722+ MessageSendEvent :: BroadcastChannelUpdate { .. } => {
1723+ // Can be generated as a result of calling `timer_tick_occurred` enough
1724+ // times while peers are disconnected
17081725 } ,
17091726 _ => if out. may_fail. load( atomic:: Ordering :: Acquire ) {
17101727 return ;
@@ -1746,8 +1763,9 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
17461763 MessageSendEvent :: SendStfu { .. } => { } ,
17471764 MessageSendEvent :: SendChannelReady { .. } => { } ,
17481765 MessageSendEvent :: SendAnnouncementSignatures { .. } => { } ,
1749- MessageSendEvent :: SendChannelUpdate { ref msg, .. } => {
1750- assert_eq!( msg. contents. channel_flags & 2 , 0 ) ; // The disable bit must never be set!
1766+ MessageSendEvent :: SendChannelUpdate { .. } => { } ,
1767+ MessageSendEvent :: HandleError { ref action, .. } => {
1768+ assert_action_timeout_awaiting_response( action) ;
17511769 } ,
17521770 _ => {
17531771 if out. may_fail. load( atomic:: Ordering :: Acquire ) {
@@ -1773,8 +1791,9 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
17731791 MessageSendEvent :: SendStfu { .. } => { } ,
17741792 MessageSendEvent :: SendChannelReady { .. } => { } ,
17751793 MessageSendEvent :: SendAnnouncementSignatures { .. } => { } ,
1776- MessageSendEvent :: SendChannelUpdate { ref msg, .. } => {
1777- assert_eq!( msg. contents. channel_flags & 2 , 0 ) ; // The disable bit must never be set!
1794+ MessageSendEvent :: SendChannelUpdate { .. } => { } ,
1795+ MessageSendEvent :: HandleError { ref action, .. } => {
1796+ assert_action_timeout_awaiting_response( action) ;
17781797 } ,
17791798 _ => {
17801799 if out. may_fail. load( atomic:: Ordering :: Acquire ) {
@@ -2248,11 +2267,11 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
22482267 if fee_est_a. ret_val . fetch_add ( 250 , atomic:: Ordering :: AcqRel ) + 250 > max_feerate {
22492268 fee_est_a. ret_val . store ( max_feerate, atomic:: Ordering :: Release ) ;
22502269 }
2251- nodes[ 0 ] . maybe_update_chan_fees ( ) ;
2270+ nodes[ 0 ] . timer_tick_occurred ( ) ;
22522271 } ,
22532272 0x81 => {
22542273 fee_est_a. ret_val . store ( 253 , atomic:: Ordering :: Release ) ;
2255- nodes[ 0 ] . maybe_update_chan_fees ( ) ;
2274+ nodes[ 0 ] . timer_tick_occurred ( ) ;
22562275 } ,
22572276
22582277 0x84 => {
@@ -2263,11 +2282,11 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
22632282 if fee_est_b. ret_val . fetch_add ( 250 , atomic:: Ordering :: AcqRel ) + 250 > max_feerate {
22642283 fee_est_b. ret_val . store ( max_feerate, atomic:: Ordering :: Release ) ;
22652284 }
2266- nodes[ 1 ] . maybe_update_chan_fees ( ) ;
2285+ nodes[ 1 ] . timer_tick_occurred ( ) ;
22672286 } ,
22682287 0x85 => {
22692288 fee_est_b. ret_val . store ( 253 , atomic:: Ordering :: Release ) ;
2270- nodes[ 1 ] . maybe_update_chan_fees ( ) ;
2289+ nodes[ 1 ] . timer_tick_occurred ( ) ;
22712290 } ,
22722291
22732292 0x88 => {
@@ -2278,11 +2297,11 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
22782297 if fee_est_c. ret_val . fetch_add ( 250 , atomic:: Ordering :: AcqRel ) + 250 > max_feerate {
22792298 fee_est_c. ret_val . store ( max_feerate, atomic:: Ordering :: Release ) ;
22802299 }
2281- nodes[ 2 ] . maybe_update_chan_fees ( ) ;
2300+ nodes[ 2 ] . timer_tick_occurred ( ) ;
22822301 } ,
22832302 0x89 => {
22842303 fee_est_c. ret_val . store ( 253 , atomic:: Ordering :: Release ) ;
2285- nodes[ 2 ] . maybe_update_chan_fees ( ) ;
2304+ nodes[ 2 ] . timer_tick_occurred ( ) ;
22862305 } ,
22872306
22882307 0xa0 => {
@@ -2779,6 +2798,14 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
27792798
27802799 process_all_events ! ( ) ;
27812800
2801+ // Since MPP payments are supported, we wait until we fully settle the state of all
2802+ // channels to see if we have any committed HTLC parts of an MPP payment that need
2803+ // to be failed back.
2804+ for node in & nodes {
2805+ node. timer_tick_occurred ( ) ;
2806+ }
2807+ process_all_events ! ( ) ;
2808+
27822809 // Verify no payments are stuck - all should have resolved
27832810 for ( idx, pending) in pending_payments. borrow ( ) . iter ( ) . enumerate ( ) {
27842811 assert ! (
0 commit comments