From 447d91d7b69b80d63cbdec1bcaf9854c63fa342c Mon Sep 17 00:00:00 2001 From: f321x Date: Mon, 6 Oct 2025 17:15:36 +0200 Subject: [PATCH] tests: lnpeer: test_trampoline_mpp_consolidation_forwarding_amount Add sanity check that bob is not forwarding more sats to carol if than he receives from alice. (he only forwards once and doesn't try to forward multiple times). This should get caught by asserts in lnworker/lnpeer, nevertheless it seems to make sense to just add this test to prevent regressions of this kind. --- tests/test_lnpeer.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_lnpeer.py b/tests/test_lnpeer.py index 97813f5f7..1ea9ae0ed 100644 --- a/tests/test_lnpeer.py +++ b/tests/test_lnpeer.py @@ -2394,6 +2394,25 @@ class TestPeerForwarding(TestPeer): graph = self.create_square_graph(direct=False, test_mpp_consolidation=True, is_legacy=True) await self._run_trampoline_payment(graph) + async def test_trampoline_mpp_consolidation_forwarding_amount(self): + """sanity check that bob is forwarding less than he is receiving""" + # alice->bob->carol->dave + graph = self.create_square_graph(direct=False, test_mpp_consolidation=True, is_legacy=True) + # bump alices trampoline fee level so the first payment succeeds and the htlc sums can be compared usefully below. + alice = graph.workers['alice'] + alice.config.INITIAL_TRAMPOLINE_FEE_LEVEL = 6 + with self.assertRaises(PaymentDone): + await self._run_trampoline_payment(graph, attempts=1) + + # assert bob hasn't forwarded more than he received + bob_alice_channel = graph.channels[('bob', 'alice')] + htlcs_bob_received_from_alice = bob_alice_channel.hm.all_htlcs_ever() + bob_carol_channel = graph.channels[('bob', 'carol')] + htlcs_bob_sent_to_carol = bob_carol_channel.hm.all_htlcs_ever() + sum_bob_received = sum(htlc.amount_msat for (direction, htlc) in htlcs_bob_received_from_alice) + sum_bob_sent = sum(htlc.amount_msat for (direction, htlc) in htlcs_bob_sent_to_carol) + assert sum_bob_sent < sum_bob_received, f"{sum_bob_sent=} > {sum_bob_received=}" + async def test_trampoline_mpp_consolidation_with_hold_invoice(self): with self.assertRaises(PaymentDone): graph = self.create_square_graph(direct=False, test_mpp_consolidation=True, is_legacy=True)