104
104
//! # ) -> u64 { 0 }
105
105
//! # fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
106
106
//! # 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]) {}
107
109
//! # }
108
110
//! #
109
111
//! # struct FakeLogger {}
@@ -595,8 +597,11 @@ where
595
597
// hop and then drop the event instead of handing it up to the user's event
596
598
// handler.
597
599
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
+ }
600
605
return ;
601
606
}
602
607
}
@@ -1345,7 +1350,7 @@ mod tests {
1345
1350
. expect_send ( Amount :: ForInvoice ( final_value_msat) )
1346
1351
. expect_send ( Amount :: OnRetry ( final_value_msat / 2 ) ) ;
1347
1352
let router = TestRouter { } ;
1348
- let scorer = RefCell :: new ( TestScorer :: new ( ) . expect ( PaymentPath :: Failure {
1353
+ let scorer = RefCell :: new ( TestScorer :: new ( ) . expect ( ExpectedPaymentResult :: PathFailure {
1349
1354
path : path. clone ( ) , short_channel_id : path[ 0 ] . short_channel_id ,
1350
1355
} ) ) ;
1351
1356
let logger = TestLogger :: new ( ) ;
@@ -1381,8 +1386,8 @@ mod tests {
1381
1386
let payer = TestPayer :: new ( ) . expect_send ( Amount :: ForInvoice ( final_value_msat) ) ;
1382
1387
let router = TestRouter { } ;
1383
1388
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 ( ) } )
1386
1391
) ;
1387
1392
let logger = TestLogger :: new ( ) ;
1388
1393
let invoice_payer =
@@ -1479,13 +1484,15 @@ mod tests {
1479
1484
}
1480
1485
1481
1486
struct TestScorer {
1482
- expectations : Option < VecDeque < PaymentPath > > ,
1487
+ expectations : Option < VecDeque < ExpectedPaymentResult > > ,
1483
1488
}
1484
1489
1485
1490
#[ 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 > } ,
1489
1496
}
1490
1497
1491
1498
impl TestScorer {
@@ -1495,7 +1502,7 @@ mod tests {
1495
1502
}
1496
1503
}
1497
1504
1498
- fn expect ( mut self , expectation : PaymentPath ) -> Self {
1505
+ fn expect ( mut self , expectation : ExpectedPaymentResult ) -> Self {
1499
1506
self . expectations . get_or_insert_with ( || VecDeque :: new ( ) ) . push_back ( expectation) ;
1500
1507
self
1501
1508
}
@@ -1514,13 +1521,19 @@ mod tests {
1514
1521
fn payment_path_failed ( & mut self , actual_path : & [ & RouteHop ] , actual_short_channel_id : u64 ) {
1515
1522
if let Some ( expectations) = & mut self . expectations {
1516
1523
match expectations. pop_front ( ) {
1517
- Some ( PaymentPath :: Failure { path, short_channel_id } ) => {
1524
+ Some ( ExpectedPaymentResult :: PathFailure { path, short_channel_id } ) => {
1518
1525
assert_eq ! ( actual_path, & path. iter( ) . collect:: <Vec <_>>( ) [ ..] ) ;
1519
1526
assert_eq ! ( actual_short_channel_id, short_channel_id) ;
1520
1527
} ,
1521
- Some ( PaymentPath :: Success { path } ) => {
1528
+ Some ( ExpectedPaymentResult :: PathSuccess { path } ) => {
1522
1529
panic ! ( "Unexpected successful payment path: {:?}" , path)
1523
1530
} ,
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
+ } ,
1524
1537
None => panic ! ( "Unexpected payment_path_failed call: {:?}" , actual_path) ,
1525
1538
}
1526
1539
}
@@ -1529,10 +1542,56 @@ mod tests {
1529
1542
fn payment_path_successful ( & mut self , actual_path : & [ & RouteHop ] ) {
1530
1543
if let Some ( expectations) = & mut self . expectations {
1531
1544
match expectations. pop_front ( ) {
1532
- Some ( PaymentPath :: Failure { path, .. } ) => {
1545
+ Some ( ExpectedPaymentResult :: PathFailure { path, .. } ) => {
1533
1546
panic ! ( "Unexpected payment path failure: {:?}" , path)
1534
1547
} ,
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 } ) => {
1536
1595
assert_eq ! ( actual_path, & path. iter( ) . collect:: <Vec <_>>( ) [ ..] ) ;
1537
1596
} ,
1538
1597
None => panic ! ( "Unexpected payment_path_successful call: {:?}" , actual_path) ,
0 commit comments