Skip to content

Commit d4de9bc

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

File tree

6 files changed

+22
-16
lines changed

6 files changed

+22
-16
lines changed

docs/lightning.md

Lines changed: 7 additions & 6 deletions
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 with either `"source-policy"` (arguments added to `openchannel`)
23+
or `"target-policy"` (arguments added to `updatechanpolicy`). Therefore, the key `"source-policy"` is
24+
required to open a LN channel in warnet, and to 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-policy">--local_amt=100000</data>
3132
</edge>
3233
```
3334

src/scenarios/ln_init.py

Lines changed: 2 additions & 2 deletions
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-policy" 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["source-policy"])["funding_txid"]
5959
opening_txs.append(tx)
6060

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

src/warnet/lnnode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ 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: int, policy: str) -> str:
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+
res = self.lncli(f"openchannel --node_key={pubkey} --connect={host} {policy}")
8080
return res
8181

8282
def connect_to_tank(self, index):

src/warnet/warnet.py

Lines changed: 2 additions & 1 deletion
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-policy" in data:
154155
continue
155156
if src == node_id:
156157
tank.init_peers.append(int(dst))

test/data/ln.graphml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
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-policy" attr.type="string" for="edge" id="source-policy"/>
1010
<key attr.name="collect_logs" attr.type="boolean" for="node" id="collect_logs"/>
1111
<key attr.name="image" attr.type="string" for="node" id="image"/>
1212
<graph edgedefault="directed">
1313
<node id="0">
1414
<data key="version">26.0</data>
1515
<data key="bitcoin_config">-uacomment=w0</data>
1616
<data key="ln">lnd</data>
17+
<data key="ln_image">lightninglabs/lnd:v0.15.5-beta</data>
1718
<data key="collect_logs">true</data>
1819
</node>
1920
<node id="1">
2021
<data key="version">26.0</data>
2122
<data key="bitcoin_config">-uacomment=w1</data>
2223
<data key="ln">lnd</data>
23-
<data key="ln_image">lightninglabs/lnd:v0.15.5-beta</data>
2424
<data key="ln_cb_image">pinheadmz/circuitbreaker:278737d</data>
2525
<data key="collect_logs">true</data>
2626
<data key="ln_config">--bitcoin.timelockdelta=20</data>
@@ -41,10 +41,10 @@
4141
<edge id="4" source="3" target="0"></edge>
4242
<!-- LN channels -->
4343
<edge id="5" source="0" target="1">
44-
<data key="channel">100000</data>
44+
<data key="source-policy">--local_amt=100000</data>
4545
</edge>
4646
<edge id="6" source="1" target="2">
47-
<data key="channel">100000</data>
47+
<data key="source-policy">--local_amt=100000 --push_amt=50000 --base_fee_msat=5500 --fee_rate_ppm=3</data>
4848
</edge>
4949
</graph>
5050
</graphml>

test/ln_test.py

Lines changed: 5 additions & 1 deletion
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)