@@ -18,7 +18,7 @@ use chain::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PER
18
18
use chain:: transaction:: OutPoint ;
19
19
use chain:: keysinterface:: BaseSign ;
20
20
use ln:: { PaymentPreimage , PaymentSecret , PaymentHash } ;
21
- use ln:: channel:: { COMMITMENT_TX_BASE_WEIGHT , COMMITMENT_TX_WEIGHT_PER_HTLC } ;
21
+ use ln:: channel:: { COMMITMENT_TX_BASE_WEIGHT , COMMITMENT_TX_WEIGHT_PER_HTLC , MIN_AFFORDABLE_HTLC_COUNT } ;
22
22
use ln:: channelmanager:: { ChannelManager , ChannelManagerReadArgs , PaymentId , RAACommitmentOrder , PaymentSendFailure , BREAKDOWN_TIMEOUT , MIN_CLTV_EXPIRY_DELTA } ;
23
23
use ln:: channel:: { Channel , ChannelError } ;
24
24
use ln:: { chan_utils, onion_utils} ;
@@ -1398,16 +1398,15 @@ fn test_chan_reserve_violation_outbound_htlc_inbound_chan() {
1398
1398
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1399
1399
1400
1400
let mut push_amt = 100_000_000 ;
1401
- push_amt -= commit_tx_fee_msat ( feerate_per_kw, 4 ) ;
1401
+ push_amt -= commit_tx_fee_msat ( feerate_per_kw, MIN_AFFORDABLE_HTLC_COUNT as u64 ) ;
1402
1402
push_amt -= Channel :: < EnforcingSigner > :: get_holder_selected_channel_reserve_satoshis ( 100_000 ) * 1000 ;
1403
1403
1404
1404
let _ = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100_000 , push_amt, InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1405
1405
1406
1406
// Sending exactly enough to hit the reserve amount should be accepted
1407
- let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1408
- let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1409
- let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1410
- let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1407
+ for _ in 0 ..MIN_AFFORDABLE_HTLC_COUNT {
1408
+ let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1409
+ }
1411
1410
1412
1411
// However one more HTLC should be significantly over the reserve amount and fail.
1413
1412
let ( route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 0 ] , 1_000_000 ) ;
@@ -1429,15 +1428,14 @@ fn test_chan_reserve_violation_inbound_htlc_outbound_channel() {
1429
1428
// channel reserve violation (so their balance is channel reserve (1000 sats) + commitment
1430
1429
// transaction fee with 0 HTLCs (183 sats)).
1431
1430
let mut push_amt = 100_000_000 ;
1432
- push_amt -= commit_tx_fee_msat ( feerate_per_kw, 4 ) ;
1431
+ push_amt -= commit_tx_fee_msat ( feerate_per_kw, MIN_AFFORDABLE_HTLC_COUNT as u64 ) ;
1433
1432
push_amt -= Channel :: < EnforcingSigner > :: get_holder_selected_channel_reserve_satoshis ( 100_000 ) * 1000 ;
1434
1433
let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100_000 , push_amt, InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1435
1434
1436
1435
// Send four HTLCs to cover the initial push_msat buffer we're required to include
1437
- let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1438
- let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1439
- let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1440
- let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1436
+ for _ in 0 ..MIN_AFFORDABLE_HTLC_COUNT {
1437
+ let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1438
+ }
1441
1439
1442
1440
let ( route, payment_hash, _, payment_secret) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 0 ] , 700_000 ) ;
1443
1441
// Need to manually create the update_add_htlc message to go around the channel reserve check in send_htlc()
@@ -1449,7 +1447,7 @@ fn test_chan_reserve_violation_inbound_htlc_outbound_channel() {
1449
1447
let onion_packet = onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash) ;
1450
1448
let msg = msgs:: UpdateAddHTLC {
1451
1449
channel_id : chan. 2 ,
1452
- htlc_id : 4 ,
1450
+ htlc_id : MIN_AFFORDABLE_HTLC_COUNT as u64 ,
1453
1451
amount_msat : htlc_msat,
1454
1452
payment_hash : payment_hash,
1455
1453
cltv_expiry : htlc_cltv,
@@ -1481,7 +1479,7 @@ fn test_chan_reserve_dust_inbound_htlcs_outbound_chan() {
1481
1479
// channel reserve violation (so their balance is channel reserve (1000 sats) + commitment
1482
1480
// transaction fee with 0 HTLCs (183 sats)).
1483
1481
let mut push_amt = 100_000_000 ;
1484
- push_amt -= commit_tx_fee_msat ( feerate_per_kw, 4 ) ;
1482
+ push_amt -= commit_tx_fee_msat ( feerate_per_kw, MIN_AFFORDABLE_HTLC_COUNT as u64 ) ;
1485
1483
push_amt -= Channel :: < EnforcingSigner > :: get_holder_selected_channel_reserve_satoshis ( 100_000 ) * 1000 ;
1486
1484
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , push_amt, InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1487
1485
@@ -1493,10 +1491,9 @@ fn test_chan_reserve_dust_inbound_htlcs_outbound_chan() {
1493
1491
let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , dust_amt) ;
1494
1492
1495
1493
// Send four HTLCs to cover the initial push_msat buffer we're required to include
1496
- let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1497
- let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1498
- let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1499
- let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1494
+ for _ in 0 ..MIN_AFFORDABLE_HTLC_COUNT {
1495
+ let ( _, _, _) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1496
+ }
1500
1497
1501
1498
// One more than the dust amt should fail, however.
1502
1499
let ( route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 0 ] , dust_amt + 1 ) ;
0 commit comments