104104//! # ) -> u64 { 0 }
105105//! # fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
106106//! # fn payment_path_successful(&mut self, _path: &[&RouteHop]) {}
107+ //! # fn probe_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
108+ //! # fn probe_successful(&mut self, _path: &[&RouteHop]) {}
107109//! # }
108110//! #
109111//! # struct FakeLogger {}
@@ -595,8 +597,11 @@ where
595597 // hop and then drop the event instead of handing it up to the user's event
596598 // handler.
597599 if self . payer . payment_is_probe ( * payment_hash, * payment_id) {
598- let scid = if * rejected_by_dest { u64:: max_value ( ) } else { * short_channel_id } ;
599- self . scorer . lock ( ) . payment_path_failed ( & path, scid) ;
600+ if * rejected_by_dest {
601+ self . scorer . lock ( ) . probe_successful ( & path) ;
602+ } else {
603+ self . scorer . lock ( ) . probe_failed ( & path, * short_channel_id) ;
604+ }
600605 return ;
601606 }
602607 }
@@ -1345,7 +1350,7 @@ mod tests {
13451350 . expect_send ( Amount :: ForInvoice ( final_value_msat) )
13461351 . expect_send ( Amount :: OnRetry ( final_value_msat / 2 ) ) ;
13471352 let router = TestRouter { } ;
1348- let scorer = RefCell :: new ( TestScorer :: new ( ) . expect ( PaymentPath :: Failure {
1353+ let scorer = RefCell :: new ( TestScorer :: new ( ) . expect ( ExpectedPaymentResult :: PathFailure {
13491354 path : path. clone ( ) , short_channel_id : path[ 0 ] . short_channel_id ,
13501355 } ) ) ;
13511356 let logger = TestLogger :: new ( ) ;
@@ -1381,8 +1386,8 @@ mod tests {
13811386 let payer = TestPayer :: new ( ) . expect_send ( Amount :: ForInvoice ( final_value_msat) ) ;
13821387 let router = TestRouter { } ;
13831388 let scorer = RefCell :: new ( TestScorer :: new ( )
1384- . expect ( PaymentPath :: Success { path : route. paths [ 0 ] . clone ( ) } )
1385- . expect ( PaymentPath :: Success { path : route. paths [ 1 ] . clone ( ) } )
1389+ . expect ( ExpectedPaymentResult :: PathSuccess { path : route. paths [ 0 ] . clone ( ) } )
1390+ . expect ( ExpectedPaymentResult :: PathSuccess { path : route. paths [ 1 ] . clone ( ) } )
13861391 ) ;
13871392 let logger = TestLogger :: new ( ) ;
13881393 let invoice_payer =
@@ -1479,13 +1484,15 @@ mod tests {
14791484 }
14801485
14811486 struct TestScorer {
1482- expectations : Option < VecDeque < PaymentPath > > ,
1487+ expectations : Option < VecDeque < ExpectedPaymentResult > > ,
14831488 }
14841489
14851490 #[ derive( Debug ) ]
1486- enum PaymentPath {
1487- Failure { path : Vec < RouteHop > , short_channel_id : u64 } ,
1488- Success { path : Vec < RouteHop > } ,
1491+ enum ExpectedPaymentResult {
1492+ PathFailure { path : Vec < RouteHop > , short_channel_id : u64 } ,
1493+ PathSuccess { path : Vec < RouteHop > } ,
1494+ ProbeFailure { path : Vec < RouteHop > , short_channel_id : u64 } ,
1495+ ProbeSuccess { path : Vec < RouteHop > } ,
14891496 }
14901497
14911498 impl TestScorer {
@@ -1495,7 +1502,7 @@ mod tests {
14951502 }
14961503 }
14971504
1498- fn expect ( mut self , expectation : PaymentPath ) -> Self {
1505+ fn expect ( mut self , expectation : ExpectedPaymentResult ) -> Self {
14991506 self . expectations . get_or_insert_with ( || VecDeque :: new ( ) ) . push_back ( expectation) ;
15001507 self
15011508 }
@@ -1514,13 +1521,19 @@ mod tests {
15141521 fn payment_path_failed ( & mut self , actual_path : & [ & RouteHop ] , actual_short_channel_id : u64 ) {
15151522 if let Some ( expectations) = & mut self . expectations {
15161523 match expectations. pop_front ( ) {
1517- Some ( PaymentPath :: Failure { path, short_channel_id } ) => {
1524+ Some ( ExpectedPaymentResult :: PathFailure { path, short_channel_id } ) => {
15181525 assert_eq ! ( actual_path, & path. iter( ) . collect:: <Vec <_>>( ) [ ..] ) ;
15191526 assert_eq ! ( actual_short_channel_id, short_channel_id) ;
15201527 } ,
1521- Some ( PaymentPath :: Success { path } ) => {
1528+ Some ( ExpectedPaymentResult :: PathSuccess { path } ) => {
15221529 panic ! ( "Unexpected successful payment path: {:?}" , path)
15231530 } ,
1531+ Some ( ExpectedPaymentResult :: ProbeFailure { path, .. } ) => {
1532+ panic ! ( "Unexpected failed payment probe: {:?}" , path)
1533+ } ,
1534+ Some ( ExpectedPaymentResult :: ProbeSuccess { path } ) => {
1535+ panic ! ( "Unexpected successful payment probe: {:?}" , path)
1536+ } ,
15241537 None => panic ! ( "Unexpected payment_path_failed call: {:?}" , actual_path) ,
15251538 }
15261539 }
@@ -1529,10 +1542,56 @@ mod tests {
15291542 fn payment_path_successful ( & mut self , actual_path : & [ & RouteHop ] ) {
15301543 if let Some ( expectations) = & mut self . expectations {
15311544 match expectations. pop_front ( ) {
1532- Some ( PaymentPath :: Failure { path, .. } ) => {
1545+ Some ( ExpectedPaymentResult :: PathFailure { path, .. } ) => {
15331546 panic ! ( "Unexpected payment path failure: {:?}" , path)
15341547 } ,
1535- Some ( PaymentPath :: Success { path } ) => {
1548+ Some ( ExpectedPaymentResult :: PathSuccess { path } ) => {
1549+ assert_eq ! ( actual_path, & path. iter( ) . collect:: <Vec <_>>( ) [ ..] ) ;
1550+ } ,
1551+ Some ( ExpectedPaymentResult :: ProbeFailure { path, .. } ) => {
1552+ panic ! ( "Unexpected failed payment probe: {:?}" , path)
1553+ } ,
1554+ Some ( ExpectedPaymentResult :: ProbeSuccess { path } ) => {
1555+ panic ! ( "Unexpected successful payment probe: {:?}" , path)
1556+ } ,
1557+ None => panic ! ( "Unexpected payment_path_successful call: {:?}" , actual_path) ,
1558+ }
1559+ }
1560+ }
1561+
1562+ fn probe_failed ( & mut self , actual_path : & [ & RouteHop ] , actual_short_channel_id : u64 ) {
1563+ if let Some ( expectations) = & mut self . expectations {
1564+ match expectations. pop_front ( ) {
1565+ Some ( ExpectedPaymentResult :: PathFailure { path, .. } ) => {
1566+ panic ! ( "Unexpected failed payment path: {:?}" , path)
1567+ } ,
1568+ Some ( ExpectedPaymentResult :: PathSuccess { path } ) => {
1569+ panic ! ( "Unexpected successful payment path: {:?}" , path)
1570+ } ,
1571+ Some ( ExpectedPaymentResult :: ProbeFailure { path, short_channel_id } ) => {
1572+ assert_eq ! ( actual_path, & path. iter( ) . collect:: <Vec <_>>( ) [ ..] ) ;
1573+ assert_eq ! ( actual_short_channel_id, short_channel_id) ;
1574+ } ,
1575+ Some ( ExpectedPaymentResult :: ProbeSuccess { path } ) => {
1576+ panic ! ( "Unexpected successful payment probe: {:?}" , path)
1577+ } ,
1578+ None => panic ! ( "Unexpected payment_path_failed call: {:?}" , actual_path) ,
1579+ }
1580+ }
1581+ }
1582+ fn probe_successful ( & mut self , actual_path : & [ & RouteHop ] ) {
1583+ if let Some ( expectations) = & mut self . expectations {
1584+ match expectations. pop_front ( ) {
1585+ Some ( ExpectedPaymentResult :: PathFailure { path, .. } ) => {
1586+ panic ! ( "Unexpected payment path failure: {:?}" , path)
1587+ } ,
1588+ Some ( ExpectedPaymentResult :: PathSuccess { path } ) => {
1589+ panic ! ( "Unexpected successful payment path: {:?}" , path)
1590+ } ,
1591+ Some ( ExpectedPaymentResult :: ProbeFailure { path, .. } ) => {
1592+ panic ! ( "Unexpected failed payment probe: {:?}" , path)
1593+ } ,
1594+ Some ( ExpectedPaymentResult :: ProbeSuccess { path } ) => {
15361595 assert_eq ! ( actual_path, & path. iter( ) . collect:: <Vec <_>>( ) [ ..] ) ;
15371596 } ,
15381597 None => panic ! ( "Unexpected payment_path_successful call: {:?}" , actual_path) ,
0 commit comments