feat: corelightning maxfee and custom pay command (#2464)

* feat: corelightning `maxfee` and custom pay command
we should use maxfee instead of calculating the ratio and pass it
through.
also make it possible to run a custom pay command
* change for cln rest aswell
This commit is contained in:
dni ⚡ 2024-04-25 12:54:00 +02:00 committed by GitHub
parent 4a0fb59461
commit 4b4bed59cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 23 additions and 36 deletions

View file

@ -164,6 +164,7 @@ class ClicheFundingSource(LNbitsSettings):
class CoreLightningFundingSource(LNbitsSettings):
corelightning_rpc: Optional[str] = Field(default=None)
corelightning_pay_command: str = Field(default="pay")
clightning_rpc: Optional[str] = Field(default=None)

File diff suppressed because one or more lines are too long

View file

@ -31,7 +31,8 @@ Vue.component('lnbits-funding-sources', {
'CoreLightningWallet',
'Core Lightning',
{
corelightning_rpc: 'Endpoint'
corelightning_rpc: 'Endpoint',
corelightning_pay_command: 'Custom Pay Command'
}
],
[

View file

@ -40,7 +40,7 @@ class CoreLightningWallet(Wallet):
raise ValueError(
"cannot initialize CoreLightningWallet: missing corelightning_rpc"
)
self.pay = settings.corelightning_pay_command
self.ln = LightningRpc(rpc)
# check if description_hash is supported (from corelightning>=v0.11.0)
command = self.ln.help("invoice")["help"][0]["command"] # type: ignore
@ -135,20 +135,18 @@ class CoreLightningWallet(Wallet):
False, None, None, None, "CLN 0 amount invoice not supported"
)
fee_limit_percent = fee_limit_msat / invoice.amount_msat * 100
# so fee_limit_percent is applied even
# on payments with fee < 5000 millisatoshi
# (which is default value of exemptfee)
# maxfee overrides both maxfeepercent and exemptfee defaults (and
# if you specify maxfee you cannot specify either of those), and
# creates an absolute limit on what fee we will pay. This allows you to
# implement your own heuristics rather than the primitive ones used
# here.
payload = {
"bolt11": bolt11,
"maxfeepercent": f"{fee_limit_percent:.11}",
"exemptfee": 0,
# so fee_limit_percent is applied even on payments with fee < 5000
# millisatoshi (which is default value of exemptfee)
"maxfee": fee_limit_msat,
"description": invoice.description,
}
r = await run_sync(lambda: self.ln.call("pay", payload))
r = await run_sync(lambda: self.ln.call(self.pay, payload))
fee_msat = -int(r["amount_sent_msat"] - r["amount_msat"])
return PaymentResponse(

View file

@ -163,15 +163,12 @@ class CoreLightningRestWallet(Wallet):
if not invoice.amount_msat or invoice.amount_msat <= 0:
error_message = "0 amount invoices are not allowed"
return PaymentResponse(False, None, None, None, error_message)
fee_limit_percent = fee_limit_msat / invoice.amount_msat * 100
try:
r = await self.client.post(
f"{self.url}/v1/pay",
data={
"invoice": bolt11,
"maxfeepercent": f"{fee_limit_percent:.11}",
"exemptfee": 0, # so fee_limit_percent is applied even on payments
# with fee < 5000 millisatoshi (which is default value of exemptfee)
"maxfee": fee_limit_msat,
},
timeout=None,
)

View file

@ -1012,8 +1012,7 @@
"request_type": "data",
"request_body": {
"invoice": "lnbc210n1pjlgal5sp5xr3uwlfm7ltumdjyukhys0z2rw6grgm8me9k4w9vn05zt9svzzjspp5ud2jdfpaqn5c2k2vphatsjypfafyk8rcvkvwexnrhmwm94ex4jtqdqu24hxjapq23jhxapqf9h8vmmfvdjscqpjrzjqta942048v7qxh5x7pxwplhmtwfl0f25cq23jh87rhx7lgrwwvv86r90guqqnwgqqqqqqqqqqqqqqpsqyg9qxpqysgqylngsyg960lltngzy90e8n22v4j2hvjs4l4ttuy79qqefjv8q87q9ft7uhwdjakvnsgk44qyhalv6ust54x98whl3q635hkwgsyw8xgqjl7jwu",
"maxfeepercent": "119.04761905",
"exemptfee": 0
"maxfee": 25000
},
"response_type": "json",
"response": {
@ -1292,8 +1291,7 @@
"request_type": "data",
"request_body": {
"invoice": "lnbc210n1pjlgal5sp5xr3uwlfm7ltumdjyukhys0z2rw6grgm8me9k4w9vn05zt9svzzjspp5ud2jdfpaqn5c2k2vphatsjypfafyk8rcvkvwexnrhmwm94ex4jtqdqu24hxjapq23jhxapqf9h8vmmfvdjscqpjrzjqta942048v7qxh5x7pxwplhmtwfl0f25cq23jh87rhx7lgrwwvv86r90guqqnwgqqqqqqqqqqqqqqpsqyg9qxpqysgqylngsyg960lltngzy90e8n22v4j2hvjs4l4ttuy79qqefjv8q87q9ft7uhwdjakvnsgk44qyhalv6ust54x98whl3q635hkwgsyw8xgqjl7jwu",
"maxfeepercent": "119.04761905",
"exemptfee": 0
"maxfee": 25000
},
"response_type": "json",
"response": {
@ -1396,8 +1394,7 @@
"request_type": "data",
"request_body": {
"invoice": "lnbc210n1pjlgal5sp5xr3uwlfm7ltumdjyukhys0z2rw6grgm8me9k4w9vn05zt9svzzjspp5ud2jdfpaqn5c2k2vphatsjypfafyk8rcvkvwexnrhmwm94ex4jtqdqu24hxjapq23jhxapqf9h8vmmfvdjscqpjrzjqta942048v7qxh5x7pxwplhmtwfl0f25cq23jh87rhx7lgrwwvv86r90guqqnwgqqqqqqqqqqqqqqpsqyg9qxpqysgqylngsyg960lltngzy90e8n22v4j2hvjs4l4ttuy79qqefjv8q87q9ft7uhwdjakvnsgk44qyhalv6ust54x98whl3q635hkwgsyw8xgqjl7jwu",
"maxfeepercent": "119.04761905",
"exemptfee": 0
"maxfee": 25000
},
"response_type": "json",
"response": {}
@ -1478,8 +1475,7 @@
"request_type": "data",
"request_body": {
"invoice": "lnbc210n1pjlgal5sp5xr3uwlfm7ltumdjyukhys0z2rw6grgm8me9k4w9vn05zt9svzzjspp5ud2jdfpaqn5c2k2vphatsjypfafyk8rcvkvwexnrhmwm94ex4jtqdqu24hxjapq23jhxapqf9h8vmmfvdjscqpjrzjqta942048v7qxh5x7pxwplhmtwfl0f25cq23jh87rhx7lgrwwvv86r90guqqnwgqqqqqqqqqqqqqqpsqyg9qxpqysgqylngsyg960lltngzy90e8n22v4j2hvjs4l4ttuy79qqefjv8q87q9ft7uhwdjakvnsgk44qyhalv6ust54x98whl3q635hkwgsyw8xgqjl7jwu",
"maxfeepercent": "119.04761905",
"exemptfee": 0
"maxfee": 25000
},
"response_type": "data",
"response": "data-not-json"
@ -1584,8 +1580,7 @@
"request_type": "data",
"request_body": {
"invoice": "lnbc210n1pjlgal5sp5xr3uwlfm7ltumdjyukhys0z2rw6grgm8me9k4w9vn05zt9svzzjspp5ud2jdfpaqn5c2k2vphatsjypfafyk8rcvkvwexnrhmwm94ex4jtqdqu24hxjapq23jhxapqf9h8vmmfvdjscqpjrzjqta942048v7qxh5x7pxwplhmtwfl0f25cq23jh87rhx7lgrwwvv86r90guqqnwgqqqqqqqqqqqqqqpsqyg9qxpqysgqylngsyg960lltngzy90e8n22v4j2hvjs4l4ttuy79qqefjv8q87q9ft7uhwdjakvnsgk44qyhalv6ust54x98whl3q635hkwgsyw8xgqjl7jwu",
"maxfeepercent": "119.04761905",
"exemptfee": 0
"maxfee": 25000
},
"response_type": "response",
"response": {

View file

@ -731,8 +731,7 @@
{
"bolt11": "lnbc210n1pjlgal5sp5xr3uwlfm7ltumdjyukhys0z2rw6grgm8me9k4w9vn05zt9svzzjspp5ud2jdfpaqn5c2k2vphatsjypfafyk8rcvkvwexnrhmwm94ex4jtqdqu24hxjapq23jhxapqf9h8vmmfvdjscqpjrzjqta942048v7qxh5x7pxwplhmtwfl0f25cq23jh87rhx7lgrwwvv86r90guqqnwgqqqqqqqqqqqqqqpsqyg9qxpqysgqylngsyg960lltngzy90e8n22v4j2hvjs4l4ttuy79qqefjv8q87q9ft7uhwdjakvnsgk44qyhalv6ust54x98whl3q635hkwgsyw8xgqjl7jwu",
"description": "Unit Test Invoice",
"exemptfee": 0,
"maxfeepercent": "119.04761905"
"maxfee": 25000
}
]
},
@ -862,8 +861,7 @@
{
"bolt11": "lnbc210n1pjlgal5sp5xr3uwlfm7ltumdjyukhys0z2rw6grgm8me9k4w9vn05zt9svzzjspp5ud2jdfpaqn5c2k2vphatsjypfafyk8rcvkvwexnrhmwm94ex4jtqdqu24hxjapq23jhxapqf9h8vmmfvdjscqpjrzjqta942048v7qxh5x7pxwplhmtwfl0f25cq23jh87rhx7lgrwwvv86r90guqqnwgqqqqqqqqqqqqqqpsqyg9qxpqysgqylngsyg960lltngzy90e8n22v4j2hvjs4l4ttuy79qqefjv8q87q9ft7uhwdjakvnsgk44qyhalv6ust54x98whl3q635hkwgsyw8xgqjl7jwu",
"description": "Unit Test Invoice",
"exemptfee": 0,
"maxfeepercent": "119.04761905"
"maxfee": 25000
}
]
},
@ -1049,8 +1047,7 @@
{
"bolt11": "lnbc210n1pjlgal5sp5xr3uwlfm7ltumdjyukhys0z2rw6grgm8me9k4w9vn05zt9svzzjspp5ud2jdfpaqn5c2k2vphatsjypfafyk8rcvkvwexnrhmwm94ex4jtqdqu24hxjapq23jhxapqf9h8vmmfvdjscqpjrzjqta942048v7qxh5x7pxwplhmtwfl0f25cq23jh87rhx7lgrwwvv86r90guqqnwgqqqqqqqqqqqqqqpsqyg9qxpqysgqylngsyg960lltngzy90e8n22v4j2hvjs4l4ttuy79qqefjv8q87q9ft7uhwdjakvnsgk44qyhalv6ust54x98whl3q635hkwgsyw8xgqjl7jwu",
"description": "Unit Test Invoice",
"exemptfee": 0,
"maxfeepercent": "119.04761905"
"maxfee": 25000
}
]
},
@ -1097,8 +1094,7 @@
{
"bolt11": "lnbc210n1pjlgal5sp5xr3uwlfm7ltumdjyukhys0z2rw6grgm8me9k4w9vn05zt9svzzjspp5ud2jdfpaqn5c2k2vphatsjypfafyk8rcvkvwexnrhmwm94ex4jtqdqu24hxjapq23jhxapqf9h8vmmfvdjscqpjrzjqta942048v7qxh5x7pxwplhmtwfl0f25cq23jh87rhx7lgrwwvv86r90guqqnwgqqqqqqqqqqqqqqpsqyg9qxpqysgqylngsyg960lltngzy90e8n22v4j2hvjs4l4ttuy79qqefjv8q87q9ft7uhwdjakvnsgk44qyhalv6ust54x98whl3q635hkwgsyw8xgqjl7jwu",
"description": "Unit Test Invoice",
"exemptfee": 0,
"maxfeepercent": "119.04761905"
"maxfee": 25000
}
]
},
@ -1132,8 +1128,7 @@
{
"bolt11": "lnbc210n1pjlgal5sp5xr3uwlfm7ltumdjyukhys0z2rw6grgm8me9k4w9vn05zt9svzzjspp5ud2jdfpaqn5c2k2vphatsjypfafyk8rcvkvwexnrhmwm94ex4jtqdqu24hxjapq23jhxapqf9h8vmmfvdjscqpjrzjqta942048v7qxh5x7pxwplhmtwfl0f25cq23jh87rhx7lgrwwvv86r90guqqnwgqqqqqqqqqqqqqqpsqyg9qxpqysgqylngsyg960lltngzy90e8n22v4j2hvjs4l4ttuy79qqefjv8q87q9ft7uhwdjakvnsgk44qyhalv6ust54x98whl3q635hkwgsyw8xgqjl7jwu",
"description": "Unit Test Invoice",
"exemptfee": 0,
"maxfeepercent": "119.04761905"
"maxfee": 25000
}
]
},