Skip to content

Commit 2170119

Browse files
obscurenfjl
authored andcommitted
les: cleaned up logging (#3256)
1 parent 932d973 commit 2170119

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

les/handler.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (pm *ProtocolManager) findServers() {
248248
select {
249249
case enode := <-enodes:
250250
if !added[enode] {
251-
fmt.Println("Found LES server:", enode)
251+
glog.V(logger.Info).Infoln("Found LES server:", enode)
252252
added[enode] = true
253253
if node, err := discover.ParseNode(enode); err == nil {
254254
pm.p2pServer.AddPeer(node)
@@ -279,9 +279,9 @@ func (pm *ProtocolManager) Start(srvr *p2p.Server) {
279279
} else {
280280
if pm.topicDisc != nil {
281281
go func() {
282-
fmt.Println("Starting topic register")
282+
glog.V(logger.Debug).Infoln("Starting topic register")
283283
pm.topicDisc.RegisterTopic(pm.lesTopic, pm.quitSync)
284-
fmt.Println("Stopped topic register")
284+
glog.V(logger.Debug).Infoln("Stopped topic register")
285285
}()
286286
}
287287
go func() {
@@ -381,7 +381,6 @@ func (pm *ProtocolManager) handle(p *peer) error {
381381
select {
382382
case announce := <-p.announceChn:
383383
p.SendAnnounce(announce)
384-
//fmt.Println(" BROADCAST sent")
385384
case <-stop:
386385
return
387386
}
@@ -392,7 +391,6 @@ func (pm *ProtocolManager) handle(p *peer) error {
392391
for {
393392
if err := pm.handleMsg(p); err != nil {
394393
glog.V(logger.Debug).Infof("%v: message handling failed: %v", p, err)
395-
//fmt.Println("handleMsg err:", err)
396394
return err
397395
}
398396
}
@@ -412,7 +410,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
412410
var costs *requestCosts
413411
var reqCnt, maxReqs int
414412

415-
//fmt.Println("MSG", msg.Code, msg.Size)
413+
glog.V(logger.Debug).Infoln("msg:", msg.Code, msg.Size)
416414
if rc, ok := p.fcCosts[msg.Code]; ok { // check if msg is a supported request type
417415
costs = rc
418416
if p.fcClient == nil {
@@ -441,21 +439,23 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
441439
// Handle the message depending on its contents
442440
switch msg.Code {
443441
case StatusMsg:
444-
glog.V(logger.Debug).Infof("LES: received StatusMsg from peer %v", p.id)
442+
glog.V(logger.Debug).Infof("<=== StatusMsg from peer %v", p.id)
445443
// Status messages should never arrive after the handshake
446444
return errResp(ErrExtraStatusMsg, "uncontrolled status message")
447445

448446
// Block header query, collect the requested headers and reply
449447
case AnnounceMsg:
448+
glog.V(logger.Debug).Infoln("<=== AnnounceMsg from peer %v:", p.id)
449+
450450
var req announceData
451451
if err := msg.Decode(&req); err != nil {
452452
return errResp(ErrDecode, "%v: %v", msg, err)
453453
}
454-
//fmt.Println("RECEIVED", req.Number, req.Hash, req.Td, req.ReorgDepth)
454+
glog.V(logger.Detail).Infoln("AnnounceMsg:", req.Number, req.Hash, req.Td, req.ReorgDepth)
455455
pm.fetcher.notify(p, &req)
456456

457457
case GetBlockHeadersMsg:
458-
glog.V(logger.Debug).Infof("LES: received GetBlockHeadersMsg from peer %v", p.id)
458+
glog.V(logger.Debug).Infof("<=== GetBlockHeadersMsg from peer %v", p.id)
459459
// Decode the complex header query
460460
var req struct {
461461
ReqID uint64
@@ -540,7 +540,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
540540
return errResp(ErrUnexpectedResponse, "")
541541
}
542542

543-
glog.V(logger.Debug).Infof("LES: received BlockHeadersMsg from peer %v", p.id)
543+
glog.V(logger.Debug).Infof("<=== BlockHeadersMsg from peer %v", p.id)
544544
// A batch of headers arrived to one of our previous requests
545545
var resp struct {
546546
ReqID, BV uint64
@@ -560,7 +560,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
560560
}
561561

562562
case GetBlockBodiesMsg:
563-
glog.V(logger.Debug).Infof("LES: received GetBlockBodiesMsg from peer %v", p.id)
563+
glog.V(logger.Debug).Infof("<=== GetBlockBodiesMsg from peer %v", p.id)
564564
// Decode the retrieval message
565565
var req struct {
566566
ReqID uint64
@@ -597,7 +597,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
597597
return errResp(ErrUnexpectedResponse, "")
598598
}
599599

600-
glog.V(logger.Debug).Infof("LES: received BlockBodiesMsg from peer %v", p.id)
600+
glog.V(logger.Debug).Infof("<=== BlockBodiesMsg from peer %v", p.id)
601601
// A batch of block bodies arrived to one of our previous requests
602602
var resp struct {
603603
ReqID, BV uint64
@@ -614,7 +614,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
614614
}
615615

616616
case GetCodeMsg:
617-
glog.V(logger.Debug).Infof("LES: received GetCodeMsg from peer %v", p.id)
617+
glog.V(logger.Debug).Infof("<=== GetCodeMsg from peer %v", p.id)
618618
// Decode the retrieval message
619619
var req struct {
620620
ReqID uint64
@@ -658,7 +658,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
658658
return errResp(ErrUnexpectedResponse, "")
659659
}
660660

661-
glog.V(logger.Debug).Infof("LES: received CodeMsg from peer %v", p.id)
661+
glog.V(logger.Debug).Infof("<=== CodeMsg from peer %v", p.id)
662662
// A batch of node state data arrived to one of our previous requests
663663
var resp struct {
664664
ReqID, BV uint64
@@ -675,7 +675,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
675675
}
676676

677677
case GetReceiptsMsg:
678-
glog.V(logger.Debug).Infof("LES: received GetReceiptsMsg from peer %v", p.id)
678+
glog.V(logger.Debug).Infof("<=== GetReceiptsMsg from peer %v", p.id)
679679
// Decode the retrieval message
680680
var req struct {
681681
ReqID uint64
@@ -721,7 +721,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
721721
return errResp(ErrUnexpectedResponse, "")
722722
}
723723

724-
glog.V(logger.Debug).Infof("LES: received ReceiptsMsg from peer %v", p.id)
724+
glog.V(logger.Debug).Infof("<=== ReceiptsMsg from peer %v", p.id)
725725
// A batch of receipts arrived to one of our previous requests
726726
var resp struct {
727727
ReqID, BV uint64
@@ -738,7 +738,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
738738
}
739739

740740
case GetProofsMsg:
741-
glog.V(logger.Debug).Infof("LES: received GetProofsMsg from peer %v", p.id)
741+
glog.V(logger.Debug).Infof("<=== GetProofsMsg from peer %v", p.id)
742742
// Decode the retrieval message
743743
var req struct {
744744
ReqID uint64
@@ -788,7 +788,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
788788
return errResp(ErrUnexpectedResponse, "")
789789
}
790790

791-
glog.V(logger.Debug).Infof("LES: received ProofsMsg from peer %v", p.id)
791+
glog.V(logger.Debug).Infof("<=== ProofsMsg from peer %v", p.id)
792792
// A batch of merkle proofs arrived to one of our previous requests
793793
var resp struct {
794794
ReqID, BV uint64
@@ -805,7 +805,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
805805
}
806806

807807
case GetHeaderProofsMsg:
808-
glog.V(logger.Debug).Infof("LES: received GetHeaderProofsMsg from peer %v", p.id)
808+
glog.V(logger.Debug).Infof("<=== GetHeaderProofsMsg from peer %v", p.id)
809809
// Decode the retrieval message
810810
var req struct {
811811
ReqID uint64
@@ -849,7 +849,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
849849
return errResp(ErrUnexpectedResponse, "")
850850
}
851851

852-
glog.V(logger.Debug).Infof("LES: received HeaderProofsMsg from peer %v", p.id)
852+
glog.V(logger.Debug).Infof("<=== HeaderProofsMsg from peer %v", p.id)
853853
var resp struct {
854854
ReqID, BV uint64
855855
Data []ChtResp
@@ -882,7 +882,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
882882
pm.server.fcCostStats.update(msg.Code, uint64(reqCnt), rcost)
883883

884884
default:
885-
glog.V(logger.Debug).Infof("LES: received unknown message with code %d from peer %v", msg.Code, p.id)
885+
glog.V(logger.Debug).Infof("<=== unknown message with code %d from peer %v", msg.Code, p.id)
886886
return errResp(ErrInvalidMsgCode, "%v", msg.Code)
887887
}
888888

les/server.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package les
1919

2020
import (
2121
"encoding/binary"
22-
"fmt"
2322
"math"
2423
"sync"
2524
"time"
@@ -31,6 +30,8 @@ import (
3130
"github.com/ethereum/go-ethereum/ethdb"
3231
"github.com/ethereum/go-ethereum/les/flowcontrol"
3332
"github.com/ethereum/go-ethereum/light"
33+
"github.com/ethereum/go-ethereum/logger"
34+
"github.com/ethereum/go-ethereum/logger/glog"
3435
"github.com/ethereum/go-ethereum/p2p"
3536
"github.com/ethereum/go-ethereum/rlp"
3637
"github.com/ethereum/go-ethereum/trie"
@@ -288,7 +289,9 @@ func (pm *ProtocolManager) blockLoop() {
288289
}
289290
lastHead = header
290291
lastBroadcastTd = td
291-
//fmt.Println("BROADCAST", number, hash, td, reorg)
292+
293+
glog.V(logger.Debug).Infoln("===> ", number, hash, td, reorg)
294+
292295
announce := announceData{Hash: hash, Number: number, Td: td, ReorgDepth: reorg}
293296
for _, p := range peers {
294297
select {
@@ -391,7 +394,9 @@ func makeCht(db ethdb.Database) bool {
391394
lastChtNum = 0
392395
} else {
393396
lastChtNum++
394-
fmt.Printf("CHT %d %064x\n", lastChtNum, root)
397+
398+
glog.V(logger.Info).Infoln("CHT %d %064x\n", lastChtNum, root)
399+
395400
storeChtRoot(db, lastChtNum, root)
396401
var data [8]byte
397402
binary.BigEndian.PutUint64(data[:], lastChtNum)

0 commit comments

Comments
 (0)