From 6e21bc57648c2336e33c2138c8ea92c884cd80fc Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 1 Sep 2025 16:25:50 -0700 Subject: [PATCH] lnwallet: replace spew.Sdump with lnutils.SpewLogClosure for lazy evaluation In this commit, we replace all instances of spew.Sdump in the lnwallet package and its subpackages with lnutils.SpewLogClosure. This change ensures that expensive debug dump operations are only performed when the log level actually requires them. --- lnwallet/btcwallet/btcwallet.go | 8 +++++--- lnwallet/chancloser/chancloser.go | 3 +-- lnwallet/chancloser/rbf_coop_transitions.go | 3 +-- lnwallet/channel.go | 3 +-- lnwallet/wallet.go | 13 +++++++------ 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 682908cd0..7762dc514 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -24,12 +24,12 @@ import ( "github.com/btcsuite/btcwallet/wallet/txrules" "github.com/btcsuite/btcwallet/walletdb" "github.com/btcsuite/btcwallet/wtxmgr" - "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lnd/blockcache" "github.com/lightningnetwork/lnd/fn/v2" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/kvdb" + "github.com/lightningnetwork/lnd/lnutils" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet/chainfee" ) @@ -1184,7 +1184,8 @@ func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx, label string) error { } result := results[0] - log.Debugf("TestMempoolAccept result: %s", spew.Sdump(result)) + log.Debugf("TestMempoolAccept result: %s", + lnutils.SpewLogClosure(result)) // Once mempool check passed, we can publish the transaction. if result.Allowed { @@ -1833,7 +1834,8 @@ func (b *BtcWallet) CheckMempoolAcceptance(tx *wire.MsgTx) error { } result := results[0] - log.Debugf("TestMempoolAccept result: %s", spew.Sdump(result)) + log.Debugf("TestMempoolAccept result: %s", + lnutils.SpewLogClosure(result)) // Mempool check failed, we now map the reject reason to a proper RPC // error and return it. diff --git a/lnwallet/chancloser/chancloser.go b/lnwallet/chancloser/chancloser.go index 0751c2906..cc6ccffa8 100644 --- a/lnwallet/chancloser/chancloser.go +++ b/lnwallet/chancloser/chancloser.go @@ -10,7 +10,6 @@ import ( "github.com/btcsuite/btcd/chaincfg" "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/fn/v2" "github.com/lightningnetwork/lnd/htlcswitch" @@ -414,7 +413,7 @@ func (c *ChanCloser) initChanShutdown() (*lnwire.Shutdown, error) { ) chancloserLog.Infof("Initiating shutdown w/ nonce: %v", - spew.Sdump(firstClosingNonce.PubNonce)) + lnutils.SpewLogClosure(firstClosingNonce.PubNonce)) } // Before closing, we'll attempt to send a disable update for the diff --git a/lnwallet/chancloser/rbf_coop_transitions.go b/lnwallet/chancloser/rbf_coop_transitions.go index 0fd202d1f..ac9432a5c 100644 --- a/lnwallet/chancloser/rbf_coop_transitions.go +++ b/lnwallet/chancloser/rbf_coop_transitions.go @@ -9,7 +9,6 @@ import ( "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/mempool" "github.com/btcsuite/btcd/wire" - "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lnd/fn/v2" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/labels" @@ -799,7 +798,7 @@ func (l *LocalCloseStart) ProcessEvent(event ProtocolEvent, l.RemoteDeliveryScript[:], absoluteFee) chancloserLog.Infof("proposing closing_tx=%v", - spew.Sdump(closeTx)) + lnutils.SpewLogClosure(closeTx)) // Now that we have our signature, we'll set the proper // closingSigs field based on if the remote party's output is diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 29de01618..c96a35b45 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -21,7 +21,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/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/fn/v2" @@ -2850,7 +2849,7 @@ func (lc *LightningChannel) fetchCommitmentView( return nil, fmt.Errorf("height=%v, for ChannelPoint(%v) "+ "attempts to create commitment with feerate %v: %v", nextHeight, lc.channelState.FundingOutpoint, - effFeeRate, spew.Sdump(commitTx)) + effFeeRate, lnutils.SpewLogClosure(commitTx)) } // Given the custom blob of the past state, and this new HTLC view, diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 2646d7c8f..daba09925 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -21,12 +21,12 @@ import ( "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcwallet/wallet" - "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/fn/v2" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/lntypes" + "github.com/lightningnetwork/lnd/lnutils" "github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chanfunding" "github.com/lightningnetwork/lnd/lnwallet/chanvalidate" @@ -1733,7 +1733,8 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) { } walletLog.Tracef("Funding tx for ChannelPoint(%v) "+ - "generated: %v", chanPoint, spew.Sdump(fundingTx)) + "generated: %v", chanPoint, + lnutils.SpewLogClosure(fundingTx)) } // If we landed here and didn't exit early, it means we already have @@ -2001,9 +2002,9 @@ func (l *LightningWallet) handleChanPointReady(req *continueContributionMsg) { txsort.InPlaceSort(theirCommitTx) walletLog.Tracef("Local commit tx for ChannelPoint(%v): %v", - chanPoint, spew.Sdump(ourCommitTx)) + chanPoint, lnutils.SpewLogClosure(ourCommitTx)) walletLog.Tracef("Remote commit tx for ChannelPoint(%v): %v", - chanPoint, spew.Sdump(theirCommitTx)) + chanPoint, lnutils.SpewLogClosure(theirCommitTx)) // Record newly available information within the open channel state. chanState.FundingOutpoint = chanPoint @@ -2449,9 +2450,9 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) { chanState.RemoteCommitment.CommitTx = theirCommitTx walletLog.Debugf("Local commit tx for ChannelPoint(%v): %v", - req.fundingOutpoint, spew.Sdump(ourCommitTx)) + req.fundingOutpoint, lnutils.SpewLogClosure(ourCommitTx)) walletLog.Debugf("Remote commit tx for ChannelPoint(%v): %v", - req.fundingOutpoint, spew.Sdump(theirCommitTx)) + req.fundingOutpoint, lnutils.SpewLogClosure(theirCommitTx)) // With both commitment transactions created, we'll now verify their // signature on our commitment.