From 9bd7eb74b68504d683a5310b406a1e68c4f3bef6 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Thu, 16 Apr 2020 15:22:44 +0200 Subject: [PATCH] routing: add prefix logger for payment session --- routing/payment_session.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/routing/payment_session.go b/routing/payment_session.go index 2eef929e..6c467768 100644 --- a/routing/payment_session.go +++ b/routing/payment_session.go @@ -1,6 +1,10 @@ package routing import ( + "fmt" + + "github.com/btcsuite/btclog" + "github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/routing/route" @@ -124,6 +128,9 @@ type paymentSession struct { // specified in the payment is one, under no circumstances splitting // will happen and this value remains unused. minShardAmt lnwire.MilliSatoshi + + // log is a payment session-specific logger. + log btclog.Logger } // newPaymentSession instantiates a new payment session. @@ -138,6 +145,8 @@ func newPaymentSession(p *LightningPayment, return nil, err } + logPrefix := fmt.Sprintf("PaymentSession(%x):", p.PaymentHash) + return &paymentSession{ additionalEdges: edges, getBandwidthHints: getBandwidthHints, @@ -147,6 +156,7 @@ func newPaymentSession(p *LightningPayment, pathFindingConfig: pathFindingConfig, missionControl: missionControl, minShardAmt: DefaultShardMinAmt, + log: build.NewPrefixLog(logPrefix, log), }, nil } @@ -206,8 +216,7 @@ func (p *paymentSession) RequestRoute(maxAmt, feeLimit lnwire.MilliSatoshi, return nil, err } - log.Debugf("PaymentSession for %x: trying pathfinding with %v", - p.payment.PaymentHash, maxAmt) + p.log.Debugf("pathfinding for amt=%v", maxAmt) // Get a routing graph. 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. isLastShard := activeShards+1 >= p.payment.MaxShards if isLastShard { + p.log.Debugf("not splitting because shard "+ + "limit %v has been reached", + p.payment.MaxShards) + return nil, errNoPathFound } @@ -246,6 +259,10 @@ func (p *paymentSession) RequestRoute(maxAmt, feeLimit lnwire.MilliSatoshi, // Put a lower bound on the minimum shard size. if maxAmt < p.minShardAmt { + p.log.Debugf("not splitting because minimum "+ + "shard amount %v has been reached", + p.minShardAmt) + return nil, errNoPathFound }