0

I'm trying to compute the routing fees for a lightning network payment of 100,000 msats. The route uses the following sequence of channels (CHAN1 is not shown for privacy reasons):

CHAN1 (base fee: 1000, ppm: 9)
647868x2102x1 (base fee: 0, ppm: 5000)
751905x3128x0 (base fee: 0, ppm: 5000)
751905x3125x0 (base fee: 1000, ppm: 1)

The route that lightning-cli returns is the following:

"route": [
   {
      "id": "0298f6074a454a1f5345cb2a7c6f9fce206cd0bf675d177cdbf0ca7508dd28852f",
      "channel": "CHAN1",
      "direction": 1,
      "msatoshi": 101505,
      "amount_msat": "101505msat",
      "delay": 123,
      "style": "tlv"
   },
   {
      "id": "023d70f2f76d283c6c4e58109ee3a2816eb9d8feb40b23d62469060a2b2867b77f",
      "channel": "647868x2102x1",
      "direction": 1,
      "msatoshi": 101505,
      "amount_msat": "101505msat",
      "delay": 89,
      "style": "tlv"
   },
   {
      "id": "0265c45476ef53365755f7076eef987965f308b04dba1d8f74638e75b3164eafdd",
      "channel": "751905x3128x0",
      "direction": 0,
      "msatoshi": 101000,
      "amount_msat": "101000msat",
      "delay": 49,
      "style": "tlv"
   },
   {
      "id": "026165850492521f4ac8abd9bd8088123446d126f648ca35e60f88177dc149ceb2",
      "channel": "751905x3125x0",
      "direction": 1,
      "msatoshi": 100000,
      "amount_msat": "100000msat",
      "delay": 9,
      "style": "tlv"
   }
]

The second to last channel is routing 101,000 msat, which means that the second to last node (0265c4...) receives 1,000 msats as a routing fee. I don't understand how this number is calculated.

I thought the correct fee is:
math.ceil(base + 100,000 * ppm) = math.ceil(1,000 + 100,000 * (1/1,000,000)) = math.ceil(1,000.1) = 1,001 msats.

What is the correct formula?

1 Answer 1

0

I think the confusion is that you assume math.ceil. I believe once everything is expressed in msat everything after the decimal is truncated. so yes while your computation of 1,000.1 is correct the .1 will be truncated. I think you can just think of a casting to int as in int(1,000.1)=1,000 I think msat is just considered to be u_int

3
  • Yes, you are right. Thank you, Rene! Oct 14, 2022 at 0:09
  • Btw, I think the wording in BOLT 7 is confusing: "SHOULD accept HTLCs that pay a fee equal to or greater than: fee_base_msat + ( amount_to_forward * fee_proportional_millionths / 1000000 )". It doesn't specify that this is integer division. Oct 14, 2022 at 0:13
  • But it specifies all relevant variabls as integers. But I agree it could be more specific. You could open an issue or PR Oct 15, 2022 at 3:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.