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

rpcserver: better rfq channel selection #1357

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

GeorgeTsagk
Copy link
Member

Previously, callers of rfqChannel would just get the first channel from the list of candidates. This is sufficient, but we could easily optimise this depending on the intention. Depending on whether we want to receive or send over the channel, we return the channel with the best remote or local balance accordingly.

@GeorgeTsagk GeorgeTsagk self-assigned this Feb 6, 2025
@coveralls
Copy link

coveralls commented Feb 6, 2025

Pull Request Test Coverage Report for Build 13238262829

Details

  • 0 of 32 (0.0%) changed or added relevant lines in 1 file are covered.
  • 20 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.009%) to 40.73%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rpcserver.go 0 32 0.0%
Files with Coverage Reduction New Missed Lines %
tappsbt/create.go 2 53.22%
asset/asset.go 2 77.18%
tapchannel/aux_leaf_signer.go 3 43.43%
tapgarden/caretaker.go 4 68.11%
commitment/tap.go 4 83.64%
asset/mock.go 5 92.13%
Totals Coverage Status
Change from base Build 13201002768: -0.009%
Covered Lines: 26782
Relevant Lines: 65755

💛 - Coveralls

Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Nice and easy fix for better invoice peer selection!

rpcserver.go Outdated
@@ -7786,12 +7791,30 @@ func (r *rpcServer) DecDisplayForAssetID(ctx context.Context,
return meta.DecDisplayOption()
}

// rfqChannelIntention defines the intention of calling rfqChannel. This helps
// with returning the channel that is most suitable for what we want to do.
type rfqChannelIntention uint8
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be moved into the rfq package. Then the name prefix isn't required and it just becomes rfq.ChannelIntention (or maybe even just rfq.Intention?). That would also make it an exported type (which makes more sense, given that the individual constants are also exported).

Copy link
Member Author

@GeorgeTsagk GeorgeTsagk Feb 10, 2025

Choose a reason for hiding this comment

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

Not sure I follow here

This enum is specifically defined for the call func below named rpcServer.rfqChannel which just picks a channel to use for either sending or receiving. Having its definition be remote to it, in a diff package, seems quite hard to keep track of. Also it doesn't seem like something that can be used in another point in the code.

Will rename to chanIntention to better reflect the scope. As the "rfq" part for this type was just a naive copy of the func name "rfqChannel"

rpcserver.go Outdated
case SendIntention:
// If the intention is to send, return the channel with
// the biggest local balance.
fn.ForEach(assetBalances, func(b channelWithAsset) {
Copy link
Member

Choose a reason for hiding this comment

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

Just to check my understanding: When sending, this code path only really matters if the peerPubKey isn't set and you have multiple channels with a given asset to different peers. Then we select the peer with the best inbound liquidity to us (the actual channel is ignored on the send related call sites).
But if peerPubKey is specified, this is basically a no-op, since it doesn't matter which channel of a peer we choose, as we only need the pubKey anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Our code currently fails if we have multiple candidate channels with different peers, asking the user to specify a peer.

This code really matters when user specifies a peer, and that peer has multiple channels with us.

Copy link
Member Author

@GeorgeTsagk GeorgeTsagk Feb 7, 2025

Choose a reason for hiding this comment

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

I could also address the issue of selecting a peer automatically, but that's a bit more involved and is part of #1052 so leaving it out of the picture for now

@GeorgeTsagk GeorgeTsagk requested a review from ffranr February 11, 2025 09:43
Previously, callers of rfqChannel would just get the first channel from
the list of candidates. This is sufficient, but we could easily optimise
this depending on the intention. Depending on whether we want to receive
or send over the channel, we return the channel with the best remote or
local balance accordingly.
@GeorgeTsagk GeorgeTsagk force-pushed the better-chan-selection branch from 7eab028 to dbef1d4 Compare February 12, 2025 14:19
@GeorgeTsagk GeorgeTsagk requested a review from ffranr February 12, 2025 14:19
@ffranr ffranr added this pull request to the merge queue Feb 12, 2025
Merged via the queue into lightninglabs:main with commit 28c4ea8 Feb 12, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

4 participants