rpc: fix queryroutes bug that assumed precise number of returned routes
In this commit, we fix a bug in the query routes RPC that could at times lead to a panic. This would happen if the number of returned routes was less than the number of expected routes. To remedy this, we’ll return the minimum of the number of requested routes, and the number of routes actually returned.
This commit is contained in:
parent
158c78da60
commit
7f04d927a0
10
rpcserver.go
10
rpcserver.go
@ -2617,12 +2617,20 @@ func (r *rpcServer) QueryRoutes(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// As the number of returned routes can be less than the number of
|
||||
// requested routes, we'll clamp down the length of the response to the
|
||||
// minimum of the two.
|
||||
numRoutes := int32(len(routes))
|
||||
if in.NumRoutes < numRoutes {
|
||||
numRoutes = in.NumRoutes
|
||||
}
|
||||
|
||||
// For each valid route, we'll convert the result into the format
|
||||
// required by the RPC system.
|
||||
routeResp := &lnrpc.QueryRoutesResponse{
|
||||
Routes: make([]*lnrpc.Route, 0, in.NumRoutes),
|
||||
}
|
||||
for i := int32(0); i < in.NumRoutes; i++ {
|
||||
for i := int32(0); i < numRoutes; i++ {
|
||||
routeResp.Routes = append(
|
||||
routeResp.Routes, marshallRoute(routes[i]),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user