-
Notifications
You must be signed in to change notification settings - Fork 131
Allow setting sats/msats to taprpc.AddInvoice
#1448
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
Conversation
Pull Request Test Coverage Report for Build 14488405809Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
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.
Nice work! Pretty straight forward implementation. The main thing we need to ensure is that the negotiated quote has a total amount that's greater than the sats input of the user.
rpcserver.go
Outdated
// will help us establish a quote with the correct amount of asset | ||
// units. | ||
if satsMode { | ||
amtMsat = lnwire.MilliSatoshi(req.InvoiceRequest.ValueMsat + |
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.
Typically we just accept either sats _or msat and not a combination of them. Also you can use the helper function ToSatoshis()
if you need to go back n forth.
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.
Yeah, I check that only one of the two is set above. In order to avoid assigning to each one separately, I just add them as one of them at this point is 0
. Tried to code-golf it
rpcserver.go
Outdated
if oracleRes.Err != nil { | ||
return nil, fmt.Errorf("cannot query oracle: %v", | ||
oracleRes.Err.Error()) | ||
} |
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.
Would be good to start to split up some of this logic into helper functions. Looks like we have the distinct phases of:
- initial parsing/validation
- creation of the receive/buy order
- invoice creation
rpcserver.go
Outdated
// avoid ambiguous behavior. This field dictates the actual value of the | ||
// invoice so let's be strict and only allow one possible value to be | ||
// set. | ||
if req.AssetAmount > 0 && (req.InvoiceRequest.ValueMsat > 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.
shouldn't the proto files be updated in the same Merge Request ? like adding of new keys ValueMsat
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.
These fields were already included in the proto request, see here
They were just being ignored.
Thanks for the comment, realized I need to update the doc!
3dd15ef
to
76212e2
Compare
Getting the following error when trying to build litd with this PR
===== skipping part about the web UI build ==========
then when I do
I can build taproot-assets with this PR outside of litd though. I can also build litd with taproot-assets |
OK, looks like I am having the same problem if I try to build litd with the taproot assets main branch tip too. |
@guggero Not sure if this issue is the cause? |
This will be required first: lightninglabs/lightning-terminal#998 |
OK, so https://github.com./lightninglabs/taproot-assets/blame/5290f9c3e811bb327a8f8a446d7b3519daf2b453/rfq/order.go#L16 is not the cause, but instead, the fix for taproot-assets and other dependencies are basically missing that same fix? |
The update to lnd 19 was already done in |
OK, so no way to test this (and any other open taproot-assets) PR with lightning channels then until lightninglabs/lightning-terminal#998 is merged? |
Correct. I'm working on it. |
Now that lightninglabs/lightning-terminal#998 is merged, I'm getting.
However, I do have a cached version of branch lnd-19 at lightninglabs/lightning-terminal@453835f which does compile. So, I'm wondering if there was some change to taproot-assets that was required to merge the latest version of branch lnd-19 in lightning-terminal and addinvoice-sats-amt (this PR) needs to be rebased on that? |
@ZZiigguurraatt this PR needs a rebase, will soon update it |
76212e2
to
2614f53
Compare
Rebased on latest |
rpcserver.go
Outdated
amtMsat, *askAssetRate, | ||
).ScaleTo(0).ToUint64() | ||
|
||
// Now let's see if the negotiated quote can actually route the |
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.
are we actually checking if this quote can "route" the payment? seems like this has nothing to do with routing through channels, more if the RFQ is big enough to accept it? or do we still consider this part of "routing" because the HTLC will be rejected if it doesn't fit within the RFQ?
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.
yeah what we check here is if the quote, along with the agreed upon max units, can evaluate to the amount we want to add to the invoice
we don't do any liquidity related check with channels, as that's out of the scope of this func
similarly to LND, when I call AddInvoice
for 1BTC I don't want to get an error if at the time I don't have 1BTC of inbound
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.
Yes, we have lightningnetwork/lnd#9380 that could add such checks for AddInvoice.
Just thinking the word "route" should not be used here so we don't confuse people to think we are actually checking if the payment could really be routed.
e488107
to
47dd304
Compare
We add a simple helper to expose the configured price deviation ppm to be used by other systems. This is used in a following commit.
We move the validation around in preparation for the next commit that adds more logic. The diff will be smaller and focused on the important change thanks to this move.
The previously ignored value/value_msat fields are now properly being accounted for. We now accept only one value related field to be set.
Since we now support setting the existing fields value/value_msat we need to update the godoc in order to reflect the new behavior to the RPC user.
47dd304
to
cb13676
Compare
I pushed up a version that simplifies the commit structure, so we don't touch the same code multiple times. Should also make it easier to spot what exactly in the logic is changed (don't want to introduce a potential siphon or other kind of exploitable vulnerability here, so yes, I'm extra strict with reviewer friendliness of commit structure). |
Litd test will succeed after merging lightninglabs/lightning-terminal#1040. |
Also fixes #1306. |
@Roasbeef: review reminder |
Seeing this failure in the litd itest;, not sure if related:
|
Ah I see this comment now , so does this just need a rebase now? |
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.
LGTM 🥦
Litd itest is expected to fail now, because the referenced branch requires #1478 to be merged. So this will become stable again soon. |
Description
This PR allows for the user to set the invoice value via the
Value
/ValueMsat
fields.Previously we'd take the asset units and the agreed upon quote, then we'd convert that to an msat amount. Now the value of the invoice can be directly set via the previously ignored fields, while also still acquiring a sufficient quote and returning that to the user.
Closes #1440
Fixes #1306