blink icon indicating copy to clipboard operation
blink copied to clipboard

Standardize lighting invoice amount rounding

Open vindard opened this issue 3 years ago • 4 comments

Background

The Lightning Network is denominated in millisatoshis but amounts in our system are usually presented as a rounded version of satoshis.

Within lnd there are usually two types of token amounts quoted:

  • tokens: a rounded down version of millitokens
  • safe_tokens: a rounded up version of millitokens

In our own domain we express this distinction with the roundedUp- and roundedDown- prefixs, and you will see types defined as things like roundedUpAmount or roundedDownFees

Issue

There's a discrepancy in the amount we present in a fee probe and the amount we write to the ledger. These two values are usually off by exactly 1 satoshi and the issue may be coming from inconsistent rounding.

To observe the issue someone can:

  • call our lnInvoiceFeeProbe mutation with an invoice and note the fee returned
  • call our lnInvoicePaymentSend mutation with the same invoice and make sure it returns SUCCESS
  • fetch the last transaction via our me query and compare the fee recorded in the transaction

Suggested Task

This issue has two potential tiers to solve:

  1. Investigate and fix the immediate discrepancy

  2. Look at how we use roundedUp/roundedDown values across the codebase to see if there are any other potential discrepancies. My initial instinct is that we can probably standardize on using one of these (roundedUp- maybe) consistently and phase out our roundedDown- usage but this would need to be investigated.

vindard avatar Jan 27 '22 14:01 vindard

Hey @vindard I started working on this but am having trouble initiating lnInvoiceCreate to get a paymentRequest to start investigating lnInvoiceFeeProbe Do I need to be using a testnet invoice when mocking these API calls locally, or am I missing something else?

AustinKelsay avatar Feb 10 '22 02:02 AustinKelsay

Hey @vindard I started working on this but am having trouble initiating lnInvoiceCreate to get a paymentRequest to start investigating lnInvoiceFeeProbe Do I need to be using a testnet invoice when mocking these API calls locally, or am I missing something else?

Hey awesome, are you in our Slack yet?

With the dev setup it's testnet format yea. That one runs in regtest mode.

vindard avatar Feb 10 '22 02:02 vindard

Ahh ok that makes sense Not yet but I would love to join!

AustinKelsay avatar Feb 10 '22 02:02 AustinKelsay

Ahh ok that makes sense Not yet but I would love to join!

Can join here

vindard avatar Feb 10 '22 03:02 vindard