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

lnrpc: allow pubkey in SendToRoute #1944

Merged
merged 2 commits into from
Nov 5, 2018

Conversation

joostjager
Copy link
Collaborator

@joostjager joostjager commented Sep 20, 2018

The information in the Route RPC message is not enough to directly send out the payment. First the local channel graph needs to be queried to complete the data. A lookup is executed to retrieve the public key of a node based on channel id. This does not work with private channels.

In this PR, we allow the hop pubkeys to be passed in so that execution of the payment becomes independent of the channel graph.

It is also a step towards the unbundling of lnd. (maybe, in the future, we get a node that doesn't track the channel graph at all anymore and is just a payment executor. mobile maybe?)

Fixes #2139.

@Roasbeef Roasbeef added enhancement Improvements to existing features / behaviour routing P4 low prio rpc Related to the RPC interface labels Sep 21, 2018
@joostjager joostjager changed the title lnrpc: allow pubkey in SendToRoute [DO NOT REVIEW] lnrpc: allow pubkey in SendToRoute Oct 24, 2018
@halseth halseth added this to the 0.5.2 milestone Oct 24, 2018
Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

Cool change! We should add a godoc to each of the existing and new methods.

@joostjager
Copy link
Collaborator Author

godoc added

rpcserver.go Outdated
// If no pub key is given of the hop, the local channel
// graph needs to be queried to complete the information
// necessary for routing.
routeHop, err = unmarshallHopByChannelLookup(graph,
Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding commit structure: it looks like this change (extracting logic into unmarshallHopByChannelLookup) could be done in an individual commit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Commit added

rpcserver.go Outdated
"channel ID for hop (%d): %v", i, err)
var routeHop *routing.Hop

if hop.PubKey == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would prefer this check be done inside the unmarshal method. Shouldn't be a problem passing in the graph even though it might not be needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My goal was to have a version of unmarshall that does not have that dependency. I refactored it into a form that satisfies both our requirements.

rpcserver.go Outdated
@@ -3509,57 +3509,109 @@ func (r *rpcServer) marshallRoute(route *routing.Route) *lnrpc.Route {
Fee: int64(fee.ToSatoshis()),
FeeMsat: int64(fee),
Expiry: uint32(hop.OutgoingTimeLock),

// Include public key of hop in response, so that
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment belongs by the definition of the PubKey field.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved

@joostjager
Copy link
Collaborator Author

Comments processed

@@ -3509,6 +3509,8 @@ func (r *rpcServer) marshallRoute(route *routing.Route) *lnrpc.Route {
Fee: int64(fee.ToSatoshis()),
FeeMsat: int64(fee),
Expiry: uint32(hop.OutgoingTimeLock),
PubKey: hex.EncodeToString(
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, strange wrapping?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought so too, but this is what gofmt does.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this works?

PubKey: hex.EncodeToString(
                hop.PubKeyBytes[:],
        ),
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No

rpcserver.go Outdated
// unmarshallHop unmarshalls an rpc hop that may or may not contain a node
// pubkey.
func unmarshallHop(graph *channeldb.ChannelGraph, hop *lnrpc.Hop,
prevNodePubKey []byte) (*routing.Hop, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

prevNodePubKey should be made [33]byte

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why? This way there is less byte copying.

Copy link
Contributor

Choose a reason for hiding this comment

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

It makes the length clear, and makes sure it is non-nil. I don't think any extra byte copying makes a difference in this case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed. Not sure it was worth it. It is a minor thing which to me is also a matter of preference.

By passing a pubkey into SendToRoute, it becomes unnecessary for lnd to
query the channel graph to retrieve the hop pubkey. This allows routes
over private channels that are not present in the graph.
Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

LGTM 🏁

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 c0fadcc into lightningnetwork:master Nov 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to existing features / behaviour P4 low prio routing rpc Related to the RPC interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants