Skip to content

Commit

Permalink
wallet: downgrade spew log to debug and limit its size
Browse files Browse the repository at this point in the history
This commit removes using `spew` on production as the tx log can be
extremely large.
  • Loading branch information
yyforyongyu committed Jan 25, 2024
1 parent 6b096b0 commit 1b81bb1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -3819,15 +3819,21 @@ func (w *Wallet) publishTransaction(tx *wire.MsgTx) (*chainhash.Hash, error) {
log.Warnf("Unable to remove invalid transaction %v: %v",
tx.TxHash(), dbErr)
} else {
// The spew output is pretty nice to directly see how many
// inputs/outputs of what type there are.
log.Infof("Removed invalid transaction: %v", spew.Sdump(tx))
log.Infof("Removed invalid transaction: %v", tx.TxHash())

// The serialized transaction is for logging only, don't fail on
// the error.
// The serialized transaction is for logging only, don't fail
// on the error.
var txRaw bytes.Buffer
_ = tx.Serialize(&txRaw)
log.Infof("Removed invalid transaction: %x", txRaw.Bytes())

// Optionally log the tx in debug when the size is manageable.
if txRaw.Len() < 1_000_000 {
log.Debugf("Removed invalid transaction: %v \n hex=%x",
spew.Sdump(tx), txRaw.Bytes())
} else {
log.Debug("Removed invalid transaction due to size " +
"too large")
}
}

return nil, returnErr
Expand Down

0 comments on commit 1b81bb1

Please sign in to comment.