mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-08 14:57:38 +02:00
routing: add exitWithErr
to handle error logging
This commit is contained in:
committed by
Olaoluwa Osuntokun
parent
e5840f6216
commit
c412ab5ccb
@@ -69,7 +69,6 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
|||||||
// If we had any existing attempts outstanding, we'll start by spinning
|
// If we had any existing attempts outstanding, we'll start by spinning
|
||||||
// up goroutines that'll collect their results and deliver them to the
|
// up goroutines that'll collect their results and deliver them to the
|
||||||
// lifecycle loop below.
|
// lifecycle loop below.
|
||||||
// Fetch the latest payment from db.
|
|
||||||
payment, err := p.router.cfg.Control.FetchPayment(p.identifier)
|
payment, err := p.router.cfg.Control.FetchPayment(p.identifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return [32]byte{}, nil, err
|
return [32]byte{}, nil, err
|
||||||
@@ -84,6 +83,13 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
|||||||
shardHandler.collectResultAsync(&a.HTLCAttemptInfo)
|
shardHandler.collectResultAsync(&a.HTLCAttemptInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// exitWithErr is a helper closure that logs and returns an error.
|
||||||
|
exitWithErr := func(err error) ([32]byte, *route.Route, error) {
|
||||||
|
log.Errorf("Payment %v with status=%v failed: %v",
|
||||||
|
p.identifier, payment.Status, err)
|
||||||
|
return [32]byte{}, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// We'll continue until either our payment succeeds, or we encounter a
|
// We'll continue until either our payment succeeds, or we encounter a
|
||||||
// critical error during path finding.
|
// critical error during path finding.
|
||||||
lifecycle:
|
lifecycle:
|
||||||
@@ -91,7 +97,7 @@ lifecycle:
|
|||||||
// Start by quickly checking if there are any outcomes already
|
// Start by quickly checking if there are any outcomes already
|
||||||
// available to handle before we reevaluate our state.
|
// available to handle before we reevaluate our state.
|
||||||
if err := shardHandler.checkShards(); err != nil {
|
if err := shardHandler.checkShards(); err != nil {
|
||||||
return [32]byte{}, nil, err
|
return exitWithErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We update the payment state on every iteration. Since the
|
// We update the payment state on every iteration. Since the
|
||||||
@@ -103,7 +109,7 @@ lifecycle:
|
|||||||
// Fetch the latest payment from db.
|
// Fetch the latest payment from db.
|
||||||
payment, err := p.router.cfg.Control.FetchPayment(p.identifier)
|
payment, err := p.router.cfg.Control.FetchPayment(p.identifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return [32]byte{}, nil, err
|
return exitWithErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ps := payment.State
|
ps := payment.State
|
||||||
@@ -140,7 +146,7 @@ lifecycle:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Payment failed.
|
// Payment failed.
|
||||||
return [32]byte{}, nil, *payment.FailureReason
|
return exitWithErr(*payment.FailureReason)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we either reached a terminal error condition (but had
|
// If we either reached a terminal error condition (but had
|
||||||
@@ -148,7 +154,7 @@ lifecycle:
|
|||||||
// we'll wait for a shard outcome.
|
// we'll wait for a shard outcome.
|
||||||
wait, err := payment.NeedWaitAttempts()
|
wait, err := payment.NeedWaitAttempts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return [32]byte{}, nil, err
|
return exitWithErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if wait {
|
if wait {
|
||||||
@@ -156,7 +162,7 @@ lifecycle:
|
|||||||
// outcome to be available before re-evaluating our
|
// outcome to be available before re-evaluating our
|
||||||
// state.
|
// state.
|
||||||
if err := shardHandler.waitForShard(); err != nil {
|
if err := shardHandler.waitForShard(); err != nil {
|
||||||
return [32]byte{}, nil, err
|
return exitWithErr(err)
|
||||||
}
|
}
|
||||||
continue lifecycle
|
continue lifecycle
|
||||||
}
|
}
|
||||||
@@ -179,13 +185,13 @@ lifecycle:
|
|||||||
p.identifier, channeldb.FailureReasonTimeout,
|
p.identifier, channeldb.FailureReasonTimeout,
|
||||||
)
|
)
|
||||||
if saveErr != nil {
|
if saveErr != nil {
|
||||||
return [32]byte{}, nil, saveErr
|
return exitWithErr(saveErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
continue lifecycle
|
continue lifecycle
|
||||||
|
|
||||||
case <-p.router.quit:
|
case <-p.router.quit:
|
||||||
return [32]byte{}, nil, ErrRouterShuttingDown
|
return exitWithErr(ErrRouterShuttingDown)
|
||||||
|
|
||||||
// Fall through if we haven't hit our time limit.
|
// Fall through if we haven't hit our time limit.
|
||||||
default:
|
default:
|
||||||
@@ -203,7 +209,7 @@ lifecycle:
|
|||||||
|
|
||||||
routeErr, ok := err.(noRouteError)
|
routeErr, ok := err.(noRouteError)
|
||||||
if !ok {
|
if !ok {
|
||||||
return [32]byte{}, nil, err
|
return exitWithErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// There is no route to try, and we have no active
|
// There is no route to try, and we have no active
|
||||||
@@ -219,7 +225,7 @@ lifecycle:
|
|||||||
p.identifier, failureCode,
|
p.identifier, failureCode,
|
||||||
)
|
)
|
||||||
if saveErr != nil {
|
if saveErr != nil {
|
||||||
return [32]byte{}, nil, saveErr
|
return exitWithErr(saveErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
continue lifecycle
|
continue lifecycle
|
||||||
@@ -228,7 +234,7 @@ lifecycle:
|
|||||||
// We still have active shards, we'll wait for an
|
// We still have active shards, we'll wait for an
|
||||||
// outcome to be available before retrying.
|
// outcome to be available before retrying.
|
||||||
if err := shardHandler.waitForShard(); err != nil {
|
if err := shardHandler.waitForShard(); err != nil {
|
||||||
return [32]byte{}, nil, err
|
return exitWithErr(err)
|
||||||
}
|
}
|
||||||
continue lifecycle
|
continue lifecycle
|
||||||
}
|
}
|
||||||
@@ -253,7 +259,7 @@ lifecycle:
|
|||||||
continue lifecycle
|
continue lifecycle
|
||||||
|
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return [32]byte{}, nil, err
|
return exitWithErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we encountered a non-critical error when launching the
|
// If we encountered a non-critical error when launching the
|
||||||
@@ -270,7 +276,7 @@ lifecycle:
|
|||||||
attempt, outcome.err,
|
attempt, outcome.err,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return [32]byte{}, nil, err
|
return exitWithErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error was handled successfully, continue to make a
|
// Error was handled successfully, continue to make a
|
||||||
|
Reference in New Issue
Block a user