Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: skip fee probe for flagged destinations #1505

Merged
merged 8 commits into from
Aug 1, 2022
Merged

Conversation

vindard
Copy link
Contributor

@vindard vindard commented Aug 1, 2022

Description

This PR fixes an issue where some services will always fail the fee probe whether there is a route or not (e.g. Muun). This is an issue because the attempt is logged in lnd's mission-control and it blocks any real payments attempts that are tried soon after the probe.

This PR allows us to configure flagged destinations that will fail and to skip the probe and simply return a max fee for these routes.

Related issues:

src/config/schema.ts Outdated Show resolved Hide resolved

skipFeeProbe:
muun:
- "038f8f113c580048d847d6949371726653e02b928196bad310e3eda39ff61723f6"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on muun we should not skip the final hop, but the penultimate (one before last) node.

because muun uses a private channel for the last hop.

ie: the last hop will be an unpublished nodes, but if you look at the route hints encoded in the invoice, they would both be linked between muun and this unpublished nodes.

is that something you taken into consideration in this PR?

Copy link
Contributor Author

@vindard vindard Aug 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, it's captured in the code logic and in the test (test has an actual Muun invoice)

src/config/utils.ts Outdated Show resolved Hide resolved
@@ -855,6 +889,40 @@ describe("UserWallet - Lightning Pay", () => {
expect(balanceAfter).toBe(0)
})

it("skips fee probe for flagged pubkeys", async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't like that this is an integration test. The logic doesn't depend on user input - should be a unit test.

Copy link
Contributor Author

@vindard vindard Aug 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added domain + unit test changes (1ba3743), but I think this integration test is still useful to confirm that the lnd service method isn't actually being called when we're using domain calculated states to pull together the final use-case.

amount: btcPaymentAmount,
})
const skipProbe =
intersect(parseFinalHopsFromInvoice(invoice), getPubkeysToSkipProbe()).length > 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this logic belongs inside the builder - it can take the pub keys to skip as config:

type LightningPaymentFlowBuilderConfig = {
  localNodeIds: Pubkey[]
  skipProbeKeys: Pubkey[]
  usdFromBtcMidPriceFn: UsdFromBtcMidPriceFn
  btcFromUsdMidPriceFn: BtcFromUsdMidPriceFn
}

or something like that.

This step:

type LPFBWithConversion<S extends WalletCurrency, R extends WalletCurrency> = {
  withRoute({
    pubkey,
    rawRoute,
  }: {
    pubkey: Pubkey
    rawRoute: RawRoute
  }): Promise<PaymentFlow<S, R> | ValidationError | DealerPriceServiceError>
  withoutRoute(): Promise<PaymentFlow<S, R> | ValidationError | DealerPriceServiceError>

  btcPaymentAmount(): Promise<BtcPaymentAmount | DealerPriceServiceError>
  usdPaymentAmount(): Promise<UsdPaymentAmount | DealerPriceServiceError>

  isIntraLedger(): Promise<boolean | DealerPriceServiceError>
}

Already has some query methods - could also add another one shouldSkipProbe?

There is no way this logic should be integration tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: 1ba3743

@@ -188,3 +188,7 @@ kratosConfig:

captcha:
mandatory: false

skipFeeProbe:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just an array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it would be useful to have some context if we had to add any other services.

Copy link
Member

@nicolasburtey nicolasburtey Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree with @dolcalmi that just a series of keys would be enough.

you could have the name of the service in comments, or it's easy enough to fetch it otherwise.

ie:

skipFeeProbe:
  - "038f8f113c580048d847d6949371726653e02b928196bad310e3eda39ff61723f6" # muun

src/domain/payments/payment-flow-builder.ts Show resolved Hide resolved
@@ -415,6 +415,7 @@ export const mapError = (error: ApplicationError): CustomApolloError => {
case "SafeWrapperError":
case "InvalidFeeProbeStateError":
case "InvalidPubKeyError":
case "SkipProbeForPubkeyError":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have a custom message. Sending Unknown error occurred is not good for this case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to satisfy the type checker. This error never gets returned to the user right now. It's just used in a conditional to determine if to call withoutRoute or withRoute on the builder.

usdFromBtcMidPriceFn,
btcFromUsdMidPriceFn,
},
flaggedPubkeys: getPubkeysToSkipProbe(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good except I don't understand the extra config key... flaggedPubkeys is also config isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good except I don't understand the extra config key... flaggedPubkeys is also config isn't it?

Yup I noticed this literally after I pushed the last commit. Changed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants