Skip to content

Conversation

@elsirion
Copy link
Contributor

@elsirion elsirion commented Jan 20, 2026

This PR adds a function to the client that calculates the total federation fees paid during an operation. This is done by subtracting the total outputs from the total inputs of all transactions within an operation.

For that I had to add functions to the client module interface that return the amount represented by an input/output and for all but LNv2 this was pretty easy. Unfortunately, to avoid redundancy and extra checks against inconsistency, LNv2 doesn't include the amount in its inputs (it's deterministically defined by the contract being claimed). So for that case I needed to add a cache of all contracts the client ever interacted with.

For implementation complexity reasons the function returns an option and returns none for LNv2 transactions from before the functionality was enabled.

Considered Approaches

The question now is, what to do about old transactions for which that cache isn't populated yet? Two-ish options:

  1. DB migration: we could add a DB migration that fills the cache from the state machine history. Unfortunately, while we have all the contracts, we don't have OutPoints for incoming ones (and these are used to identify contracts). That means we'd have to find some way to fetch these from the federation again, either in the DB migration or in a process that is started after.
  2. Ignore old LNv2 tx: make the function fallible and just ignore any old LNv2 tx from before contract caching started. UIs will just have to show a ? or something for fees for these, but LNv2 isn't that widely adopted yet anyway, so that's likely ok.

There's a hybrid approach where we do a DB migration for outgoing contracts where we have the out point, but idk if that's worth it once go route 2 anyway.

@elsirion elsirion force-pushed the 2026-01-fee-endpoint branch from 41a1303 to e8efaa3 Compare January 27, 2026 13:43
This function can be used to calculate federation fees paid for an
operaton retroactively. E.g. ecash fees can't be determined ahead
of time, so the best we can do is report them after the fact.
@elsirion elsirion force-pushed the 2026-01-fee-endpoint branch from e8efaa3 to cf1869d Compare January 27, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant