@@ -1560,7 +1560,8 @@ mod tests {
1560
1560
assert_eq ! ( inflight_map. get( & ( 2 , false ) ) . unwrap( ) . clone( ) , 64 ) ;
1561
1561
1562
1562
// Second path check
1563
- assert_eq ! ( inflight_map. get( & ( 1 , false ) ) . unwrap( ) . clone( ) , 64 ) ;
1563
+ assert_eq ! ( inflight_map. get( & ( 3 , false ) ) . unwrap( ) . clone( ) , 74 ) ;
1564
+ assert_eq ! ( inflight_map. get( & ( 4 , false ) ) . unwrap( ) . clone( ) , 64 ) ;
1564
1565
1565
1566
invoice_payer. handle_event ( & Event :: PaymentPathSuccessful {
1566
1567
payment_id, payment_hash, path : route. paths [ 0 ] . clone ( )
@@ -1573,7 +1574,8 @@ mod tests {
1573
1574
assert_eq ! ( inflight_map. get( & ( 2 , false ) ) , None ) ;
1574
1575
1575
1576
// Second path should still be inflight
1576
- assert_eq ! ( inflight_map. get( & ( 1 , false ) ) . unwrap( ) . clone( ) , 64 )
1577
+ assert_eq ! ( inflight_map. get( & ( 3 , false ) ) . unwrap( ) . clone( ) , 74 ) ;
1578
+ assert_eq ! ( inflight_map. get( & ( 4 , false ) ) . unwrap( ) . clone( ) , 64 )
1577
1579
}
1578
1580
1579
1581
#[ test]
@@ -1595,17 +1597,19 @@ mod tests {
1595
1597
let router = TestRouter { } ;
1596
1598
let scorer = RefCell :: new ( TestScorer :: new ( )
1597
1599
// 1st invoice, 1st path
1598
- . expect_usage ( ChannelUsage { amount_msat : 10 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1599
- . expect_usage ( ChannelUsage { amount_msat : 20 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1600
1600
. expect_usage ( ChannelUsage { amount_msat : 64 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1601
+ . expect_usage ( ChannelUsage { amount_msat : 84 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1602
+ . expect_usage ( ChannelUsage { amount_msat : 94 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1601
1603
// 1st invoice, 2nd path
1602
1604
. expect_usage ( ChannelUsage { amount_msat : 64 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1605
+ . expect_usage ( ChannelUsage { amount_msat : 74 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1603
1606
// 2nd invoice, 1st path
1604
- . expect_usage ( ChannelUsage { amount_msat : 10 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1605
- . expect_usage ( ChannelUsage { amount_msat : 20 , inflight_htlc_msat : 64 , effective_capacity : EffectiveCapacity :: Unknown } )
1606
1607
. expect_usage ( ChannelUsage { amount_msat : 64 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1608
+ . expect_usage ( ChannelUsage { amount_msat : 84 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1609
+ . expect_usage ( ChannelUsage { amount_msat : 94 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1607
1610
// 2nd invoice, 2nd path
1608
1611
. expect_usage ( ChannelUsage { amount_msat : 64 , inflight_htlc_msat : 64 , effective_capacity : EffectiveCapacity :: Unknown } )
1612
+ . expect_usage ( ChannelUsage { amount_msat : 74 , inflight_htlc_msat : 74 , effective_capacity : EffectiveCapacity :: Unknown } )
1609
1613
) ;
1610
1614
let logger = TestLogger :: new ( ) ;
1611
1615
let invoice_payer =
@@ -1640,26 +1644,31 @@ mod tests {
1640
1644
let payer = TestPayer :: new ( )
1641
1645
. expect_send ( Amount :: ForInvoice ( final_value_msat) )
1642
1646
. expect_send ( Amount :: OnRetry ( final_value_msat / 2 ) )
1643
- . expect_send ( Amount :: OnRetry ( final_value_msat / 2 ) ) ;
1647
+ . expect_send ( Amount :: OnRetry ( final_value_msat / 4 ) ) ;
1644
1648
let final_value_msat = payment_invoice. amount_milli_satoshis ( ) . unwrap ( ) ;
1645
1649
let router = TestRouter { } ;
1646
1650
let scorer = RefCell :: new ( TestScorer :: new ( )
1647
1651
// 1st invoice, 1st path
1648
- . expect_usage ( ChannelUsage { amount_msat : 10 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1649
- . expect_usage ( ChannelUsage { amount_msat : 20 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1650
1652
. expect_usage ( ChannelUsage { amount_msat : 64 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1653
+ . expect_usage ( ChannelUsage { amount_msat : 84 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1654
+ . expect_usage ( ChannelUsage { amount_msat : 94 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1651
1655
// 1st invoice, 2nd path
1652
1656
. expect_usage ( ChannelUsage { amount_msat : 64 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1653
- // Retry 1
1654
- . expect_usage ( ChannelUsage { amount_msat : 10 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1655
- . expect_usage ( ChannelUsage { amount_msat : 20 , inflight_htlc_msat : 64 , effective_capacity : EffectiveCapacity :: Unknown } )
1657
+ . expect_usage ( ChannelUsage { amount_msat : 74 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1658
+ // Retry 1, 1st path
1656
1659
. expect_usage ( ChannelUsage { amount_msat : 32 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1660
+ . expect_usage ( ChannelUsage { amount_msat : 52 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1661
+ . expect_usage ( ChannelUsage { amount_msat : 62 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1662
+ // Retry 1, 2nd path
1657
1663
. expect_usage ( ChannelUsage { amount_msat : 32 , inflight_htlc_msat : 64 , effective_capacity : EffectiveCapacity :: Unknown } )
1658
- // Retry 2
1659
- . expect_usage ( ChannelUsage { amount_msat : 10 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1660
- . expect_usage ( ChannelUsage { amount_msat : 20 , inflight_htlc_msat : 96 , effective_capacity : EffectiveCapacity :: Unknown } )
1661
- . expect_usage ( ChannelUsage { amount_msat : 32 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1662
- . expect_usage ( ChannelUsage { amount_msat : 32 , inflight_htlc_msat : 96 , effective_capacity : EffectiveCapacity :: Unknown } )
1664
+ . expect_usage ( ChannelUsage { amount_msat : 42 , inflight_htlc_msat : 64 + 10 , effective_capacity : EffectiveCapacity :: Unknown } )
1665
+ // Retry 2, 1st path
1666
+ . expect_usage ( ChannelUsage { amount_msat : 16 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1667
+ . expect_usage ( ChannelUsage { amount_msat : 36 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1668
+ . expect_usage ( ChannelUsage { amount_msat : 46 , inflight_htlc_msat : 0 , effective_capacity : EffectiveCapacity :: Unknown } )
1669
+ // Retry 2, 2nd path
1670
+ . expect_usage ( ChannelUsage { amount_msat : 16 , inflight_htlc_msat : 64 + 32 , effective_capacity : EffectiveCapacity :: Unknown } )
1671
+ . expect_usage ( ChannelUsage { amount_msat : 26 , inflight_htlc_msat : 74 + 32 + 10 , effective_capacity : EffectiveCapacity :: Unknown } )
1663
1672
) ;
1664
1673
let logger = TestLogger :: new ( ) ;
1665
1674
let invoice_payer =
@@ -1688,7 +1697,7 @@ mod tests {
1688
1697
path : TestRouter :: path_for_value ( final_value_msat / 2 ) ,
1689
1698
short_channel_id : None ,
1690
1699
retry : Some ( RouteParameters {
1691
- final_value_msat : final_value_msat / 2 ,
1700
+ final_value_msat : final_value_msat / 4 ,
1692
1701
..TestRouter :: retry_for_invoice ( & payment_invoice)
1693
1702
} ) ,
1694
1703
} ) ;
@@ -1723,7 +1732,7 @@ mod tests {
1723
1732
1724
1733
// Only the second path, which failed with `MonitorUpdateFailed` should be added to our
1725
1734
// inflight map because retries are disabled.
1726
- assert_eq ! ( inflight_map. len( ) , 1 ) ;
1735
+ assert_eq ! ( inflight_map. len( ) , 2 ) ;
1727
1736
}
1728
1737
1729
1738
#[ test]
@@ -1753,8 +1762,8 @@ mod tests {
1753
1762
invoice_payer. pay_invoice ( & invoice_to_pay) . unwrap ( ) ;
1754
1763
let inflight_map = invoice_payer. create_inflight_map ( ) ;
1755
1764
1756
- // All paths successful, hence we check of the existence of all 4 hops.
1757
- assert_eq ! ( inflight_map. len( ) , 4 ) ;
1765
+ // All paths successful, hence we check of the existence of all 5 hops.
1766
+ assert_eq ! ( inflight_map. len( ) , 5 ) ;
1758
1767
}
1759
1768
1760
1769
struct TestRouter ;
@@ -1789,12 +1798,24 @@ mod tests {
1789
1798
cltv_expiry_delta: 0
1790
1799
} ,
1791
1800
] ,
1792
- vec![ RouteHop {
1793
- pubkey: PublicKey :: from_slice( & hex:: decode( "0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c" ) . unwrap( ) [ ..] ) . unwrap( ) ,
1794
- channel_features: ChannelFeatures :: empty( ) ,
1795
- node_features: NodeFeatures :: empty( ) ,
1796
- short_channel_id: 1 , fee_msat: final_value_msat / 2 , cltv_expiry_delta: 144
1797
- } ] ,
1801
+ vec![
1802
+ RouteHop {
1803
+ pubkey: PublicKey :: from_slice( & hex:: decode( "029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c77255" ) . unwrap( ) [ ..] ) . unwrap( ) ,
1804
+ channel_features: ChannelFeatures :: empty( ) ,
1805
+ node_features: NodeFeatures :: empty( ) ,
1806
+ short_channel_id: 3 ,
1807
+ fee_msat: 10 ,
1808
+ cltv_expiry_delta: 144
1809
+ } ,
1810
+ RouteHop {
1811
+ pubkey: PublicKey :: from_slice( & hex:: decode( "027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007" ) . unwrap( ) [ ..] ) . unwrap( ) ,
1812
+ channel_features: ChannelFeatures :: empty( ) ,
1813
+ node_features: NodeFeatures :: empty( ) ,
1814
+ short_channel_id: 4 ,
1815
+ fee_msat: final_value_msat / 2 ,
1816
+ cltv_expiry_delta: 144
1817
+ }
1818
+ ] ,
1798
1819
] ,
1799
1820
payment_params : None ,
1800
1821
}
@@ -1828,13 +1849,22 @@ mod tests {
1828
1849
// Simulate calling the Scorer just as you would in find_route
1829
1850
let route = Self :: route_for_value ( route_params. final_value_msat ) ;
1830
1851
for path in route. paths {
1831
- for hop in path {
1852
+ let mut aggregate_msat = 0u64 ;
1853
+ for ( idx, hop) in path. iter ( ) . rev ( ) . enumerate ( ) {
1854
+ aggregate_msat += hop. fee_msat ;
1832
1855
let usage = ChannelUsage {
1833
- amount_msat : hop . fee_msat ,
1856
+ amount_msat : aggregate_msat ,
1834
1857
inflight_htlc_msat : 0 ,
1835
1858
effective_capacity : EffectiveCapacity :: Unknown ,
1836
1859
} ;
1837
- scorer. channel_penalty_msat ( hop. short_channel_id , & NodeId :: from_pubkey ( payer) , & NodeId :: from_pubkey ( & hop. pubkey ) , usage) ;
1860
+
1861
+ // Since the path is reversed, the last element in our iteration is the first
1862
+ // hop.
1863
+ if idx == path. len ( ) - 1 {
1864
+ scorer. channel_penalty_msat ( hop. short_channel_id , & NodeId :: from_pubkey ( payer) , & NodeId :: from_pubkey ( & hop. pubkey ) , usage) ;
1865
+ } else {
1866
+ scorer. channel_penalty_msat ( hop. short_channel_id , & NodeId :: from_pubkey ( & path[ idx + 1 ] . pubkey ) , & NodeId :: from_pubkey ( & hop. pubkey ) , usage) ;
1867
+ }
1838
1868
}
1839
1869
}
1840
1870
0 commit comments