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

CC BY-SA 4.0
2022-10-14T00:09:43.273Z
Yes, you are right. Thank you, Rene!
Tasos Sidiropoulos
CC BY-SA 4.0
2022-10-14T00:13:49.410Z
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.
Tasos Sidiropoulos
CC BY-SA 4.0
2022-10-15T03:29:55.140Z
But it specifies all relevant variabls as integers. But I agree it could be more specific. You could open an issue or PR
Rene Pickhardt
CC BY-SA 4.0
2022-10-12T14:56:24.207Z
2022-10-12T14:56:24.207Z
Rene Pickhardt
<p>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):</p>
<p>CHAN1 (base fee: 1000,  ppm: 9)<br />
647868x2102x1 (base fee: 0, ppm: 5000)<br />
751905x3128x0 (base fee: 0, ppm: 5000)<br />
751905x3125x0 (base fee: 1000, ppm: 1)</p>
<p>The route that lightning-cli returns is the following:</p>
<pre><code>&quot;route&quot;: [
   {
      &quot;id&quot;: &quot;0298f6074a454a1f5345cb2a7c6f9fce206cd0bf675d177cdbf0ca7508dd28852f&quot;,
      &quot;channel&quot;: &quot;CHAN1&quot;,
      &quot;direction&quot;: 1,
      &quot;msatoshi&quot;: 101505,
      &quot;amount_msat&quot;: &quot;101505msat&quot;,
      &quot;delay&quot;: 123,
      &quot;style&quot;: &quot;tlv&quot;
   },
   {
      &quot;id&quot;: &quot;023d70f2f76d283c6c4e58109ee3a2816eb9d8feb40b23d62469060a2b2867b77f&quot;,
      &quot;channel&quot;: &quot;647868x2102x1&quot;,
      &quot;direction&quot;: 1,
      &quot;msatoshi&quot;: 101505,
      &quot;amount_msat&quot;: &quot;101505msat&quot;,
      &quot;delay&quot;: 89,
      &quot;style&quot;: &quot;tlv&quot;
   },
   {
      &quot;id&quot;: &quot;0265c45476ef53365755f7076eef987965f308b04dba1d8f74638e75b3164eafdd&quot;,
      &quot;channel&quot;: &quot;751905x3128x0&quot;,
      &quot;direction&quot;: 0,
      &quot;msatoshi&quot;: 101000,
      &quot;amount_msat&quot;: &quot;101000msat&quot;,
      &quot;delay&quot;: 49,
      &quot;style&quot;: &quot;tlv&quot;
   },
   {
      &quot;id&quot;: &quot;026165850492521f4ac8abd9bd8088123446d126f648ca35e60f88177dc149ceb2&quot;,
      &quot;channel&quot;: &quot;751905x3125x0&quot;,
      &quot;direction&quot;: 1,
      &quot;msatoshi&quot;: 100000,
      &quot;amount_msat&quot;: &quot;100000msat&quot;,
      &quot;delay&quot;: 9,
      &quot;style&quot;: &quot;tlv&quot;
   }
]
</code></pre>
<p>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.</p>
<p>I thought the correct fee is:<br />
math.ceil(base + 100,000 * ppm) = math.ceil(1,000 + 100,000 * (1/1,000,000)) = math.ceil(1,000.1) = 1,001 msats.</p>
<p>What is the correct formula?</p>

<lightning-network><lightning-routing><lightning-fees>
Problem calculating routing fees
Tasos Sidiropoulos
# Problem calculating routing fees

(Asked by: username_0 on 2022-10-12)

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?

**Tags:** lightning-network, lightning-routing, lightning-fees


---

## 1 answers

### Answer by username_1 on 2022-10-12. Score: 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`

> **Comments:**
> **username_0**: Yes, you are right. Thank you, Rene!  
> **username_0**: 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.  
> **username_1**: But it specifies all relevant variabls as integers. But I agree it could be more specific. You could open an issue or PR  

---

