Reconcile the actual fee of a completed Lightning payment
A route estimate can differ from the payment that ultimately succeeds. The sender's completed payment record gives the delivered amount and the amount actually sent.
Read the completed payment
Set HASH to the payment hash of an outgoing invoice. The jq filter excludes records without both amount fields. These amounts are in millisatoshis.
lightning-cli -k listpays payment_hash="$HASH" status=complete | jq '.pays[] | select(.amount_msat != null and .amount_sent_msat != null) | {payment_hash, fee_msat: (.amount_sent_msat - .amount_msat)}'
Record the difference once
Sending 3,015,000 msat to deliver 3,000,000 msat costs 15,000 msat, or 15 sat. For a multipart payment use the aggregate record for this calculation. Lower-level attempts remain useful for diagnosis, but adding their values again would double count the settled payment.