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

[custom channels]: add new RPC methods for asset channel specific calls #1048

Merged
merged 5 commits into from
Aug 9, 2024

Conversation

guggero
Copy link
Member

@guggero guggero commented Jul 24, 2024

Adds standalone RPC calls to the tapchannelrpc package to simplify usage for RPC users.
These RPCs mirror the functionality that is currently only available in the command line in litd:

  • litcli ln addinvoice -> tapchannelrpc.AddInvoice
  • litcli ln payinvoice -> tapchannelrpc.SendPayment
  • litcli ln sendpayment -> tapchannelrpc.SendPayment

@guggero
Copy link
Member Author

guggero commented Jul 29, 2024

Ready for review. Will do manual and integration test validation in lightninglabs/lightning-terminal#807 (since these new RPCs can't really be tested well in tapd standalone).

@guggero guggero requested review from ffranr and GeorgeTsagk July 29, 2024 16:26
@guggero guggero changed the title [WIP]: add new RPC methods for asset channel specific calls [custom channels]: add new RPC methods for asset channel specific calls Jul 29, 2024
@guggero
Copy link
Member Author

guggero commented Jul 30, 2024

Looking at the failure in the itest (https://github.com/lightninglabs/lightning-terminal/actions/runs/10148102664/job/28060046297?pr=807), I think we need to pass in the RFQ peer's public key to the new calls, so we know what peer to ask for a quote if there are multiple channels with the given asset.
So I'll need to update this PR slightly.

@guggero guggero force-pushed the tap-channel-rpcs branch 2 times, most recently from 4000798 to 664a6a1 Compare July 30, 2024 16:07
Copy link
Member

@GeorgeTsagk GeorgeTsagk left a comment

Choose a reason for hiding this comment

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

looks good!
have some Qs

switch {
// If there are multiple asset channels for the same asset, we need to
// ask the user to specify the peer public key. Otherwise, we don't know
// who to ask for a quote.
Copy link
Member

Choose a reason for hiding this comment

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

nit: we could convert this into a feature in next versions, the user may not want to pick a single peer here so instead we could ask for a quote from all peers and choose the "best" one

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. But that would be a larger overhaul of the whole RFQ system, so I'd rather do that in a follow-up PR.

// channels, it means we have multiple channels with the same asset and
// the same peer. So we just return the first channel.
case len(assetBalances) >= 1:
return &assetBalances[0], nil
Copy link
Member

Choose a reason for hiding this comment

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

nit: the first channel may be depleted, need to think of rotation

Copy link
Member Author

Choose a reason for hiding this comment

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

At this level the actual channel balance doesn't matter. We only need the channel object to get the peer public key. We don't want to do balance checks at this level really, as that should be handled by the sending logic.

// (invoice amount plus fee limit) in milli-satoshi, not the
// asset amount. Need to change the whole RFQ API to do that
// though.
maxAssetAmount := assetChan.assetInfo.LocalBalance
Copy link
Member

Choose a reason for hiding this comment

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

I don't get the TODO
Isn't this the asset local balance?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is currently, but will the threshold will be lowered to match the payment rather than just the entire channel outgoing balance.

Copy link
Member Author

Choose a reason for hiding this comment

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

We set it to the asset balance because the unit is wrong (right now it's the maximum amount in assets, but the user doesn't know how many assets they need to send, that's the question the RFQ call should answer in the first place). We'll do some refactor and eventually this should be the maximum amount the user is willing to pay in satoshis (invoice amount plus the user-defined maximum routing fee they're willing to pay).

rpcserver.go Show resolved Hide resolved
Copy link
Contributor

@ffranr ffranr left a comment

Choose a reason for hiding this comment

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

Would it be valuable to add itests which exercise the new endpoints in this PR? Just checking for example that the outgoing HTLC contains the correct fields.

rpcserver.go Outdated
// The last step is to create a hop hint that includes the fake SCID of
// the quote, alongside the channel's routing policy.
channelID := assetChan.channelInfo.ChannelID
ourPolicy, err := r.getOurPolicy(ctx, channelID, peerPubKey.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps instead of ourPolicy in both variable name and method name, just channelPolicy? Because "their" policy isn't something we deal with. I have the same sort of thoughts around the getOurPolicy method name and doc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Every channel has two routing policies: those set by us (valid for the outbound direction) and those set by our peer (valid for the inbound direction). So the our/their kind of made sense IMO.
But while thinking about the name and how to make it more easy to understand, I actually noticed that we need to use the inbound policies (those set by the peer), since this is for a payment coming in.

While doing that, I renamed the function to getInboundPolicy.

@dstadulis dstadulis added this to the v0.4.2 milestone Aug 5, 2024
@lightninglabs-deploy
Copy link

@guggero, remember to re-request review from reviewers when ready

guggero added 5 commits August 7, 2024 13:30
This commit allows us to use the gRPC import statement to re-use lnd
protobuf definitions. We'll use that to be able to embed lnd RPC
messages in some of the new tapchannelrpc calls.
With this commit we make sure that the taproot asset channel
functionality RPCs are correctly configured and return the expected
error when being called.
We can't actually test any of their intended functionality because that
would require us to run within a litd context.
But the integration tests in the litd repo make sure these RPCs work as
expected.
@guggero
Copy link
Member Author

guggero commented Aug 7, 2024

Would it be valuable to add itests which exercise the new endpoints in this PR? Just checking for example that the outgoing HTLC contains the correct fields.

As mentioned in the PR body, the full functionality test is done in the litd integration tests.
But I added minimal calls to the RPCs to make sure they're hooked up correctly.

@guggero guggero requested a review from ffranr August 8, 2024 15:38
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 🌛

@Roasbeef Roasbeef merged commit a8d8b5a into main Aug 9, 2024
16 checks passed
@guggero guggero deleted the tap-channel-rpcs branch August 9, 2024 06:43
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]: Add Tapd Sub-Server RPC for simplified LN Functionality
6 participants