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]: create OrderHandler RFQ service #778

Closed
ffranr opened this issue Jan 31, 2024 · 0 comments
Closed

[feature]: create OrderHandler RFQ service #778

ffranr opened this issue Jan 31, 2024 · 0 comments
Labels
enhancement New feature or request rfq
Milestone

Comments

@ffranr
Copy link
Contributor

ffranr commented Jan 31, 2024

Parent issue: #683

Quoting the relevant section of the parent issue:

This module will manage the accepted set of RFQ bundles. Using the HtlcInterceptor RPC call, it'll attempt to interecept any HTLCs that have an scid that matches the set of active rfq_scid. The set of active rfq_scid will need to be persisted to disk in a reliable manner. In addition to using the interceptor to reject HTLCs that match the rfq_scid but don't adhere to the accepted terms, we'll also need a background routine that removes expired quotes (all quotes expire after a period of time).

We'll also want a set of RPCs to introspect into this state, and potentially modify, or expire the set of accepted quotes early.

Accepting/rejecting incoming HTLCs

The order handler (manager) intercepts incoming HTLCs. It then and accepts/rejects each HTLC based on any associated channel remit.

A channel remit is a data structure that describes the payment conditions which must be satisfied before a particular HTLC can be accepted. The channel remits are organised (keyed) by short channel IDs (SCIDs).

These are the fields available to inspect an intercepted HTLC:

// InterceptedHtlc contains information about a htlc that was intercepted in
// lnd's switch.
type InterceptedHtlc struct {
	// IncomingCircuitKey is lnd's unique identfier for the incoming htlc.
	IncomingCircuitKey invpkg.CircuitKey

	// Hash is the payment hash for the htlc. This may not be unique for
	// MPP htlcs.
	Hash lntypes.Hash

	// AmountInMsat is the incoming htlc amount.
	AmountInMsat lnwire.MilliSatoshi

	// AmountOutMsat is the outgoing htlc amount.
	AmountOutMsat lnwire.MilliSatoshi

	// IncomingExpiryHeight is the expiry height of the incoming htlc.
	IncomingExpiryHeight uint32

	// OutgoingExpiryHeight is the expiry height of the outgoing htlcs.
	OutgoingExpiryHeight uint32

	// OutgoingChannelID is the outgoing channel id proposed by the sender.
	// Since lnd has non-strict forwarding, this may not be the channel that
	// the htlc ends up being forwarded on.
	OutgoingChannelID lnwire.ShortChannelID
}

The final recipient node (which receives the tap asset) is only concerned with payments from the channel ID specified in the OutgoingChannelID field. Therefore, this is the channel ID that we must use to retrieve the corresponding channel remit data.

Before we can accept the HTLC, the sats amount specified by AmountOutMsat must be equal to or greater than the amount specified in the channel remit. The threshold sats amount specified in the channel remit is calculated from the target asset amount that the recipient node intends to receive and the accepted asset specific exchange rate (btc/asset).

@ffranr ffranr added enhancement New feature or request rfq labels Jan 31, 2024
@ffranr ffranr added this to the v0.4 milestone Jan 31, 2024
@ffranr ffranr moved this from 🆕 New to 💇‍♂️Needs Shaping in Taproot-Assets Project Board Feb 1, 2024
@ffranr ffranr moved this from 💇‍♂️Needs Shaping to 🏗 In progress in Taproot-Assets Project Board Feb 15, 2024
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Taproot-Assets Project Board Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rfq
Projects
Status: ✅ Done
Development

No branches or pull requests

2 participants