Skip to content

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

Merged
merged 7 commits into from
Apr 24, 2025
Merged

Conversation

GeorgeTsagk
Copy link
Member

@GeorgeTsagk GeorgeTsagk commented Mar 21, 2025

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

@GeorgeTsagk GeorgeTsagk self-assigned this Mar 21, 2025
@coveralls
Copy link

coveralls commented Mar 21, 2025

Pull Request Test Coverage Report for Build 14488405809

Warning: 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

  • 14 of 147 (9.52%) changed or added relevant lines in 3 files are covered.
  • 48 unchanged lines in 10 files lost coverage.
  • Overall coverage decreased (-0.05%) to 28.327%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rfq/manager.go 0 21 0.0%
rpcserver.go 0 112 0.0%
Files with Coverage Reduction New Missed Lines %
rpcserver.go 1 0.0%
asset/group_key.go 2 57.89%
tapchannel/aux_leaf_signer.go 2 43.08%
tappsbt/create.go 2 26.74%
asset/asset.go 3 48.1%
address/address.go 6 67.47%
asset/mock.go 6 63.56%
commitment/tap.go 6 71.36%
tapgarden/caretaker.go 6 68.63%
address/mock.go 14 89.54%
Totals Coverage Status
Change from base Build 14474635473: -0.05%
Covered Lines: 25922
Relevant Lines: 91511

💛 - Coveralls

Copy link
Member

@Roasbeef Roasbeef left a 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 +
Copy link
Member

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.

Copy link
Member Author

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())
}
Copy link
Member

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 ||

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

Copy link
Member Author

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!

@ZZiigguurraatt
Copy link

Getting the following error when trying to build litd with this PR

$ make

===== skipping part about the web UI build ==========

 Building lightning-terminal.
go build -v -tags="litd autopilotrpc signrpc walletrpc chainrpc invoicesrpc watchtowerrpc neutrinorpc peersrpc" -ldflags " -X github.com./lightningnetwork/lnd/build.Commit=lightning-terminal-v0.14.1-alpha-82-gbad957bedc7f37950de33f5f15a3f00ed29e8f8d-dirty -X github.com./lightningnetwork/lnd/build.CommitHash=bad957bedc7f37950de33f5f15a3f00ed29e8f8d -X github.com./lightningnetwork/lnd/build.GoVersion= -X github.com./lightningnetwork/lnd/build.RawTags=litd,autopilotrpc,signrpc,walletrpc,chainrpc,invoicesrpc,watchtowerrpc,neutrinorpc,peersrpc -X github.com./lightninglabs/lightning-terminal.appFilesPrefix= -X github.com./lightninglabs/lightning-terminal.Commit=v0.14.1-alpha-82-gbad957bedc7f37950de33f5f15a3f00ed29e8f8d-dirty -X github.com./lightninglabs/loop.Commit=v0.29.0-beta -X github.com./lightninglabs/pool.Commit=v0.6.5-beta.0.20241015105339-044cb451b5df -X github.com./lightninglabs/taproot-assets.Commit=github.com." -o litd-debug github.com./lightninglabs/lightning-terminal/cmd/litd
go: updates to go.mod needed; to update it:
	go mod tidy
make: *** [Makefile:132: go-build] Error 1

then when I do go mod tidy as it says, I get

go: finding module for package github.com./lightningnetwork/lnd/graph/db/models
go: github.com./lightninglabs/lightning-terminal/cmd/litcli imports
	github.com./lightninglabs/taproot-assets/rfq imports
	github.com./lightningnetwork/lnd/graph/db/models: module github.com./lightningnetwork/lnd@latest found (v0.0.2), but does not contain package github.com./lightningnetwork/lnd/graph/db/models

I can build taproot-assets with this PR outside of litd though. I can also build litd with taproot-assets v0.5.1.

@ZZiigguurraatt
Copy link

OK, looks like I am having the same problem if I try to build litd with the taproot assets main branch tip too.

@guggero
Copy link
Member

guggero commented Mar 25, 2025

@ZZiigguurraatt
Copy link

@guggero Not sure if this issue is the cause?
https://github.com./lightninglabs/taproot-assets/blame/5290f9c3e811bb327a8f8a446d7b3519daf2b453/rfq/order.go#L16

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?

@guggero
Copy link
Member

guggero commented Mar 25, 2025

The update to lnd 19 was already done in taproot-assets, which came with a bunch of changes. Those changes also need to be done in litd for things to be compile-time compatible. Which is what the PR I linked to does.

@ZZiigguurraatt
Copy link

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?

@guggero
Copy link
Member

guggero commented Mar 25, 2025

Correct. I'm working on it.

@ZZiigguurraatt
Copy link

ZZiigguurraatt commented Mar 27, 2025

Now that lightninglabs/lightning-terminal#998 is merged, I'm getting.

# github.com./lightninglabs/taproot-assets/tapchannel
../../taproot-assets/addinvoice-sats-amt/tapchannel/aux_funding_controller.go:2259:38: cannot use (*FundingController)(nil) (value of type *FundingController) as funding.AuxFundingController value in variable declaration: *FundingController does not implement funding.AuxFundingController (wrong type for method SendMessage)
		have SendMessage(msgmux.PeerMsg) bool
		want SendMessage("context".Context, msgmux.PeerMsg) bool
make: *** [Makefile:132: go-build] Error 1

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?

@GeorgeTsagk
Copy link
Member Author

@ZZiigguurraatt this PR needs a rebase, will soon update it

@GeorgeTsagk GeorgeTsagk force-pushed the addinvoice-sats-amt branch from 76212e2 to 2614f53 Compare March 28, 2025 07:49
@GeorgeTsagk
Copy link
Member Author

Rebased on latest main

rpcserver.go Outdated
amtMsat, *askAssetRate,
).ScaleTo(0).ToUint64()

// Now let's see if the negotiated quote can actually route the

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?

Copy link
Member Author

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

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.

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.
@guggero guggero force-pushed the addinvoice-sats-amt branch from 47dd304 to cb13676 Compare April 16, 2025 08:38
@guggero
Copy link
Member

guggero commented Apr 16, 2025

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).

@guggero
Copy link
Member

guggero commented Apr 16, 2025

Litd test will succeed after merging lightninglabs/lightning-terminal#1040.

@guggero
Copy link
Member

guggero commented Apr 16, 2025

Also fixes #1306.

@guggero guggero linked an issue Apr 16, 2025 that may be closed by this pull request
@GeorgeTsagk GeorgeTsagk requested review from ffranr and removed request for ZZiigguurraatt April 22, 2025 19:10
@lightninglabs-deploy
Copy link

@Roasbeef: review reminder
@GeorgeTsagk, remember to re-request review from reviewers when ready

@Roasbeef
Copy link
Member

Seeing this failure in the litd itest;, not sure if related:

    assets_test.go:1428: Asking peer 03a024e1ee071b31d510d75a7794f979ed1131b1b021492f7613f82fda9530c84a for quote to buy assets to receive for invoice over 1 units; waiting up to 300s
    assets_test.go:1445: 
        	Error Trace:	/home/runner/work/taproot-assets/taproot-assets/lightning-terminal/itest/assets_test.go:1445
        	            				/home/runner/work/taproot-assets/taproot-assets/lightning-terminal/itest/litd_custom_channels_test.go:2163
        	            				/home/runner/work/taproot-assets/taproot-assets/lightning-terminal/itest/test_harness.go:103
        	            				/home/runner/work/taproot-assets/taproot-assets/lightning-terminal/itest/litd_test.go:87
        	Error:      	Error "rpc error: code = Unknown desc = error validating invoice amount: cannot create invoice for 1 asset units, as the minimal transportable amount is 20 units with the current rate of coefficient:\"5820600\" units/BTC" does not contain "cannot create invoice over 1 asset units, as the minimal transportable amount"
        	Test:       	TestLightningTerminal/custom_channels_liquidity
    harness.go:381: finished test: , start height=438, end height=483, mined blocks=45
    harness.go:403: !============================================!
        Too many blocks (45) mined in one test! Tips:
        1. break test into smaller individual tests, especially if this is a table-drive test.
        2. use smaller CSV via `--bitcoin.defaultremotedelay=1.`
        3. use smaller CLTV via `--bitcoin.timelockdelta=18.`
        4. remove unnecessary CloseChannel when test ends.
        5. use `CreateSimpleNetwork` for efficient channel creation.

@Roasbeef
Copy link
Member

Ah I see this comment now , so does this just need a rebase now?

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🥦

@guggero
Copy link
Member

guggero commented Apr 24, 2025

Litd itest is expected to fail now, because the referenced branch requires #1478 to be merged. So this will become stable again soon.

@guggero guggero merged commit 25ff294 into main Apr 24, 2025
17 of 18 checks passed
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Taproot-Assets Project Board Apr 24, 2025
@guggero guggero deleted the addinvoice-sats-amt branch April 24, 2025 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[feature]: generate asset invoice with fix amount of SATs instead of asset amount fix typo in error message
8 participants