Skip to content

Commit e6d74b3

Browse files
Support overpayment in test util pass_along_path.
Useful for payments to blinded paths where rounding errors during BlindedPayInfo aggregation may result in overpayment.
1 parent e299867 commit e6d74b3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,6 +2407,9 @@ pub struct PassAlongPathArgs<'a, 'b, 'c, 'd> {
24072407
pub clear_recipient_events: bool,
24082408
pub expected_preimage: Option<PaymentPreimage>,
24092409
pub is_probe: bool,
2410+
// Allow overpayment to the recipient up to this amount. Useful for payments to blinded paths
2411+
// where rounding errors during `BlindedPayInfo` aggregation may result in overpayment.
2412+
pub overpay_limit: u64,
24102413
}
24112414

24122415
impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
@@ -2417,7 +2420,7 @@ impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
24172420
Self {
24182421
origin_node, expected_path, recv_value, payment_hash, payment_secret: None, event,
24192422
payment_claimable_expected: true, clear_recipient_events: true, expected_preimage: None,
2420-
is_probe: false,
2423+
is_probe: false, overpay_limit: 0,
24212424
}
24222425
}
24232426
pub fn clear_recipient_events(mut self, clear_recipient_events: bool) -> Self {
@@ -2441,13 +2444,17 @@ impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
24412444
self.expected_preimage = Some(payment_preimage);
24422445
self
24432446
}
2447+
pub fn with_overpay_limit(mut self, overpay_limit: u64) -> Self {
2448+
self.overpay_limit = overpay_limit;
2449+
self
2450+
}
24442451
}
24452452

24462453
pub fn do_pass_along_path<'a, 'b, 'c>(args: PassAlongPathArgs) -> Option<Event> {
24472454
let PassAlongPathArgs {
24482455
origin_node, expected_path, recv_value, payment_hash: our_payment_hash,
24492456
payment_secret: our_payment_secret, event: ev, payment_claimable_expected,
2450-
clear_recipient_events, expected_preimage, is_probe
2457+
clear_recipient_events, expected_preimage, is_probe, overpay_limit,
24512458
} = args;
24522459

24532460
let mut payment_event = SendEvent::from_event(ev);
@@ -2491,7 +2498,8 @@ pub fn do_pass_along_path<'a, 'b, 'c>(args: PassAlongPathArgs) -> Option<Event>
24912498
assert_eq!(our_payment_secret, onion_fields.as_ref().unwrap().payment_secret);
24922499
},
24932500
}
2494-
assert_eq!(*amount_msat, recv_value);
2501+
assert!(*amount_msat >= recv_value);
2502+
assert!(*amount_msat <= recv_value + overpay_limit);
24952503
assert!(node.node.list_channels().iter().any(|details| details.channel_id == via_channel_id.unwrap()));
24962504
assert!(node.node.list_channels().iter().any(|details| details.user_channel_id == via_user_channel_id.unwrap()));
24972505
assert!(claim_deadline.unwrap() > node.best_block_info().1);

0 commit comments

Comments
 (0)