-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
af39bad
to
73902e8
Compare
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.
Cool change! We should add a godoc
to each of the existing and new methods.
73902e8
to
758638a
Compare
|
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, |
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.
Regarding commit structure: it looks like this change (extracting logic into unmarshallHopByChannelLookup
) could be done in an individual commit.
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.
Commit added
rpcserver.go
Outdated
"channel ID for hop (%d): %v", i, err) | ||
var routeHop *routing.Hop | ||
|
||
if hop.PubKey == "" { |
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.
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.
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.
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 |
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.
I think this comment belongs by the definition of the PubKey
field.
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.
Moved
758638a
to
386738d
Compare
386738d
to
b2c8bfa
Compare
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( |
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.
hmm, strange wrapping?
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.
I thought so too, but this is what gofmt does.
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.
Maybe this works?
PubKey: hex.EncodeToString(
hop.PubKeyBytes[:],
),
}
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.
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) { |
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.
prevNodePubKey
should be made [33]byte
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.
Why? This way there is less byte copying.
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.
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.
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.
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.
b2c8bfa
to
28ae028
Compare
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 🏁
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 🧶
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.