Skip to content

Commit d992cf9

Browse files
committed
multi: add SpewLogClosure to avoid code repetition
1 parent b6049ff commit d992cf9

File tree

19 files changed

+57
-144
lines changed

19 files changed

+57
-144
lines changed

chanbackup/recover.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"net"
55

66
"github.com/btcsuite/btcd/btcec/v2"
7-
"github.com/davecgh/go-spew/spew"
87
"github.com/lightningnetwork/lnd/channeldb"
98
"github.com/lightningnetwork/lnd/keychain"
109
"github.com/lightningnetwork/lnd/lnutils"
@@ -64,9 +63,8 @@ func Recover(backups []Single, restorer ChannelRestorer,
6463
log.Infof("Attempting to connect to node=%x (addrs=%v) to "+
6564
"restore ChannelPoint(%v)",
6665
backup.RemoteNodePub.SerializeCompressed(),
67-
lnutils.NewLogClosure(func() string {
68-
return spew.Sdump(backups[i].Addresses)
69-
}), backup.FundingOutpoint)
66+
lnutils.SpewLogClosure(backups[i].Addresses),
67+
backup.FundingOutpoint)
7068

7169
err = peerConnector.ConnectPeer(
7270
backup.RemoteNodePub, backup.Addresses,

contractcourt/breach_arbitrator.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/btcsuite/btcd/chaincfg/chainhash"
1414
"github.com/btcsuite/btcd/txscript"
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/input"
@@ -733,10 +732,8 @@ justiceTxBroadcast:
733732
}
734733
finalTx := justiceTxs.spendAll
735734

736-
brarLog.Debugf("Broadcasting justice tx: %v", lnutils.NewLogClosure(
737-
func() string {
738-
return spew.Sdump(finalTx)
739-
}))
735+
brarLog.Debugf("Broadcasting justice tx: %v", lnutils.SpewLogClosure(
736+
finalTx))
740737

741738
// We'll now attempt to broadcast the transaction which finalized the
742739
// channel's retribution against the cheating counter party.
@@ -859,9 +856,7 @@ Loop:
859856

860857
brarLog.Debugf("Broadcasting justice tx "+
861858
"spending commitment outs: %v",
862-
lnutils.NewLogClosure(func() string {
863-
return spew.Sdump(tx)
864-
}))
859+
lnutils.SpewLogClosure(tx))
865860

866861
err = b.cfg.PublishTransaction(tx, label)
867862
if err != nil {
@@ -876,9 +871,7 @@ Loop:
876871

877872
brarLog.Debugf("Broadcasting justice tx "+
878873
"spending HTLC outs: %v",
879-
lnutils.NewLogClosure(func() string {
880-
return spew.Sdump(tx)
881-
}))
874+
lnutils.SpewLogClosure(tx))
882875

883876
err = b.cfg.PublishTransaction(tx, label)
884877
if err != nil {
@@ -893,9 +886,7 @@ Loop:
893886

894887
brarLog.Debugf("Broadcasting justice tx "+
895888
"spending second-level HTLC output: %v",
896-
lnutils.NewLogClosure(func() string {
897-
return spew.Sdump(tx)
898-
}))
889+
lnutils.SpewLogClosure(tx))
899890

900891
err = b.cfg.PublishTransaction(tx, label)
901892
if err != nil {

contractcourt/channel_arbitrator.go

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/btcsuite/btcd/chaincfg/chainhash"
1515
"github.com/btcsuite/btcd/txscript"
1616
"github.com/btcsuite/btcd/wire"
17-
"github.com/davecgh/go-spew/spew"
1817
"github.com/lightningnetwork/lnd/channeldb"
1918
"github.com/lightningnetwork/lnd/channeldb/models"
2019
"github.com/lightningnetwork/lnd/fn"
@@ -466,10 +465,8 @@ func (c *ChannelArbitrator) Start(state *chanArbStartState) error {
466465
}
467466

468467
log.Debugf("Starting ChannelArbitrator(%v), htlc_set=%v, state=%v",
469-
c.cfg.ChanPoint, lnutils.NewLogClosure(func() string {
470-
return spew.Sdump(c.activeHTLCs)
471-
}), state.currentState,
472-
)
468+
c.cfg.ChanPoint, lnutils.SpewLogClosure(c.activeHTLCs),
469+
state.currentState)
473470

474471
// Set our state from our starting state.
475472
c.state = state.currentState
@@ -959,10 +956,7 @@ func (c *ChannelArbitrator) stateStep(
959956
// Otherwise, we'll log that we checked the HTLC actions as the
960957
// commitment transaction has already been broadcast.
961958
log.Tracef("ChannelArbitrator(%v): logging chain_actions=%v",
962-
c.cfg.ChanPoint,
963-
lnutils.NewLogClosure(func() string {
964-
return spew.Sdump(chainActions)
965-
}))
959+
c.cfg.ChanPoint, lnutils.SpewLogClosure(chainActions))
966960

967961
// Depending on the type of trigger, we'll either "tunnel"
968962
// through to a farther state, or just proceed linearly to the
@@ -1097,10 +1091,7 @@ func (c *ChannelArbitrator) stateStep(
10971091
// channel resolution state.
10981092
log.Infof("Broadcasting force close transaction %v, "+
10991093
"ChannelPoint(%v): %v", closeTx.TxHash(),
1100-
c.cfg.ChanPoint,
1101-
lnutils.NewLogClosure(func() string {
1102-
return spew.Sdump(closeTx)
1103-
}))
1094+
c.cfg.ChanPoint, lnutils.SpewLogClosure(closeTx))
11041095

11051096
// At this point, we'll now broadcast the commitment
11061097
// transaction itself.
@@ -1225,9 +1216,7 @@ func (c *ChannelArbitrator) stateStep(
12251216
if len(pktsToSend) != 0 {
12261217
log.Debugf("ChannelArbitrator(%v): sending "+
12271218
"resolution message=%v", c.cfg.ChanPoint,
1228-
lnutils.NewLogClosure(func() string {
1229-
return spew.Sdump(pktsToSend)
1230-
}))
1219+
lnutils.SpewLogClosure(pktsToSend))
12311220

12321221
err := c.cfg.DeliverResolutionMsg(pktsToSend...)
12331222
if err != nil {
@@ -2742,11 +2731,7 @@ func (c *ChannelArbitrator) notifyContractUpdate(upd *ContractUpdate) {
27422731
c.unmergedSet[upd.HtlcKey] = newHtlcSet(upd.Htlcs)
27432732

27442733
log.Tracef("ChannelArbitrator(%v): fresh set of htlcs=%v",
2745-
c.cfg.ChanPoint,
2746-
lnutils.NewLogClosure(func() string {
2747-
return spew.Sdump(upd)
2748-
}),
2749-
)
2734+
c.cfg.ChanPoint, lnutils.SpewLogClosure(upd))
27502735
}
27512736

27522737
// updateActiveHTLCs merges the unmerged set of HTLCs from the link with

contractcourt/utxonursery.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -948,10 +948,7 @@ func (u *UtxoNursery) waitForSweepConf(classHeight uint32,
948948
func (u *UtxoNursery) sweepCribOutput(classHeight uint32, baby *babyOutput) error {
949949
utxnLog.Infof("Publishing CLTV-delayed HTLC output using timeout tx "+
950950
"(txid=%v): %v", baby.timeoutTx.TxHash(),
951-
lnutils.NewLogClosure(func() string {
952-
return spew.Sdump(baby.timeoutTx)
953-
}),
954-
)
951+
lnutils.SpewLogClosure(baby.timeoutTx))
955952

956953
// We'll now broadcast the HTLC transaction, then wait for it to be
957954
// confirmed before transitioning it to kindergarten.

discovery/bootstrapper.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"github.com/btcsuite/btcd/btcec/v2"
1616
"github.com/btcsuite/btcd/btcutil/bech32"
17-
"github.com/davecgh/go-spew/spew"
1817
"github.com/lightningnetwork/lnd/autopilot"
1918
"github.com/lightningnetwork/lnd/lnutils"
2019
"github.com/lightningnetwork/lnd/lnwire"
@@ -432,10 +431,7 @@ search:
432431
}
433432

434433
log.Tracef("Retrieved SRV records from dns seed: %v",
435-
lnutils.NewLogClosure(func() string {
436-
return spew.Sdump(addrs)
437-
}),
438-
)
434+
lnutils.SpewLogClosure(addrs))
439435

440436
// Next, we'll need to issue an A record request for each of
441437
// the nodes, skipping it if nothing comes back.

graph/builder.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/btcsuite/btcd/btcec/v2"
1313
"github.com/btcsuite/btcd/btcutil"
1414
"github.com/btcsuite/btcd/wire"
15-
"github.com/davecgh/go-spew/spew"
1615
"github.com/go-errors/errors"
1716
"github.com/lightningnetwork/lnd/batch"
1817
"github.com/lightningnetwork/lnd/chainntnfs"
@@ -1432,9 +1431,7 @@ func (b *Builder) processUpdate(msg interface{},
14321431
}
14331432

14341433
log.Tracef("New channel update applied: %v",
1435-
lnutils.NewLogClosure(func() string {
1436-
return spew.Sdump(msg)
1437-
}))
1434+
lnutils.SpewLogClosure(msg))
14381435
b.stats.incNumChannelUpdates()
14391436

14401437
default:

htlcswitch/circuit_map.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"sync"
77

8-
"github.com/davecgh/go-spew/spew"
98
"github.com/go-errors/errors"
109
"github.com/lightningnetwork/lnd/channeldb"
1110
"github.com/lightningnetwork/lnd/htlcswitch/hop"
@@ -801,10 +800,8 @@ func (cm *circuitMap) CommitCircuits(circuits ...*PaymentCircuit) (
801800
inKeys = append(inKeys, circuit.Incoming)
802801
}
803802

804-
log.Tracef("Committing fresh circuits: %v", lnutils.NewLogClosure(
805-
func() string {
806-
return spew.Sdump(inKeys)
807-
}))
803+
log.Tracef("Committing fresh circuits: %v", lnutils.SpewLogClosure(
804+
inKeys))
808805

809806
actions := &CircuitFwdActions{}
810807

@@ -950,10 +947,8 @@ func (cm *circuitMap) OpenCircuits(keystones ...Keystone) error {
950947
return nil
951948
}
952949

953-
log.Tracef("Opening finalized circuits: %v", lnutils.NewLogClosure(
954-
func() string {
955-
return spew.Sdump(keystones)
956-
}))
950+
log.Tracef("Opening finalized circuits: %v", lnutils.SpewLogClosure(
951+
keystones))
957952

958953
// Check that all keystones correspond to committed-but-unopened
959954
// circuits.
@@ -1081,10 +1076,8 @@ func (cm *circuitMap) CloseCircuit(outKey CircuitKey) (*PaymentCircuit, error) {
10811076
// circuit was already cleaned up at a different point in time.
10821077
func (cm *circuitMap) DeleteCircuits(inKeys ...CircuitKey) error {
10831078

1084-
log.Tracef("Deleting resolved circuits: %v", lnutils.NewLogClosure(
1085-
func() string {
1086-
return spew.Sdump(inKeys)
1087-
}))
1079+
log.Tracef("Deleting resolved circuits: %v", lnutils.SpewLogClosure(
1080+
inKeys))
10881081

10891082
var (
10901083
closingCircuits = make(map[CircuitKey]struct{})

htlcswitch/link.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/btcsuite/btcd/btcutil"
1414
"github.com/btcsuite/btcd/wire"
1515
"github.com/btcsuite/btclog"
16-
"github.com/davecgh/go-spew/spew"
1716
"github.com/go-errors/errors"
1817
"github.com/lightningnetwork/lnd/build"
1918
"github.com/lightningnetwork/lnd/channeldb"
@@ -2537,13 +2536,9 @@ func (l *channelLink) updateCommitTx() error {
25372536
l.log.Tracef("revocation window exhausted, unable to send: "+
25382537
"%v, pend_updates=%v, dangling_closes%v",
25392538
l.channel.PendingLocalUpdateCount(),
2540-
lnutils.NewLogClosure(func() string {
2541-
return spew.Sdump(l.openedCircuits)
2542-
}),
2543-
lnutils.NewLogClosure(func() string {
2544-
return spew.Sdump(l.closedCircuits)
2545-
}),
2546-
)
2539+
lnutils.SpewLogClosure(l.openedCircuits),
2540+
lnutils.SpewLogClosure(l.closedCircuits))
2541+
25472542
return nil
25482543
} else if err != nil {
25492544
return err

htlcswitch/switch.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,8 @@ func (s *Switch) SendHTLC(firstHop lnwire.ShortChannelID, attemptID uint64,
614614
func (s *Switch) UpdateForwardingPolicies(
615615
chanPolicies map[wire.OutPoint]models.ForwardingPolicy) {
616616

617-
log.Tracef("Updating link policies: %v", lnutils.NewLogClosure(
618-
func() string {
619-
return spew.Sdump(chanPolicies)
620-
}))
617+
log.Tracef("Updating link policies: %v", lnutils.SpewLogClosure(
618+
chanPolicies))
621619

622620
s.indexMtx.RLock()
623621

@@ -1216,9 +1214,7 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
12161214
log.Warnf("unable to find err source for "+
12171215
"outgoing_link=%v, errors=%v",
12181216
packet.outgoingChanID,
1219-
lnutils.NewLogClosure(func() string {
1220-
return spew.Sdump(linkErrs)
1221-
}))
1217+
lnutils.SpewLogClosure(linkErrs))
12221218
}
12231219

12241220
log.Tracef("incoming HTLC(%x) violated "+
@@ -1999,9 +1995,7 @@ out:
19991995

20001996
log.Tracef("Acked %d settle fails: %v",
20011997
len(s.pendingSettleFails),
2002-
lnutils.NewLogClosure(func() string {
2003-
return spew.Sdump(s.pendingSettleFails)
2004-
}))
1998+
lnutils.SpewLogClosure(s.pendingSettleFails))
20051999

20062000
// Reset the pendingSettleFails buffer while keeping acquired
20072001
// memory.

lnrpc/invoicesrpc/addinvoice.go

Lines changed: 1 addition & 5 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"
1717
"github.com/btcsuite/btcd/wire"
18-
"github.com/davecgh/go-spew/spew"
1918
"github.com/lightningnetwork/lnd/channeldb"
2019
"github.com/lightningnetwork/lnd/channeldb/models"
2120
"github.com/lightningnetwork/lnd/invoices"
@@ -474,10 +473,7 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
474473
}
475474

476475
log.Tracef("[addinvoice] adding new invoice %v",
477-
lnutils.NewLogClosure(func() string {
478-
return spew.Sdump(newInvoice)
479-
}),
480-
)
476+
lnutils.SpewLogClosure(newInvoice))
481477

482478
// With all sanity checks passed, write the invoice to the database.
483479
_, err = cfg.AddInvoice(ctx, newInvoice, paymentHash)

0 commit comments

Comments
 (0)