Skip to content

Commit 8f31bab

Browse files
Test utils: support intermediate nodes taking 1msat extra fee.
See docs on the new field.
1 parent b72de97 commit 8f31bab

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,14 @@ pub struct ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
25902590
pub expected_extra_fees: Vec<u32>,
25912591
pub skip_last: bool,
25922592
pub payment_preimage: PaymentPreimage,
2593+
// Allow forwarding nodes to have taken 1 msat more fee than expected based on the downstream
2594+
// fulfill amount.
2595+
//
2596+
// Necessary because our test utils calculate the expected fee for an intermediate node based on
2597+
// the amount was claimed in their downstream peer's fulfill, but blinded intermediate nodes
2598+
// calculate their fee based on the inbound amount from their upstream peer, causing a difference
2599+
// in rounding.
2600+
pub allow_1_msat_fee_overpay: bool,
25932601
}
25942602

25952603
impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
@@ -2599,7 +2607,7 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
25992607
) -> Self {
26002608
Self {
26012609
origin_node, expected_paths, expected_extra_fees: vec![0; expected_paths.len()],
2602-
skip_last: false, payment_preimage,
2610+
skip_last: false, payment_preimage, allow_1_msat_fee_overpay: false,
26032611
}
26042612
}
26052613
pub fn skip_last(mut self, skip_last: bool) -> Self {
@@ -2610,12 +2618,16 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
26102618
self.expected_extra_fees = extra_fees;
26112619
self
26122620
}
2621+
pub fn allow_1_msat_fee_overpay(mut self) -> Self {
2622+
self.allow_1_msat_fee_overpay = true;
2623+
self
2624+
}
26132625
}
26142626

26152627
pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArgs) -> u64 {
26162628
let ClaimAlongRouteArgs {
26172629
origin_node, expected_paths, expected_extra_fees, skip_last,
2618-
payment_preimage: our_payment_preimage
2630+
payment_preimage: our_payment_preimage, allow_1_msat_fee_overpay
26192631
} = args;
26202632
let claim_event = expected_paths[0].last().unwrap().node.get_and_clear_pending_events();
26212633
assert_eq!(claim_event.len(), 1);
@@ -2726,9 +2738,11 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArg
27262738
(fwd_amt_msat * prop_fee / 1_000_000) + base_fee
27272739
};
27282740
if $idx == 1 { fee += expected_extra_fees[i] as u64; }
2729-
expect_payment_forwarded!(*$node, $next_node, $prev_node, Some(fee as u64), false, false);
2730-
expected_total_fee_msat += fee as u64;
2731-
fwd_amt_msat += fee as u64;
2741+
let mut events = $node.node.get_and_clear_pending_events();
2742+
assert_eq!(events.len(), 1);
2743+
let actual_fee = expect_payment_forwarded(events.pop().unwrap(), $node, &$next_node, $prev_node, Some(fee as u64), false, false, allow_1_msat_fee_overpay);
2744+
expected_total_fee_msat += actual_fee.unwrap();
2745+
fwd_amt_msat += actual_fee.unwrap();
27322746
check_added_monitors!($node, 1);
27332747
let new_next_msgs = if $new_msgs {
27342748
let events = $node.node.get_and_clear_pending_msg_events();

0 commit comments

Comments
 (0)