Skip to content

Commit f03cf47

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 49b28b0 commit f03cf47

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
@@ -2470,6 +2470,9 @@ pub struct PassAlongPathArgs<'a, 'b, 'c, 'd> {
24702470
pub clear_recipient_events: bool,
24712471
pub expected_preimage: Option<PaymentPreimage>,
24722472
pub is_probe: bool,
2473+
// Allow overpayment to the recipient up to this amount. Useful for payments to blinded paths
2474+
// where rounding errors during `BlindedPayInfo` aggregation may result in overpayment.
2475+
pub overpay_limit: u64,
24732476
}
24742477

24752478
impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
@@ -2480,7 +2483,7 @@ impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
24802483
Self {
24812484
origin_node, expected_path, recv_value, payment_hash, payment_secret: None, event,
24822485
payment_claimable_expected: true, clear_recipient_events: true, expected_preimage: None,
2483-
is_probe: false,
2486+
is_probe: false, overpay_limit: 0,
24842487
}
24852488
}
24862489
pub fn clear_recipient_events(mut self, clear_recipient_events: bool) -> Self {
@@ -2504,13 +2507,17 @@ impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
25042507
self.expected_preimage = Some(payment_preimage);
25052508
self
25062509
}
2510+
pub fn with_overpay_limit(mut self, overpay_limit: u64) -> Self {
2511+
self.overpay_limit = overpay_limit;
2512+
self
2513+
}
25072514
}
25082515

25092516
pub fn do_pass_along_path<'a, 'b, 'c>(args: PassAlongPathArgs) -> Option<Event> {
25102517
let PassAlongPathArgs {
25112518
origin_node, expected_path, recv_value, payment_hash: our_payment_hash,
25122519
payment_secret: our_payment_secret, event: ev, payment_claimable_expected,
2513-
clear_recipient_events, expected_preimage, is_probe
2520+
clear_recipient_events, expected_preimage, is_probe, overpay_limit,
25142521
} = args;
25152522

25162523
let mut payment_event = SendEvent::from_event(ev);
@@ -2554,7 +2561,8 @@ pub fn do_pass_along_path<'a, 'b, 'c>(args: PassAlongPathArgs) -> Option<Event>
25542561
assert_eq!(our_payment_secret, onion_fields.as_ref().unwrap().payment_secret);
25552562
},
25562563
}
2557-
assert_eq!(*amount_msat, recv_value);
2564+
assert!(*amount_msat >= recv_value);
2565+
assert!(*amount_msat <= recv_value + overpay_limit);
25582566
assert!(node.node.list_channels().iter().any(|details| details.channel_id == via_channel_id.unwrap()));
25592567
assert!(node.node.list_channels().iter().any(|details| details.user_channel_id == via_user_channel_id.unwrap()));
25602568
assert!(claim_deadline.unwrap() > node.best_block_info().1);

0 commit comments

Comments
 (0)