fedimint / fedimint

Federated E-Cash Mint
https://fedimint.org/
MIT License
568 stars 219 forks source link

Gateways should account for routing fees when deciding whether to pay an invoice #1519

Closed justinmoon closed 1 year ago

justinmoon commented 1 year ago

When user client's fund an outgoing contract, they currently choose an amount that is 1% more than the invoice amount. The gateway pays their routing fees from this fee and takes the rest as profit.

When deciding whether to pay an invoice or not, a gateway should take routing fees into account. Currently, it does not. It just checks if the outgoing account isn't more than the invoice amount. It should check invoice_amount + expected_routing_fees >= contract_amount. Left side is what gateway pays, right side is what it receives. Might want to also include a profit margin, but that's another topic.

justinmoon commented 1 year ago

Actually I think this is already enforced with the maxfeelimit parameter we send to the pay RPC to Core Lightning. The problem is that in practice routing doesn't work very well when we send the parameter on mainnet.

elsirion commented 1 year ago

Also, the % fee parameter is ignored for small payments that would have too low of a fee limit, which is actually an attack vector. Afaik the absolute fee limit option doesn't have this problem and we should use it.

justinmoon commented 1 year ago

Closing in favor of https://github.com/fedimint/fedimint/issues/524