From f77cd5167181be8e9c55b23efd6983b1aa5ef5dc Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 1 Sep 2025 16:29:13 -0700 Subject: [PATCH] autopilot+funding+rpc+invoices: complete migration to lazy debug logging In this commit, we complete the migration to lnutils.SpewLogClosure for the remaining application-layer components. This includes the autopilot channel management system, the funding manager, the RPC server, and the invoice storage subsystem. --- autopilot/agent.go | 13 ++++++++----- funding/manager.go | 7 ++++--- invoices/sql_store.go | 4 ++-- rpcserver.go | 6 +++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/autopilot/agent.go b/autopilot/agent.go index 30e76d3d9..ffb3d38fe 100644 --- a/autopilot/agent.go +++ b/autopilot/agent.go @@ -11,8 +11,8 @@ import ( "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcutil" - "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lnd/fn/v2" + "github.com/lightningnetwork/lnd/lnutils" "github.com/lightningnetwork/lnd/lnwire" ) @@ -443,7 +443,7 @@ func (a *Agent) controller(ctx context.Context) { case *chanOpenUpdate: log.Debugf("New channel successfully opened, "+ "updating state with: %v", - spew.Sdump(update.newChan)) + lnutils.SpewLogClosure(update.newChan)) newChan := update.newChan a.chanStateMtx.Lock() @@ -460,7 +460,9 @@ func (a *Agent) controller(ctx context.Context) { case *chanCloseUpdate: log.Debugf("Applying closed channel "+ "updates: %v", - spew.Sdump(update.closedChans)) + lnutils.SpewLogClosure( + update.closedChans), + ) a.chanStateMtx.Lock() for _, closedChan := range update.closedChans { @@ -515,7 +517,8 @@ func (a *Agent) controller(ctx context.Context) { } a.pendingMtx.Lock() - log.Debugf("Pending channels: %v", spew.Sdump(a.pendingOpens)) + log.Debugf("Pending channels: %v", + lnutils.SpewLogClosure(a.pendingOpens)) a.pendingMtx.Unlock() // With all the updates applied, we'll obtain a set of the @@ -699,7 +702,7 @@ func (a *Agent) openChans(ctx context.Context, availableFunds btcutil.Amount, } log.Infof("Attempting to execute channel attachment "+ - "directives: %v", spew.Sdump(chanCandidates)) + "directives: %v", lnutils.SpewLogClosure(chanCandidates)) // Before proceeding, check to see if we have any slots // available to open channels. If there are any, we will attempt diff --git a/funding/manager.go b/funding/manager.go index c78bf8ddd..87ec549d6 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -18,7 +18,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/chanacceptor" "github.com/lightningnetwork/lnd/channeldb" @@ -992,7 +991,9 @@ func (f *Manager) failFundingFlow(peer lnpeer.Peer, cid *chanIdentifier, } log.Debugf("Sending funding error to peer (%x): %v", - peer.IdentityKey().SerializeCompressed(), spew.Sdump(errMsg)) + peer.IdentityKey().SerializeCompressed(), + lnutils.SpewLogClosure(errMsg)) + if err := peer.SendMessage(false, errMsg); err != nil { log.Errorf("unable to send error message to peer %v", err) } @@ -1012,7 +1013,7 @@ func (f *Manager) sendWarning(peer lnpeer.Peer, cid *chanIdentifier, log.Debugf("Sending funding warning to peer (%x): %v", peer.IdentityKey().SerializeCompressed(), - spew.Sdump(errMsg), + lnutils.SpewLogClosure(errMsg), ) if err := peer.SendMessage(false, errMsg); err != nil { diff --git a/invoices/sql_store.go b/invoices/sql_store.go index fc82e41b9..ff718ba1e 100644 --- a/invoices/sql_store.go +++ b/invoices/sql_store.go @@ -10,10 +10,10 @@ import ( "strconv" "time" - "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lnd/clock" "github.com/lightningnetwork/lnd/graph/db/models" "github.com/lightningnetwork/lnd/lntypes" + "github.com/lightningnetwork/lnd/lnutils" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/record" "github.com/lightningnetwork/lnd/sqldb" @@ -409,7 +409,7 @@ func getInvoiceByRef(ctx context.Context, // In case the reference is ambiguous, meaning it matches more // than one invoice, we'll return an error. return sqlc.Invoice{}, fmt.Errorf("ambiguous invoice ref: "+ - "%s: %s", ref.String(), spew.Sdump(rows)) + "%s: %s", ref.String(), lnutils.SpewLogClosure(rows)) case err != nil: return sqlc.Invoice{}, fmt.Errorf("unable to fetch invoice: %w", diff --git a/rpcserver.go b/rpcserver.go index 0c19c876a..9056474da 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -33,7 +33,6 @@ import ( "github.com/btcsuite/btcwallet/waddrmgr" "github.com/btcsuite/btcwallet/wallet" "github.com/btcsuite/btcwallet/wallet/txauthor" - "github.com/davecgh/go-spew/spew" proxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "github.com/lightningnetwork/lnd/autopilot" "github.com/lightningnetwork/lnd/build" @@ -1526,7 +1525,8 @@ func (r *rpcServer) SendCoins(ctx context.Context, } rpcsLog.Debugf("Sweeping coins from wallet to addr=%v, "+ - "with tx=%v", in.Addr, spew.Sdump(sweepTxPkg.SweepTx)) + "with tx=%v", in.Addr, + lnutils.SpewLogClosure(sweepTxPkg.SweepTx)) // As our sweep transaction was created, successfully, we'll // now attempt to publish it, cancelling the sweep pkg to @@ -1612,7 +1612,7 @@ func (r *rpcServer) SendMany(ctx context.Context, } rpcsLog.Infof("[sendmany] outputs=%v, sat/kw=%v", - spew.Sdump(in.AddrToAmount), int64(feePerKw)) + lnutils.SpewLogClosure(in.AddrToAmount), int64(feePerKw)) var txid *chainhash.Hash