@@ -981,7 +981,9 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
981981 lock_fundings ! ( nodes) ;
982982
983983 let chan_a = nodes[ 0 ] . list_usable_channels ( ) [ 0 ] . short_channel_id . unwrap ( ) ;
984+ let chan_a_id = nodes[ 0 ] . list_usable_channels ( ) [ 0 ] . channel_id ;
984985 let chan_b = nodes[ 2 ] . list_usable_channels ( ) [ 0 ] . short_channel_id . unwrap ( ) ;
986+ let chan_b_id = nodes[ 2 ] . list_usable_channels ( ) [ 0 ] . channel_id ;
985987
986988 let mut p_id: u8 = 0 ;
987989 let mut p_idx: u64 = 0 ;
@@ -1042,6 +1044,10 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
10421044 if Some ( * node_id) == expect_drop_id { panic!( "peer_disconnected should drop msgs bound for the disconnected peer" ) ; }
10431045 * node_id == a_id
10441046 } ,
1047+ events:: MessageSendEvent :: SendStfu { ref node_id, .. } => {
1048+ if Some ( * node_id) == expect_drop_id { panic!( "peer_disconnected should drop msgs bound for the disconnected peer" ) ; }
1049+ * node_id == a_id
1050+ } ,
10451051 events:: MessageSendEvent :: SendChannelReady { .. } => continue ,
10461052 events:: MessageSendEvent :: SendAnnouncementSignatures { .. } => continue ,
10471053 events:: MessageSendEvent :: SendChannelUpdate { ref node_id, ref msg } => {
@@ -1104,7 +1110,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11041110 for ( idx, dest) in nodes. iter( ) . enumerate( ) {
11051111 if dest. get_our_node_id( ) == node_id {
11061112 for update_add in update_add_htlcs. iter( ) {
1107- out. locked_write( format!( "Delivering update_add_htlc to node {}.\n " , idx) . as_bytes( ) ) ;
1113+ out. locked_write( format!( "Delivering update_add_htlc from node {} to node {}.\n " , $node , idx) . as_bytes( ) ) ;
11081114 if !$corrupt_forward {
11091115 dest. handle_update_add_htlc( nodes[ $node] . get_our_node_id( ) , update_add) ;
11101116 } else {
@@ -1119,19 +1125,19 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11191125 }
11201126 }
11211127 for update_fulfill in update_fulfill_htlcs. iter( ) {
1122- out. locked_write( format!( "Delivering update_fulfill_htlc to node {}.\n " , idx) . as_bytes( ) ) ;
1128+ out. locked_write( format!( "Delivering update_fulfill_htlc from node {} to node {}.\n " , $node , idx) . as_bytes( ) ) ;
11231129 dest. handle_update_fulfill_htlc( nodes[ $node] . get_our_node_id( ) , update_fulfill) ;
11241130 }
11251131 for update_fail in update_fail_htlcs. iter( ) {
1126- out. locked_write( format!( "Delivering update_fail_htlc to node {}.\n " , idx) . as_bytes( ) ) ;
1132+ out. locked_write( format!( "Delivering update_fail_htlc from node {} to node {}.\n " , $node , idx) . as_bytes( ) ) ;
11271133 dest. handle_update_fail_htlc( nodes[ $node] . get_our_node_id( ) , update_fail) ;
11281134 }
11291135 for update_fail_malformed in update_fail_malformed_htlcs. iter( ) {
1130- out. locked_write( format!( "Delivering update_fail_malformed_htlc to node {}.\n " , idx) . as_bytes( ) ) ;
1136+ out. locked_write( format!( "Delivering update_fail_malformed_htlc from node {} to node {}.\n " , $node , idx) . as_bytes( ) ) ;
11311137 dest. handle_update_fail_malformed_htlc( nodes[ $node] . get_our_node_id( ) , update_fail_malformed) ;
11321138 }
11331139 if let Some ( msg) = update_fee {
1134- out. locked_write( format!( "Delivering update_fee to node {}.\n " , idx) . as_bytes( ) ) ;
1140+ out. locked_write( format!( "Delivering update_fee from node {} to node {}.\n " , $node , idx) . as_bytes( ) ) ;
11351141 dest. handle_update_fee( nodes[ $node] . get_our_node_id( ) , & msg) ;
11361142 }
11371143 let processed_change = !update_add_htlcs. is_empty( ) || !update_fulfill_htlcs. is_empty( ) ||
@@ -1148,7 +1154,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11481154 } } ) ;
11491155 break ;
11501156 }
1151- out. locked_write( format!( "Delivering commitment_signed to node {}.\n " , idx) . as_bytes( ) ) ;
1157+ out. locked_write( format!( "Delivering commitment_signed from node {} to node {}.\n " , $node , idx) . as_bytes( ) ) ;
11521158 dest. handle_commitment_signed( nodes[ $node] . get_our_node_id( ) , & commitment_signed) ;
11531159 break ;
11541160 }
@@ -1157,19 +1163,27 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11571163 events:: MessageSendEvent :: SendRevokeAndACK { ref node_id, ref msg } => {
11581164 for ( idx, dest) in nodes. iter( ) . enumerate( ) {
11591165 if dest. get_our_node_id( ) == * node_id {
1160- out. locked_write( format!( "Delivering revoke_and_ack to node {}.\n " , idx) . as_bytes( ) ) ;
1166+ out. locked_write( format!( "Delivering revoke_and_ack from node {} to node {}.\n " , $node , idx) . as_bytes( ) ) ;
11611167 dest. handle_revoke_and_ack( nodes[ $node] . get_our_node_id( ) , msg) ;
11621168 }
11631169 }
11641170 } ,
11651171 events:: MessageSendEvent :: SendChannelReestablish { ref node_id, ref msg } => {
11661172 for ( idx, dest) in nodes. iter( ) . enumerate( ) {
11671173 if dest. get_our_node_id( ) == * node_id {
1168- out. locked_write( format!( "Delivering channel_reestablish to node {}.\n " , idx) . as_bytes( ) ) ;
1174+ out. locked_write( format!( "Delivering channel_reestablish from node {} to node {}.\n " , $node , idx) . as_bytes( ) ) ;
11691175 dest. handle_channel_reestablish( nodes[ $node] . get_our_node_id( ) , msg) ;
11701176 }
11711177 }
11721178 } ,
1179+ events:: MessageSendEvent :: SendStfu { ref node_id, ref msg } => {
1180+ for ( idx, dest) in nodes. iter( ) . enumerate( ) {
1181+ if dest. get_our_node_id( ) == * node_id {
1182+ out. locked_write( format!( "Delivering stfu from node {} to node {}.\n " , $node, idx) . as_bytes( ) ) ;
1183+ dest. handle_stfu( nodes[ $node] . get_our_node_id( ) , msg) ;
1184+ }
1185+ }
1186+ }
11731187 events:: MessageSendEvent :: SendChannelReady { .. } => {
11741188 // Can be generated as a reestablish response
11751189 } ,
@@ -1222,6 +1236,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
12221236 events:: MessageSendEvent :: UpdateHTLCs { .. } => { } ,
12231237 events:: MessageSendEvent :: SendRevokeAndACK { .. } => { } ,
12241238 events:: MessageSendEvent :: SendChannelReestablish { .. } => { } ,
1239+ events:: MessageSendEvent :: SendStfu { .. } => { } ,
12251240 events:: MessageSendEvent :: SendChannelReady { .. } => { } ,
12261241 events:: MessageSendEvent :: SendAnnouncementSignatures { .. } => { } ,
12271242 events:: MessageSendEvent :: SendChannelUpdate { ref msg, .. } => {
@@ -1248,6 +1263,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
12481263 events:: MessageSendEvent :: UpdateHTLCs { .. } => { } ,
12491264 events:: MessageSendEvent :: SendRevokeAndACK { .. } => { } ,
12501265 events:: MessageSendEvent :: SendChannelReestablish { .. } => { } ,
1266+ events:: MessageSendEvent :: SendStfu { .. } => { } ,
12511267 events:: MessageSendEvent :: SendChannelReady { .. } => { } ,
12521268 events:: MessageSendEvent :: SendAnnouncementSignatures { .. } => { } ,
12531269 events:: MessageSendEvent :: SendChannelUpdate { ref msg, .. } => {
@@ -1691,6 +1707,19 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
16911707 nodes[ 2 ] . maybe_update_chan_fees ( ) ;
16921708 } ,
16931709
1710+ 0xa0 => {
1711+ nodes[ 0 ] . maybe_propose_quiescence ( & nodes[ 1 ] . get_our_node_id ( ) , & chan_a_id) . unwrap ( )
1712+ } ,
1713+ 0xa1 => {
1714+ nodes[ 1 ] . maybe_propose_quiescence ( & nodes[ 0 ] . get_our_node_id ( ) , & chan_a_id) . unwrap ( )
1715+ } ,
1716+ 0xa2 => {
1717+ nodes[ 1 ] . maybe_propose_quiescence ( & nodes[ 2 ] . get_our_node_id ( ) , & chan_b_id) . unwrap ( )
1718+ } ,
1719+ 0xa3 => {
1720+ nodes[ 2 ] . maybe_propose_quiescence ( & nodes[ 1 ] . get_our_node_id ( ) , & chan_b_id) . unwrap ( )
1721+ } ,
1722+
16941723 0xf0 => complete_monitor_update ( & monitor_a, & chan_1_id, & complete_first) ,
16951724 0xf1 => complete_monitor_update ( & monitor_a, & chan_1_id, & complete_second) ,
16961725 0xf2 => complete_monitor_update ( & monitor_a, & chan_1_id, & Vec :: pop) ,
@@ -1756,34 +1785,49 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
17561785 chan_b_disconnected = false ;
17571786 }
17581787
1759- for i in 0 ..std:: usize:: MAX {
1760- if i == 100 {
1761- panic ! ( "It may take may iterations to settle the state, but it should not take forever" ) ;
1762- }
1763- // Then, make sure any current forwards make their way to their destination
1764- if process_msg_events ! ( 0 , false , ProcessMessages :: AllMessages ) {
1765- continue ;
1766- }
1767- if process_msg_events ! ( 1 , false , ProcessMessages :: AllMessages ) {
1768- continue ;
1769- }
1770- if process_msg_events ! ( 2 , false , ProcessMessages :: AllMessages ) {
1771- continue ;
1772- }
1773- // ...making sure any pending PendingHTLCsForwardable events are handled and
1774- // payments claimed.
1775- if process_events ! ( 0 , false ) {
1776- continue ;
1777- }
1778- if process_events ! ( 1 , false ) {
1779- continue ;
1780- }
1781- if process_events ! ( 2 , false ) {
1782- continue ;
1783- }
1784- break ;
1788+ macro_rules! process_all_events {
1789+ ( ) => {
1790+ for i in 0 ..std:: usize :: MAX {
1791+ if i == 100 {
1792+ panic!( "It may take may iterations to settle the state, but it should not take forever" ) ;
1793+ }
1794+ // Then, make sure any current forwards make their way to their destination
1795+ if process_msg_events!( 0 , false , ProcessMessages :: AllMessages ) {
1796+ continue ;
1797+ }
1798+ if process_msg_events!( 1 , false , ProcessMessages :: AllMessages ) {
1799+ continue ;
1800+ }
1801+ if process_msg_events!( 2 , false , ProcessMessages :: AllMessages ) {
1802+ continue ;
1803+ }
1804+ // ...making sure any pending PendingHTLCsForwardable events are handled and
1805+ // payments claimed.
1806+ if process_events!( 0 , false ) {
1807+ continue ;
1808+ }
1809+ if process_events!( 1 , false ) {
1810+ continue ;
1811+ }
1812+ if process_events!( 2 , false ) {
1813+ continue ;
1814+ }
1815+ break ;
1816+ }
1817+ } ;
17851818 }
17861819
1820+ // At this point, we may be pending quiescence, so we'll process all messages to
1821+ // ensure we can complete its handshake. We'll then exit quiescence and process all
1822+ // messages again, to resolve any pending HTLCs (only irrevocably committed ones)
1823+ // before attempting to send more payments.
1824+ process_all_events ! ( ) ;
1825+ nodes[ 0 ] . exit_quiescence ( & nodes[ 1 ] . get_our_node_id ( ) , & chan_a_id) . unwrap ( ) ;
1826+ nodes[ 1 ] . exit_quiescence ( & nodes[ 0 ] . get_our_node_id ( ) , & chan_a_id) . unwrap ( ) ;
1827+ nodes[ 1 ] . exit_quiescence ( & nodes[ 2 ] . get_our_node_id ( ) , & chan_b_id) . unwrap ( ) ;
1828+ nodes[ 2 ] . exit_quiescence ( & nodes[ 1 ] . get_our_node_id ( ) , & chan_b_id) . unwrap ( ) ;
1829+ process_all_events ! ( ) ;
1830+
17871831 // Finally, make sure that at least one end of each channel can make a substantial payment
17881832 assert ! (
17891833 send_payment( & nodes[ 0 ] , & nodes[ 1 ] , chan_a, 10_000_000 , & mut p_id, & mut p_idx)
0 commit comments