diff --git a/config/default.js b/config/default.js index a70129b4ca4..585c20d0351 100644 --- a/config/default.js +++ b/config/default.js @@ -103,8 +103,13 @@ module.exports = { useAddressFallback: false, retryCount: 2, // Number of retries for pay invoice failure feeIncrementExponent: 1.1, // Exponent applied to fee limit on payment retry attempts - probeTimeout: 30, // Upper limit on the amount of time (s) we should spend when attempting to probe the payment - paymentTimeout: 30, // Upper limit on the amount of time (s) we should spend when attempting to fulfill the payment + }, + + payments: { + timeout: 30, // Upper limit on the amount of time (s) we should spend when attempting to probe a payment + feeLimit: 1000, // Upper limit on the routing fees we should accept when sending payment without a limit + probeTimeout: 30, // Upper limit on the amount of time (s) we should spend when attempting to send a payment + probeFeeLimit: 1000, // Upper limit on the routing fees we want to consider in payment probes }, autopay: { diff --git a/renderer/reducers/payment.js b/renderer/reducers/payment.js index d5e0e269b97..d18b4bf3d4b 100644 --- a/renderer/reducers/payment.js +++ b/renderer/reducers/payment.js @@ -279,6 +279,7 @@ export const payInvoice = ({ if (infoSelectors.hasRouterSupport(getState())) { payload = { ...payload, + feeLimit, timeoutSeconds: PAYMENT_TIMEOUT, } diff --git a/services/grpc/router.methods.js b/services/grpc/router.methods.js index 6f6f23be127..ed7df92bcb2 100644 --- a/services/grpc/router.methods.js +++ b/services/grpc/router.methods.js @@ -1,10 +1,16 @@ import { randomBytes } from 'crypto' import config from 'config' -import get from 'lodash/get' +import defaults from 'lodash/defaults' +import omitBy from 'lodash/omitBy' +import isNil from 'lodash/isNil' import { grpcLog } from '@zap/utils/log' import { logGrpcCmd } from './helpers' -const PAYMENT_PROBE_TIMEOUT = config.invoices.probeTimeout +const PAYMENT_TIMEOUT = config.payments.timeout +const PAYMENT_FEE_LIMIT = config.payments.feeLimit + +const PAYMENT_PROBE_TIMEOUT = config.payments.probeTimeout +const PAYMENT_PROBE_FEE_LIMIT = config.payments.probeFeeLimit // ------------------------------------ // Wrappers / Overrides @@ -17,15 +23,15 @@ const PAYMENT_PROBE_TIMEOUT = config.invoices.probeTimeout * @returns {Promise} The route route when state is SUCCEEDED */ async function probePayment(options) { - logGrpcCmd('Router.probePayment', options) - // Use a payload that has the payment hash set to some random bytes. // This will cause the payment to fail at the final destination. - const payload = { - ...options, + const payload = defaults(omitBy(options, isNil), { payment_hash: new Uint8Array(randomBytes(32)), - timeout_seconds: get(options, 'timeout_seconds', PAYMENT_PROBE_TIMEOUT), - } + timeout_seconds: PAYMENT_PROBE_TIMEOUT, + fee_limit_sat: PAYMENT_PROBE_FEE_LIMIT, + }) + + logGrpcCmd('Router.probePayment', payload) let result let error @@ -84,10 +90,17 @@ async function probePayment(options) { /** * sendPayment - Call lnd grpc sendPayment method. * - * @param {object} payload Payload + * @param {object} options Options * @returns {Promise} Original payload augmented with lnd sendPayment response data */ -async function sendPayment(payload = {}) { +async function sendPayment(options = {}) { + // Use a payload that has the payment hash set to some random bytes. + // This will cause the payment to fail at the final destination. + const payload = defaults(omitBy(options, isNil), { + timeout_seconds: PAYMENT_TIMEOUT, + fee_limit: PAYMENT_FEE_LIMIT, + }) + logGrpcCmd('Router.sendPayment', payload) // Our response will always include the original payload.