Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature]: persist payment+invoice HTLC custom wire records and return them in RPCs #1091

Open
1 task
lukegao209 opened this issue Aug 19, 2024 · 8 comments
Open
1 task
Assignees
Labels
dependencies Pull requests that update a dependency file enhancement New feature or request gRPC P2 payment-channel tap-channels user request
Milestone

Comments

@lukegao209
Copy link
Contributor

lukegao209 commented Aug 19, 2024

[Maintainer edit: Depends on lightningnetwork/lnd/issues/8769]
[Maintainer edit]: TODO

  • extend itests in litd to ensure this property holds

Is your feature request related to a problem? Please describe.
When using stable-coins to pay a regular BTC invoice, the user is effectively selling stable-coins and buying BTC.
However, the current sendPayment interface does not return the amount of stable-coins sold, making it difficult for the Edge Node to maintain its balance and perform reconciliation. This is nearly the final step required for the Edge Node to operate normally.
hope this can be addressed with high priority by:

  1. Having the sendPayment API return SendPaymentResponse_AcceptedSellOrder, and
  2. Providing an query api to retrieve historical information
type SendPaymentResponse struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	// Types that are assignable to Result:
	//
	//	*SendPaymentResponse_AcceptedSellOrder
	//	*SendPaymentResponse_PaymentResult
	Result isSendPaymentResponse_Result `protobuf_oneof:"result"`
}
for {
		select {
		case <-ctx.Done():
			return ctx.Err()

		case <-r.quit:
			return fmt.Errorf("server shutting down")

		default:
		}

		update, err := updateStream.Recv()
		if err != nil {
			return err
		}

		err = stream.Send(&tchrpc.SendPaymentResponse{
			Result: &tchrpc.SendPaymentResponse_PaymentResult{
				PaymentResult: update,
			},
		})
		if err != nil {
			return err
		}
	}
@lukegao209 lukegao209 added the enhancement New feature or request label Aug 19, 2024
@guggero guggero self-assigned this Aug 19, 2024
@guggero
Copy link
Member

guggero commented Aug 19, 2024

Thanks for the feature request.
I'm not sure I understand the first part of it. We already do send the SendPaymentResponse_AcceptedSellOrder here:

err = stream.Send(&tchrpc.SendPaymentResponse{

That is only sent when paying an invoice though, not when using keysend.
Do you not receive that message?

For the second part, I'm going to extend the lnd RPCs with the custom data fields that we also have for ListChannels, PendingChannels and ChannelBalance.

Adding the custom data to the lnrpc.InvoiceHtlc and lnrpc.HtlcAttempt should be enough for you to find out how many assets you received for an invoice or how many you paid for a payment.
Does that sound good?

@lukegao209
Copy link
Contributor Author

For the first part, it seems that the assets amount is not being returned

image

image

@lukegao209
Copy link
Contributor Author

Adding the custom data to the lnrpc.InvoiceHtlc and lnrpc.HtlcAttempt should be enough for you to find out how many assets you received for an invoice or how many you paid for a payment.

For the second part, I agree with you; it seems like a great idea.

@guggero
Copy link
Member

guggero commented Aug 19, 2024

But you do get the SendPaymentResponse_AcceptedSellOrder response, right?
Then you can calculate the number of assets exactly like this:

numUnits := uint64(*invoice.MilliSat) / msatPerUnit

@guggero guggero changed the title [feature]: taprpc return SendPaymentResponse_AcceptedSellOrder SendPayment in api [feature]: persist payment+invoice HTLC custom wire records and return them in RPCs Aug 19, 2024
@guggero
Copy link
Member

guggero commented Aug 19, 2024

I looked into the second part ("Providing an query api to retrieve historical information") a bit more and it looks like that's not going to be super quick. We don't currently persist the wire-level custom message data that's attached to the HTLCs in the invoice and payments. We need to add that in lnd first, see some of the open issues here: lightningnetwork/lnd#8769

So as a workaround you unfortunately need to store the buy or sell quote from the AddInvoice or SendPayment calls so you can calculate the number of units as mentioned above.

We'll look into fixing this soon, but can't promise anything as it's quite a bit of work required still.

@lukegao209
Copy link
Contributor Author

I looked into the second part ("Providing an query api to retrieve historical information") a bit more and it looks like that's not going to be super quick. We don't currently persist the wire-level custom message data that's attached to the HTLCs in the invoice and payments. We need to add that in lnd first, see some of the open issues here: lightningnetwork/lnd#8769

So as a workaround you unfortunately need to store the buy or sell quote from the AddInvoice or SendPayment calls so you can calculate the number of units as mentioned above.

We'll look into fixing this soon, but can't promise anything as it's quite a bit of work required still.

understand. thanks

@dstadulis dstadulis added gRPC dependencies Pull requests that update a dependency file user request labels Aug 23, 2024
@dstadulis dstadulis added this to the v0.4.2 milestone Aug 23, 2024
@Roasbeef Roasbeef added the P2 label Aug 27, 2024
@dstadulis
Copy link
Collaborator

Part 3 and 5 of staging branch will ship this

@guggero
Copy link
Member

guggero commented Sep 17, 2024

We'll want to update the litd integration tests to assert these changes though, so won't be exclusively fixed by the mega staging branch being fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement New feature or request gRPC P2 payment-channel tap-channels user request
Projects
Status: 👀 In review
Development

No branches or pull requests

4 participants