routing: add prefix logger for payment session

This commit is contained in:
Joost Jager 2020-04-16 15:22:44 +02:00
parent 6e8442b333
commit 9bd7eb74b6
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -1,6 +1,10 @@
package routing package routing
import ( import (
"fmt"
"github.com/btcsuite/btclog"
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/routing/route"
@ -124,6 +128,9 @@ type paymentSession struct {
// specified in the payment is one, under no circumstances splitting // specified in the payment is one, under no circumstances splitting
// will happen and this value remains unused. // will happen and this value remains unused.
minShardAmt lnwire.MilliSatoshi minShardAmt lnwire.MilliSatoshi
// log is a payment session-specific logger.
log btclog.Logger
} }
// newPaymentSession instantiates a new payment session. // newPaymentSession instantiates a new payment session.
@ -138,6 +145,8 @@ func newPaymentSession(p *LightningPayment,
return nil, err return nil, err
} }
logPrefix := fmt.Sprintf("PaymentSession(%x):", p.PaymentHash)
return &paymentSession{ return &paymentSession{
additionalEdges: edges, additionalEdges: edges,
getBandwidthHints: getBandwidthHints, getBandwidthHints: getBandwidthHints,
@ -147,6 +156,7 @@ func newPaymentSession(p *LightningPayment,
pathFindingConfig: pathFindingConfig, pathFindingConfig: pathFindingConfig,
missionControl: missionControl, missionControl: missionControl,
minShardAmt: DefaultShardMinAmt, minShardAmt: DefaultShardMinAmt,
log: build.NewPrefixLog(logPrefix, log),
}, nil }, nil
} }
@ -206,8 +216,7 @@ func (p *paymentSession) RequestRoute(maxAmt, feeLimit lnwire.MilliSatoshi,
return nil, err return nil, err
} }
log.Debugf("PaymentSession for %x: trying pathfinding with %v", p.log.Debugf("pathfinding for amt=%v", maxAmt)
p.payment.PaymentHash, maxAmt)
// Get a routing graph. // Get a routing graph.
routingGraph, cleanup, err := p.getRoutingGraph() routingGraph, cleanup, err := p.getRoutingGraph()
@ -237,6 +246,10 @@ func (p *paymentSession) RequestRoute(maxAmt, feeLimit lnwire.MilliSatoshi,
// No splitting if this is the last shard. // No splitting if this is the last shard.
isLastShard := activeShards+1 >= p.payment.MaxShards isLastShard := activeShards+1 >= p.payment.MaxShards
if isLastShard { if isLastShard {
p.log.Debugf("not splitting because shard "+
"limit %v has been reached",
p.payment.MaxShards)
return nil, errNoPathFound return nil, errNoPathFound
} }
@ -246,6 +259,10 @@ func (p *paymentSession) RequestRoute(maxAmt, feeLimit lnwire.MilliSatoshi,
// Put a lower bound on the minimum shard size. // Put a lower bound on the minimum shard size.
if maxAmt < p.minShardAmt { if maxAmt < p.minShardAmt {
p.log.Debugf("not splitting because minimum "+
"shard amount %v has been reached",
p.minShardAmt)
return nil, errNoPathFound return nil, errNoPathFound
} }