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

Function test_node_bias_routes

tests/test_askrene.py:502–563  ·  view source on GitHub ↗

Test getroutes with biased nodes.

(node_factory)

Source from the content-addressed store, hash-verified

500
501
502def test_node_bias_routes(node_factory):
503 """Test getroutes with biased nodes."""
504 # There are many cheap routes that go through node 2:
505 # 0->2->x->1
506 # And a very expensive route that go through node 3:
507 # 0->3->1
508 gsfile, nodemap = generate_gossip_store(
509 [
510 GenChannel(0, 2, forward=GenChannel.Half(propfee=10)),
511 GenChannel(2, 11, forward=GenChannel.Half(propfee=10)),
512 GenChannel(2, 12, forward=GenChannel.Half(propfee=10)),
513 GenChannel(2, 13, forward=GenChannel.Half(propfee=10)),
514 GenChannel(2, 14, forward=GenChannel.Half(propfee=10)),
515 GenChannel(2, 15, forward=GenChannel.Half(propfee=10)),
516 GenChannel(2, 16, forward=GenChannel.Half(propfee=10)),
517 GenChannel(2, 17, forward=GenChannel.Half(propfee=10)),
518 GenChannel(2, 18, forward=GenChannel.Half(propfee=10)),
519 GenChannel(2, 19, forward=GenChannel.Half(propfee=10)),
520 GenChannel(11, 1, forward=GenChannel.Half(propfee=10)),
521 GenChannel(12, 1, forward=GenChannel.Half(propfee=10)),
522 GenChannel(13, 1, forward=GenChannel.Half(propfee=10)),
523 GenChannel(14, 1, forward=GenChannel.Half(propfee=10)),
524 GenChannel(15, 1, forward=GenChannel.Half(propfee=10)),
525 GenChannel(16, 1, forward=GenChannel.Half(propfee=10)),
526 GenChannel(17, 1, forward=GenChannel.Half(propfee=10)),
527 GenChannel(18, 1, forward=GenChannel.Half(propfee=10)),
528 GenChannel(19, 1, forward=GenChannel.Half(propfee=10)),
529 GenChannel(0, 3, forward=GenChannel.Half(propfee=1000)),
530 GenChannel(3, 1, forward=GenChannel.Half(propfee=1000)),
531 ]
532 )
533 l1 = node_factory.get_node(gossip_store_file=gsfile.name)
534 l1.rpc.askrene_create_layer(layer="mylayer")
535 l1.rpc.askrene_bias_node(layer="mylayer", node=nodemap[2], direction="out", bias=-50)
536
537 # by default the best route goes through node 2
538 r = l1.rpc.getroutes(
539 source=nodemap[0],
540 destination=nodemap[1],
541 amount_msat=10000000,
542 layers=[],
543 maxfee_msat=1000000,
544 final_cltv=99,
545 )
546 assert len(r["routes"]) == 1
547 assert len(r["routes"][0]["path"]) == 3
548 assert r["routes"][0]["path"][0]["node_id_out"] == nodemap[2]
549 assert r["routes"][0]["path"][2]["node_id_out"] == nodemap[1]
550
551 # by using the layer that penalizes node 2, we end up routing through node 3
552 r = l1.rpc.getroutes(
553 source=nodemap[0],
554 destination=nodemap[1],
555 amount_msat=10000000,
556 layers=["mylayer"],
557 maxfee_msat=1000000,
558 final_cltv=99,
559 )

Callers

nothing calls this directly

Calls 5

generate_gossip_storeFunction · 0.90
GenChannelClass · 0.90
askrene_bias_nodeMethod · 0.80
getroutesMethod · 0.80
get_nodeMethod · 0.45

Tested by

no test coverage detected