Skip to content

Commit 252529b

Browse files
committed
LN: pass openchannel args from graphml file to ln node
1 parent c954707 commit 252529b

File tree

6 files changed

+33
-16
lines changed

6 files changed

+33
-16
lines changed

docs/lightning.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ Example:
1717

1818
## Adding LN channels to graph
1919

20-
LN channels are represented in the graphml file as edges with an extra data element
21-
with key `"channel"` and a value in satoshis representing channel capacity. Note
22-
that this data element is the only difference between LN channels and regular bitcoin
23-
p2p connections. The graph will be considered a `MultiDiGraph` and contain two different
24-
kinds of edges.
20+
LN channels are represented in the graphml file as edges with extra data elements
21+
that correspond to arguments to the lnd `openchannel` and `updatechanpolicy` RPC
22+
commands. The keys are prefixed with either `"source"` (`openchannel`) or
23+
`"target"` (`updatechanpolicy`). Therefore, the key `"source:local_amt"` is
24+
required to open a LN channel in warnet, and identify an edge in the graphml file
25+
as a LN channel.
2526

2627
Example:
2728

2829
```
2930
<edge id="0" source="0" target="1">
30-
<data key="channel">100000</data>
31+
<data key="source:local_amt">100000</data>
3132
</edge>
3233
```
3334

src/scenarios/ln_init.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def run_test(self):
5050
ln_edges = []
5151
for edge in self.warnet.graph.edges(data=True):
5252
(src, dst, data) = edge
53-
if "channel" in data:
53+
if "source:local_amt" in data:
5454
src_node = self.warnet.get_ln_node_from_tank(src)
5555
assert src_node is not None
5656
assert self.warnet.get_ln_node_from_tank(dst) is not None
5757
ln_edges.append(edge)
58-
tx = src_node.open_channel_to_tank(dst, data["channel"])["funding_txid"]
58+
tx = src_node.open_channel_to_tank(dst, data)["funding_txid"]
5959
opening_txs.append(tx)
6060

6161
self.log.info("Waiting for all channel open txs in mempool")

src/warnet/lnnode.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,15 @@ def get_wallet_balance(self):
7373
res = self.lncli("walletbalance")
7474
return res
7575

76-
def open_channel_to_tank(self, index, amt):
76+
def open_channel_to_tank(self, index, data):
7777
tank = self.warnet.tanks[index]
7878
[pubkey, host] = tank.lnnode.getURI().split("@")
79-
res = self.lncli(f"openchannel --node_key={pubkey} --connect={host} --local_amt={amt}")
79+
args = ""
80+
for key, value in data.items():
81+
if "source:" not in key:
82+
continue
83+
args += f" --{key[len('source:'):]}={value}"
84+
res = self.lncli(f"openchannel --node_key={pubkey} --connect={host} {args}")
8085
return res
8186

8287
def connect_to_tank(self, index):

src/warnet/warnet.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def tanks_from_graph(self):
150150
# import edges as list of destinations to connect to
151151
for edge in self.graph.edges(data=True):
152152
(src, dst, data) = edge
153-
if "channel" in data:
153+
# Ignore LN edges for now
154+
if "source:local_amt" in data:
154155
continue
155156
if src == node_id:
156157
tank.init_peers.append(int(dst))

test/data/ln.graphml

+10-4
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@
66
<key attr.name="ln_image" attr.type="string" for="node" id="ln_image"/>
77
<key attr.name="ln_cb_image" attr.type="string" for="node" id="ln_cb_image"/>
88
<key attr.name="ln_config" attr.type="string" for="node" id="ln_config"/>
9-
<key attr.name="channel" attr.type="string" for="edge" id="channel"/>
9+
<key attr.name="source:local_amt" attr.type="int" for="edge" id="source:local_amt"/>
10+
<key attr.name="source:push_amt" attr.type="int" for="edge" id="source:push_amt"/>
11+
<key attr.name="source:base_fee_msat" attr.type="int" for="edge" id="source:base_fee_msat"/>
12+
<key attr.name="source:fee_rate_ppm" attr.type="int" for="edge" id="source:fee_rate_ppm"/>
1013
<key attr.name="collect_logs" attr.type="boolean" for="node" id="collect_logs"/>
1114
<key attr.name="image" attr.type="string" for="node" id="image"/>
1215
<graph edgedefault="directed">
1316
<node id="0">
1417
<data key="version">26.0</data>
1518
<data key="bitcoin_config">-uacomment=w0</data>
1619
<data key="ln">lnd</data>
20+
<data key="ln_image">lightninglabs/lnd:v0.15.5-beta</data>
1721
<data key="collect_logs">true</data>
1822
</node>
1923
<node id="1">
2024
<data key="version">26.0</data>
2125
<data key="bitcoin_config">-uacomment=w1</data>
2226
<data key="ln">lnd</data>
23-
<data key="ln_image">lightninglabs/lnd:v0.15.5-beta</data>
2427
<data key="ln_cb_image">pinheadmz/circuitbreaker:278737d</data>
2528
<data key="collect_logs">true</data>
2629
<data key="ln_config">--bitcoin.timelockdelta=20</data>
@@ -41,10 +44,13 @@
4144
<edge id="4" source="3" target="0"></edge>
4245
<!-- LN channels -->
4346
<edge id="5" source="0" target="1">
44-
<data key="channel">100000</data>
47+
<data key="source:local_amt">100000</data>
4548
</edge>
4649
<edge id="6" source="1" target="2">
47-
<data key="channel">100000</data>
50+
<data key="source:local_amt">100000</data>
51+
<data key="source:push_amt">50000</data>
52+
<data key="source:base_fee_msat">5500</data>
53+
<data key="source:fee_rate_ppm">3</data>
4854
</edge>
4955
</graph>
5056
</graphml>

test/ln_test.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def get_cb_forwards(index):
4444
base.warcli("scenarios run ln_init")
4545
base.wait_for_all_scenarios()
4646

47-
print("\nEnsuring channel policy settings")
47+
print("\nEnsuring node-level channel policy settings")
4848
chans = json.loads(base.warcli("lncli 1 describegraph"))["edges"]
4949
for chan in chans:
5050
# node_1 or node_2 is tank 1 with its non-default --bitcoin.timelockdelta=20
@@ -71,6 +71,10 @@ def check_invoices():
7171
return False
7272
base.wait_for_predicate(check_invoices)
7373

74+
print("\nEnsuring channel-level channel policy settings")
75+
payment = json.loads(base.warcli("lncli 0 listpayments"))["payments"][0]
76+
assert payment["fee_msat"] == "5503"
77+
7478
print("\nEnsuring circuit breaker tracked payment")
7579
assert len(get_cb_forwards(1)["forwards"]) == 1
7680

0 commit comments

Comments
 (0)