-
Notifications
You must be signed in to change notification settings - Fork 114
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
Support user-generated RFQ on tchrpc.SendPayment
#1224
base: main
Are you sure you want to change the base?
Support user-generated RFQ on tchrpc.SendPayment
#1224
Conversation
Pull Request Test Coverage Report for Build 12074134958Details
💛 - Coveralls |
rpcserver.go
Outdated
var quote rfqmsg.BuyAccept | ||
for id, q := range r.cfg.RfqManager.PeerAcceptedBuyQuotes() { | ||
if id == rfqmsg.SerialisedScid(req.Scid) { | ||
quote = q | ||
break | ||
} | ||
} |
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.
what if the quote isn't found?
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.
in that case we don't want to protect the user, we're assuming they know what they're doing
code wise we should fail the RPC
// The rfq scid to use for this payment. If the user sets this value then | ||
// the payment will immediately be dispatched, skipping the rfq negotiation | ||
// phase, and using the following rfq scid. | ||
uint64 scid = 5; |
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.
Should this skip RFQ completely or just override scid? Where does the asset rate come from?
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.
it's supposed to skip the entire RFQ negotiation phase that is happening in the case
statement below
if the user is using this option then they have negotiated a quote already, outside of the RPC
so all that's needed now is for us to map the scid to the full quote and use that in the outgoing htlc wire records
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 we'll instead want the full 32-byte RFQ ID to be passed in. Then we can validate it exists and hasn't expired yet. If all is okay, we can easily derive the SCID from it.
5976aac
to
f2557d3
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.
Very nice! Simple enough approach. Have two suggestions though, otherwise looks good, thank you 🎉
// The rfq scid to use for this payment. If the user sets this value then | ||
// the payment will immediately be dispatched, skipping the rfq negotiation | ||
// phase, and using the following rfq scid. | ||
uint64 scid = 5; |
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 we'll instead want the full 32-byte RFQ ID to be passed in. Then we can validate it exists and hasn't expired yet. If all is okay, we can easily derive the SCID from it.
} | ||
} | ||
|
||
htlc := rfqmsg.NewHtlc(nil, fn.Some(quote.ID)) |
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 should probably do this part as well to remain RPC compatible:
// Send out the information about the quote on the stream.
err = stream.Send(&tchrpc.SendPaymentResponse{
Result: &tchrpc.SendPaymentResponse_AcceptedSellOrder{
AcceptedSellOrder: quote,
},
})
if err != nil {
return err
}
// Unmarshall the accepted quote's asset rate.
assetRate, err := rfqrpc.UnmarshalFixedPoint(
acceptedQuote.BidAssetRate,
)
if err != nil {
return fmt.Errorf("error unmarshalling asset rate: %w",
err)
}
// Calculate the equivalent asset units for the given invoice
// amount based on the asset-to-BTC conversion rate.
numAssetUnits := rfqmath.MilliSatoshiToUnits(
*invoice.MilliSat, *assetRate,
)
rpcsLog.Infof("Using quote for %v asset units at %v asset/BTC "+
"from peer %x with SCID %d", numAssetUnits, assetRate,
peerPubKey, acceptedQuote.Scid)
var rfqID rfqmsg.ID
copy(rfqID[:], acceptedQuote.Id)
Closes #1215