-
Notifications
You must be signed in to change notification settings - Fork 132
Add Multi-RFQ Send #1613
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
base: main
Are you sure you want to change the base?
Add Multi-RFQ Send #1613
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good! Have a couple of questions and suggestions, nothing major though.
rfqmsg/records.go
Outdated
if err != nil { | ||
return err | ||
} | ||
list := make([]ID, num) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We allocate memory from a number we received over the wire. Need to check and error out the length before to make sure we limit the number of bytes we allocate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, so far the total length of available RFQ IDs is open ended.
We should introduce a static limit (which would also limit the max number of quotes we acquire) and enforce it everywhere.
@@ -456,16 +457,43 @@ func (s *AuxTrafficShaper) ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi, | |||
return totalAmount, htlcCustomRecords, nil | |||
} | |||
|
|||
if htlc.RfqID.ValOpt().IsNone() { | |||
return 0, nil, fmt.Errorf("no RFQ ID present in HTLC blob") | |||
if htlc.AvailableRfqIDs.IsNone() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here re backward compatibility. And also just to make sure we don't miss any edge case. After all, we explicitly set the singular htlc.RfqID
in this function, so are we a 100% sure there is no code path where either the ProduceHtlcExtraData
or PaymentBandwidth
would be called with htlc.RfqID
set?
IMO we should check both and only error out if none of them (or both) are set at the same time, with a comment that we'd only really expect the list to be set in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the PaymentBandwidth
and ProduceHtlcExtraData
the htlc.RfqID
is replaced by htlc.AvailableRfqIDs
The only use of htlc.RfqID
is when ProduceHtlcExtraData
locks into a specific RFQ, which will be used to produce the actual HTLC that will be sent out to our peer
From that point forward everything is the same (we only use the htlc.RfqID
to route HTLCs / accept HTLCs to invoices)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here re using an existing quote in the SendPayment
RPC... Don't we have that covered by an itest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap, we have it covered, and the itest was failing! so +1 for our coverage, but I realize I never noticed the itest failing
So the reason it failed is because we were setting the existing RPC user provided RFQ as the single RfqID, instead it had to change to instead set it as the only available RFQ ID in the new field
2bb2369
to
df8ce52
Compare
Pull Request Test Coverage Report for Build 16071985844Details
💛 - Coveralls |
Please update taproot-assets/taprpc/tapchannelrpc/tapchannel.proto Lines 125 to 130 in df8ce52
group_key in addition to asset_id in there.
|
What is this expected to do with an invoice with no amount specified? |
taproot-assets/taprpc/tapchannelrpc/tapchannel.proto Lines 139 to 144 in df8ce52
but with multi-rfq send, I would expect the ability to provide an array. Not sure that you want to fix that in this PR, but maybe it should be a separate issue? I did not make this comment for multi-rfq receive because of #1442 . |
df8ce52
to
aa55b42
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did another pass, getting very close here too.
"outgoing channel") | ||
// If the HTLC doesn't have any available RFQ IDs, it's incomplete, and | ||
// we cannot determine the bandwidth. | ||
if htlc.AvailableRfqIDs.IsNone() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you're 100% certain for all the code paths that lead into paymentBandwidth
there isn't a single one where potentially we only have the old RFQ ID set? What about this for example:
Line 7674 in 2e7ae0b
nil, fn.Some(quote.ID), fn.None[[]rfqmsg.ID](), |
default: | ||
return 0, fmt.Errorf("no accepted quote found for RFQ ID "+ | ||
"%x (SCID %d)", rfqID[:], rfqID.Scid()) | ||
if bandwidth > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "Given we establish 1 quote per peer, only one of the RFQ IDs in the array should produce some bandwidth." would probably be a good comment to add above this statement.
@@ -456,16 +457,43 @@ func (s *AuxTrafficShaper) ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi, | |||
return totalAmount, htlcCustomRecords, nil | |||
} | |||
|
|||
if htlc.RfqID.ValOpt().IsNone() { | |||
return 0, nil, fmt.Errorf("no RFQ ID present in HTLC blob") | |||
if htlc.AvailableRfqIDs.IsNone() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here re using an existing quote in the SendPayment
RPC... Don't we have that covered by an itest?
We add a new field to rfqmsg.Htlc which expresses the available quotes that may be used to send out this HTLC. This is done to allow LND to store an array of RFQ IDs to use later via the AuxTrafficShaper interface in order to query asset bandwidth and produce the correct asset related records for outgoing HTLCs.
This commit performs a small refactor to the paymentBandwidth helper. Since we now have multiple candidate RFQ IDs, we extract the main logic of calculating the bandwidth into a helper, and call it once for each of the available RFQ IDs.
When LND queries the PaymentBandwidth there's no way to signal back which RFQ ID ended up being used for that bandwidth calculation. We rely on the assumption that one quote is established per peer within the scope of a payment. This way, the AuxTrafficShaper methods spot the quote that it needs to use by matching the peer of the quote with the peer that LND is going to send this HTLC to.
aa55b42
to
019b54a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments around robustness within the context of multi peer RFQ queries.
rpcserver.go
Outdated
// For each peer that satisfies our query above, we'll try and | ||
// establish an RFQ quote for the asset specifier and max amount | ||
// of this payment. | ||
for peer := range chanMap { | ||
quote, err := r.acquireSellOrder( | ||
ctx, &rpcSpecifier, paymentMaxAmt, expiry, | ||
&peer, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code would be better if this for-loop happened in a separate function.
I think acquireSellOrder
is blocking, am I right? If so then the first peer could block until expiry
(which i think is the invoice expiry) and then we don't have a chance to query any other peer.
We might need to call r.acquireSellOrder
for each peer synchronously here. And the quote response timeout should be much less than the invoice expiry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the quote acquisition to be async, also used a shorter timeout for the RFQ negotiation
Getting a vague error with
|
The RPC method now uses all of the introduced features. Instead of acquiring just one quote we now extract that logic into a helper and call it once for each valid peer. We then encode the array of available RFQ IDs into the first hop records and hand it over to LND.
019b54a
to
d90193a
Compare
Description
Allows payments to use multiple quotes across multiple peers in order to pay an invoice. Previously we had to define a specific peer to negotiate a quote with, with this PR this is no longer required (but still supported) as Tapd will automatically scan our peers and establish quotes with all valid ones for the asset/amount of this payment.
The signature of
ProduceHtlcExtraData
had to be changed, as it's not possible to distinguish which of the quotes in therfqmsg.Htlc
should be used. We now provide the pubkey of the peer this HTLC is being sent to, in order to help Tapd extract the corresponding quote and calculate the correct amount of asset units.Closes #1358
Depends on: lightningnetwork/lnd#9980