@@ -16,12 +16,13 @@ use crate::chain::channelmonitor::{ANTI_REORG_DELAY, LATENCY_GRACE_PERIOD_BLOCKS
16
16
use crate :: chain:: transaction:: OutPoint ;
17
17
use crate :: chain:: keysinterface:: { EntropySource , KeysInterface } ;
18
18
use crate :: ln:: channel:: EXPIRE_PREV_CONFIG_TICKS ;
19
- use crate :: ln:: channelmanager:: { self , BREAKDOWN_TIMEOUT , ChannelManager , MPP_TIMEOUT_TICKS , MIN_CLTV_EXPIRY_DELTA , PaymentId , PaymentSendFailure , IDEMPOTENCY_TIMEOUT_TICKS , Retry } ;
19
+ use crate :: ln:: channelmanager:: { self , BREAKDOWN_TIMEOUT , ChannelManager , MPP_TIMEOUT_TICKS , MIN_CLTV_EXPIRY_DELTA , PaymentId , PaymentSendFailure , IDEMPOTENCY_TIMEOUT_TICKS } ;
20
20
use crate :: ln:: features:: InvoiceFeatures ;
21
21
use crate :: ln:: msgs;
22
22
use crate :: ln:: msgs:: ChannelMessageHandler ;
23
+ use crate :: ln:: outbound_payment:: Retry ;
23
24
use crate :: routing:: gossip:: RoutingFees ;
24
- use crate :: routing:: router:: { get_route, PaymentParameters , RouteHint , RouteHintHop , RouteParameters } ;
25
+ use crate :: routing:: router:: { get_route, PaymentParameters , Route , RouteHint , RouteHintHop , RouteHop , RouteParameters } ;
25
26
use crate :: util:: events:: { ClosureReason , Event , HTLCDestination , MessageSendEvent , MessageSendEventsProvider } ;
26
27
use crate :: util:: test_utils;
27
28
use crate :: util:: errors:: APIError ;
@@ -1758,22 +1759,22 @@ fn do_automatic_retries(test: AutoRetry) {
1758
1759
#[ test]
1759
1760
fn auto_retry_partial_failure ( ) {
1760
1761
// Test that we'll retry appropriately on send partial failure and retry partial failure.
1761
- let chanmon_cfgs = create_chanmon_cfgs ( 4 ) ;
1762
- let node_cfgs = create_node_cfgs ( 4 , & chanmon_cfgs) ;
1763
- let node_chanmgrs = create_node_chanmgrs ( 4 , & node_cfgs, & [ None , None , None , None ] ) ;
1764
- let mut nodes = create_network ( 4 , & node_cfgs, & node_chanmgrs) ;
1762
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1763
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1764
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1765
+ let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1765
1766
1766
1767
let chan_1_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) . 0 . contents . short_channel_id ;
1767
- let ( chan_2_ann , _ , chan_2_id, _ ) = create_announced_chan_between_nodes ( & nodes, 0 , 2 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
1768
- let chan_3_id = create_announced_chan_between_nodes ( & nodes, 1 , 3 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) . 0 . contents . short_channel_id ;
1769
- let chan_4_id = create_announced_chan_between_nodes ( & nodes, 2 , 3 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) . 0 . contents . short_channel_id ;
1768
+ let chan_2_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) . 0 . contents . short_channel_id ;
1769
+ let chan_3_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) . 0 . contents . short_channel_id ;
1770
+ let chan_4_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) . 0 . contents . short_channel_id ;
1770
1771
1771
1772
1772
1773
// This amount should force the router to split across nodes[0]'s two channels.
1773
- let amt_msat = 18_000_000 ;
1774
+ let amt_msat = 20_000 ;
1774
1775
1775
1776
// Marshall data to send the payment
1776
- let ( _, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash ! ( & nodes[ 0 ] , nodes[ 3 ] , amt_msat) ;
1777
+ let ( _, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash ! ( & nodes[ 0 ] , nodes[ 1 ] , amt_msat) ;
1777
1778
#[ cfg( feature = "std" ) ]
1778
1779
let payment_expiry_secs = SystemTime :: UNIX_EPOCH . elapsed ( ) . unwrap ( ) . as_secs ( ) + 60 * 60 ;
1779
1780
#[ cfg( not( feature = "std" ) ) ]
@@ -1782,7 +1783,7 @@ fn auto_retry_partial_failure() {
1782
1783
invoice_features. set_variable_length_onion_required ( ) ;
1783
1784
invoice_features. set_payment_secret_required ( ) ;
1784
1785
invoice_features. set_basic_mpp_optional ( ) ;
1785
- let payment_params = PaymentParameters :: from_node_id ( nodes[ 3 ] . node . get_our_node_id ( ) )
1786
+ let payment_params = PaymentParameters :: from_node_id ( nodes[ 1 ] . node . get_our_node_id ( ) )
1786
1787
. with_expiry_time ( payment_expiry_secs as u64 )
1787
1788
. with_features ( invoice_features) ;
1788
1789
let route_params = RouteParameters {
@@ -1791,34 +1792,85 @@ fn auto_retry_partial_failure() {
1791
1792
final_cltv_expiry_delta : TEST_FINAL_CLTV ,
1792
1793
} ;
1793
1794
1794
- // Ensure the first monitor update (for the initial send path 0 -> 1 -> 3 ) succeeds, but the
1795
- // second (for the initial send path 0 -> 2 -> 3 ) fails.
1795
+ // Ensure the first monitor update (for the initial send path1 over chan_1 ) succeeds, but the
1796
+ // second (for the initial send path2 over chan_2 ) fails.
1796
1797
chanmon_cfgs[ 0 ] . persister . set_next_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
1797
1798
chanmon_cfgs[ 0 ] . persister . set_next_update_ret ( ChannelMonitorUpdateStatus :: PermanentFailure ) ;
1798
- // Ensure third monitor update (for the retry0 's path 0 -> 1 -> 3 ) succeeds, but the fourth (for
1799
- // the retry0 's path 0 -> 2 -> 3 ) fails, and monitor updates succeed after that.
1799
+ // Ensure third monitor update (for the retry1 's path1 over chan_1 ) succeeds, but the fourth (for
1800
+ // the retry1 's path2 over chan_3 ) fails, and monitor updates succeed after that.
1800
1801
chanmon_cfgs[ 0 ] . persister . set_next_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
1801
1802
chanmon_cfgs[ 0 ] . persister . set_next_update_ret ( ChannelMonitorUpdateStatus :: PermanentFailure ) ;
1802
- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
1803
+ chanmon_cfgs[ 0 ] . persister . set_next_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
1803
1804
1804
- // Configure the initial send, retry0 and retry1's paths.
1805
+ // Configure the initial send, retry1 and retry2's paths.
1806
+ let send_route = Route {
1807
+ paths : vec ! [
1808
+ vec![ RouteHop {
1809
+ pubkey: nodes[ 1 ] . node. get_our_node_id( ) ,
1810
+ node_features: channelmanager:: provided_node_features( ) ,
1811
+ short_channel_id: chan_1_id,
1812
+ channel_features: channelmanager:: provided_channel_features( ) ,
1813
+ fee_msat: amt_msat / 2 ,
1814
+ cltv_expiry_delta: 100 ,
1815
+ } ] ,
1816
+ vec![ RouteHop {
1817
+ pubkey: nodes[ 1 ] . node. get_our_node_id( ) ,
1818
+ node_features: channelmanager:: provided_node_features( ) ,
1819
+ short_channel_id: chan_2_id,
1820
+ channel_features: channelmanager:: provided_channel_features( ) ,
1821
+ fee_msat: amt_msat / 2 ,
1822
+ cltv_expiry_delta: 100 ,
1823
+ } ] ,
1824
+ ] ,
1825
+ payment_params : Some ( PaymentParameters :: from_node_id ( nodes[ 1 ] . node . get_our_node_id ( ) ) ) ,
1826
+ } ;
1827
+ let retry_1_route = Route {
1828
+ paths : vec ! [
1829
+ vec![ RouteHop {
1830
+ pubkey: nodes[ 1 ] . node. get_our_node_id( ) ,
1831
+ node_features: channelmanager:: provided_node_features( ) ,
1832
+ short_channel_id: chan_1_id,
1833
+ channel_features: channelmanager:: provided_channel_features( ) ,
1834
+ fee_msat: amt_msat / 4 ,
1835
+ cltv_expiry_delta: 100 ,
1836
+ } ] ,
1837
+ vec![ RouteHop {
1838
+ pubkey: nodes[ 1 ] . node. get_our_node_id( ) ,
1839
+ node_features: channelmanager:: provided_node_features( ) ,
1840
+ short_channel_id: chan_3_id,
1841
+ channel_features: channelmanager:: provided_channel_features( ) ,
1842
+ fee_msat: amt_msat / 4 ,
1843
+ cltv_expiry_delta: 100 ,
1844
+ } ] ,
1845
+ ] ,
1846
+ payment_params : Some ( PaymentParameters :: from_node_id ( nodes[ 1 ] . node . get_our_node_id ( ) ) ) ,
1847
+ } ;
1848
+ let retry_2_route = Route {
1849
+ paths : vec ! [
1850
+ vec![ RouteHop {
1851
+ pubkey: nodes[ 1 ] . node. get_our_node_id( ) ,
1852
+ node_features: channelmanager:: provided_node_features( ) ,
1853
+ short_channel_id: chan_1_id,
1854
+ channel_features: channelmanager:: provided_channel_features( ) ,
1855
+ fee_msat: amt_msat / 4 ,
1856
+ cltv_expiry_delta: 100 ,
1857
+ } ] ,
1858
+ ] ,
1859
+ payment_params : Some ( PaymentParameters :: from_node_id ( nodes[ 1 ] . node . get_our_node_id ( ) ) ) ,
1860
+ } ;
1861
+ nodes[ 0 ] . router . expect_find_route ( Ok ( send_route) ) ;
1862
+ nodes[ 0 ] . router . expect_find_route ( Ok ( retry_1_route) ) ;
1863
+ nodes[ 0 ] . router . expect_find_route ( Ok ( retry_2_route) ) ;
1805
1864
1806
1865
// Send a payment that will partially fail on send, then partially fail on retry, then succeed.
1807
- match nodes[ 0 ] . node . send_payment_with_retry ( payment_hash, & Some ( payment_secret) , PaymentId ( payment_hash. 0 ) , route_params, Retry :: Attempts ( 1 ) ) {
1808
- Err ( PaymentSendFailure :: PartialFailure { results, ..} ) => {
1809
- assert_eq ! ( results[ 0 ] , Ok ( ( ) ) ) ;
1810
- assert_eq ! ( results[ 1 ] , Err ( APIError :: ChannelUnavailable {
1811
- err: "ChannelMonitor storage failure" . to_owned( ) ,
1812
- } ) ) ;
1813
- } ,
1814
- _ => panic ! ( "Unexpected result" ) ,
1815
- }
1866
+ nodes[ 0 ] . node . send_payment_with_retry ( payment_hash, & Some ( payment_secret) , PaymentId ( payment_hash. 0 ) , route_params, Retry :: Attempts ( 3 ) ) . unwrap ( ) ;
1816
1867
1817
1868
// Pass the first part of the payment along the path.
1818
- check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1869
+ check_added_monitors ! ( nodes[ 0 ] , 5 ) ; // three outbound channel updates succeeded, two PermFailed
1819
1870
let mut msg_events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
1871
+ println ! ( "VMW: msg events: {:?}" , msg_events) ;
1820
1872
assert_eq ! ( msg_events. len( ) , 1 ) ;
1821
- pass_along_path ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes [ 3 ] ] , amt_msat, payment_hash, Some ( payment_secret) , msg_events. pop ( ) . unwrap ( ) , true , None ) ;
1873
+ pass_along_path ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , amt_msat, payment_hash, Some ( payment_secret) , msg_events. pop ( ) . unwrap ( ) , true , None ) ;
1822
1874
1823
1875
//
1824
1876
}
0 commit comments