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

Add asset sell support to the RFQ service #835

Merged
merged 15 commits into from
Mar 28, 2024
Merged

Add asset sell support to the RFQ service #835

merged 15 commits into from
Mar 28, 2024

Conversation

ffranr
Copy link
Contributor

@ffranr ffranr commented Mar 14, 2024

Closes #818

This PR builds on top of the refactoring work from #814 .

It adds asset sell request and sell request accept support to the RFQ service.

@ffranr ffranr changed the title RFQ add sell support RFQ add asset sell support Mar 14, 2024
@ffranr ffranr force-pushed the rfq-add-sell-support branch 2 times, most recently from c37a1fd to cbc287a Compare March 14, 2024 15:20
@ffranr ffranr changed the title RFQ add asset sell support Add asset sell support to the RFQ service Mar 14, 2024
@dstadulis dstadulis added the rfq label Mar 14, 2024
@dstadulis
Copy link
Collaborator

There's local code
need to rebase code
getting the itest

Base automatically changed from rfq-sell-asset to main March 15, 2024 11:03
@ffranr ffranr force-pushed the rfq-add-sell-support branch 5 times, most recently from 08b298f to 35e9ce6 Compare March 18, 2024 19:34
@ffranr
Copy link
Contributor Author

ffranr commented Mar 18, 2024

I'm not sure how to setup the itest for the case where we sell a tap asset as the payment to satisfy the first hop in a lightning payment route.

Alice wants to pay Carol. Carol generates the invoice.

Alice wants to sell a tap asset to Bob, and Alice would like Bob to send the bid payment in that sale to Carol. In so doing Bob would satisfy the invoice that Carol generated for Alice.

I can currently:

  • Reach a sale quote agreement between Alice and Bob.
  • Generate an invoice with Carol.
  • Generate a custom route from Alice, to Bob, and then to Carol.

Bob can use his RFQ service to listen for a HTLC from Alice that satisfies the agreed Alice sale quote. And Alice can create a custom route with an input amount of 0 to Bob, but then stipulate that Bob must pay Carol the balance agreed upon in Alice-Bob's sale quote.

Is that the way forward? @guggero ?

@guggero
Copy link
Member

guggero commented Mar 18, 2024

There are important parts missing on the lnd side for this to work fully. So we need to find a compromise so we can test something. I think what we discussed offline at some point was that for now Alice would embed custom data to Bob (the same way you can embed dest_custom_records for the final receiver, we'd want to include a custom TLV record for Bob, I think we found that the SendToRoute might allow that or might need some additions to allow for it).
The custom data at this moment could just be the RFQ ID. Then Bob's tapd could intercept the HTLC, decode the custom record data and check that an offer with that RFQ ID exists, then check that the outgoing amount matches that offer.

@ffranr
Copy link
Contributor Author

ffranr commented Mar 19, 2024

There are important parts missing on the lnd side for this to work fully. So we need to find a compromise so we can test something. I think what we discussed offline at some point was that for now Alice would embed custom data to Bob (the same way you can embed dest_custom_records for the final receiver, we'd want to include a custom TLV record for Bob, I think we found that the SendToRoute might allow that or might need some additions to allow for it). The custom data at this moment could just be the RFQ ID. Then Bob's tapd could intercept the HTLC, decode the custom record data and check that an offer with that RFQ ID exists, then check that the outgoing amount matches that offer.

@guggero In the asset buy payment initiation case the HTLC intercepting node uses the SCID to identify the relevant HTLC. Both peers are aware of the SCID as it is present in the accepted quote (SCID is derived from message ID). Why do we need custom records? Can't we just forward a HTLC over the accepted quote SCID?

@ffranr ffranr force-pushed the rfq-add-sell-support branch 2 times, most recently from 746b5af to d2bc336 Compare March 19, 2024 16:11
@guggero
Copy link
Member

guggero commented Mar 19, 2024

@guggero In the asset buy payment initiation case the HTLC intercepting node uses the SCID to identify the relevant HTLC. Both peers are aware of the SCID as it is present in the accepted quote (SCID is derived from message ID). Why do we need custom records? Can't we just forward a HTLC over the accepted quote SCID?

Oh, you're right, we have the incoming_channel_id, I wasn't aware of that. I thought we'd only have the outgoing one, which in this case would be a "real" channel in the network. But then yes, we can just use the quote SCID to match things, no need for custom records.

@ffranr ffranr force-pushed the rfq-add-sell-support branch from d2bc336 to a9a93fe Compare March 19, 2024 17:42
@ffranr
Copy link
Contributor Author

ffranr commented Mar 19, 2024

@guggero In the asset buy payment initiation case the HTLC intercepting node uses the SCID to identify the relevant HTLC. Both peers are aware of the SCID as it is present in the accepted quote (SCID is derived from message ID). Why do we need custom records? Can't we just forward a HTLC over the accepted quote SCID?

Oh, you're right, we have the incoming_channel_id, I wasn't aware of that. I thought we'd only have the outgoing one, which in this case would be a "real" channel in the network. But then yes, we can just use the quote SCID to match things, no need for custom records.

I've managed to get the custom records method to work with a custom route. But I didn't manage to forward a HTLC when I set ChanId on the custom route or set the incoming channel on a hop hint. Not sure what's going on there, perhaps LND is rejecting the channel ID given that an actual channel exists.

@ffranr
Copy link
Contributor Author

ffranr commented Mar 19, 2024

I wander if the itest error is because of some side effect from the other RFQ itest. Passes locally for me.

The first 10 commits can be split out into a separate PR. They are effectively refactor commits.

@ffranr ffranr force-pushed the rfq-add-sell-support branch from a9a93fe to 4c382c4 Compare March 19, 2024 18:17
@ffranr ffranr marked this pull request as ready for review March 19, 2024 18:20
@dstadulis
Copy link
Collaborator

itests are failing when running together

@dstadulis
Copy link
Collaborator

@ffranr will split out PRs to get merge faster

@ffranr ffranr self-assigned this Mar 19, 2024
@ffranr ffranr changed the base branch from main to rfq-refactor-for-sell-support March 19, 2024 18:50
@ffranr ffranr marked this pull request as draft March 19, 2024 18:51
@ffranr ffranr requested review from guggero and GeorgeTsagk March 22, 2024 12:48
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, very nice work 🎉
Just a few minor comments

rfqmsg/sell_request.go Show resolved Hide resolved
rfq/negotiator.go Outdated Show resolved Hide resolved
rfqmsg/sell_accept.go Outdated Show resolved Hide resolved
rfq/negotiator.go Show resolved Hide resolved
taprpc/rfqrpc/rfq.proto Outdated Show resolved Hide resolved
taprpc/rfqrpc/rfq.proto Show resolved Hide resolved
rpcserver.go Show resolved Hide resolved
itest/rfq_test.go Outdated Show resolved Hide resolved
itest/rfq_test.go Outdated Show resolved Hide resolved
itest/rfq_test.go Outdated Show resolved Hide resolved
Copy link
Member

@GeorgeTsagk GeorgeTsagk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, a few Qs
very nice commit structure

rfq/manager.go Show resolved Hide resolved
rfq/negotiator.go Show resolved Hide resolved
rfq/negotiator.go Show resolved Hide resolved
itest/rfq_test.go Show resolved Hide resolved
itest/rfq_test.go Outdated Show resolved Hide resolved
@ffranr ffranr force-pushed the rfq-add-sell-support branch 2 times, most recently from 560845d to 611353a Compare March 26, 2024 18:17
ffranr added 13 commits March 26, 2024 19:15
This commit adds an RPC endpoint for uploading an asset sell order to
the RFQ service manager. This asset sell order will be converted into
a sell request (or multiple) by the RFQ service negotiator.
Up until this commit in the PR, we've constructed sell request messages
and have sent them to our peer (outgoing).

In this commit we start modifying the RFQ service such that it can also
receive those sell request messages from peers.
We will use this new type in a subsequent commit where we respond to an
incoming sell request message.
In this commit we enhance the RFQ service such that the manager directs
an incoming (from a peer) asset sell quote request message to the
RFQ negotiator sub-service. The negotiator then populates the outgoing
messages channel with a sell request accept message. This message will
eventually be forwarded to the peer by the streamer RFQ sub-service.
This commit adds a new policy type to the order handler RFQ service. The
new policy type is specific to asset purchases (where the counterparty
has requested to sell an asset to our node). With this new type we can
check that a HTLC is valid in the context of an asset purchase
specifically.

In this commit we ensure that before an asset sell quote request accept
message is sent to our peer, the RFQ order handler registers a new
asset purchase policy.
In this commit, we enable parsing of sell quote request accept messages
from wire messages. We also store incoming (sent from our peer) asset
sell quote request messages in the RFQ manager.
In this commit we add a new RFQ event type `PeerAcceptedSellQuoteEvent`.
This event is published to RFQ event subscribers when the RFQ service
receives an asset sell quote request accept message from a peer.
In this commit we extend RPC endpoint `QueryPeerAcceptedQuotes` such
that it returns peer accepted sell quotes in addition to the existing
peer accepted buy quotes.

This change also includes expanding the RFQ manager
`QueryPeerAcceptedQuotes` method return values.
The goal of this commit is to simplify troubleshooting LND node
management.
The RFQ test scenario generates new LND nodes. In this commit we modify
the test scenario cleanup routine to ensure that those nodes are killed
at the end of each test.
@ffranr ffranr force-pushed the rfq-add-sell-support branch from 611353a to ba506bc Compare March 26, 2024 19:16
@ffranr
Copy link
Contributor Author

ffranr commented Mar 26, 2024

Some of the review comments also apply to existing code that the PR doesn't touch. I've made a note of them and I'll create another PR address those code changes.

Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! LGTM pending unit tests for encode/decode of messages.

@ffranr ffranr requested a review from GeorgeTsagk March 26, 2024 19:44
Copy link
Member

@GeorgeTsagk GeorgeTsagk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

are the encode/decode unit tests landing in a diff PR?
otherwise lgtm

@ffranr ffranr added this pull request to the merge queue Mar 28, 2024
Merged via the queue into main with commit e5a4a16 Mar 28, 2024
14 checks passed
@ffranr ffranr mentioned this pull request Mar 28, 2024
@guggero guggero deleted the rfq-add-sell-support branch March 28, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[feature]: Extend the RFQ service to handle asset sell (send) initiated lightning payments
4 participants