lib: Calculate fees independent of VTXO order

I think this one can take a bit of explanation. I struggled a little bit with reviewing this and figuring out what the issue was.

Scenario

The root of the issue is that client and server compute fees slightly differently. Let's assume we will pay 15_000 sats and use the following vtxos as input.

Vtxo Amount Expiry fee_ppm
vtxo_b 10_000 sat 1001 0.2%
vtxo_a 10_000 sat 5000 0.5%

Client

The client will compute the following vtxos in soonest-to-expire order as inputs for the 15_000 sat payment.

The client expects to pay 45 sats for the fee.

Vtxo Amount Expiry fee_ppm Fee
vtxo_b 10_000 sat (fully used) 1001 0.2% 20 sat
vtxo_a 10_000 sat (5_000 used) 5000 0.5% 25 sat

Server

The server will compute fees with the vtxos sorted by id

Vtxo Amount Expiry fee_ppm Fee
vtxo_a 10_000 sat (fully used) 5000 0.5% 50 sat
vtxo_a 10_000 sat (5_000 used) 1001 0.2% 10 sat

The server will expect a fee of 60 sats and refuse the payment because the client only paid 45 sats

What this MR does

This MR ensures that the server also sorts on expiry and computes the cheapest possible fee.

This prevents us from falsely refusing stuff

  • check or remove this line after you've added a CHANGELOG entry or if your PR doesn't need one (they should go into CHANGELOG/unreleased/)
Edited by Peter

Merge request reports

Loading