mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
Merge pull request #4170 from joostjager/fix-payment-fee
lnrpc: fix payment marshalling
This commit is contained in:
commit
2c2b79d300
@ -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())
|
||||
|
||||
@ -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,
|
||||
|
1517
lnrpc/rpc.pb.go
1517
lnrpc/rpc.pb.go
File diff suppressed because it is too large
Load Diff
@ -3097,8 +3097,7 @@ message Payment {
|
||||
/// Deprecated, use creation_time_ns
|
||||
int64 creation_date = 3 [deprecated = true];
|
||||
|
||||
/// The path this payment took.
|
||||
repeated string path = 4 [deprecated = true];
|
||||
reserved 4;
|
||||
|
||||
/// Deprecated, use fee_sat or fee_msat.
|
||||
int64 fee = 5 [deprecated = true];
|
||||
|
@ -3936,13 +3936,6 @@
|
||||
"format": "int64",
|
||||
"title": "/ Deprecated, use creation_time_ns"
|
||||
},
|
||||
"path": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "/ The path this payment took."
|
||||
},
|
||||
"fee": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
|
@ -4336,15 +4336,12 @@ func testListPayments(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
len(paymentsResp.Payments), 1)
|
||||
}
|
||||
p := paymentsResp.Payments[0]
|
||||
path := p.Htlcs[len(p.Htlcs)-1].Route.Hops
|
||||
|
||||
// Ensure that the stored path shows a direct payment to Bob with no
|
||||
// other nodes in-between.
|
||||
expectedPath := []string{
|
||||
net.Bob.PubKeyStr,
|
||||
}
|
||||
if !reflect.DeepEqual(p.Path, expectedPath) {
|
||||
t.Fatalf("incorrect path, got %v, want %v",
|
||||
p.Path, expectedPath)
|
||||
if len(path) != 1 || path[0].PubKey != net.Bob.PubKeyStr {
|
||||
t.Fatalf("incorrect path")
|
||||
}
|
||||
|
||||
// The payment amount should also match our previous payment directly.
|
||||
@ -14317,8 +14314,8 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
|
||||
// We wait for the payment attempt to have been
|
||||
// properly recorded in the DB.
|
||||
if len(payment.Path) == 0 {
|
||||
return fmt.Errorf("path is empty")
|
||||
if len(payment.Htlcs) == 0 {
|
||||
return fmt.Errorf("no attempt recorded")
|
||||
}
|
||||
|
||||
delete(payHashes, payment.PaymentHash)
|
||||
|
Loading…
Reference in New Issue
Block a user