@@ -1568,18 +1568,8 @@ fn test_fee_spike_violation_fails_htlc() {
1568
1568
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1569
1569
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1570
1570
let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 95000000 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1571
- let logger = test_utils:: TestLogger :: new ( ) ;
1572
-
1573
- macro_rules! get_route_and_payment_hash {
1574
- ( $recv_value: expr) => { {
1575
- let ( payment_preimage, payment_hash) = get_payment_preimage_hash!( nodes[ 1 ] ) ;
1576
- let net_graph_msg_handler = & nodes[ 0 ] . net_graph_msg_handler. network_graph. read( ) . unwrap( ) ;
1577
- let route = get_route( & nodes[ 0 ] . node. get_our_node_id( ) , net_graph_msg_handler, & nodes. last( ) . unwrap( ) . node. get_our_node_id( ) , None , None , & Vec :: new( ) , $recv_value, TEST_FINAL_CLTV , & logger) . unwrap( ) ;
1578
- ( route, payment_hash, payment_preimage)
1579
- } }
1580
- }
1581
1571
1582
- let ( route, payment_hash, _) = get_route_and_payment_hash ! ( 3460001 ) ;
1572
+ let ( route, payment_hash, _) = get_route_and_payment_hash ! ( nodes [ 0 ] , nodes [ 1 ] , 3460001 ) ;
1583
1573
// Need to manually create the update_add_htlc message to go around the channel reserve check in send_htlc()
1584
1574
let secp_ctx = Secp256k1 :: new ( ) ;
1585
1575
let session_priv = SecretKey :: from_slice ( & [ 42 ; 32 ] ) . expect ( "RNG is bad!" ) ;
@@ -1708,18 +1698,8 @@ fn test_chan_reserve_violation_outbound_htlc_inbound_chan() {
1708
1698
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1709
1699
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1710
1700
let _ = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 95000000 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1711
- let logger = test_utils:: TestLogger :: new ( ) ;
1712
-
1713
- macro_rules! get_route_and_payment_hash {
1714
- ( $recv_value: expr) => { {
1715
- let ( payment_preimage, payment_hash) = get_payment_preimage_hash!( nodes[ 1 ] ) ;
1716
- let net_graph_msg_handler = & nodes[ 1 ] . net_graph_msg_handler;
1717
- let route = get_route( & nodes[ 1 ] . node. get_our_node_id( ) , & net_graph_msg_handler. network_graph. read( ) . unwrap( ) , & nodes. first( ) . unwrap( ) . node. get_our_node_id( ) , None , None , & Vec :: new( ) , $recv_value, TEST_FINAL_CLTV , & logger) . unwrap( ) ;
1718
- ( route, payment_hash, payment_preimage)
1719
- } }
1720
- }
1721
1701
1722
- let ( route, our_payment_hash, _) = get_route_and_payment_hash ! ( 4843000 ) ;
1702
+ let ( route, our_payment_hash, _) = get_route_and_payment_hash ! ( nodes [ 1 ] , nodes [ 0 ] , 4843000 ) ;
1723
1703
unwrap_send_err ! ( nodes[ 1 ] . node. send_payment( & route, our_payment_hash, & None ) , true , APIError :: ChannelUnavailable { ref err } ,
1724
1704
assert_eq!( err, "Cannot send value that would put counterparty balance under holder-announced channel reserve value" ) ) ;
1725
1705
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
@@ -1740,18 +1720,8 @@ fn test_chan_reserve_violation_inbound_htlc_outbound_channel() {
1740
1720
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1741
1721
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1742
1722
let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 95000000 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1743
- let logger = test_utils:: TestLogger :: new ( ) ;
1744
1723
1745
- macro_rules! get_route_and_payment_hash {
1746
- ( $recv_value: expr) => { {
1747
- let ( payment_preimage, payment_hash) = get_payment_preimage_hash!( nodes[ 1 ] ) ;
1748
- let net_graph_msg_handler = & nodes[ 0 ] . net_graph_msg_handler;
1749
- let route = get_route( & nodes[ 1 ] . node. get_our_node_id( ) , & net_graph_msg_handler. network_graph. read( ) . unwrap( ) , & nodes. first( ) . unwrap( ) . node. get_our_node_id( ) , None , None , & Vec :: new( ) , $recv_value, TEST_FINAL_CLTV , & logger) . unwrap( ) ;
1750
- ( route, payment_hash, payment_preimage)
1751
- } }
1752
- }
1753
-
1754
- let ( route, payment_hash, _) = get_route_and_payment_hash ! ( 1000 ) ;
1724
+ let ( route, payment_hash, _) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 0 ] , 1000 ) ;
1755
1725
// Need to manually create the update_add_htlc message to go around the channel reserve check in send_htlc()
1756
1726
let secp_ctx = Secp256k1 :: new ( ) ;
1757
1727
let session_priv = SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
@@ -1836,16 +1806,6 @@ fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
1836
1806
let mut nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
1837
1807
let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 95000000 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1838
1808
let _ = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 100000 , 95000000 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1839
- let logger = test_utils:: TestLogger :: new ( ) ;
1840
-
1841
- macro_rules! get_route_and_payment_hash {
1842
- ( $recv_value: expr) => { {
1843
- let ( payment_preimage, payment_hash) = get_payment_preimage_hash!( nodes[ 0 ] ) ;
1844
- let net_graph_msg_handler = & nodes[ 0 ] . net_graph_msg_handler;
1845
- let route = get_route( & nodes[ 0 ] . node. get_our_node_id( ) , & net_graph_msg_handler. network_graph. read( ) . unwrap( ) , & nodes. last( ) . unwrap( ) . node. get_our_node_id( ) , None , None , & Vec :: new( ) , $recv_value, TEST_FINAL_CLTV , & logger) . unwrap( ) ;
1846
- ( route, payment_hash, payment_preimage)
1847
- } }
1848
- }
1849
1809
1850
1810
let feemsat = 239 ;
1851
1811
let total_routing_fee_msat = ( nodes. len ( ) - 2 ) as u64 * feemsat;
@@ -1858,7 +1818,7 @@ fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
1858
1818
let amt_msat_1 = recv_value_1 + total_routing_fee_msat;
1859
1819
1860
1820
// Add a pending HTLC.
1861
- let ( route_1, our_payment_hash_1, _) = get_route_and_payment_hash ! ( amt_msat_1) ;
1821
+ let ( route_1, our_payment_hash_1, _) = get_route_and_payment_hash ! ( nodes [ 0 ] , nodes [ 2 ] , amt_msat_1) ;
1862
1822
let payment_event_1 = {
1863
1823
nodes[ 0 ] . node . send_payment ( & route_1, our_payment_hash_1, & None ) . unwrap ( ) ;
1864
1824
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
@@ -1873,7 +1833,7 @@ fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
1873
1833
let commit_tx_fee_2_htlcs = commit_tx_fee_msat ( feerate, 2 ) ;
1874
1834
let recv_value_2 = chan_stat. value_to_self_msat - amt_msat_1 - chan_stat. channel_reserve_msat - total_routing_fee_msat - commit_tx_fee_2_htlcs + 1 ;
1875
1835
let amt_msat_2 = recv_value_2 + total_routing_fee_msat;
1876
- let ( route_2, _, _) = get_route_and_payment_hash ! ( amt_msat_2) ;
1836
+ let ( route_2, _, _) = get_route_and_payment_hash ! ( nodes [ 0 ] , nodes [ 2 ] , amt_msat_2) ;
1877
1837
1878
1838
// Need to manually create the update_add_htlc message to go around the channel reserve check in send_htlc()
1879
1839
let secp_ctx = Secp256k1 :: new ( ) ;
@@ -1931,23 +1891,13 @@ fn test_channel_reserve_holding_cell_htlcs() {
1931
1891
let mut nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
1932
1892
let chan_1 = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 190000 , 1001 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1933
1893
let chan_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 190000 , 1001 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1934
- let logger = test_utils:: TestLogger :: new ( ) ;
1935
1894
1936
1895
let mut stat01 = get_channel_value_stat ! ( nodes[ 0 ] , chan_1. 2 ) ;
1937
1896
let mut stat11 = get_channel_value_stat ! ( nodes[ 1 ] , chan_1. 2 ) ;
1938
1897
1939
1898
let mut stat12 = get_channel_value_stat ! ( nodes[ 1 ] , chan_2. 2 ) ;
1940
1899
let mut stat22 = get_channel_value_stat ! ( nodes[ 2 ] , chan_2. 2 ) ;
1941
1900
1942
- macro_rules! get_route_and_payment_hash {
1943
- ( $recv_value: expr) => { {
1944
- let ( payment_preimage, payment_hash) = get_payment_preimage_hash!( nodes[ 0 ] ) ;
1945
- let net_graph_msg_handler = & nodes[ 0 ] . net_graph_msg_handler;
1946
- let route = get_route( & nodes[ 0 ] . node. get_our_node_id( ) , & net_graph_msg_handler. network_graph. read( ) . unwrap( ) , & nodes. last( ) . unwrap( ) . node. get_our_node_id( ) , None , None , & Vec :: new( ) , $recv_value, TEST_FINAL_CLTV , & logger) . unwrap( ) ;
1947
- ( route, payment_hash, payment_preimage)
1948
- } }
1949
- }
1950
-
1951
1901
macro_rules! expect_forward {
1952
1902
( $node: expr) => { {
1953
1903
let mut events = $node. node. get_and_clear_pending_msg_events( ) ;
@@ -1966,7 +1916,7 @@ fn test_channel_reserve_holding_cell_htlcs() {
1966
1916
1967
1917
// attempt to send amt_msat > their_max_htlc_value_in_flight_msat
1968
1918
{
1969
- let ( mut route, our_payment_hash, _) = get_route_and_payment_hash ! ( recv_value_0) ;
1919
+ let ( mut route, our_payment_hash, _) = get_route_and_payment_hash ! ( nodes [ 0 ] , nodes [ 2 ] , recv_value_0) ;
1970
1920
route. paths [ 0 ] . last_mut ( ) . unwrap ( ) . fee_msat += 1 ;
1971
1921
assert ! ( route. paths[ 0 ] . iter( ) . rev( ) . skip( 1 ) . all( |h| h. fee_msat == feemsat) ) ;
1972
1922
unwrap_send_err ! ( nodes[ 0 ] . node. send_payment( & route, our_payment_hash, & None ) , true , APIError :: ChannelUnavailable { ref err } ,
@@ -2018,7 +1968,7 @@ fn test_channel_reserve_holding_cell_htlcs() {
2018
1968
let recv_value_1 = ( stat01. value_to_self_msat - stat01. channel_reserve_msat - total_fee_msat - commit_tx_fee_2_htlcs) /2 ;
2019
1969
let amt_msat_1 = recv_value_1 + total_fee_msat;
2020
1970
2021
- let ( route_1, our_payment_hash_1, our_payment_preimage_1) = get_route_and_payment_hash ! ( recv_value_1) ;
1971
+ let ( route_1, our_payment_hash_1, our_payment_preimage_1) = get_route_and_payment_hash ! ( nodes [ 0 ] , nodes [ 2 ] , recv_value_1) ;
2022
1972
let payment_event_1 = {
2023
1973
nodes[ 0 ] . node . send_payment ( & route_1, our_payment_hash_1, & None ) . unwrap ( ) ;
2024
1974
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
@@ -2032,7 +1982,7 @@ fn test_channel_reserve_holding_cell_htlcs() {
2032
1982
// channel reserve test with htlc pending output > 0
2033
1983
let recv_value_2 = stat01. value_to_self_msat - amt_msat_1 - stat01. channel_reserve_msat - total_fee_msat - commit_tx_fee_2_htlcs;
2034
1984
{
2035
- let ( route, our_payment_hash, _) = get_route_and_payment_hash ! ( recv_value_2 + 1 ) ;
1985
+ let ( route, our_payment_hash, _) = get_route_and_payment_hash ! ( nodes [ 0 ] , nodes [ 2 ] , recv_value_2 + 1 ) ;
2036
1986
unwrap_send_err ! ( nodes[ 0 ] . node. send_payment( & route, our_payment_hash, & None ) , true , APIError :: ChannelUnavailable { ref err } ,
2037
1987
assert!( regex:: Regex :: new( r"Cannot send value that would put our balance under counterparty-announced channel reserve value \(\d+\)" ) . unwrap( ) . is_match( err) ) ) ;
2038
1988
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
@@ -2049,7 +1999,7 @@ fn test_channel_reserve_holding_cell_htlcs() {
2049
1999
}
2050
2000
2051
2001
// now see if they go through on both sides
2052
- let ( route_21, our_payment_hash_21, our_payment_preimage_21) = get_route_and_payment_hash ! ( recv_value_21) ;
2002
+ let ( route_21, our_payment_hash_21, our_payment_preimage_21) = get_route_and_payment_hash ! ( nodes [ 0 ] , nodes [ 2 ] , recv_value_21) ;
2053
2003
// but this will stuck in the holding cell
2054
2004
nodes[ 0 ] . node . send_payment ( & route_21, our_payment_hash_21, & None ) . unwrap ( ) ;
2055
2005
check_added_monitors ! ( nodes[ 0 ] , 0 ) ;
@@ -2058,14 +2008,14 @@ fn test_channel_reserve_holding_cell_htlcs() {
2058
2008
2059
2009
// test with outbound holding cell amount > 0
2060
2010
{
2061
- let ( route, our_payment_hash, _) = get_route_and_payment_hash ! ( recv_value_22+1 ) ;
2011
+ let ( route, our_payment_hash, _) = get_route_and_payment_hash ! ( nodes [ 0 ] , nodes [ 2 ] , recv_value_22+1 ) ;
2062
2012
unwrap_send_err ! ( nodes[ 0 ] . node. send_payment( & route, our_payment_hash, & None ) , true , APIError :: ChannelUnavailable { ref err } ,
2063
2013
assert!( regex:: Regex :: new( r"Cannot send value that would put our balance under counterparty-announced channel reserve value \(\d+\)" ) . unwrap( ) . is_match( err) ) ) ;
2064
2014
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
2065
2015
nodes[ 0 ] . logger . assert_log_contains ( "lightning::ln::channelmanager" . to_string ( ) , "Cannot send value that would put our balance under counterparty-announced channel reserve value" . to_string ( ) , 2 ) ;
2066
2016
}
2067
2017
2068
- let ( route_22, our_payment_hash_22, our_payment_preimage_22) = get_route_and_payment_hash ! ( recv_value_22) ;
2018
+ let ( route_22, our_payment_hash_22, our_payment_preimage_22) = get_route_and_payment_hash ! ( nodes [ 0 ] , nodes [ 2 ] , recv_value_22) ;
2069
2019
// this will also stuck in the holding cell
2070
2020
nodes[ 0 ] . node . send_payment ( & route_22, our_payment_hash_22, & None ) . unwrap ( ) ;
2071
2021
check_added_monitors ! ( nodes[ 0 ] , 0 ) ;
0 commit comments