Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix(lnd): use route hints from invoice when probing
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed May 18, 2020
1 parent 88a9bf2 commit f46938b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@
"bip21": "2.0.3",
"bip39-en": "1.1.1",
"bitcoinjs-lib": "5.1.7",
"bolt07": "1.5.0",
"bolt11": "1.2.7",
"coininfo": "https://github.com/LN-Zap/coininfo#d7ac7be9c9c4ee74dada187f7762a55887a9c6ca",
"comlinkjs": "3.2.0",
Expand Down
12 changes: 12 additions & 0 deletions renderer/reducers/payment/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import config from 'config'
import get from 'lodash/get'
import cloneDeep from 'lodash/cloneDeep'
import { chanNumber } from 'bolt07'
import { getTag, decodePayReq, getNodeAlias, generatePreimage } from '@zap/utils/crypto'
import { convert } from '@zap/utils/btc'
import { getIntl } from '@zap/i18n'
Expand Down Expand Up @@ -184,12 +185,23 @@ export const prepareBolt11Probe = (payReq, feeLimit) => {
const invoice = decodePayReq(payReq)
const { millisatoshis, payeeNodeKey: pubkey } = invoice

// Extract route hints from the invoice.
const routingInfo = getTag(invoice, 'routing_info') || []
const hopHints = routingInfo.map(hint => ({
nodeId: hint.pubkey,
chanId: chanNumber({ id: hint.short_channel_id }).number,
feeBaseMsat: hint.fee_base_msat,
feeProportionalMillionths: hint.fee_proportional_millionths,
cltvExpiryDelta: hint.cltv_expiry_delta,
}))

return {
...getPaymentConfig(),
dest: Buffer.from(pubkey, 'hex'),
feeLimitSat: feeLimit,
amtMsat: millisatoshis,
finalCltvDelta: getTag(invoice, 'min_final_cltv_expiry') || DEFAULT_CLTV_DELTA,
routeHints: [{ hopHints }],
}
}

Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4810,6 +4810,11 @@ bluebird@^3.3.5, bluebird@^3.5.0, bluebird@^3.5.5:
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==

bn.js@5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.1.tgz#48efc4031a9c4041b9c99c6941d903463ab62eb5"
integrity sha512-IUTD/REb78Z2eodka1QZyyEk66pciRcP6Sroka0aI3tG/iwIdYLrBD62RsubR7vqdt3WyX8p4jxeatzmRSphtA==

bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.8, bn.js@^4.4.0:
version "4.11.8"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"
Expand All @@ -4831,6 +4836,13 @@ body-parser@1.19.0:
raw-body "2.4.0"
type-is "~1.6.17"

bolt07@1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/bolt07/-/bolt07-1.5.0.tgz#4200e574226c7d540a36e6cce42a35c9f4ac0213"
integrity sha512-56MzzIej8xP5Ksl+8AwOSMkbFWX9HG3/3qG+2lwxpvkoUQJVUSjyj/JKx+6qaJdarv1XcpNbtGfpixCKIlI+sg==
dependencies:
bn.js "5.1.1"

bolt11@1.2.7:
version "1.2.7"
resolved "https://registry.yarnpkg.com/bolt11/-/bolt11-1.2.7.tgz#75852e215aeb28d6ccd6dd7c721c09d8ccb40a88"
Expand Down

0 comments on commit f46938b

Please sign in to comment.