Skip to content

Commit bc83a9a

Browse files
Test utils: support intermediate nodes taking 1msat extra fee.
See docs on the new field.
1 parent 850bd88 commit bc83a9a

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
@@ -2604,6 +2604,14 @@ pub struct ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
26042604
pub expected_extra_fees: Vec<u32>,
26052605
pub skip_last: bool,
26062606
pub payment_preimage: PaymentPreimage,
2607+
// Allow forwarding nodes to have taken 1 msat more fee than expected based on the downstream
2608+
// fulfill amount.
2609+
//
2610+
// Necessary because our test utils calculate the expected fee for an intermediate node based on
2611+
// the amount was claimed in their downstream peer's fulfill, but blinded intermediate nodes
2612+
// calculate their fee based on the inbound amount from their upstream peer, causing a difference
2613+
// in rounding.
2614+
pub allow_1_msat_fee_overpay: bool,
26072615
}
26082616

26092617
impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
@@ -2613,7 +2621,7 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
26132621
) -> Self {
26142622
Self {
26152623
origin_node, expected_paths, expected_extra_fees: vec![0; expected_paths.len()],
2616-
skip_last: false, payment_preimage,
2624+
skip_last: false, payment_preimage, allow_1_msat_fee_overpay: false,
26172625
}
26182626
}
26192627
pub fn skip_last(mut self, skip_last: bool) -> Self {
@@ -2624,12 +2632,16 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
26242632
self.expected_extra_fees = extra_fees;
26252633
self
26262634
}
2635+
pub fn allow_1_msat_fee_overpay(mut self) -> Self {
2636+
self.allow_1_msat_fee_overpay = true;
2637+
self
2638+
}
26272639
}
26282640

26292641
pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArgs) -> u64 {
26302642
let ClaimAlongRouteArgs {
26312643
origin_node, expected_paths, expected_extra_fees, skip_last,
2632-
payment_preimage: our_payment_preimage
2644+
payment_preimage: our_payment_preimage, allow_1_msat_fee_overpay
26332645
} = args;
26342646
let claim_event = expected_paths[0].last().unwrap().node.get_and_clear_pending_events();
26352647
assert_eq!(claim_event.len(), 1);
@@ -2740,9 +2752,11 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArg
27402752
(fwd_amt_msat * prop_fee / 1_000_000) + base_fee
27412753
};
27422754
if $idx == 1 { fee += expected_extra_fees[i] as u64; }
2743-
expect_payment_forwarded!(*$node, $next_node, $prev_node, Some(fee as u64), false, false);
2744-
expected_total_fee_msat += fee as u64;
2745-
fwd_amt_msat += fee as u64;
2755+
let mut events = $node.node.get_and_clear_pending_events();
2756+
assert_eq!(events.len(), 1);
2757+
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);
2758+
expected_total_fee_msat += actual_fee.unwrap();
2759+
fwd_amt_msat += actual_fee.unwrap();
27462760
check_added_monitors!($node, 1);
27472761
let new_next_msgs = if $new_msgs {
27482762
let events = $node.node.get_and_clear_pending_msg_events();

0 commit comments

Comments
 (0)