Skip to content

Commit da26793

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 029902a commit da26793

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
@@ -2492,6 +2492,9 @@ pub struct PassAlongPathArgs<'a, 'b, 'c, 'd> {
24922492
pub clear_recipient_events: bool,
24932493
pub expected_preimage: Option<PaymentPreimage>,
24942494
pub is_probe: bool,
2495+
// Allow overpayment to the recipient up to this amount. Useful for payments to blinded paths
2496+
// where rounding errors during `BlindedPayInfo` aggregation may result in overpayment.
2497+
pub overpay_limit: u64,
24952498
}
24962499

24972500
impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
@@ -2502,7 +2505,7 @@ impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
25022505
Self {
25032506
origin_node, expected_path, recv_value, payment_hash, payment_secret: None, event,
25042507
payment_claimable_expected: true, clear_recipient_events: true, expected_preimage: None,
2505-
is_probe: false,
2508+
is_probe: false, overpay_limit: 0,
25062509
}
25072510
}
25082511
pub fn clear_recipient_events(mut self, clear_recipient_events: bool) -> Self {
@@ -2526,13 +2529,17 @@ impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
25262529
self.expected_preimage = Some(payment_preimage);
25272530
self
25282531
}
2532+
pub fn with_overpay_limit(mut self, overpay_limit: u64) -> Self {
2533+
self.overpay_limit = overpay_limit;
2534+
self
2535+
}
25292536
}
25302537

25312538
pub fn do_pass_along_path<'a, 'b, 'c>(args: PassAlongPathArgs) -> Option<Event> {
25322539
let PassAlongPathArgs {
25332540
origin_node, expected_path, recv_value, payment_hash: our_payment_hash,
25342541
payment_secret: our_payment_secret, event: ev, payment_claimable_expected,
2535-
clear_recipient_events, expected_preimage, is_probe
2542+
clear_recipient_events, expected_preimage, is_probe, overpay_limit,
25362543
} = args;
25372544

25382545
let mut payment_event = SendEvent::from_event(ev);
@@ -2576,7 +2583,8 @@ pub fn do_pass_along_path<'a, 'b, 'c>(args: PassAlongPathArgs) -> Option<Event>
25762583
assert_eq!(our_payment_secret, onion_fields.as_ref().unwrap().payment_secret);
25772584
},
25782585
}
2579-
assert_eq!(*amount_msat, recv_value);
2586+
assert!(*amount_msat >= recv_value);
2587+
assert!(*amount_msat <= recv_value + overpay_limit);
25802588
assert!(node.node.list_channels().iter().any(|details| details.channel_id == via_channel_id.unwrap()));
25812589
assert!(node.node.list_channels().iter().any(|details| details.user_channel_id == via_user_channel_id.unwrap()));
25822590
assert!(claim_deadline.unwrap() > node.best_block_info().1);

0 commit comments

Comments
 (0)