Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions libs/gl-client-py/glclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,10 @@ def wait(self, subsystem, indexname, nextvalue: int) -> clnpb.WaitResponse:
res = clnpb.WaitResponse
return res.FromString(bytes(self.inner.call(uri, bytes(req))))

def lsp_invoice(self, label: str, description: str, amount_msat: int | None = None):
def lsp_invoice(self, label: str, description: str, amount_msat: int | None = None, expiry: int | None = None):
uri = "/greenlight.Node/LspInvoice"
req = nodepb.LspInvoiceRequest(
label=label, description=description, amount_msat=amount_msat
label=label, description=description, amount_msat=amount_msat, expiry=expiry
).SerializeToString()
res = nodepb.LspInvoiceResponse
return res.FromString(bytes(self.inner.call(uri, bytes(req))))
Expand Down
2 changes: 2 additions & 0 deletions libs/gl-client-py/glclient/greenlight.proto
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ message LspInvoiceRequest {
uint64 amount_msat = 3; // 0 => Any
string description = 4;
string label = 5;
optional uint64 expiry = 6;
}

message LspInvoiceResponse {
string bolt11 = 1;
uint32 created_index = 2;
Expand Down
30 changes: 15 additions & 15 deletions libs/gl-client-py/glclient/greenlight_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion libs/gl-client-py/glclient/greenlight_pb2.pyi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions libs/gl-client-py/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ impl Node {
description: String,
amount_msat: Option<u64>,
token: Option<String>,
expiry: Option<u64>,
) -> PyResult<Vec<u8>> {
let req = pb::LspInvoiceRequest {
amount_msat: amount_msat.unwrap_or_default(),
description: description,
label: label,
description,
label,
lsp_id: "".to_owned(),
token: token.unwrap_or_default(),
expiry,
};

let res = exec(async { self.client.clone().lsp_invoice(req).await })
Expand Down
51 changes: 51 additions & 0 deletions libs/gl-client-py/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,54 @@ def test_lsps_plugin_calls(clients, bitcoind, node_factory, lsps_server):
# the LSPS2 fee parameters (min_fee_msat=1000, proportional=1000).
# For 31337 msat: max(1000, ceil(31337 * 1000 / 1_000_000)) = 1000
assert res.opening_fee_msat == 1000


def test_lsp_invoice_expiry(clients, bitcoind, node_factory, lsps_server):
"""An invoice created with an `expiry` carries that expiry.

```ditaa
LSP --- GL
```

Assume we already have a channel between LSP and GL node, which gives it
inbound capacity, so `lsp_invoice` takes the plain-invoice path (no
JIT negotiation), where the requested `expiry` is passed to CLN's
`invoice`.
"""
lsp = lsps_server
lsp.fundwallet(sats=2 * 10**6)

c = clients.new()
c.register()
signer = c.signer()
signer.run_in_thread()
gl = c.node()
gl.connect_peer(lsp.info["id"], f"localhost:{lsp.port}")
gl_id = gl.get_info().id.hex()

# Fund channel between LSP and GL node (liquidity is on LSP side)
lsp.rpc.fundchannel(gl_id, 10**6)
bitcoind.generate_block(6, wait_for_mempool=1)
wait_for(lambda: lsp.rpc.listpeerchannels(gl_id)["channels"][0]["state"] == "CHANNELD_NORMAL")

amount_msat = 10_000_000

# The requested expiry ends up in the invoice.
expiry = 3600
res = gl.lsp_invoice(
label="with-expiry",
description="with-expiry",
amount_msat=amount_msat,
expiry=expiry,
)
assert res.opening_fee_msat == 0 # plain invoice, no JIT channel
assert lsp.rpc.decode(res.bolt11)["expiry"] == expiry

# Without an expiry, CLN's default (one week) still applies.
res = gl.lsp_invoice(
label="default-expiry",
description="default-expiry",
amount_msat=amount_msat,
)
assert res.opening_fee_msat == 0
assert lsp.rpc.decode(res.bolt11)["expiry"] == 7 * 24 * 3600
2 changes: 2 additions & 0 deletions libs/gl-client/.resources/proto/glclient/greenlight.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions libs/gl-plugin/.resources/proto/glclient/greenlight.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions libs/gl-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ tokio-util = { version = "0.7", features = ["codec"] }
tonic = { version = "0.11", features = ["tls", "transport"] }
tower = { version = "0.4" }
vls-protocol = { workspace = true }
chrono = { version = "0.4" }

[build-dependencies]
tonic-build = "0.11"
Loading
Loading