Merge pull request #4170 from joostjager/fix-payment-fee

lnrpc: fix payment marshalling
This commit is contained in:
Olaoluwa Osuntokun 2020-04-10 13:52:46 -07:00 committed by GitHub
commit 2c2b79d300
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 765 additions and 797 deletions

View File

@ -1095,29 +1095,20 @@ func marshallChannelUpdate(update *lnwire.ChannelUpdate) *lnrpc.ChannelUpdate {
func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) ( func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) (
*lnrpc.Payment, error) { *lnrpc.Payment, error) {
// Fetch the payment's route and preimage. If no HTLC was // Fetch the payment's preimage and the total paid in fees.
// successful, an empty route and preimage will be used.
var ( var (
route route.Route fee lnwire.MilliSatoshi
preimage lntypes.Preimage preimage lntypes.Preimage
) )
for _, htlc := range payment.HTLCs { for _, htlc := range payment.HTLCs {
// Display the last route attempted.
route = htlc.Route
// If any of the htlcs have settled, extract a valid // If any of the htlcs have settled, extract a valid
// preimage. // preimage.
if htlc.Settle != nil { if htlc.Settle != nil {
preimage = htlc.Settle.Preimage 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) msatValue := int64(payment.Info.Value)
satValue := int64(payment.Info.Value.ToSatoshis()) satValue := int64(payment.Info.Value.ToSatoshis())
@ -1153,10 +1144,9 @@ func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) (
ValueSat: satValue, ValueSat: satValue,
CreationDate: payment.Info.CreationTime.Unix(), CreationDate: payment.Info.CreationTime.Unix(),
CreationTimeNs: creationTimeNS, CreationTimeNs: creationTimeNS,
Path: path, Fee: int64(fee.ToSatoshis()),
Fee: int64(route.TotalFees().ToSatoshis()), FeeSat: int64(fee.ToSatoshis()),
FeeSat: int64(route.TotalFees().ToSatoshis()), FeeMsat: int64(fee),
FeeMsat: int64(route.TotalFees()),
PaymentPreimage: hex.EncodeToString(preimage[:]), PaymentPreimage: hex.EncodeToString(preimage[:]),
PaymentRequest: string(payment.Info.PaymentRequest), PaymentRequest: string(payment.Info.PaymentRequest),
Status: status, Status: status,

File diff suppressed because it is too large Load Diff

View File

@ -3097,8 +3097,7 @@ message Payment {
/// Deprecated, use creation_time_ns /// Deprecated, use creation_time_ns
int64 creation_date = 3 [deprecated = true]; int64 creation_date = 3 [deprecated = true];
/// The path this payment took. reserved 4;
repeated string path = 4 [deprecated = true];
/// Deprecated, use fee_sat or fee_msat. /// Deprecated, use fee_sat or fee_msat.
int64 fee = 5 [deprecated = true]; int64 fee = 5 [deprecated = true];

View File

@ -3936,13 +3936,6 @@
"format": "int64", "format": "int64",
"title": "/ Deprecated, use creation_time_ns" "title": "/ Deprecated, use creation_time_ns"
}, },
"path": {
"type": "array",
"items": {
"type": "string"
},
"description": "/ The path this payment took."
},
"fee": { "fee": {
"type": "string", "type": "string",
"format": "int64", "format": "int64",

View File

@ -4336,15 +4336,12 @@ func testListPayments(net *lntest.NetworkHarness, t *harnessTest) {
len(paymentsResp.Payments), 1) len(paymentsResp.Payments), 1)
} }
p := paymentsResp.Payments[0] 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 // Ensure that the stored path shows a direct payment to Bob with no
// other nodes in-between. // other nodes in-between.
expectedPath := []string{ if len(path) != 1 || path[0].PubKey != net.Bob.PubKeyStr {
net.Bob.PubKeyStr, t.Fatalf("incorrect path")
}
if !reflect.DeepEqual(p.Path, expectedPath) {
t.Fatalf("incorrect path, got %v, want %v",
p.Path, expectedPath)
} }
// The payment amount should also match our previous payment directly. // 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 // We wait for the payment attempt to have been
// properly recorded in the DB. // properly recorded in the DB.
if len(payment.Path) == 0 { if len(payment.Htlcs) == 0 {
return fmt.Errorf("path is empty") return fmt.Errorf("no attempt recorded")
} }
delete(payHashes, payment.PaymentHash) delete(payHashes, payment.PaymentHash)