WIP: Add operation fee calculation function #8194
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.?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.