Merge pull request #8346 from yyforyongyu/remove-error-return

routing+routerrpc: remove redudant error check
This commit is contained in:
Oliver Gugger authored and GitHub committed 2024-01-08 17:41:32 +01:00
commit 7cb53020ee
2 files changed
+15 -27

No files matched your search

+14 -24
View File
@@ -347,30 +347,13 @@ func (s *Server) SendPaymentV2(req *SendPaymentRequest,
return err return err
} }
// Send the payment. // Send the payment asynchronously.
err = s.cfg.Router.SendPaymentAsync(payment, paySession, shardTracker) 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,
)
}
// Otherwise, transform user errors to grpc code. // Track the payment and return.
if errors.Is(err, channeldb.ErrPaymentInFlight) || return s.trackPayment(
errors.Is(err, channeldb.ErrAlreadyPaid) { sub, payHash, stream, req.NoInflightUpdates,
)
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
} }
// EstimateRouteFee allows callers to obtain a lower bound w.r.t how much it // EstimateRouteFee allows callers to obtain a lower bound w.r.t how much it
@@ -889,10 +872,17 @@ func (s *Server) trackPayment(subscription routing.ControlTowerSubscriber,
stream.Context(), subscription, noInflightUpdates, stream.Send, stream.Context(), subscription, noInflightUpdates, stream.Send,
) )
// If the context is canceled, we don't return an error.
if errors.Is(err, context.Canceled) { 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 return err
} }
+1 -3
View File
@@ -2386,7 +2386,7 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte,
// SendPaymentAsync is the non-blocking version of SendPayment. The payment // SendPaymentAsync is the non-blocking version of SendPayment. The payment
// result needs to be retrieved via the control tower. // result needs to be retrieved via the control tower.
func (r *ChannelRouter) SendPaymentAsync(payment *LightningPayment, 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 // Since this is the first time this payment is being made, we pass nil
// for the existing attempt. // for the existing attempt.
@@ -2406,8 +2406,6 @@ func (r *ChannelRouter) SendPaymentAsync(payment *LightningPayment,
payment.Identifier(), err) payment.Identifier(), err)
} }
}() }()
return nil
} }
// spewPayment returns a log closures that provides a spewed string // spewPayment returns a log closures that provides a spewed string