Skip to content

Commit 89caa21

Browse files
gertjaapadiabat
authored andcommitted
Fixed log level issues, replaced use of fmt.Printf where appropriate (#361)
* Fixed log level issues, replaced use of fmt.Printf where appropriate * Additional logging fixes
1 parent 502780c commit 89caa21

File tree

12 files changed

+40
-39
lines changed

12 files changed

+40
-39
lines changed

btcutil/txscript/opcode.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
"fmt"
1313
"hash"
1414

15-
"github.com/mit-dci/lit/crypto/koblitz"
1615
"github.com/mit-dci/lit/btcutil/chaincfg/chainhash"
1716
"github.com/mit-dci/lit/crypto/fastsha256"
17+
"github.com/mit-dci/lit/crypto/koblitz"
1818
"github.com/mit-dci/lit/crypto/ripemd160"
1919
"github.com/mit-dci/lit/wire"
2020
)

btcutil/txscript/script.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/mit-dci/lit/btcutil/chaincfg/chainhash"
14+
"github.com/mit-dci/lit/logging"
1415
"github.com/mit-dci/lit/wire"
1516
)
1617

@@ -418,7 +419,7 @@ func CalcWitnessSignatureHash(subScript []parsedOpcode, sigHashes *TxSigHashes,
418419
// As a sanity check, ensure the passed input index for the transaction
419420
// is valid.
420421
if idx > len(tx.TxIn)-1 {
421-
fmt.Printf("calcWitnessSignatureHash error: idx %d but %d txins",
422+
logging.Errorf("calcWitnessSignatureHash error: idx %d but %d txins",
422423
idx, len(tx.TxIn))
423424
return nil
424425
}

cmd/lit-af/dlccmds.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/fatih/color"
1111
"github.com/mit-dci/lit/litrpc"
1212
"github.com/mit-dci/lit/lnutil"
13+
"github.com/mit-dci/lit/logging"
1314
)
1415

1516
var dlcCommand = &Command{
@@ -389,7 +390,7 @@ func (lc *litAfClient) DlcListOracles(textArgs []string) error {
389390
return err
390391
}
391392
if len(reply.Oracles) == 0 {
392-
fmt.Println("No oracles found")
393+
logging.Infof("No oracles found")
393394
}
394395
for _, o := range reply.Oracles {
395396
fmt.Fprintf(color.Output, "%04d: [%x...%x...%x] %s\n",

cmd/lit-af/walletcmds.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/fatih/color"
88
"github.com/mit-dci/lit/litrpc"
99
"github.com/mit-dci/lit/lnutil"
10+
"github.com/mit-dci/lit/logging"
1011
)
1112

1213
var sendCommand = &Command{
@@ -166,7 +167,7 @@ func (lc *litAfClient) Fee(textArgs []string) error {
166167
if len(textArgs) > 0 {
167168
feeint, err := strconv.Atoi(textArgs[0])
168169
if err != nil {
169-
fmt.Printf("Can't set fee to %s, querying current fee instead\n", textArgs[0])
170+
logging.Errorf("Can't set fee to %s, querying current fee instead\n", textArgs[0])
170171
} else {
171172
set = true
172173
SetArgs.Fee = int64(feeint)

eventbus/bus_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package eventbus
22

33
import (
4-
"fmt"
54
"testing"
65
"time"
6+
7+
"github.com/mit-dci/lit/logging"
78
)
89

910
func TestBusSimple(t *testing.T) {
@@ -57,7 +58,7 @@ func TestBusAsync(t *testing.T) {
5758
})
5859

5960
r := <-c
60-
fmt.Printf("got result: %d\n", r)
61+
logging.Infof("got result: %d\n", r)
6162

6263
}
6364

lnutil/dlclib.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import (
55
"bytes"
66
"encoding/binary"
77
"fmt"
8+
"math/big"
9+
810
"github.com/mit-dci/lit/btcutil/chaincfg/chainhash"
911
"github.com/mit-dci/lit/consts"
1012
"github.com/mit-dci/lit/crypto/koblitz"
1113
"github.com/mit-dci/lit/logging"
1214
"github.com/mit-dci/lit/wire"
13-
"math/big"
1415
)
1516

1617
// DlcContractStatus is an enumeration containing the various statuses a
@@ -96,14 +97,14 @@ func DlcContractFromBytes(b []byte) (*DlcContract, error) {
9697

9798
ourIdx, err := wire.ReadVarInt(buf, 0)
9899
if err != nil {
99-
fmt.Println("Error while deserializing varint for theirIdx")
100+
logging.Errorf("Error while deserializing varint for theirIdx: %s", err.Error())
100101
return nil, err
101102
}
102103
c.Idx = ourIdx
103104

104105
theirIdx, err := wire.ReadVarInt(buf, 0)
105106
if err != nil {
106-
fmt.Println("Error while deserializing varint for theirIdx")
107+
logging.Errorf("Error while deserializing varint for theirIdx: %s", err.Error())
107108
return nil, err
108109
}
109110
c.TheirIdx = theirIdx
@@ -113,14 +114,14 @@ func DlcContractFromBytes(b []byte) (*DlcContract, error) {
113114

114115
peerIdx, err := wire.ReadVarInt(buf, 0)
115116
if err != nil {
116-
fmt.Println("Error while deserializing varint for peerIdx")
117+
logging.Errorf("Error while deserializing varint for peerIdx: %s", err.Error())
117118
return nil, err
118119
}
119120
c.PeerIdx = uint32(peerIdx)
120121

121122
coinType, err := wire.ReadVarInt(buf, 0)
122123
if err != nil {
123-
fmt.Println("Error while deserializing varint for coinType")
124+
logging.Errorf("Error while deserializing varint for coinType: %s", err.Error())
124125
return nil, err
125126
}
126127
c.CoinType = uint32(coinType)
@@ -153,7 +154,7 @@ func DlcContractFromBytes(b []byte) (*DlcContract, error) {
153154

154155
status, err := wire.ReadVarInt(buf, 0)
155156
if err != nil {
156-
fmt.Println("Error while deserializing varint for status")
157+
logging.Errorf("Error while deserializing varint for status: %s", err.Error())
157158
return nil, err
158159
}
159160

nat/upnp.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package nat
22

33
import (
44
"context"
5-
"fmt"
65

76
"github.com/mit-dci/lit/logging"
87

@@ -13,21 +12,18 @@ func SetupUpnp(port uint16) error {
1312
// Connect to router
1413
deliver, err := UpnP.DiscoverCtx(context.Background())
1514
if err != nil {
16-
fmt.Printf("Unable to discover router %v\n", err)
17-
logging.Fatal(err)
15+
logging.Fatalf("Unable to discover router %v\n", err)
1816
}
1917
// Get external IP
2018
ip, err := deliver.ExternalIP()
2119
if err != nil {
22-
fmt.Printf("Unable to get external ip %v\n", err)
23-
logging.Fatal(err)
20+
logging.Fatalf("Unable to get external ip %v\n", err)
2421
}
2522
logging.Infof("Your external IP is %s", ip)
2623
// Forward peer port
2724
err = deliver.Forward(uint16(port), "lnd peer port")
2825
if err != nil {
29-
fmt.Printf("UpnP: Unable to forward pear port ip %v\n", err)
30-
logging.Fatal(err)
26+
logging.Fatalf("UpnP: Unable to forward pear port ip %v\n", err)
3127
}
3228
return nil
3329
}

qln/buildtx.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (q *Qchan) BuildStateTxs(mine bool) (*wire.MsgTx, []*wire.MsgTx, []*wire.Tx
200200
outFancy := wire.NewTxOut(fancyAmt, fancyScript)
201201
outPKH := wire.NewTxOut(pkhAmt, pkhScript)
202202

203-
fmt.Printf("\tcombined refund %x, pkh %x, amt %d\n", pkhPub, outPKH.PkScript, pkhAmt)
203+
logging.Infof("\tcombined refund %x, pkh %x, amt %d\n", pkhPub, outPKH.PkScript, pkhAmt)
204204

205205
var HTLCTxOuts []*wire.TxOut
206206

qln/htlc.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (nd *LitNode) HashSigHandler(msg lnutil.HashSigMsg, qc *Qchan) error {
196196
collision = true
197197
}
198198

199-
fmt.Printf("COLLISION is (%t)\n", collision)
199+
logging.Infof("COLLISION is (%t)\n", collision)
200200

201201
// load state from disk
202202
err := nd.ReloadQchanState(qc)
@@ -294,7 +294,7 @@ func (nd *LitNode) HashSigHandler(msg lnutil.HashSigMsg, qc *Qchan) error {
294294
// update to the next state to verify
295295
qc.State.StateIdx++
296296

297-
fmt.Printf("Got message %x", msg.Data)
297+
logging.Infof("Got message %x", msg.Data)
298298
qc.State.Data = msg.Data
299299

300300
// verify sig for the next state. only save if this works
@@ -563,7 +563,7 @@ func (nd *LitNode) PreimageSigHandler(msg lnutil.PreimageSigMsg, qc *Qchan) erro
563563
collision = true
564564
}
565565

566-
fmt.Printf("COLLISION is (%t)\n", collision)
566+
logging.Infof("COLLISION is (%t)\n", collision)
567567

568568
// load state from disk
569569
err := nd.ReloadQchanState(qc)
@@ -596,7 +596,7 @@ func (nd *LitNode) PreimageSigHandler(msg lnutil.PreimageSigMsg, qc *Qchan) erro
596596
}
597597

598598
if qc.State.Delta > 0 {
599-
fmt.Printf(
599+
logging.Errorf(
600600
"PreimageSigHandler err: chan %d delta %d, expect rev, send empty rev",
601601
qc.Idx(), qc.State.Delta)
602602

@@ -667,7 +667,7 @@ func (nd *LitNode) PreimageSigHandler(msg lnutil.PreimageSigMsg, qc *Qchan) erro
667667
// update to the next state to verify
668668
qc.State.StateIdx++
669669

670-
fmt.Printf("Got message %x", msg.Data)
670+
logging.Infof("Got message %x", msg.Data)
671671
qc.State.Data = msg.Data
672672

673673
h := &qc.State.HTLCs[msg.Idx]

qln/msghandler.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -210,33 +210,33 @@ func (nd *LitNode) ChannelHandler(msg lnutil.LitMsg, peer *RemotePeer) error {
210210
func (nd *LitNode) DualFundingHandler(msg lnutil.LitMsg, peer *RemotePeer) error {
211211
switch message := msg.(type) {
212212
case lnutil.DualFundingReqMsg: // DUAL FUNDING REQUEST
213-
fmt.Printf("Got dual funding request from %x\n", message.Peer())
213+
logging.Infof("Got dual funding request from %x\n", message.Peer())
214214
nd.DualFundingReqHandler(message)
215215
return nil
216216

217217
case lnutil.DualFundingAcceptMsg: // DUAL FUNDING ACCEPT
218-
fmt.Printf("Got dual funding acceptance from %x\n", msg.Peer())
218+
logging.Infof("Got dual funding acceptance from %x\n", msg.Peer())
219219
nd.DualFundingAcceptHandler(message)
220220
return nil
221221

222222
case lnutil.DualFundingDeclMsg: // DUAL FUNDING DECLINE
223-
fmt.Printf("Got dual funding decline from %x\n", msg.Peer())
223+
logging.Infof("Got dual funding decline from %x\n", msg.Peer())
224224
nd.DualFundingDeclHandler(message)
225225
return nil
226226

227227
case lnutil.ChanDescMsg: // CHANNEL DESCRIPTION
228-
fmt.Printf("Got (dual funding) channel description from %x\n", msg.Peer())
228+
logging.Infof("Got (dual funding) channel description from %x\n", msg.Peer())
229229
nd.DualFundChanDescHandler(message)
230230
return nil
231231

232232
case lnutil.DualFundingChanAckMsg: // CHANNEL ACKNOWLEDGE
233-
fmt.Printf("Got (dual funding) channel acknowledgement from %x\n", msg.Peer())
233+
logging.Infof("Got (dual funding) channel acknowledgement from %x\n", msg.Peer())
234234

235235
nd.DualFundChanAckHandler(message, peer)
236236
return nil
237237

238238
case lnutil.SigProofMsg: // HERE'S YOUR CHANNEL
239-
fmt.Printf("Got (dual funding) channel proof from %x\n", msg.Peer())
239+
logging.Infof("Got (dual funding) channel proof from %x\n", msg.Peer())
240240
nd.DualFundSigProofHandler(message, peer)
241241
return nil
242242

qln/signtx.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"bytes"
55
"fmt"
66

7-
"github.com/mit-dci/lit/crypto/koblitz"
87
"github.com/mit-dci/lit/btcutil/txscript"
8+
"github.com/mit-dci/lit/crypto/koblitz"
99
"github.com/mit-dci/lit/lnutil"
1010
"github.com/mit-dci/lit/logging"
1111
"github.com/mit-dci/lit/sig64"
@@ -205,10 +205,10 @@ func (nd *LitNode) SignState(q *Qchan) ([64]byte, [][64]byte, error) {
205205
return sig, nil, err
206206
}
207207

208-
fmt.Printf("____ sig creation for channel (%d,%d):\n", q.Peer(), q.Idx())
209-
fmt.Printf("\tinput %s\n", commitmentTx.TxIn[0].PreviousOutPoint.String())
208+
logging.Infof("____ sig creation for channel (%d,%d):\n", q.Peer(), q.Idx())
209+
logging.Infof("\tinput %s\n", commitmentTx.TxIn[0].PreviousOutPoint.String())
210210
for i, txout := range commitmentTx.TxOut {
211-
fmt.Printf("\toutput %d: %x %d\n", i, txout.PkScript, txout.Value)
211+
logging.Infof("\toutput %d: %x %d\n", i, txout.PkScript, txout.Value)
212212
}
213213

214214
logging.Infof("\tstate %d myamt: %d theiramt: %d\n", q.State.StateIdx, q.State.MyAmt, q.Value-q.State.MyAmt)
@@ -354,10 +354,10 @@ func (q *Qchan) VerifySigs(sig [64]byte, HTLCSigs [][64]byte) error {
354354
if err != nil {
355355
return err
356356
}
357-
fmt.Printf("____ sig verification for channel (%d,%d):\n", q.Peer(), q.Idx())
358-
fmt.Printf("\tinput %s\n", commitmentTx.TxIn[0].PreviousOutPoint.String())
357+
logging.Infof("____ sig verification for channel (%d,%d):\n", q.Peer(), q.Idx())
358+
logging.Infof("\tinput %s\n", commitmentTx.TxIn[0].PreviousOutPoint.String())
359359
for i, txout := range commitmentTx.TxOut {
360-
fmt.Printf("\toutput %d: %x %d\n", i, txout.PkScript, txout.Value)
360+
logging.Infof("\toutput %d: %x %d\n", i, txout.PkScript, txout.Value)
361361
}
362362
logging.Infof("\tstate %d myamt: %d theiramt: %d\n", q.State.StateIdx, q.State.MyAmt, q.Value-q.State.MyAmt)
363363
logging.Infof("\tsig: %x\n", sig)

uspv/eight333.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ func (s *SPVCon) AskForBlocks() error {
373373
return nil
374374
}
375375

376-
logging.Errorf("will request blocks %d to %d\n", s.syncHeight+1, headerTip)
376+
logging.Debugf("will request blocks %d to %d\n", s.syncHeight+1, headerTip)
377377
reqHeight := s.syncHeight
378378

379379
// loop through all heights where we want merkleblocks.

0 commit comments

Comments
 (0)