94
94
//! # ) -> u64 { 0 }
95
95
//! # fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
96
96
//! # fn payment_path_successful(&mut self, _path: &[&RouteHop]) {}
97
+ //! # fn probe_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
98
+ //! # fn probe_successful(&mut self, _path: &[&RouteHop]) {}
97
99
//! # }
98
100
//! #
99
101
//! # struct FakeLogger {}
@@ -584,6 +586,18 @@ where
584
586
. map_or ( 1 , |attempts| attempts. count + 1 ) ;
585
587
log_trace ! ( self . logger, "Payment {} succeeded (attempts: {})" , log_bytes!( payment_hash. 0 ) , attempts) ;
586
588
} ,
589
+ Event :: ProbeSuccessful { payment_hash, path, .. } => {
590
+ log_trace ! ( self . logger, "Probe payment {} of {}msat was successful" , log_bytes!( payment_hash. 0 ) , path. last( ) . unwrap( ) . fee_msat) ;
591
+ let path = path. iter ( ) . collect :: < Vec < _ > > ( ) ;
592
+ self . scorer . lock ( ) . probe_successful ( & path) ;
593
+ } ,
594
+ Event :: ProbeFailed { payment_hash, path, short_channel_id, .. } => {
595
+ if let Some ( short_channel_id) = short_channel_id {
596
+ log_trace ! ( self . logger, "Probe payment {} of {}msat failed at channel {}" , log_bytes!( payment_hash. 0 ) , path. last( ) . unwrap( ) . fee_msat, * short_channel_id) ;
597
+ let path = path. iter ( ) . collect :: < Vec < _ > > ( ) ;
598
+ self . scorer . lock ( ) . probe_failed ( & path, * short_channel_id) ;
599
+ }
600
+ } ,
587
601
_ => { } ,
588
602
}
589
603
@@ -1296,7 +1310,7 @@ mod tests {
1296
1310
. expect_send ( Amount :: ForInvoice ( final_value_msat) )
1297
1311
. expect_send ( Amount :: OnRetry ( final_value_msat / 2 ) ) ;
1298
1312
let router = TestRouter { } ;
1299
- let scorer = RefCell :: new ( TestScorer :: new ( ) . expect ( PaymentPath :: Failure {
1313
+ let scorer = RefCell :: new ( TestScorer :: new ( ) . expect ( TestResult :: PaymentFailure {
1300
1314
path : path. clone ( ) , short_channel_id : path[ 0 ] . short_channel_id ,
1301
1315
} ) ) ;
1302
1316
let logger = TestLogger :: new ( ) ;
@@ -1332,8 +1346,8 @@ mod tests {
1332
1346
let payer = TestPayer :: new ( ) . expect_send ( Amount :: ForInvoice ( final_value_msat) ) ;
1333
1347
let router = TestRouter { } ;
1334
1348
let scorer = RefCell :: new ( TestScorer :: new ( )
1335
- . expect ( PaymentPath :: Success { path : route. paths [ 0 ] . clone ( ) } )
1336
- . expect ( PaymentPath :: Success { path : route. paths [ 1 ] . clone ( ) } )
1349
+ . expect ( TestResult :: PaymentSuccess { path : route. paths [ 0 ] . clone ( ) } )
1350
+ . expect ( TestResult :: PaymentSuccess { path : route. paths [ 1 ] . clone ( ) } )
1337
1351
) ;
1338
1352
let logger = TestLogger :: new ( ) ;
1339
1353
let invoice_payer =
@@ -1416,13 +1430,15 @@ mod tests {
1416
1430
}
1417
1431
1418
1432
struct TestScorer {
1419
- expectations : Option < VecDeque < PaymentPath > > ,
1433
+ expectations : Option < VecDeque < TestResult > > ,
1420
1434
}
1421
1435
1422
1436
#[ derive( Debug ) ]
1423
- enum PaymentPath {
1424
- Failure { path : Vec < RouteHop > , short_channel_id : u64 } ,
1425
- Success { path : Vec < RouteHop > } ,
1437
+ enum TestResult {
1438
+ PaymentFailure { path : Vec < RouteHop > , short_channel_id : u64 } ,
1439
+ PaymentSuccess { path : Vec < RouteHop > } ,
1440
+ ProbeFailure { path : Vec < RouteHop > , short_channel_id : u64 } ,
1441
+ ProbeSuccess { path : Vec < RouteHop > } ,
1426
1442
}
1427
1443
1428
1444
impl TestScorer {
@@ -1432,7 +1448,7 @@ mod tests {
1432
1448
}
1433
1449
}
1434
1450
1435
- fn expect ( mut self , expectation : PaymentPath ) -> Self {
1451
+ fn expect ( mut self , expectation : TestResult ) -> Self {
1436
1452
self . expectations . get_or_insert_with ( || VecDeque :: new ( ) ) . push_back ( expectation) ;
1437
1453
self
1438
1454
}
@@ -1451,13 +1467,19 @@ mod tests {
1451
1467
fn payment_path_failed ( & mut self , actual_path : & [ & RouteHop ] , actual_short_channel_id : u64 ) {
1452
1468
if let Some ( expectations) = & mut self . expectations {
1453
1469
match expectations. pop_front ( ) {
1454
- Some ( PaymentPath :: Failure { path, short_channel_id } ) => {
1470
+ Some ( TestResult :: PaymentFailure { path, short_channel_id } ) => {
1455
1471
assert_eq ! ( actual_path, & path. iter( ) . collect:: <Vec <_>>( ) [ ..] ) ;
1456
1472
assert_eq ! ( actual_short_channel_id, short_channel_id) ;
1457
1473
} ,
1458
- Some ( PaymentPath :: Success { path } ) => {
1474
+ Some ( TestResult :: PaymentSuccess { path } ) => {
1459
1475
panic ! ( "Unexpected successful payment path: {:?}" , path)
1460
1476
} ,
1477
+ Some ( TestResult :: ProbeFailure { path, .. } ) => {
1478
+ panic ! ( "Unexpected failed payment probe: {:?}" , path)
1479
+ } ,
1480
+ Some ( TestResult :: ProbeSuccess { path } ) => {
1481
+ panic ! ( "Unexpected successful payment probe: {:?}" , path)
1482
+ } ,
1461
1483
None => panic ! ( "Unexpected payment_path_failed call: {:?}" , actual_path) ,
1462
1484
}
1463
1485
}
@@ -1466,10 +1488,56 @@ mod tests {
1466
1488
fn payment_path_successful ( & mut self , actual_path : & [ & RouteHop ] ) {
1467
1489
if let Some ( expectations) = & mut self . expectations {
1468
1490
match expectations. pop_front ( ) {
1469
- Some ( PaymentPath :: Failure { path, .. } ) => {
1491
+ Some ( TestResult :: PaymentFailure { path, .. } ) => {
1470
1492
panic ! ( "Unexpected payment path failure: {:?}" , path)
1471
1493
} ,
1472
- Some ( PaymentPath :: Success { path } ) => {
1494
+ Some ( TestResult :: PaymentSuccess { path } ) => {
1495
+ assert_eq ! ( actual_path, & path. iter( ) . collect:: <Vec <_>>( ) [ ..] ) ;
1496
+ } ,
1497
+ Some ( TestResult :: ProbeFailure { path, .. } ) => {
1498
+ panic ! ( "Unexpected failed payment probe: {:?}" , path)
1499
+ } ,
1500
+ Some ( TestResult :: ProbeSuccess { path } ) => {
1501
+ panic ! ( "Unexpected successful payment probe: {:?}" , path)
1502
+ } ,
1503
+ None => panic ! ( "Unexpected payment_path_successful call: {:?}" , actual_path) ,
1504
+ }
1505
+ }
1506
+ }
1507
+
1508
+ fn probe_failed ( & mut self , actual_path : & [ & RouteHop ] , actual_short_channel_id : u64 ) {
1509
+ if let Some ( expectations) = & mut self . expectations {
1510
+ match expectations. pop_front ( ) {
1511
+ Some ( TestResult :: PaymentFailure { path, .. } ) => {
1512
+ panic ! ( "Unexpected failed payment path: {:?}" , path)
1513
+ } ,
1514
+ Some ( TestResult :: PaymentSuccess { path } ) => {
1515
+ panic ! ( "Unexpected successful payment path: {:?}" , path)
1516
+ } ,
1517
+ Some ( TestResult :: ProbeFailure { path, short_channel_id } ) => {
1518
+ assert_eq ! ( actual_path, & path. iter( ) . collect:: <Vec <_>>( ) [ ..] ) ;
1519
+ assert_eq ! ( actual_short_channel_id, short_channel_id) ;
1520
+ } ,
1521
+ Some ( TestResult :: ProbeSuccess { path } ) => {
1522
+ panic ! ( "Unexpected successful payment probe: {:?}" , path)
1523
+ } ,
1524
+ None => panic ! ( "Unexpected payment_path_failed call: {:?}" , actual_path) ,
1525
+ }
1526
+ }
1527
+ }
1528
+ fn probe_successful ( & mut self , actual_path : & [ & RouteHop ] ) {
1529
+ if let Some ( expectations) = & mut self . expectations {
1530
+ match expectations. pop_front ( ) {
1531
+ Some ( TestResult :: PaymentFailure { path, .. } ) => {
1532
+ panic ! ( "Unexpected payment path failure: {:?}" , path)
1533
+ } ,
1534
+ Some ( TestResult :: PaymentSuccess { path } ) => {
1535
+ panic ! ( "Unexpected successful payment path: {:?}" , path)
1536
+ } ,
1537
+ Some ( TestResult :: ProbeFailure { path, .. } ) => {
1538
+ panic ! ( "Unexpected failed payment probe: {:?}" , path)
1539
+ } ,
1540
+ Some ( TestResult :: ProbeSuccess { path } ) => {
1473
1541
assert_eq ! ( actual_path, & path. iter( ) . collect:: <Vec <_>>( ) [ ..] ) ;
1474
1542
} ,
1475
1543
None => panic ! ( "Unexpected payment_path_successful call: {:?}" , actual_path) ,
0 commit comments