routing+htlcswitch+discovery+peer+netann: optimize debug logging with lazy evaluation

In this commit, we update the network and routing layer components to use
lnutils.SpewLogClosure for debug logging.
This commit is contained in:
Olaoluwa Osuntokun committed 2025-09-05 18:20:51 -07:00
1 parent 77f2d8a572
commit 2cc4079a0e
6 files changed
+15 -19

No files matched your search

+2 -3
View File
@@ -15,7 +15,6 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/davecgh/go-spew/spew"
"github.com/lightninglabs/neutrino/cache"
"github.com/lightninglabs/neutrino/cache/lru"
"github.com/lightningnetwork/lnd/batch"
@@ -1650,7 +1649,7 @@ func (d *AuthenticatedGossiper) handleNetworkMessages(ctx context.Context,
if err != nil {
// Something is wrong if SignalDependents returns an error.
log.Errorf("SignalDependents returned error for msg=%v with "+
"JobID=%v", spew.Sdump(nMsg.msg), jobID)
"JobID=%v", lnutils.SpewLogClosure(nMsg.msg), jobID)
nMsg.err <- err
@@ -3196,7 +3195,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(ctx context.Context,
if err != nil {
rErr := fmt.Errorf("unable to validate channel update "+
"announcement for short_chan_id=%v: %v",
spew.Sdump(upd.ShortChannelID), err)
lnutils.SpewLogClosure(upd.ShortChannelID), err)
log.Error(rErr)
nMsg.err <- rErr
+1 -2
View File
@@ -13,7 +13,6 @@ import (
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/wire"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/clock"
@@ -1625,7 +1624,7 @@ out:
}
log.Debugf("Received outside contract resolution, "+
"mapping to: %v", spew.Sdump(pkt))
"mapping to: %v", lnutils.SpewLogClosure(pkt))
// We don't check the error, as the only failure we can
// encounter is due to the circuit already being
+6 -6
View File
@@ -8,9 +8,9 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnutils"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/tlv"
@@ -226,7 +226,7 @@ func verifyChannelUpdate1Signature(msg *lnwire.ChannelUpdate1,
if !nodeSig.Verify(dataHash, pubKey) {
return fmt.Errorf("invalid signature for channel update %v",
spew.Sdump(msg))
lnutils.SpewLogClosure(msg))
}
return nil
@@ -249,7 +249,7 @@ func verifyChannelUpdate2Signature(c *lnwire.ChannelUpdate2,
if !nodeSig.Verify(digest, pubKey) {
return fmt.Errorf("invalid signature for channel update %v",
spew.Sdump(c))
lnutils.SpewLogClosure(c))
}
return nil
@@ -279,13 +279,13 @@ func validateChannelUpdate1Fields(capacity btcutil.Amount,
// The maxHTLC flag is mandatory.
if !msg.MessageFlags.HasMaxHtlc() {
return fmt.Errorf("max htlc flag not set for channel "+
"update %v", spew.Sdump(msg))
"update %v", lnutils.SpewLogClosure(msg))
}
maxHtlc := msg.HtlcMaximumMsat
if maxHtlc == 0 || maxHtlc < msg.HtlcMinimumMsat {
return fmt.Errorf("invalid max htlc for channel "+
"update %v", spew.Sdump(msg))
"update %v", lnutils.SpewLogClosure(msg))
}
// For light clients, the capacity will not be set so we'll skip
@@ -308,7 +308,7 @@ func validateChannelUpdate2Fields(capacity btcutil.Amount,
maxHtlc := c.HTLCMaximumMsat.Val
if maxHtlc == 0 || maxHtlc < c.HTLCMinimumMsat.Val {
return fmt.Errorf("invalid max htlc for channel update %v",
spew.Sdump(c))
lnutils.SpewLogClosure(c))
}
// Checking whether the MaxHTLC value respects the channel's capacity.
+2 -3
View File
@@ -19,7 +19,6 @@ import (
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btclog/v2"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/buffer"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
@@ -1230,7 +1229,7 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
}
p.log.Tracef("Using link policy of: %v",
spew.Sdump(forwardingPolicy))
lnutils.SpewLogClosure(forwardingPolicy))
// If the channel is pending, set the value to nil in the
// activeChannels map. This is done to signify that the channel
@@ -2839,7 +2838,7 @@ func (p *Brontide) queue(priority bool, msg lnwire.Message,
case p.outgoingQueue <- outgoingMsg{priority, msg, errChan}:
case <-p.cg.Done():
p.log.Tracef("Peer shutting down, could not enqueue msg: %v.",
spew.Sdump(msg))
lnutils.SpewLogClosure(msg))
if errChan != nil {
errChan <- lnpeer.ErrPeerExiting
}
+2 -3
View File
@@ -7,7 +7,6 @@ import (
"time"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/davecgh/go-spew/spew"
sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/graph/db/models"
@@ -301,7 +300,7 @@ lifecycle:
continue lifecycle
}
log.Tracef("Found route: %s", spew.Sdump(rt.Hops))
log.Tracef("Found route: %s", lnutils.SpewLogClosure(rt.Hops))
// We found a route to try, create a new HTLC attempt to try.
attempt, err := p.registerAttempt(rt, ps.RemainingAmt)
@@ -767,7 +766,7 @@ func (p *paymentLifecycle) amendFirstHopData(rt *route.Route) error {
log.Debugf("Aux traffic shaper returned custom "+
"records %v and amount %d msat for HTLC",
spew.Sdump(newRecords), newAmt)
lnutils.SpewLogClosure(newRecords), newAmt)
return fn.Ok(extraDataRequest{
customRecords: fn.Some(newRecords),
+2 -2
View File
@@ -13,7 +13,6 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/amp"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/fn/v2"
@@ -958,7 +957,8 @@ func spewPayment(payment *LightningPayment) lnutils.LogClosure {
}
p := *payment
p.RouteHints = routeHints
return spew.Sdump(p)
return lnutils.SpewLogClosure(p)()
})
}