Skip to content

Commit 2cc4079

Browse files
committed
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.
1 parent 77f2d8a commit 2cc4079

File tree

6 files changed

+15
-19
lines changed

6 files changed

+15
-19
lines changed

discovery/gossiper.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/btcsuite/btcd/btcutil"
1616
"github.com/btcsuite/btcd/chaincfg/chainhash"
1717
"github.com/btcsuite/btcd/wire"
18-
"github.com/davecgh/go-spew/spew"
1918
"github.com/lightninglabs/neutrino/cache"
2019
"github.com/lightninglabs/neutrino/cache/lru"
2120
"github.com/lightningnetwork/lnd/batch"
@@ -1650,7 +1649,7 @@ func (d *AuthenticatedGossiper) handleNetworkMessages(ctx context.Context,
16501649
if err != nil {
16511650
// Something is wrong if SignalDependents returns an error.
16521651
log.Errorf("SignalDependents returned error for msg=%v with "+
1653-
"JobID=%v", spew.Sdump(nMsg.msg), jobID)
1652+
"JobID=%v", lnutils.SpewLogClosure(nMsg.msg), jobID)
16541653

16551654
nMsg.err <- err
16561655

@@ -3196,7 +3195,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(ctx context.Context,
31963195
if err != nil {
31973196
rErr := fmt.Errorf("unable to validate channel update "+
31983197
"announcement for short_chan_id=%v: %v",
3199-
spew.Sdump(upd.ShortChannelID), err)
3198+
lnutils.SpewLogClosure(upd.ShortChannelID), err)
32003199

32013200
log.Error(rErr)
32023201
nMsg.err <- rErr

htlcswitch/switch.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
1414
"github.com/btcsuite/btcd/btcutil"
1515
"github.com/btcsuite/btcd/wire"
16-
"github.com/davecgh/go-spew/spew"
1716
"github.com/lightningnetwork/lnd/chainntnfs"
1817
"github.com/lightningnetwork/lnd/channeldb"
1918
"github.com/lightningnetwork/lnd/clock"
@@ -1625,7 +1624,7 @@ out:
16251624
}
16261625

16271626
log.Debugf("Received outside contract resolution, "+
1628-
"mapping to: %v", spew.Sdump(pkt))
1627+
"mapping to: %v", lnutils.SpewLogClosure(pkt))
16291628

16301629
// We don't check the error, as the only failure we can
16311630
// encounter is due to the circuit already being

netann/channel_update.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"github.com/btcsuite/btcd/btcec/v2"
99
"github.com/btcsuite/btcd/btcutil"
1010
"github.com/btcsuite/btcd/chaincfg/chainhash"
11-
"github.com/davecgh/go-spew/spew"
1211
"github.com/lightningnetwork/lnd/graph/db/models"
1312
"github.com/lightningnetwork/lnd/keychain"
13+
"github.com/lightningnetwork/lnd/lnutils"
1414
"github.com/lightningnetwork/lnd/lnwallet"
1515
"github.com/lightningnetwork/lnd/lnwire"
1616
"github.com/lightningnetwork/lnd/tlv"
@@ -226,7 +226,7 @@ func verifyChannelUpdate1Signature(msg *lnwire.ChannelUpdate1,
226226

227227
if !nodeSig.Verify(dataHash, pubKey) {
228228
return fmt.Errorf("invalid signature for channel update %v",
229-
spew.Sdump(msg))
229+
lnutils.SpewLogClosure(msg))
230230
}
231231

232232
return nil
@@ -249,7 +249,7 @@ func verifyChannelUpdate2Signature(c *lnwire.ChannelUpdate2,
249249

250250
if !nodeSig.Verify(digest, pubKey) {
251251
return fmt.Errorf("invalid signature for channel update %v",
252-
spew.Sdump(c))
252+
lnutils.SpewLogClosure(c))
253253
}
254254

255255
return nil
@@ -279,13 +279,13 @@ func validateChannelUpdate1Fields(capacity btcutil.Amount,
279279
// The maxHTLC flag is mandatory.
280280
if !msg.MessageFlags.HasMaxHtlc() {
281281
return fmt.Errorf("max htlc flag not set for channel "+
282-
"update %v", spew.Sdump(msg))
282+
"update %v", lnutils.SpewLogClosure(msg))
283283
}
284284

285285
maxHtlc := msg.HtlcMaximumMsat
286286
if maxHtlc == 0 || maxHtlc < msg.HtlcMinimumMsat {
287287
return fmt.Errorf("invalid max htlc for channel "+
288-
"update %v", spew.Sdump(msg))
288+
"update %v", lnutils.SpewLogClosure(msg))
289289
}
290290

291291
// For light clients, the capacity will not be set so we'll skip
@@ -308,7 +308,7 @@ func validateChannelUpdate2Fields(capacity btcutil.Amount,
308308
maxHtlc := c.HTLCMaximumMsat.Val
309309
if maxHtlc == 0 || maxHtlc < c.HTLCMinimumMsat.Val {
310310
return fmt.Errorf("invalid max htlc for channel update %v",
311-
spew.Sdump(c))
311+
lnutils.SpewLogClosure(c))
312312
}
313313

314314
// Checking whether the MaxHTLC value respects the channel's capacity.

peer/brontide.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/btcsuite/btcd/txscript"
2020
"github.com/btcsuite/btcd/wire"
2121
"github.com/btcsuite/btclog/v2"
22-
"github.com/davecgh/go-spew/spew"
2322
"github.com/lightningnetwork/lnd/buffer"
2423
"github.com/lightningnetwork/lnd/chainntnfs"
2524
"github.com/lightningnetwork/lnd/channeldb"
@@ -1230,7 +1229,7 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
12301229
}
12311230

12321231
p.log.Tracef("Using link policy of: %v",
1233-
spew.Sdump(forwardingPolicy))
1232+
lnutils.SpewLogClosure(forwardingPolicy))
12341233

12351234
// If the channel is pending, set the value to nil in the
12361235
// activeChannels map. This is done to signify that the channel
@@ -2839,7 +2838,7 @@ func (p *Brontide) queue(priority bool, msg lnwire.Message,
28392838
case p.outgoingQueue <- outgoingMsg{priority, msg, errChan}:
28402839
case <-p.cg.Done():
28412840
p.log.Tracef("Peer shutting down, could not enqueue msg: %v.",
2842-
spew.Sdump(msg))
2841+
lnutils.SpewLogClosure(msg))
28432842
if errChan != nil {
28442843
errChan <- lnpeer.ErrPeerExiting
28452844
}

routing/payment_lifecycle.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"github.com/btcsuite/btcd/btcec/v2"
10-
"github.com/davecgh/go-spew/spew"
1110
sphinx "github.com/lightningnetwork/lightning-onion"
1211
"github.com/lightningnetwork/lnd/fn/v2"
1312
"github.com/lightningnetwork/lnd/graph/db/models"
@@ -301,7 +300,7 @@ lifecycle:
301300
continue lifecycle
302301
}
303302

304-
log.Tracef("Found route: %s", spew.Sdump(rt.Hops))
303+
log.Tracef("Found route: %s", lnutils.SpewLogClosure(rt.Hops))
305304

306305
// We found a route to try, create a new HTLC attempt to try.
307306
attempt, err := p.registerAttempt(rt, ps.RemainingAmt)
@@ -767,7 +766,7 @@ func (p *paymentLifecycle) amendFirstHopData(rt *route.Route) error {
767766

768767
log.Debugf("Aux traffic shaper returned custom "+
769768
"records %v and amount %d msat for HTLC",
770-
spew.Sdump(newRecords), newAmt)
769+
lnutils.SpewLogClosure(newRecords), newAmt)
771770

772771
return fn.Ok(extraDataRequest{
773772
customRecords: fn.Some(newRecords),

routing/router.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/btcsuite/btcd/btcec/v2"
1515
"github.com/btcsuite/btcd/btcutil"
16-
"github.com/davecgh/go-spew/spew"
1716
"github.com/lightningnetwork/lnd/amp"
1817
"github.com/lightningnetwork/lnd/clock"
1918
"github.com/lightningnetwork/lnd/fn/v2"
@@ -958,7 +957,8 @@ func spewPayment(payment *LightningPayment) lnutils.LogClosure {
958957
}
959958
p := *payment
960959
p.RouteHints = routeHints
961-
return spew.Sdump(p)
960+
961+
return lnutils.SpewLogClosure(p)()
962962
})
963963
}
964964

0 commit comments

Comments
 (0)