Skip to content

Commit

Permalink
lnrpc: report total fees paid
Browse files Browse the repository at this point in the history
Fixes a bug where only the fees of the last route where reported.
  • Loading branch information
joostjager committed Apr 10, 2020
1 parent 06f73c0 commit e61ff22
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lnrpc/routerrpc/router_backend.go
Expand Up @@ -1095,20 +1095,17 @@ func marshallChannelUpdate(update *lnwire.ChannelUpdate) *lnrpc.ChannelUpdate {
func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) (
*lnrpc.Payment, error) {

// Fetch the payment's route and preimage. If no HTLC was
// successful, an empty route and preimage will be used.
// Fetch the payment's preimage and the total paid in fees.
var (
route route.Route
fee lnwire.MilliSatoshi
preimage lntypes.Preimage
)
for _, htlc := range payment.HTLCs {
// Display the last route attempted.
route = htlc.Route

// If any of the htlcs have settled, extract a valid
// preimage.
if htlc.Settle != nil {
preimage = htlc.Settle.Preimage
fee += htlc.Route.TotalFees()
}
}

Expand Down Expand Up @@ -1147,9 +1144,9 @@ func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) (
ValueSat: satValue,
CreationDate: payment.Info.CreationTime.Unix(),
CreationTimeNs: creationTimeNS,
Fee: int64(route.TotalFees().ToSatoshis()),
FeeSat: int64(route.TotalFees().ToSatoshis()),
FeeMsat: int64(route.TotalFees()),
Fee: int64(fee.ToSatoshis()),
FeeSat: int64(fee.ToSatoshis()),
FeeMsat: int64(fee),
PaymentPreimage: hex.EncodeToString(preimage[:]),
PaymentRequest: string(payment.Info.PaymentRequest),
Status: status,
Expand Down

0 comments on commit e61ff22

Please sign in to comment.