From 58677569b5213ba066187d434cfbbaca0ff36dd6 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 5 Jan 2024 18:11:04 +0800 Subject: [PATCH 1/2] routing+routerrpc: remove redudant error check Since `SendPaymentAsync` now never returns an error, there's no need to catch it and check it in `SendPaymentV2`. --- lnrpc/routerrpc/router_server.go | 29 ++++++----------------------- routing/router.go | 4 +--- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/lnrpc/routerrpc/router_server.go b/lnrpc/routerrpc/router_server.go index 5414f9e60..a294c999f 100644 --- a/lnrpc/routerrpc/router_server.go +++ b/lnrpc/routerrpc/router_server.go @@ -347,30 +347,13 @@ func (s *Server) SendPaymentV2(req *SendPaymentRequest, return err } - // Send the payment. - err = s.cfg.Router.SendPaymentAsync(payment, paySession, shardTracker) - if err == nil { - // If the payment was sent successfully, we can start tracking - // the events. - return s.trackPayment( - sub, payHash, stream, req.NoInflightUpdates, - ) - } + // Send the payment asynchronously. + s.cfg.Router.SendPaymentAsync(payment, paySession, shardTracker) - // Otherwise, transform user errors to grpc code. - if errors.Is(err, channeldb.ErrPaymentInFlight) || - errors.Is(err, channeldb.ErrAlreadyPaid) { - - log.Debugf("SendPayment async result for payment %x: %v", - payment.Identifier(), err) - - return status.Error(codes.AlreadyExists, err.Error()) - } - - log.Errorf("SendPayment async error for payment %x: %v", - payment.Identifier(), err) - - return err + // Track the payment and return. + return s.trackPayment( + sub, payHash, stream, req.NoInflightUpdates, + ) } // EstimateRouteFee allows callers to obtain a lower bound w.r.t how much it diff --git a/routing/router.go b/routing/router.go index 80f647807..d67535c24 100644 --- a/routing/router.go +++ b/routing/router.go @@ -2386,7 +2386,7 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte, // SendPaymentAsync is the non-blocking version of SendPayment. The payment // result needs to be retrieved via the control tower. func (r *ChannelRouter) SendPaymentAsync(payment *LightningPayment, - ps PaymentSession, st shards.ShardTracker) error { + ps PaymentSession, st shards.ShardTracker) { // Since this is the first time this payment is being made, we pass nil // for the existing attempt. @@ -2406,8 +2406,6 @@ func (r *ChannelRouter) SendPaymentAsync(payment *LightningPayment, payment.Identifier(), err) } }() - - return nil } // spewPayment returns a log closures that provides a spewed string From 6de21b2a02c0a03f0b3e19a5f9c64d59a0f83d38 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 5 Jan 2024 22:18:25 +0800 Subject: [PATCH 2/2] routerrpc: add verbose log and ignore context canceled error --- lnrpc/routerrpc/router_server.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lnrpc/routerrpc/router_server.go b/lnrpc/routerrpc/router_server.go index a294c999f..fd3f5e6cf 100644 --- a/lnrpc/routerrpc/router_server.go +++ b/lnrpc/routerrpc/router_server.go @@ -872,10 +872,17 @@ func (s *Server) trackPayment(subscription routing.ControlTowerSubscriber, stream.Context(), subscription, noInflightUpdates, stream.Send, ) + // If the context is canceled, we don't return an error. if errors.Is(err, context.Canceled) { - log.Debugf("Payment stream %v canceled", identifier) + log.Infof("Payment stream %v canceled", identifier) + + return nil } + // Otherwise, we will log and return the error as the stream has + // received an error from the payment lifecycle. + log.Errorf("TrackPayment got error for payment %x: %v", identifier, err) + return err }