@@ -149,14 +149,14 @@ var (
149149 DefaultRouterMacFilename = "router.macaroon"
150150)
151151
152- // ServerShell a is shell struct holding a reference to the actual sub-server.
152+ // ServerShell is a shell struct holding a reference to the actual sub-server.
153153// It is used to register the gRPC sub-server with the root server before we
154154// have the necessary dependencies to populate the actual sub-server.
155155type ServerShell struct {
156156 RouterServer
157157}
158158
159- // Server is a stand alone sub RPC server which exposes functionality that
159+ // Server is a stand- alone sub RPC server which exposes functionality that
160160// allows clients to route arbitrary payment through the Lightning Network.
161161type Server struct {
162162 started int32 // To be used atomically.
@@ -181,7 +181,7 @@ var _ RouterServer = (*Server)(nil)
181181// that contains all external dependencies. If the target macaroon exists, and
182182// we're unable to create it, then an error will be returned. We also return
183183// the set of permissions that we require as a server. At the time of writing
184- // of this documentation, this is the same macaroon as as the admin macaroon.
184+ // of this documentation, this is the same macaroon as the admin macaroon.
185185func New (cfg * Config ) (* Server , lnrpc.MacaroonPerms , error ) {
186186 // If the path of the router macaroon wasn't generated, then we'll
187187 // assume that it's found at the default network directory.
@@ -360,13 +360,25 @@ func (s *Server) SendPaymentV2(req *SendPaymentRequest,
360360 return err
361361 }
362362
363+ // The payment context is influenced by two user-provided parameters,
364+ // the cancelable flag and the payment attempt timeout.
365+ // If the payment is cancelable, we will use the stream context as the
366+ // payment context. That way, if the user ends the stream, the payment
367+ // loop will be canceled.
368+ // The second context parameter is the timeout. If the user provides a
369+ // timeout, we will additionally wrap the context in a deadline. If the
370+ // user provided 'cancelable' and ends the stream before the timeout is
371+ // reached the payment will be canceled.
372+ ctx := context .Background ()
373+ if req .Cancelable {
374+ ctx = stream .Context ()
375+ }
376+
363377 // Send the payment asynchronously.
364- s .cfg .Router .SendPaymentAsync (payment , paySession , shardTracker )
378+ s .cfg .Router .SendPaymentAsync (ctx , payment , paySession , shardTracker )
365379
366380 // Track the payment and return.
367- return s .trackPayment (
368- sub , payHash , stream , req .NoInflightUpdates ,
369- )
381+ return s .trackPayment (sub , payHash , stream , req .NoInflightUpdates )
370382}
371383
372384// EstimateRouteFee allows callers to obtain an expected value w.r.t how much it
@@ -986,9 +998,8 @@ func (s *Server) SetMissionControlConfig(ctx context.Context,
986998 AprioriHopProbability : float64 (
987999 req .Config .HopProbability ,
9881000 ),
989- AprioriWeight : float64 (req .Config .Weight ),
990- CapacityFraction : float64 (
991- routing .DefaultCapacityFraction ),
1001+ AprioriWeight : float64 (req .Config .Weight ),
1002+ CapacityFraction : routing .DefaultCapacityFraction , //nolint:lll
9921003 }
9931004 }
9941005
@@ -1032,8 +1043,8 @@ func (s *Server) SetMissionControlConfig(ctx context.Context,
10321043
10331044// QueryMissionControl exposes the internal mission control state to callers. It
10341045// is a development feature.
1035- func (s * Server ) QueryMissionControl (ctx context.Context ,
1036- req * QueryMissionControlRequest ) (* QueryMissionControlResponse , error ) {
1046+ func (s * Server ) QueryMissionControl (_ context.Context ,
1047+ _ * QueryMissionControlRequest ) (* QueryMissionControlResponse , error ) {
10371048
10381049 snapshot := s .cfg .RouterBackend .MissionControl .GetHistorySnapshot ()
10391050
@@ -1080,7 +1091,7 @@ func toRPCPairData(data *routing.TimedPairResult) *PairData {
10801091
10811092// XImportMissionControl imports the state provided to our internal mission
10821093// control. Only entries that are fresher than our existing state will be used.
1083- func (s * Server ) XImportMissionControl (ctx context.Context ,
1094+ func (s * Server ) XImportMissionControl (_ context.Context ,
10841095 req * XImportMissionControlRequest ) (* XImportMissionControlResponse ,
10851096 error ) {
10861097
@@ -1273,8 +1284,9 @@ func (s *Server) subscribePayment(identifier lntypes.Hash) (
12731284 sub , err := router .Tower .SubscribePayment (identifier )
12741285
12751286 switch {
1276- case err == channeldb .ErrPaymentNotInitiated :
1287+ case errors . Is ( err , channeldb .ErrPaymentNotInitiated ) :
12771288 return nil , status .Error (codes .NotFound , err .Error ())
1289+
12781290 case err != nil :
12791291 return nil , err
12801292 }
@@ -1385,7 +1397,7 @@ func (s *Server) trackPaymentStream(context context.Context,
13851397}
13861398
13871399// BuildRoute builds a route from a list of hop addresses.
1388- func (s * Server ) BuildRoute (ctx context.Context ,
1400+ func (s * Server ) BuildRoute (_ context.Context ,
13891401 req * BuildRouteRequest ) (* BuildRouteResponse , error ) {
13901402
13911403 // Unmarshall hop list.
@@ -1446,7 +1458,7 @@ func (s *Server) BuildRoute(ctx context.Context,
14461458
14471459// SubscribeHtlcEvents creates a uni-directional stream from the server to
14481460// the client which delivers a stream of htlc events.
1449- func (s * Server ) SubscribeHtlcEvents (req * SubscribeHtlcEventsRequest ,
1461+ func (s * Server ) SubscribeHtlcEvents (_ * SubscribeHtlcEventsRequest ,
14501462 stream Router_SubscribeHtlcEventsServer ) error {
14511463
14521464 htlcClient , err := s .cfg .RouterBackend .SubscribeHtlcEvents ()
@@ -1495,7 +1507,7 @@ func (s *Server) SubscribeHtlcEvents(req *SubscribeHtlcEventsRequest,
14951507
14961508// HtlcInterceptor is a bidirectional stream for streaming interception
14971509// requests to the caller.
1498- // Upon connection it does the following:
1510+ // Upon connection, it does the following:
14991511// 1. Check if there is already a live stream, if yes it rejects the request.
15001512// 2. Registered a ForwardInterceptor
15011513// 3. Delivers to the caller every √√ and detect his answer.
@@ -1525,7 +1537,7 @@ func extractOutPoint(req *UpdateChanStatusRequest) (*wire.OutPoint, error) {
15251537}
15261538
15271539// UpdateChanStatus allows channel state to be set manually.
1528- func (s * Server ) UpdateChanStatus (ctx context.Context ,
1540+ func (s * Server ) UpdateChanStatus (_ context.Context ,
15291541 req * UpdateChanStatusRequest ) (* UpdateChanStatusResponse , error ) {
15301542
15311543 outPoint , err := extractOutPoint (req )
0 commit comments