From 4d645ef97fc870abe9ddddb2a047b50891d33c10 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 24 Nov 2020 14:14:49 +0100 Subject: [PATCH 1/3] htlcswitch: add debug logs for fetching network result --- htlcswitch/payment_result.go | 4 ++++ htlcswitch/switch.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/htlcswitch/payment_result.go b/htlcswitch/payment_result.go index fa14f37a..cd5fe0a5 100644 --- a/htlcswitch/payment_result.go +++ b/htlcswitch/payment_result.go @@ -128,6 +128,8 @@ func (store *networkResultStore) storeResult(paymentID uint64, store.paymentIDMtx.Lock(paymentID) defer store.paymentIDMtx.Unlock(paymentID) + log.Debugf("Storing result for paymentID=%v", paymentID) + // Serialize the payment result. var b bytes.Buffer if err := serializeNetworkResult(&b, result); err != nil { @@ -175,6 +177,8 @@ func (store *networkResultStore) subscribeResult(paymentID uint64) ( store.paymentIDMtx.Lock(paymentID) defer store.paymentIDMtx.Unlock(paymentID) + log.Debugf("Subscribing to result for paymentID=%v", paymentID) + var ( result *networkResult resultChan = make(chan *networkResult, 1) diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 1f755bb0..5648695f 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -420,6 +420,9 @@ func (s *Switch) GetPaymentResult(paymentID uint64, paymentHash lntypes.Hash, return } + log.Debugf("Received network result %T for paymentID=%v", n.msg, + paymentID) + // Extract the result and pass it to the result channel. result, err := s.extractResult( deobfuscator, n, paymentID, paymentHash, From f8493a7522451e5ce32d2556127f1479dbd43748 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 24 Nov 2020 14:15:12 +0100 Subject: [PATCH 2/3] routing: define errShardHandlerExiting --- routing/payment_lifecycle.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go index 30a07668..aaebc5bf 100644 --- a/routing/payment_lifecycle.go +++ b/routing/payment_lifecycle.go @@ -14,6 +14,9 @@ import ( "github.com/lightningnetwork/lnd/routing/route" ) +// errShardHandlerExiting is returned from the shardHandler when it exits. +var errShardHandlerExiting = fmt.Errorf("shard handler exiting") + // paymentLifecycle holds all information about the current state of a payment // needed to resume if from any point. type paymentLifecycle struct { @@ -308,7 +311,7 @@ func (p *shardHandler) waitForShard() error { return err case <-p.quit: - return fmt.Errorf("shard handler quitting") + return errShardHandlerExiting case <-p.router.quit: return ErrRouterShuttingDown @@ -326,7 +329,7 @@ func (p *shardHandler) checkShards() error { } case <-p.quit: - return fmt.Errorf("shard handler quitting") + return errShardHandlerExiting case <-p.router.quit: return ErrRouterShuttingDown @@ -421,7 +424,8 @@ func (p *shardHandler) collectResultAsync(attempt *channeldb.HTLCAttemptInfo) { result, err := p.collectResult(attempt) if err != nil { if err != ErrRouterShuttingDown && - err != htlcswitch.ErrSwitchExiting { + err != htlcswitch.ErrSwitchExiting && + err != errShardHandlerExiting { log.Errorf("Error collecting result for "+ "shard %v for payment %v: %v", @@ -531,7 +535,7 @@ func (p *shardHandler) collectResult(attempt *channeldb.HTLCAttemptInfo) ( return nil, ErrRouterShuttingDown case <-p.quit: - return nil, fmt.Errorf("shard handler exiting") + return nil, errShardHandlerExiting } // In case of a payment failure, fail the attempt with the control From df049ad755325c8a0b7ae089e7459793c2f01cdc Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 24 Nov 2020 14:16:03 +0100 Subject: [PATCH 3/3] routing: promote shard logs on resume and terminal failure to Info --- routing/payment_lifecycle.go | 4 ++-- routing/router.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go index aaebc5bf..0e61dec1 100644 --- a/routing/payment_lifecycle.go +++ b/routing/payment_lifecycle.go @@ -107,7 +107,7 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) { for _, a := range payment.InFlightHTLCs() { a := a - log.Debugf("Resuming payment shard %v for hash %v", + log.Infof("Resuming payment shard %v for hash %v", a.AttemptID, p.paymentHash) shardHandler.collectResultAsync(&a.HTLCAttemptInfo) @@ -687,7 +687,7 @@ func (p *shardHandler) handleSendError(attempt *channeldb.HTLCAttemptInfo, return nil } - log.Debugf("Payment %v failed: final_outcome=%v, raw_err=%v", + log.Infof("Payment %v failed: final_outcome=%v, raw_err=%v", p.paymentHash, *reason, sendErr) err := p.router.cfg.Control.Fail(p.paymentHash, *reason) diff --git a/routing/router.go b/routing/router.go index af1e8d75..4e4bcbef 100644 --- a/routing/router.go +++ b/routing/router.go @@ -2006,8 +2006,8 @@ func (r *ChannelRouter) tryApplyChannelUpdate(rt *route.Route, // processSendError analyzes the error for the payment attempt received from the // switch and updates mission control and/or channel policies. Depending on the // error type, this error is either the final outcome of the payment or we need -// to continue with an alternative route. This is indicated by the boolean -// return value. +// to continue with an alternative route. A final outcome is indicated by a +// non-nil return value. func (r *ChannelRouter) processSendError(paymentID uint64, rt *route.Route, sendErr error) *channeldb.FailureReason {