MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_mpp_adaptive

Function test_mpp_adaptive

tests/test_pay.py:3926–4006  ·  view source on GitHub ↗

We have two paths, both too small on their own, let's combine them. ```dot digraph { l1 -> l2 [label="scid=103x1x1, cap=amt-1"]; l2 -> l4 [label="scid=105x1x1, cap=max"]; l1 -> l3 [label="scid=107x1x1, cap=max"]; l3 -> l4 [label="scid=109x1x1, cap=amt-1"]; }

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

3924
3925
3926def test_mpp_adaptive(node_factory, bitcoind):
3927 """We have two paths, both too small on their own, let's combine them.
3928
3929 ```dot
3930 digraph {
3931 l1 -> l2 [label="scid=103x1x1, cap=amt-1"];
3932 l2 -> l4 [label="scid=105x1x1, cap=max"];
3933 l1 -> l3 [label="scid=107x1x1, cap=max"];
3934 l3 -> l4 [label="scid=109x1x1, cap=amt-1"];
3935 }
3936 """
3937 amt = 10**7 - 1
3938 l1, l2, l3, l4 = node_factory.get_nodes(4, opts={'allow-deprecated-apis': True})
3939
3940 l1.connect(l2)
3941 l2.connect(l4)
3942 l1.connect(l3)
3943 l3.connect(l4)
3944
3945 # First roadblock right away on an outgoing channel
3946 l2.fundchannel(l1, amt)
3947 l2.fundchannel(l4, amt, wait_for_active=True)
3948 l2.rpc.pay(l1.rpc.invoice(
3949 amt + 99999000 - 1, # Slightly less than amt + reserve
3950 label="reb l1->l2",
3951 description="Rebalance l1 -> l2"
3952 )['bolt11'])
3953
3954 # Second path fails only after the first hop
3955 l1.fundchannel(l3, amt)
3956 l4.fundchannel(l3, amt, wait_for_active=True)
3957 l4.rpc.pay(l3.rpc.invoice(
3958 amt + 99999000 - 1, # Slightly less than amt + reserve
3959 label="reb l3->l4",
3960 description="Rebalance l3 -> l4"
3961 )['bolt11'])
3962 l1.rpc.listpeers()
3963
3964 # Make sure neither channel can fit the payment by itself.
3965 c12 = l1.rpc.listpeerchannels(l2.info['id'])['channels'][0]
3966 c34 = l3.rpc.listpeerchannels(l4.info['id'])['channels'][0]
3967 assert(c12['spendable_msat'] < amt)
3968 assert(c34['spendable_msat'] < amt)
3969
3970 # Make sure all HTLCs entirely resolved before we mine more blocks!
3971 def all_htlcs(n):
3972 htlcs = []
3973 for p in n.rpc.listpeers()['peers']:
3974 for c in n.rpc.listpeerchannels(p['id'])['channels']:
3975 htlcs += c['htlcs']
3976 return htlcs
3977
3978 wait_for(lambda: all([all_htlcs(n) == [] for n in [l1, l2, l3, l4]]))
3979
3980 mine_funding_to_announce(bitcoind, [l1, l2, l3, l4])
3981 wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 8)
3982
3983 inv = l4.rpc.invoice(

Callers

nothing calls this directly

Calls 15

wait_forFunction · 0.90
mine_funding_to_announceFunction · 0.90
only_oneFunction · 0.90
all_htlcsFunction · 0.85
get_nodesMethod · 0.80
listpeerchannelsMethod · 0.80
paystatusMethod · 0.80
listsendpaysMethod · 0.80
listpaysMethod · 0.80
connectMethod · 0.45
fundchannelMethod · 0.45
payMethod · 0.45

Tested by

no test coverage detected