Skip to content

Commit 59c81e7

Browse files
Test utils: support intermediate nodes taking 1msat extra fee.
See docs on the new field.
1 parent 9189a7c commit 59c81e7

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
@@ -2585,6 +2585,14 @@ pub struct ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
25852585
pub expected_extra_fees: Vec<u32>,
25862586
pub skip_last: bool,
25872587
pub payment_preimage: PaymentPreimage,
2588+
// Allow forwarding nodes to have taken 1 msat more fee than expected based on the downstream
2589+
// fulfill amount.
2590+
//
2591+
// Necessary because our test utils calculate the expected fee for an intermediate node based on
2592+
// the amount was claimed in their downstream peer's fulfill, but blinded intermediate nodes
2593+
// calculate their fee based on the inbound amount from their upstream peer, causing a difference
2594+
// in rounding.
2595+
pub allow_1_msat_fee_overpay: bool,
25882596
}
25892597

25902598
impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
@@ -2594,7 +2602,7 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
25942602
) -> Self {
25952603
Self {
25962604
origin_node, expected_paths, expected_extra_fees: vec![0; expected_paths.len()],
2597-
skip_last: false, payment_preimage,
2605+
skip_last: false, payment_preimage, allow_1_msat_fee_overpay: false,
25982606
}
25992607
}
26002608
pub fn skip_last(mut self, skip_last: bool) -> Self {
@@ -2605,12 +2613,16 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
26052613
self.expected_extra_fees = extra_fees;
26062614
self
26072615
}
2616+
pub fn allow_1_msat_fee_overpay(mut self) -> Self {
2617+
self.allow_1_msat_fee_overpay = true;
2618+
self
2619+
}
26082620
}
26092621

26102622
pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArgs) -> u64 {
26112623
let ClaimAlongRouteArgs {
26122624
origin_node, expected_paths, expected_extra_fees, skip_last,
2613-
payment_preimage: our_payment_preimage
2625+
payment_preimage: our_payment_preimage, allow_1_msat_fee_overpay
26142626
} = args;
26152627
let claim_event = expected_paths[0].last().unwrap().node.get_and_clear_pending_events();
26162628
assert_eq!(claim_event.len(), 1);
@@ -2721,9 +2733,11 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArg
27212733
(fwd_amt_msat * prop_fee / 1_000_000) + base_fee
27222734
};
27232735
if $idx == 1 { fee += expected_extra_fees[i] as u64; }
2724-
expect_payment_forwarded!(*$node, $next_node, $prev_node, Some(fee as u64), false, false);
2725-
expected_total_fee_msat += fee as u64;
2726-
fwd_amt_msat += fee as u64;
2736+
let mut events = $node.node.get_and_clear_pending_events();
2737+
assert_eq!(events.len(), 1);
2738+
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);
2739+
expected_total_fee_msat += actual_fee.unwrap();
2740+
fwd_amt_msat += actual_fee.unwrap();
27272741
check_added_monitors!($node, 1);
27282742
let new_next_msgs = if $new_msgs {
27292743
let events = $node.node.get_and_clear_pending_msg_events();

0 commit comments

Comments
 (0)