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) (
*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,

File diff suppressed because it is too large Load Diff

View File

@ -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];

View File

@ -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",

View File

@ -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)