@@ -3083,3 +3083,62 @@ def test_mpp_presplit(node_factory):
30833083 inv = l3 .rpc .listinvoices ()['invoices' ][0 ]
30843084
30853085 assert (inv ['msatoshi' ] == inv ['msatoshi_received' ])
3086+
3087+
3088+ def test_mpp_adaptive (node_factory , bitcoind ):
3089+ """We have two paths, both too small on their own, let's combine them.
3090+
3091+ ```dot
3092+ digraph {
3093+ l1 -> l2;
3094+ l2 -> l4;
3095+ l1 -> l3;
3096+ l3 -> l4;
3097+ }
3098+ """
3099+ amt = 10 ** 7 - 1
3100+ l1 , l2 , l3 , l4 = node_factory .get_nodes (4 )
3101+
3102+ l1 .connect (l2 )
3103+ l2 .connect (l4 )
3104+ l1 .connect (l3 )
3105+ l3 .connect (l4 )
3106+
3107+ # First roadblock right away on an outgoing channel
3108+ l2 .fund_channel (l1 , amt )
3109+ l2 .fund_channel (l4 , amt , wait_for_active = True )
3110+ l2 .rpc .pay (l1 .rpc .invoice (
3111+ amt + 99999000 - 1 , # Slightly less than amt + reserve
3112+ label = "reb l1->l2" ,
3113+ description = "Rebalance l1 -> l2"
3114+ )['bolt11' ])
3115+
3116+ # Second path fails only after the first hop
3117+ l1 .fund_channel (l3 , amt )
3118+ l4 .fund_channel (l3 , amt , wait_for_active = True )
3119+ l4 .rpc .pay (l3 .rpc .invoice (
3120+ amt + 99999000 - 1 , # Slightly less than amt + reserve
3121+ label = "reb l3->l4" ,
3122+ description = "Rebalance l3 -> l4"
3123+ )['bolt11' ])
3124+ l1 .rpc .listpeers ()
3125+
3126+ # Make sure neither channel can fit the payment by itself.
3127+ c12 = l1 .rpc .listpeers (l2 .info ['id' ])['peers' ][0 ]['channels' ][0 ]
3128+ c34 = l3 .rpc .listpeers (l4 .info ['id' ])['peers' ][0 ]['channels' ][0 ]
3129+ assert (c12 ['spendable_msat' ].millisatoshis < amt )
3130+ assert (c34 ['spendable_msat' ].millisatoshis < amt )
3131+
3132+ bitcoind .generate_block (5 )
3133+ wait_for (lambda : len (l1 .rpc .listchannels ()['channels' ]) == 8 )
3134+
3135+ inv = l4 .rpc .invoice (
3136+ amt ,
3137+ label = "splittest" ,
3138+ description = "Needs to be split into at least 2"
3139+ )['bolt11' ]
3140+
3141+ p = l1 .rpc .pay (inv )
3142+ from pprint import pprint
3143+ pprint (p )
3144+ pprint (l1 .rpc .paystatus (inv ))
0 commit comments