Skip to content

Commit

Permalink
Merge pull request #4170 from joostjager/fix-payment-fee
Browse files Browse the repository at this point in the history
lnrpc: fix payment marshalling
  • Loading branch information
Roasbeef committed Apr 10, 2020
2 parents b947ed5 + e61ff22 commit 2c2b79d
Show file tree
Hide file tree
Showing 5 changed files with 765 additions and 797 deletions.
22 changes: 6 additions & 16 deletions lnrpc/routerrpc/router_backend.go
Expand Up @@ -1095,29 +1095,20 @@ 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()
}
}

// Encode the hops from the successful route, if any.
path := make([]string, len(route.Hops))
for i, hop := range route.Hops {
path[i] = hex.EncodeToString(hop.PubKeyBytes[:])
}

msatValue := int64(payment.Info.Value)
satValue := int64(payment.Info.Value.ToSatoshis())

Expand Down Expand Up @@ -1153,10 +1144,9 @@ func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) (
ValueSat: satValue,
CreationDate: payment.Info.CreationTime.Unix(),
CreationTimeNs: creationTimeNS,
Path: path,
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 2c2b79d

Please sign in to comment.