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

Function test_node_bias_routes

tests/test_askrene.py:549–610  ·  view source on GitHub ↗

Test getroutes with biased nodes.

(node_factory)

Source from the content-addressed store, hash-verified

547
548
549def test_node_bias_routes(node_factory):
550 """Test getroutes with biased nodes."""
551 # There are many cheap routes that go through node 2:
552 # 0->2->x->1
553 # And a very expensive route that go through node 3:
554 # 0->3->1
555 gsfile, nodemap = generate_gossip_store(
556 [
557 GenChannel(0, 2, forward=GenChannel.Half(propfee=10)),
558 GenChannel(2, 11, forward=GenChannel.Half(propfee=10)),
559 GenChannel(2, 12, forward=GenChannel.Half(propfee=10)),
560 GenChannel(2, 13, forward=GenChannel.Half(propfee=10)),
561 GenChannel(2, 14, forward=GenChannel.Half(propfee=10)),
562 GenChannel(2, 15, forward=GenChannel.Half(propfee=10)),
563 GenChannel(2, 16, forward=GenChannel.Half(propfee=10)),
564 GenChannel(2, 17, forward=GenChannel.Half(propfee=10)),
565 GenChannel(2, 18, forward=GenChannel.Half(propfee=10)),
566 GenChannel(2, 19, forward=GenChannel.Half(propfee=10)),
567 GenChannel(11, 1, forward=GenChannel.Half(propfee=10)),
568 GenChannel(12, 1, forward=GenChannel.Half(propfee=10)),
569 GenChannel(13, 1, forward=GenChannel.Half(propfee=10)),
570 GenChannel(14, 1, forward=GenChannel.Half(propfee=10)),
571 GenChannel(15, 1, forward=GenChannel.Half(propfee=10)),
572 GenChannel(16, 1, forward=GenChannel.Half(propfee=10)),
573 GenChannel(17, 1, forward=GenChannel.Half(propfee=10)),
574 GenChannel(18, 1, forward=GenChannel.Half(propfee=10)),
575 GenChannel(19, 1, forward=GenChannel.Half(propfee=10)),
576 GenChannel(0, 3, forward=GenChannel.Half(propfee=1000)),
577 GenChannel(3, 1, forward=GenChannel.Half(propfee=1000)),
578 ]
579 )
580 l1 = node_factory.get_node(gossip_store_file=gsfile.name)
581 l1.rpc.askrene_create_layer(layer="mylayer")
582 l1.rpc.askrene_bias_node(layer="mylayer", node=nodemap[2], direction="out", bias=-50)
583
584 # by default the best route goes through node 2
585 r = l1.rpc.getroutes(
586 source=nodemap[0],
587 destination=nodemap[1],
588 amount_msat=10000000,
589 layers=[],
590 maxfee_msat=1000000,
591 final_cltv=99,
592 )
593 assert len(r["routes"]) == 1
594 assert len(r["routes"][0]["path"]) == 3
595 assert r["routes"][0]["path"][0]["node_id_out"] == nodemap[2]
596 assert r["routes"][0]["path"][2]["node_id_out"] == nodemap[1]
597
598 # by using the layer that penalizes node 2, we end up routing through node 3
599 r = l1.rpc.getroutes(
600 source=nodemap[0],
601 destination=nodemap[1],
602 amount_msat=10000000,
603 layers=["mylayer"],
604 maxfee_msat=1000000,
605 final_cltv=99,
606 )

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