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

Function test_setchannel_routing

tests/test_pay.py:2269–2381  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

2267
2268
2269def test_setchannel_routing(node_factory, bitcoind):
2270 # TEST SETUP
2271 #
2272 # [l1] <--default_fees--> [l2] <--specific_fees--> [l3]
2273 #
2274 # - json listchannels is able to see the new values in foreign node
2275 # - routing calculates fees correctly
2276 # - payment can be done using specific fees
2277 # - channel specific fees can be disabled again
2278 # - payment can be done using global fees
2279 # - htlc max is honored
2280 DEF_BASE = 1
2281 DEF_PPM = 10
2282 MAX_HTLC = Millisatoshi(int(FUNDAMOUNT * 1000 * 0.99))
2283 MIN_HTLC = Millisatoshi(0)
2284
2285 l1, l2, l3 = node_factory.line_graph(
2286 3, announce_channels=True, wait_for_announce=True,
2287 opts={'fee-base': DEF_BASE, 'fee-per-satoshi': DEF_PPM,
2288 'disable-mpp': None})
2289
2290 # get short channel id for 2->3
2291 scid = l2.get_channel_scid(l3)
2292
2293 # TEST CUSTOM VALUES
2294 l2.rpc.setchannel(scid, 1337, 137, 17, 4000000, enforcedelay=0)
2295
2296 # wait for l1 to see updated channel via gossip
2297 wait_for(lambda: [c['base_fee_millisatoshi'] for c in l1.rpc.listchannels(scid)['channels']] == [1337, DEF_BASE])
2298 wait_for(lambda: [c['fee_per_millionth'] for c in l1.rpc.listchannels(scid)['channels']] == [137, DEF_PPM])
2299 wait_for(lambda: [c['htlc_minimum_msat'] for c in l1.rpc.listchannels(scid)['channels']] == [17, MIN_HTLC])
2300 wait_for(lambda: [c['htlc_maximum_msat'] for c in l1.rpc.listchannels(scid)['channels']] == [4000000, MAX_HTLC])
2301
2302 # test fees are applied to HTLC forwards
2303 #
2304 # If l1 were to send 4,999,999 millisatoshi to l3 via l2, it needs to
2305 # pay l2 the fee it specified in the l2->l3 `channel_update`, calculated as
2306 # per [HTLC Fees](#htlc_fees): base + amt * pm / 10**6
2307
2308 # Note: we use fp16 internally for channel max, so we overestimate:
2309 # from devtools/fp16 4000000: fp16:5fa1 min 3999744 max 4001791
2310 # Since it rounds up, it will use 4001792 as max capacity.
2311
2312 # Should refuse to route this!
2313 with pytest.raises(RpcError, match=r'feasible|exceeds htlc_maximum_msat'):
2314 l1.rpc.getroutes(l1.info['id'], l3.info['id'], 4001793, layers=['auto.localchans', 'auto.sourcefree'], maxfee_msat=10000000, final_cltv=9, maxparts=1)
2315
2316 # We should consider this unroutable! (MPP is disabled!)
2317 inv = l3.dev_invoice(amount_msat=4001793,
2318 label='test_setchannel_1',
2319 description='desc',
2320 dev_routes=[])
2321 with pytest.raises(RpcError, match=f'The shortest path is [0-9x]*->{scid}, but {scid}/0 exceeds htlc_maximum_msat ~4001792msat'):
2322 l1.dev_pay(inv['bolt11'], dev_use_shadow=False)
2323
2324 # 1337 + 4000000 * 137 / 1000000 = 1885
2325 route_ok = l1.single_route(l3.info['id'], 4000000)
2326 assert len(route_ok) == 2

Callers

nothing calls this directly

Calls 15

MillisatoshiClass · 0.90
wait_forFunction · 0.90
line_graphMethod · 0.80
get_channel_scidMethod · 0.80
setchannelMethod · 0.80
getroutesMethod · 0.80
dev_invoiceMethod · 0.80
single_routeMethod · 0.80
sendpayMethod · 0.80
waitsendpayMethod · 0.80
listchannelsMethod · 0.45
dev_payMethod · 0.45

Tested by

no test coverage detected