Skip to content

Commit

Permalink
Support overpayment in test util pass_along_path.
Browse files Browse the repository at this point in the history
Useful for payments to blinded paths where rounding errors during
BlindedPayInfo aggregation may result in overpayment.
  • Loading branch information
valentinewallace committed Jan 9, 2024
1 parent e299867 commit e6d74b3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2407,6 +2407,9 @@ pub struct PassAlongPathArgs<'a, 'b, 'c, 'd> {
pub clear_recipient_events: bool,
pub expected_preimage: Option<PaymentPreimage>,
pub is_probe: bool,
// Allow overpayment to the recipient up to this amount. Useful for payments to blinded paths
// where rounding errors during `BlindedPayInfo` aggregation may result in overpayment.
pub overpay_limit: u64,
}

impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
Expand All @@ -2417,7 +2420,7 @@ impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
Self {
origin_node, expected_path, recv_value, payment_hash, payment_secret: None, event,
payment_claimable_expected: true, clear_recipient_events: true, expected_preimage: None,
is_probe: false,
is_probe: false, overpay_limit: 0,
}
}
pub fn clear_recipient_events(mut self, clear_recipient_events: bool) -> Self {
Expand All @@ -2441,13 +2444,17 @@ impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
self.expected_preimage = Some(payment_preimage);
self
}
pub fn with_overpay_limit(mut self, overpay_limit: u64) -> Self {
self.overpay_limit = overpay_limit;
self
}
}

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

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

0 comments on commit e6d74b3

Please sign in to comment.