diff --git a/chanbackup/recover.go b/chanbackup/recover.go index e36a6badb0..7f5502c4a2 100644 --- a/chanbackup/recover.go +++ b/chanbackup/recover.go @@ -4,7 +4,6 @@ import ( "net" "github.com/btcsuite/btcd/btcec/v2" - "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/lnutils" @@ -64,9 +63,8 @@ func Recover(backups []Single, restorer ChannelRestorer, log.Infof("Attempting to connect to node=%x (addrs=%v) to "+ "restore ChannelPoint(%v)", backup.RemoteNodePub.SerializeCompressed(), - lnutils.NewLogClosure(func() string { - return spew.Sdump(backups[i].Addresses) - }), backup.FundingOutpoint) + lnutils.SpewLogClosure(backups[i].Addresses), + backup.FundingOutpoint) err = peerConnector.ConnectPeer( backup.RemoteNodePub, backup.Addresses, diff --git a/contractcourt/breach_arbitrator.go b/contractcourt/breach_arbitrator.go index aab4e943dc..e3dd85ea6f 100644 --- a/contractcourt/breach_arbitrator.go +++ b/contractcourt/breach_arbitrator.go @@ -13,7 +13,6 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/txscript" "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/input" @@ -733,10 +732,8 @@ justiceTxBroadcast: } finalTx := justiceTxs.spendAll - brarLog.Debugf("Broadcasting justice tx: %v", lnutils.NewLogClosure( - func() string { - return spew.Sdump(finalTx) - })) + brarLog.Debugf("Broadcasting justice tx: %v", lnutils.SpewLogClosure( + finalTx)) // We'll now attempt to broadcast the transaction which finalized the // channel's retribution against the cheating counter party. @@ -859,9 +856,7 @@ Loop: brarLog.Debugf("Broadcasting justice tx "+ "spending commitment outs: %v", - lnutils.NewLogClosure(func() string { - return spew.Sdump(tx) - })) + lnutils.SpewLogClosure(tx)) err = b.cfg.PublishTransaction(tx, label) if err != nil { @@ -876,9 +871,7 @@ Loop: brarLog.Debugf("Broadcasting justice tx "+ "spending HTLC outs: %v", - lnutils.NewLogClosure(func() string { - return spew.Sdump(tx) - })) + lnutils.SpewLogClosure(tx)) err = b.cfg.PublishTransaction(tx, label) if err != nil { @@ -893,9 +886,7 @@ Loop: brarLog.Debugf("Broadcasting justice tx "+ "spending second-level HTLC output: %v", - lnutils.NewLogClosure(func() string { - return spew.Sdump(tx) - })) + lnutils.SpewLogClosure(tx)) err = b.cfg.PublishTransaction(tx, label) if err != nil { diff --git a/contractcourt/channel_arbitrator.go b/contractcourt/channel_arbitrator.go index 854bff5f65..d544e989c9 100644 --- a/contractcourt/channel_arbitrator.go +++ b/contractcourt/channel_arbitrator.go @@ -14,7 +14,6 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" - "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb/models" "github.com/lightningnetwork/lnd/fn" @@ -466,10 +465,8 @@ func (c *ChannelArbitrator) Start(state *chanArbStartState) error { } log.Debugf("Starting ChannelArbitrator(%v), htlc_set=%v, state=%v", - c.cfg.ChanPoint, lnutils.NewLogClosure(func() string { - return spew.Sdump(c.activeHTLCs) - }), state.currentState, - ) + c.cfg.ChanPoint, lnutils.SpewLogClosure(c.activeHTLCs), + state.currentState) // Set our state from our starting state. c.state = state.currentState @@ -959,10 +956,7 @@ func (c *ChannelArbitrator) stateStep( // Otherwise, we'll log that we checked the HTLC actions as the // commitment transaction has already been broadcast. log.Tracef("ChannelArbitrator(%v): logging chain_actions=%v", - c.cfg.ChanPoint, - lnutils.NewLogClosure(func() string { - return spew.Sdump(chainActions) - })) + c.cfg.ChanPoint, lnutils.SpewLogClosure(chainActions)) // Depending on the type of trigger, we'll either "tunnel" // through to a farther state, or just proceed linearly to the @@ -1097,10 +1091,7 @@ func (c *ChannelArbitrator) stateStep( // channel resolution state. log.Infof("Broadcasting force close transaction %v, "+ "ChannelPoint(%v): %v", closeTx.TxHash(), - c.cfg.ChanPoint, - lnutils.NewLogClosure(func() string { - return spew.Sdump(closeTx) - })) + c.cfg.ChanPoint, lnutils.SpewLogClosure(closeTx)) // At this point, we'll now broadcast the commitment // transaction itself. @@ -1225,9 +1216,7 @@ func (c *ChannelArbitrator) stateStep( if len(pktsToSend) != 0 { log.Debugf("ChannelArbitrator(%v): sending "+ "resolution message=%v", c.cfg.ChanPoint, - lnutils.NewLogClosure(func() string { - return spew.Sdump(pktsToSend) - })) + lnutils.SpewLogClosure(pktsToSend)) err := c.cfg.DeliverResolutionMsg(pktsToSend...) if err != nil { @@ -2742,11 +2731,7 @@ func (c *ChannelArbitrator) notifyContractUpdate(upd *ContractUpdate) { c.unmergedSet[upd.HtlcKey] = newHtlcSet(upd.Htlcs) log.Tracef("ChannelArbitrator(%v): fresh set of htlcs=%v", - c.cfg.ChanPoint, - lnutils.NewLogClosure(func() string { - return spew.Sdump(upd) - }), - ) + c.cfg.ChanPoint, lnutils.SpewLogClosure(upd)) } // updateActiveHTLCs merges the unmerged set of HTLCs from the link with diff --git a/contractcourt/utxonursery.go b/contractcourt/utxonursery.go index 95e0778e64..4073841628 100644 --- a/contractcourt/utxonursery.go +++ b/contractcourt/utxonursery.go @@ -948,10 +948,7 @@ func (u *UtxoNursery) waitForSweepConf(classHeight uint32, func (u *UtxoNursery) sweepCribOutput(classHeight uint32, baby *babyOutput) error { utxnLog.Infof("Publishing CLTV-delayed HTLC output using timeout tx "+ "(txid=%v): %v", baby.timeoutTx.TxHash(), - lnutils.NewLogClosure(func() string { - return spew.Sdump(baby.timeoutTx) - }), - ) + lnutils.SpewLogClosure(baby.timeoutTx)) // We'll now broadcast the HTLC transaction, then wait for it to be // confirmed before transitioning it to kindergarten. diff --git a/discovery/bootstrapper.go b/discovery/bootstrapper.go index 9e3c40b030..0d370663d6 100644 --- a/discovery/bootstrapper.go +++ b/discovery/bootstrapper.go @@ -14,7 +14,6 @@ import ( "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcutil/bech32" - "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lnd/autopilot" "github.com/lightningnetwork/lnd/lnutils" "github.com/lightningnetwork/lnd/lnwire" @@ -432,10 +431,7 @@ search: } log.Tracef("Retrieved SRV records from dns seed: %v", - lnutils.NewLogClosure(func() string { - return spew.Sdump(addrs) - }), - ) + lnutils.SpewLogClosure(addrs)) // Next, we'll need to issue an A record request for each of // the nodes, skipping it if nothing comes back. diff --git a/graph/builder.go b/graph/builder.go index 01ea97cf93..addec9e1b5 100644 --- a/graph/builder.go +++ b/graph/builder.go @@ -12,7 +12,6 @@ import ( "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/wire" - "github.com/davecgh/go-spew/spew" "github.com/go-errors/errors" "github.com/lightningnetwork/lnd/batch" "github.com/lightningnetwork/lnd/chainntnfs" @@ -1432,9 +1431,7 @@ func (b *Builder) processUpdate(msg interface{}, } log.Tracef("New channel update applied: %v", - lnutils.NewLogClosure(func() string { - return spew.Sdump(msg) - })) + lnutils.SpewLogClosure(msg)) b.stats.incNumChannelUpdates() default: diff --git a/htlcswitch/circuit_map.go b/htlcswitch/circuit_map.go index 06477ef986..076d6f2840 100644 --- a/htlcswitch/circuit_map.go +++ b/htlcswitch/circuit_map.go @@ -5,7 +5,6 @@ import ( "fmt" "sync" - "github.com/davecgh/go-spew/spew" "github.com/go-errors/errors" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/htlcswitch/hop" @@ -801,10 +800,8 @@ func (cm *circuitMap) CommitCircuits(circuits ...*PaymentCircuit) ( inKeys = append(inKeys, circuit.Incoming) } - log.Tracef("Committing fresh circuits: %v", lnutils.NewLogClosure( - func() string { - return spew.Sdump(inKeys) - })) + log.Tracef("Committing fresh circuits: %v", lnutils.SpewLogClosure( + inKeys)) actions := &CircuitFwdActions{} @@ -950,10 +947,8 @@ func (cm *circuitMap) OpenCircuits(keystones ...Keystone) error { return nil } - log.Tracef("Opening finalized circuits: %v", lnutils.NewLogClosure( - func() string { - return spew.Sdump(keystones) - })) + log.Tracef("Opening finalized circuits: %v", lnutils.SpewLogClosure( + keystones)) // Check that all keystones correspond to committed-but-unopened // circuits. @@ -1081,10 +1076,8 @@ func (cm *circuitMap) CloseCircuit(outKey CircuitKey) (*PaymentCircuit, error) { // circuit was already cleaned up at a different point in time. func (cm *circuitMap) DeleteCircuits(inKeys ...CircuitKey) error { - log.Tracef("Deleting resolved circuits: %v", lnutils.NewLogClosure( - func() string { - return spew.Sdump(inKeys) - })) + log.Tracef("Deleting resolved circuits: %v", lnutils.SpewLogClosure( + inKeys)) var ( closingCircuits = make(map[CircuitKey]struct{}) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 20b32596f4..712bbda9e1 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -13,7 +13,6 @@ import ( "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btclog" - "github.com/davecgh/go-spew/spew" "github.com/go-errors/errors" "github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/channeldb" @@ -2537,13 +2536,9 @@ func (l *channelLink) updateCommitTx() error { l.log.Tracef("revocation window exhausted, unable to send: "+ "%v, pend_updates=%v, dangling_closes%v", l.channel.PendingLocalUpdateCount(), - lnutils.NewLogClosure(func() string { - return spew.Sdump(l.openedCircuits) - }), - lnutils.NewLogClosure(func() string { - return spew.Sdump(l.closedCircuits) - }), - ) + lnutils.SpewLogClosure(l.openedCircuits), + lnutils.SpewLogClosure(l.closedCircuits)) + return nil } else if err != nil { return err diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 7f2661212c..a78266113c 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -614,10 +614,8 @@ func (s *Switch) SendHTLC(firstHop lnwire.ShortChannelID, attemptID uint64, func (s *Switch) UpdateForwardingPolicies( chanPolicies map[wire.OutPoint]models.ForwardingPolicy) { - log.Tracef("Updating link policies: %v", lnutils.NewLogClosure( - func() string { - return spew.Sdump(chanPolicies) - })) + log.Tracef("Updating link policies: %v", lnutils.SpewLogClosure( + chanPolicies)) s.indexMtx.RLock() @@ -1216,9 +1214,7 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error { log.Warnf("unable to find err source for "+ "outgoing_link=%v, errors=%v", packet.outgoingChanID, - lnutils.NewLogClosure(func() string { - return spew.Sdump(linkErrs) - })) + lnutils.SpewLogClosure(linkErrs)) } log.Tracef("incoming HTLC(%x) violated "+ @@ -1999,9 +1995,7 @@ out: log.Tracef("Acked %d settle fails: %v", len(s.pendingSettleFails), - lnutils.NewLogClosure(func() string { - return spew.Sdump(s.pendingSettleFails) - })) + lnutils.SpewLogClosure(s.pendingSettleFails)) // Reset the pendingSettleFails buffer while keeping acquired // memory. diff --git a/lnrpc/invoicesrpc/addinvoice.go b/lnrpc/invoicesrpc/addinvoice.go index d12dc11d79..b85feefb65 100644 --- a/lnrpc/invoicesrpc/addinvoice.go +++ b/lnrpc/invoicesrpc/addinvoice.go @@ -15,7 +15,6 @@ import ( "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/wire" - "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb/models" "github.com/lightningnetwork/lnd/invoices" @@ -474,10 +473,7 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig, } log.Tracef("[addinvoice] adding new invoice %v", - lnutils.NewLogClosure(func() string { - return spew.Sdump(newInvoice) - }), - ) + lnutils.SpewLogClosure(newInvoice)) // With all sanity checks passed, write the invoice to the database. _, err = cfg.AddInvoice(ctx, newInvoice, paymentHash) diff --git a/lnutils/log.go b/lnutils/log.go index 4bfb64b070..a32738bdf4 100644 --- a/lnutils/log.go +++ b/lnutils/log.go @@ -1,5 +1,7 @@ package lnutils +import "github.com/davecgh/go-spew/spew" + // LogClosure is used to provide a closure over expensive logging operations so // don't have to be performed when the logging level doesn't warrant it. type LogClosure func() string @@ -15,3 +17,11 @@ func (c LogClosure) String() string { func NewLogClosure(c func() string) LogClosure { return LogClosure(c) } + +// SpewLogClosure takes an interface and returns the string of it created from +// `spew.Sdump` in a LogClosure. +func SpewLogClosure(a any) LogClosure { + return func() string { + return spew.Sdump(a) + } +} diff --git a/lnwallet/chancloser/chancloser.go b/lnwallet/chancloser/chancloser.go index 477d0912f4..3f5e730c0c 100644 --- a/lnwallet/chancloser/chancloser.go +++ b/lnwallet/chancloser/chancloser.go @@ -870,10 +870,7 @@ func (c *ChanCloser) ReceiveClosingSigned( //nolint:funlen // With the closing transaction crafted, we'll now broadcast it // to the network. chancloserLog.Infof("Broadcasting cooperative close tx: %v", - lnutils.NewLogClosure(func() string { - return spew.Sdump(closeTx) - }), - ) + lnutils.SpewLogClosure(closeTx)) // Create a close channel label. chanID := c.cfg.Channel.ShortChanID() diff --git a/lnwallet/channel.go b/lnwallet/channel.go index b3ccf77d1f..b4ea2fee01 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -1870,10 +1870,7 @@ func (lc *LightningChannel) restoreCommitState( lc.localCommitChain.addCommitment(localCommit) lc.log.Tracef("starting local commitment: %v", - lnutils.NewLogClosure(func() string { - return spew.Sdump(lc.localCommitChain.tail()) - }), - ) + lnutils.SpewLogClosure(lc.localCommitChain.tail())) // We'll also do the same for the remote commitment chain. remoteCommit, err := lc.diskCommitToMemCommit( @@ -1886,10 +1883,7 @@ func (lc *LightningChannel) restoreCommitState( lc.remoteCommitChain.addCommitment(remoteCommit) lc.log.Tracef("starting remote commitment: %v", - lnutils.NewLogClosure(func() string { - return spew.Sdump(lc.remoteCommitChain.tail()) - }), - ) + lnutils.SpewLogClosure(lc.remoteCommitChain.tail())) var ( pendingRemoteCommit *commitment @@ -1921,10 +1915,7 @@ func (lc *LightningChannel) restoreCommitState( lc.remoteCommitChain.addCommitment(pendingRemoteCommit) lc.log.Debugf("pending remote commitment: %v", - lnutils.NewLogClosure(func() string { - return spew.Sdump(lc.remoteCommitChain.tip()) - }), - ) + lnutils.SpewLogClosure(lc.remoteCommitChain.tip())) // We'll also re-create the set of commitment keys needed to // fully re-derive the state. @@ -3246,12 +3237,8 @@ func (lc *LightningChannel) fetchParent(entry *PaymentDescriptor, return nil, fmt.Errorf("unable to find parent entry "+ "%d in %v update log: %v\nUpdatelog: %v", entry.ParentIndex, logName, - lnutils.NewLogClosure(func() string { - return spew.Sdump(entry) - }), lnutils.NewLogClosure(func() string { - return spew.Sdump(updateLog) - }), - ) + lnutils.SpewLogClosure(entry), + lnutils.SpewLogClosure(updateLog)) // The parent add height should never be zero at this point. If // that's the case we probably forgot to send a new commitment. @@ -4250,10 +4237,7 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) { "their_balance=%v, commit_tx: %v", newCommitView.ourBalance, newCommitView.theirBalance, - lnutils.NewLogClosure(func() string { - return spew.Sdump(newCommitView.txn) - }), - ) + lnutils.SpewLogClosure(newCommitView.txn)) // With the commitment view constructed, if there are any HTLC's, we'll // need to generate signatures of each of them for the remote party's @@ -5210,10 +5194,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error { lc.log.Tracef("local chain: our_balance=%v, "+ "their_balance=%v, commit_tx: %v", localCommitmentView.ourBalance, localCommitmentView.theirBalance, - lnutils.NewLogClosure(func() string { - return spew.Sdump(localCommitmentView.txn) - }), - ) + lnutils.SpewLogClosure(localCommitmentView.txn)) // As an optimization, we'll generate a series of jobs for the worker // pool to verify each of the HTLC signatures presented. Once diff --git a/peer/brontide.go b/peer/brontide.go index 9393acefb2..fa2c8fde9a 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -2184,9 +2184,7 @@ func (p *Brontide) logWireMessage(msg lnwire.Message, read bool) { prefix = "writeMessage to peer" } - p.log.Tracef(prefix+": %v", lnutils.NewLogClosure(func() string { - return spew.Sdump(msg) - })) + p.log.Tracef(prefix+": %v", lnutils.SpewLogClosure(msg)) } // writeMessage writes and flushes the target lnwire.Message to the remote peer. diff --git a/routing/payment_session.go b/routing/payment_session.go index 7fe9a45ba0..710318426b 100644 --- a/routing/payment_session.go +++ b/routing/payment_session.go @@ -5,7 +5,6 @@ import ( "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btclog" - "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb/models" @@ -433,7 +432,7 @@ func (p *paymentSession) UpdateAdditionalEdge(msg *lnwire.ChannelUpdate, policy.FeeProportionalMillionths = lnwire.MilliSatoshi(msg.FeeRate) log.Debugf("New private channel update applied: %v", - lnutils.NewLogClosure(func() string { return spew.Sdump(msg) })) + lnutils.SpewLogClosure(msg)) return true } diff --git a/routing/router.go b/routing/router.go index 81abb50077..35db5a779a 100644 --- a/routing/router.go +++ b/routing/router.go @@ -670,10 +670,7 @@ func (r *ChannelRouter) FindRoute(req *RouteRequest) (*route.Route, float64, } go log.Tracef("Obtained path to send %v to %x: %v", - req.Amount, req.Target, lnutils.NewLogClosure(func() string { - return spew.Sdump(route) - }), - ) + req.Amount, req.Target, lnutils.SpewLogClosure(route)) return route, probability, nil } @@ -1091,11 +1088,8 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route, return nil, err } - log.Tracef("Dispatching SendToRoute for HTLC hash %v: %v", - htlcHash, lnutils.NewLogClosure(func() string { - return spew.Sdump(rt) - }), - ) + log.Tracef("Dispatching SendToRoute for HTLC hash %v: %v", htlcHash, + lnutils.SpewLogClosure(rt)) // Since the HTLC hashes and preimages are specified manually over the // RPC for SendToRoute requests, we don't have to worry about creating diff --git a/rpcserver.go b/rpcserver.go index 26c6e4c711..ac10fc790c 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -5846,9 +5846,7 @@ func (r *rpcServer) LookupInvoice(ctx context.Context, } rpcsLog.Tracef("[lookupinvoice] located invoice %v", - lnutils.NewLogClosure(func() string { - return spew.Sdump(invoice) - })) + lnutils.SpewLogClosure(invoice)) rpcInvoice, err := invoicesrpc.CreateRPCInvoice( &invoice, r.cfg.ActiveNetParams.Params, diff --git a/sweep/fee_bumper.go b/sweep/fee_bumper.go index 761f16ecd6..452cc0dd8c 100644 --- a/sweep/fee_bumper.go +++ b/sweep/fee_bumper.go @@ -12,7 +12,6 @@ import ( "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcwallet/chain" - "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/fn" "github.com/lightningnetwork/lnd/input" @@ -313,10 +312,8 @@ func (t *TxPublisher) isNeutrinoBackend() bool { // // NOTE: part of the Bumper interface. func (t *TxPublisher) Broadcast(req *BumpRequest) (<-chan *BumpResult, error) { - log.Tracef("Received broadcast request: %s", lnutils.NewLogClosure( - func() string { - return spew.Sdump(req) - })()) + log.Tracef("Received broadcast request: %s", lnutils.SpewLogClosure( + req)) // Attempt an initial broadcast which is guaranteed to comply with the // RBF rules. diff --git a/sweep/sweeper.go b/sweep/sweeper.go index d414adc886..af2f0cec9e 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -1377,10 +1377,7 @@ func (s *UtxoSweeper) handleInputSpent(spend *chainntnfs.SpendDetail) { log.Debugf("Detected third party spend related to in flight "+ "inputs (is_ours=%v): %v", isOurTx, - lnutils.NewLogClosure(func() string { - return spew.Sdump(spend.SpendingTx) - }), - ) + lnutils.SpewLogClosure(spend.SpendingTx)) } // We now use the spending tx to update the state of the inputs.