@@ -50,8 +50,7 @@ use lightning::util::events::MessageSendEventsProvider;
5050use lightning:: util:: ser:: { Readable , ReadableArgs , Writeable , Writer } ;
5151use lightning:: routing:: router:: { Route , RouteHop } ;
5252
53-
54- use utils:: test_logger;
53+ use utils:: test_logger:: { self , Output } ;
5554use utils:: test_persister:: TestPersister ;
5655
5756use bitcoin:: secp256k1:: key:: { PublicKey , SecretKey } ;
@@ -339,7 +338,8 @@ fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, des
339338}
340339
341340#[ inline]
342- pub fn do_test < Out : test_logger:: Output > ( data : & [ u8 ] , out : Out ) {
341+ pub fn do_test < Out : Output > ( data : & [ u8 ] , underlying_out : Out ) {
342+ let out = SearchingOutput :: new ( underlying_out) ;
343343 let broadcast = Arc :: new ( TestBroadcaster { } ) ;
344344
345345 macro_rules! make_node {
@@ -734,7 +734,11 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
734734 // force-close which we should detect as an error).
735735 assert_eq!( msg. contents. flags & 2 , 0 ) ;
736736 } ,
737- _ => panic!( "Unhandled message event {:?}" , event) ,
737+ _ => if out. may_fail. load( atomic:: Ordering :: Acquire ) {
738+ return ;
739+ } else {
740+ panic!( "Unhandled message event {:?}" , event)
741+ } ,
738742 }
739743 if $limit_events != ProcessMessages :: AllMessages {
740744 break ;
@@ -766,7 +770,11 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
766770 events:: MessageSendEvent :: SendChannelUpdate { ref msg, .. } => {
767771 assert_eq!( msg. contents. flags & 2 , 0 ) ; // The disable bit must never be set!
768772 } ,
769- _ => panic!( "Unhandled message event" ) ,
773+ _ => if out. may_fail. load( atomic:: Ordering :: Acquire ) {
774+ return ;
775+ } else {
776+ panic!( "Unhandled message event" )
777+ } ,
770778 }
771779 }
772780 push_excess_b_events!( nodes[ 1 ] . get_and_clear_pending_msg_events( ) . drain( ..) , Some ( 0 ) ) ;
@@ -783,7 +791,11 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
783791 events:: MessageSendEvent :: SendChannelUpdate { ref msg, .. } => {
784792 assert_eq!( msg. contents. flags & 2 , 0 ) ; // The disable bit must never be set!
785793 } ,
786- _ => panic!( "Unhandled message event" ) ,
794+ _ => if out. may_fail. load( atomic:: Ordering :: Acquire ) {
795+ return ;
796+ } else {
797+ panic!( "Unhandled message event" )
798+ } ,
787799 }
788800 }
789801 push_excess_b_events!( nodes[ 1 ] . get_and_clear_pending_msg_events( ) . drain( ..) , Some ( 2 ) ) ;
@@ -834,7 +846,11 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
834846 events:: Event :: PendingHTLCsForwardable { .. } => {
835847 nodes[ $node] . process_pending_htlc_forwards( ) ;
836848 } ,
837- _ => panic!( "Unhandled event" ) ,
849+ _ => if out. may_fail. load( atomic:: Ordering :: Acquire ) {
850+ return ;
851+ } else {
852+ panic!( "Unhandled event" )
853+ } ,
838854 }
839855 }
840856 had_events
@@ -1125,7 +1141,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
11251141 break ;
11261142 }
11271143
1128- // Finally, make sure that at least one end of each channel can make a substantial payment.
1144+ // Finally, make sure that at least one end of each channel can make a substantial payment
11291145 assert ! (
11301146 send_payment( & nodes[ 0 ] , & nodes[ 1 ] , chan_a, 10_000_000 , & mut payment_id) ||
11311147 send_payment( & nodes[ 1 ] , & nodes[ 0 ] , chan_a, 10_000_000 , & mut payment_id) ) ;
@@ -1152,7 +1168,29 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
11521168 }
11531169}
11541170
1155- pub fn chanmon_consistency_test < Out : test_logger:: Output > ( data : & [ u8 ] , out : Out ) {
1171+ /// We actually have different behavior based on if a certain log string has been seen, so we have
1172+ /// to do a bit more tracking.
1173+ #[ derive( Clone ) ]
1174+ struct SearchingOutput < O : Output > {
1175+ output : O ,
1176+ may_fail : Arc < atomic:: AtomicBool > ,
1177+ }
1178+ impl < O : Output > Output for SearchingOutput < O > {
1179+ fn locked_write ( & self , data : & [ u8 ] ) {
1180+ // We hit a design limitation of LN state machine (see CONCURRENT_INBOUND_HTLC_FEE_BUFFER)
1181+ if std:: str:: from_utf8 ( data) . unwrap ( ) . contains ( "Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel" ) {
1182+ self . may_fail . store ( true , atomic:: Ordering :: Release ) ;
1183+ }
1184+ self . output . locked_write ( data)
1185+ }
1186+ }
1187+ impl < O : Output > SearchingOutput < O > {
1188+ pub fn new ( output : O ) -> Self {
1189+ Self { output, may_fail : Arc :: new ( atomic:: AtomicBool :: new ( false ) ) }
1190+ }
1191+ }
1192+
1193+ pub fn chanmon_consistency_test < Out : Output > ( data : & [ u8 ] , out : Out ) {
11561194 do_test ( data, out) ;
11571195}
11581196
0 commit comments