routing: add source parameter to query routes
This commit allows execution of QueryRoutes from any source node. Previously this was restricted to only the self node.
This commit is contained in:
7 files changed
+646
-586
No files matched your search
+38
-8
@@ -3997,18 +3997,48 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
||||
func (r *rpcServer) QueryRoutes(ctx context.Context,
|
||||
in *lnrpc.QueryRoutesRequest) (*lnrpc.QueryRoutesResponse, error) {
|
||||
|
||||
parsePubKey := func(key string) (routing.Vertex, error) {
|
||||
pubKeyBytes, err := hex.DecodeString(key)
|
||||
if err != nil {
|
||||
return routing.Vertex{}, err
|
||||
}
|
||||
|
||||
pubKeyBytes, err := hex.DecodeString(in.PubKey)
|
||||
if len(pubKeyBytes) != 33 {
|
||||
return routing.Vertex{},
|
||||
errors.New("invalid key length")
|
||||
}
|
||||
|
||||
var v routing.Vertex
|
||||
copy(v[:], pubKeyBytes)
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Parse the hex-encoded source and target public keys into full public
|
||||
// key objects we can properly manipulate.
|
||||
targetPubKey, err := parsePubKey(in.PubKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(pubKeyBytes) != 33 {
|
||||
return nil, errors.New("invalid key length")
|
||||
}
|
||||
var sourcePubKey routing.Vertex
|
||||
if in.SourcePubKey != "" {
|
||||
var err error
|
||||
sourcePubKey, err = parsePubKey(in.SourcePubKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
// If no source is specified, use self.
|
||||
|
||||
var pubKey routing.Vertex
|
||||
copy(pubKey[:], pubKeyBytes)
|
||||
channelGraph := r.server.chanDB.ChannelGraph()
|
||||
selfNode, err := channelGraph.SourceNode()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sourcePubKey = selfNode.PubKeyBytes
|
||||
}
|
||||
|
||||
// Currently, within the bootstrap phase of the network, we limit the
|
||||
// largest payment size allotted to (2^32) - 1 mSAT or 4.29 million
|
||||
@@ -4066,11 +4096,11 @@ func (r *rpcServer) QueryRoutes(ctx context.Context,
|
||||
|
||||
if in.FinalCltvDelta == 0 {
|
||||
routes, findErr = r.server.chanRouter.FindRoutes(
|
||||
pubKey, amtMSat, restrictions, numRoutesIn,
|
||||
sourcePubKey, targetPubKey, amtMSat, restrictions, numRoutesIn,
|
||||
)
|
||||
} else {
|
||||
routes, findErr = r.server.chanRouter.FindRoutes(
|
||||
pubKey, amtMSat, restrictions, numRoutesIn,
|
||||
sourcePubKey, targetPubKey, amtMSat, restrictions, numRoutesIn,
|
||||
uint16(in.FinalCltvDelta),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user