mirror of
https://github.com/aljazceru/cyphernode.git
synced 2025-12-17 04:35:14 +01:00
ln_pay: we now MPP pay first, legacypay on failure
This commit is contained in:
@@ -303,8 +303,8 @@ ln_connectfund() {
|
||||
ln_pay() {
|
||||
trace "Entering ln_pay()..."
|
||||
|
||||
# Let's try to legacypay (MPP disabled) for 30 seconds.
|
||||
# If this doesn't work for a routing reason, let's try to pay (MPP enabled) for 30 seconds.
|
||||
# Let's try to pay (MPP enabled) for 85 seconds.
|
||||
# If this doesn't work for a routing reason, let's try to legacypay (MPP disabled) for 85 seconds.
|
||||
# If this doesn't work, return an error.
|
||||
|
||||
local result
|
||||
@@ -347,14 +347,39 @@ ln_pay() {
|
||||
trace "[ln_pay] Expected description <> Invoice description"
|
||||
returncode=1
|
||||
else
|
||||
# Amount and description are as expected (or empty description), let's pay!
|
||||
trace "[ln_pay] Amount and description are as expected, let's try to pay without MPP!"
|
||||
# Amount and description are as expected (or empty description), let's see if already paid
|
||||
trace "[ln_pay] Amount and description are as expected, let's see if already paid"
|
||||
result=$(ln_listpays "${bolt11}")
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
trace "[ln_pay] result=${result}"
|
||||
local complete pending failed
|
||||
complete=$(echo "${result}" | jq -er '.pays | map(select(.status == "complete")) | last')
|
||||
trace "[ln_pay] complete=${complete}"
|
||||
pending=$(echo "${result}" | jq -er '.pays | map(select(.status == "pending")) | last')
|
||||
trace "[ln_pay] pending=${pending}"
|
||||
failed=$(echo "${result}" | jq -er '.pays | map(select(.status == "failed")) | last')
|
||||
trace "[ln_pay] failed=${failed}"
|
||||
|
||||
if [ "${complete}" != "null" ]; then
|
||||
trace "[ln_pay] responding complete"
|
||||
echo "${complete}"
|
||||
return 0
|
||||
fi
|
||||
if [ "${pending}" != "null" ]; then
|
||||
trace "[ln_pay] responding pending"
|
||||
echo "${pending}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Payment not previously done, let's pay!
|
||||
trace "[ln_pay] Payment not previously done, let's try to pay with MPP!"
|
||||
|
||||
if [ "${invoice_msatoshi}" = "null" ]; then
|
||||
# "any" amount on the invoice, we force paying the expected_msatoshi provided to ln_pay by the user
|
||||
result=$(ln_call_lightningd legacypay -k bolt11=${bolt11} msatoshi=${expected_msatoshi} retry_for=30)
|
||||
result=$(ln_call_lightningd pay -k bolt11=${bolt11} msatoshi=${expected_msatoshi} retry_for=85)
|
||||
else
|
||||
result=$(ln_call_lightningd legacypay -k bolt11=${bolt11} retry_for=30)
|
||||
result=$(ln_call_lightningd pay -k bolt11=${bolt11} retry_for=85)
|
||||
fi
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
@@ -363,34 +388,31 @@ ln_pay() {
|
||||
# Successful payment example:
|
||||
#
|
||||
# {
|
||||
# "id": 16,
|
||||
# "payment_hash": "f00877afeec4d771c2db68af80b8afa5dad3b495dad498828327e484c93f67d5",
|
||||
# "destination": "021ec6ccede19caa0bc7d7f9699c73e63cb2b79a4877529a60d7ac6a4ebb03487a",
|
||||
# "msatoshi": 1234,
|
||||
# "amount_msat": "1234msat",
|
||||
# "msatoshi_sent": 1235,
|
||||
# "amount_sent_msat": "1235msat",
|
||||
# "created_at": 1633373202,
|
||||
# "status": "complete",
|
||||
# "payment_preimage": "373cd9a0f83426506f1535f6ca1f08f279f0bd82d257fd3fc8cd49fbc25750f2",
|
||||
# "bolt11": "lntb1ps4kjlrpp57qy80tlwcnthrskmdzhcpw905hdd8dy4mt2f3q5ryljgfjflvl2sdq9u2d2zxqr3jscqp2sp5c2qykk0pdaeh2yrvn4cpkchsnyxwjnaptujggsd6ldqjfd8jhh3qrzjqwyx8nu2hygyvgc02cwdtvuxe0lcxz06qt3lpsldzcdr46my5epmj85hhvqqqtsqqqqqqqlgqqqqqqgq9q9qyyssqpnwtw6mzxu8pr5mrm8677ke8p5fjcu6dyrrvuy8j5f5p8mzv2phr2y0yx3z7mvgf5uqzzdytegg04u7hcu8ma50692cg69cdtsgw9hsph0xeha"
|
||||
# }
|
||||
|
||||
# Failure response examples:
|
||||
#
|
||||
# {
|
||||
# "code": -32602,
|
||||
# "message": "03c05f973d9c7218e7aec4f52c2c8ab395f51f41d627c398237b5ff056f46faf09: unknown destination node_id (no public channels?)"
|
||||
# "destination": "029b26c73b2c19ec9bdddeeec97c313670c96b6414ceacae0fb1b3502e490a6cbb",
|
||||
# "payment_hash": "0d1e62210e7af9a4146258652fd4cfecd2638086850583e994a103884e2b4e78",
|
||||
# "created_at": 1631200188.550,
|
||||
# "parts": 1,
|
||||
# "msatoshi": 530114,
|
||||
# "amount_msat": "530114msat",
|
||||
# "msatoshi_sent": 530114,
|
||||
# "amount_sent_msat": "530114msat",
|
||||
# "payment_preimage": "2672c5fa280367222bf30db82566b78909927a67d5756d5ae0227b2ff8f3a907",
|
||||
# "status": "complete"
|
||||
# }
|
||||
#
|
||||
# {
|
||||
# "code": 206,
|
||||
# "message": "Route wanted fee of 16101625msat"
|
||||
# }
|
||||
#
|
||||
# Failed payment example:
|
||||
# {
|
||||
# "code": 207,
|
||||
# "message": "Invoice expired"
|
||||
# "code": 210,
|
||||
# "message": "Destination 029b26c73b2c19ec9bdddeeec97c313670c96b6414ceacae0fb1b3502e490a6cbb is not reachable directly and all routehints were unusable.",
|
||||
# "attempts": [
|
||||
# {
|
||||
# "status": "failed",
|
||||
# "failreason": "Destination 029b26c73b2c19ec9bdddeeec97c313670c96b6414ceacae0fb1b3502e490a6cbb is not reachable directly and all routehints were unusable.",
|
||||
# "partid": 0,
|
||||
# "amount": "528214msat"
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
#
|
||||
|
||||
@@ -413,18 +435,20 @@ ln_pay() {
|
||||
|
||||
# Let's try pay if code NOT 207 or 201.
|
||||
|
||||
if [ "${code}" -eq "201" ] || [ "${code}" -eq "207" ] || [ "${code}" -lt "0" ]; then
|
||||
if [ "${code}" -eq "201" ] || [ "${code}" -eq "207" ]; then
|
||||
trace "[ln_pay] Failure code, response will be the cli result."
|
||||
else
|
||||
trace "[ln_pay] Ok let's deal with potential routing failures and retry with MPP..."
|
||||
trace "[ln_pay] Ok let's deal with potential routing failures and retry without MPP..."
|
||||
|
||||
if [ "${invoice_msatoshi}" = "null" ]; then
|
||||
# "any" amount on the invoice, we force paying the expected_msatoshi provided to ln_pay by the user
|
||||
result=$(ln_call_lightningd pay -k bolt11=${bolt11} msatoshi=${expected_msatoshi} retry_for=30)
|
||||
result=$(ln_call_lightningd legacypay -k bolt11=${bolt11} msatoshi=${expected_msatoshi} retry_for=85)
|
||||
else
|
||||
result=$(ln_call_lightningd pay -k bolt11=${bolt11} retry_for=30)
|
||||
result=$(ln_call_lightningd legacypay -k bolt11=${bolt11} retry_for=85)
|
||||
fi
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
trace "[ln_pay] result=${result}"
|
||||
|
||||
if [ "${returncode}" -ne "0" ]; then
|
||||
trace "[ln_pay] Failed!"
|
||||
@@ -435,34 +459,36 @@ ln_pay() {
|
||||
# Successful payment example:
|
||||
#
|
||||
# {
|
||||
# "destination": "029b26c73b2c19ec9bdddeeec97c313670c96b6414ceacae0fb1b3502e490a6cbb",
|
||||
# "payment_hash": "0d1e62210e7af9a4146258652fd4cfecd2638086850583e994a103884e2b4e78",
|
||||
# "created_at": 1631200188.550,
|
||||
# "parts": 1,
|
||||
# "msatoshi": 530114,
|
||||
# "amount_msat": "530114msat",
|
||||
# "msatoshi_sent": 530114,
|
||||
# "amount_sent_msat": "530114msat",
|
||||
# "payment_preimage": "2672c5fa280367222bf30db82566b78909927a67d5756d5ae0227b2ff8f3a907",
|
||||
# "status": "complete"
|
||||
# "id": 16,
|
||||
# "payment_hash": "f00877afeec4d771c2db68af80b8afa5dad3b495dad498828327e484c93f67d5",
|
||||
# "destination": "021ec6ccede19caa0bc7d7f9699c73e63cb2b79a4877529a60d7ac6a4ebb03487a",
|
||||
# "msatoshi": 1234,
|
||||
# "amount_msat": "1234msat",
|
||||
# "msatoshi_sent": 1235,
|
||||
# "amount_sent_msat": "1235msat",
|
||||
# "created_at": 1633373202,
|
||||
# "status": "complete",
|
||||
# "payment_preimage": "373cd9a0f83426506f1535f6ca1f08f279f0bd82d257fd3fc8cd49fbc25750f2",
|
||||
# "bolt11": "lntb1ps4kjlrpp57qy80tlwcnthrskmdzhcpw905hdd8dy4mt2f3q5ryljgfjflvl2sdq9u2d2zxqr3jscqp2sp5c2qykk0pdaeh2yrvn4cpkchsnyxwjnaptujggsd6ldqjfd8jhh3qrzjqwyx8nu2hygyvgc02cwdtvuxe0lcxz06qt3lpsldzcdr46my5epmj85hhvqqqtsqqqqqqqlgqqqqqqgq9q9qyyssqpnwtw6mzxu8pr5mrm8677ke8p5fjcu6dyrrvuy8j5f5p8mzv2phr2y0yx3z7mvgf5uqzzdytegg04u7hcu8ma50692cg69cdtsgw9hsph0xeha"
|
||||
# }
|
||||
#
|
||||
#
|
||||
# Failed payment example:
|
||||
# {
|
||||
# "code": 210,
|
||||
# "message": "Destination 029b26c73b2c19ec9bdddeeec97c313670c96b6414ceacae0fb1b3502e490a6cbb is not reachable directly and all routehints were unusable.",
|
||||
# "attempts": [
|
||||
# {
|
||||
# "status": "failed",
|
||||
# "failreason": "Destination 029b26c73b2c19ec9bdddeeec97c313670c96b6414ceacae0fb1b3502e490a6cbb is not reachable directly and all routehints were unusable.",
|
||||
# "partid": 0,
|
||||
# "amount": "528214msat"
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
#
|
||||
|
||||
# Failure response examples:
|
||||
#
|
||||
# {
|
||||
# "code": -32602,
|
||||
# "message": "03c05f973d9c7218e7aec4f52c2c8ab395f51f41d627c398237b5ff056f46faf09: unknown destination node_id (no public channels?)"
|
||||
# }
|
||||
#
|
||||
# {
|
||||
# "code": 206,
|
||||
# "message": "Route wanted fee of 16101625msat"
|
||||
# }
|
||||
#
|
||||
# {
|
||||
# "code": 207,
|
||||
# "message": "Invoice expired"
|
||||
# }
|
||||
#
|
||||
fi
|
||||
else
|
||||
# code tag not found
|
||||
|
||||
Reference in New Issue
Block a user