les: cleaned up logging (#3256)
This commit is contained in:
		
				
					committed by
					
						
						Felix Lange
					
				
			
			
				
	
			
			
			
						parent
						
							932d973e36
						
					
				
				
					commit
					21701190ac
				
			@@ -248,7 +248,7 @@ func (pm *ProtocolManager) findServers() {
 | 
				
			|||||||
			select {
 | 
								select {
 | 
				
			||||||
			case enode := <-enodes:
 | 
								case enode := <-enodes:
 | 
				
			||||||
				if !added[enode] {
 | 
									if !added[enode] {
 | 
				
			||||||
					fmt.Println("Found LES server:", enode)
 | 
										glog.V(logger.Info).Infoln("Found LES server:", enode)
 | 
				
			||||||
					added[enode] = true
 | 
										added[enode] = true
 | 
				
			||||||
					if node, err := discover.ParseNode(enode); err == nil {
 | 
										if node, err := discover.ParseNode(enode); err == nil {
 | 
				
			||||||
						pm.p2pServer.AddPeer(node)
 | 
											pm.p2pServer.AddPeer(node)
 | 
				
			||||||
@@ -279,9 +279,9 @@ func (pm *ProtocolManager) Start(srvr *p2p.Server) {
 | 
				
			|||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		if pm.topicDisc != nil {
 | 
							if pm.topicDisc != nil {
 | 
				
			||||||
			go func() {
 | 
								go func() {
 | 
				
			||||||
				fmt.Println("Starting topic register")
 | 
									glog.V(logger.Debug).Infoln("Starting topic register")
 | 
				
			||||||
				pm.topicDisc.RegisterTopic(pm.lesTopic, pm.quitSync)
 | 
									pm.topicDisc.RegisterTopic(pm.lesTopic, pm.quitSync)
 | 
				
			||||||
				fmt.Println("Stopped topic register")
 | 
									glog.V(logger.Debug).Infoln("Stopped topic register")
 | 
				
			||||||
			}()
 | 
								}()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		go func() {
 | 
							go func() {
 | 
				
			||||||
@@ -381,7 +381,6 @@ func (pm *ProtocolManager) handle(p *peer) error {
 | 
				
			|||||||
			select {
 | 
								select {
 | 
				
			||||||
			case announce := <-p.announceChn:
 | 
								case announce := <-p.announceChn:
 | 
				
			||||||
				p.SendAnnounce(announce)
 | 
									p.SendAnnounce(announce)
 | 
				
			||||||
				//fmt.Println("  BROADCAST sent")
 | 
					 | 
				
			||||||
			case <-stop:
 | 
								case <-stop:
 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -392,7 +391,6 @@ func (pm *ProtocolManager) handle(p *peer) error {
 | 
				
			|||||||
	for {
 | 
						for {
 | 
				
			||||||
		if err := pm.handleMsg(p); err != nil {
 | 
							if err := pm.handleMsg(p); err != nil {
 | 
				
			||||||
			glog.V(logger.Debug).Infof("%v: message handling failed: %v", p, err)
 | 
								glog.V(logger.Debug).Infof("%v: message handling failed: %v", p, err)
 | 
				
			||||||
			//fmt.Println("handleMsg err:", err)
 | 
					 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -412,7 +410,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
	var costs *requestCosts
 | 
						var costs *requestCosts
 | 
				
			||||||
	var reqCnt, maxReqs int
 | 
						var reqCnt, maxReqs int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//fmt.Println("MSG", msg.Code, msg.Size)
 | 
						glog.V(logger.Debug).Infoln("msg:", msg.Code, msg.Size)
 | 
				
			||||||
	if rc, ok := p.fcCosts[msg.Code]; ok { // check if msg is a supported request type
 | 
						if rc, ok := p.fcCosts[msg.Code]; ok { // check if msg is a supported request type
 | 
				
			||||||
		costs = rc
 | 
							costs = rc
 | 
				
			||||||
		if p.fcClient == nil {
 | 
							if p.fcClient == nil {
 | 
				
			||||||
@@ -441,21 +439,23 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
	// Handle the message depending on its contents
 | 
						// Handle the message depending on its contents
 | 
				
			||||||
	switch msg.Code {
 | 
						switch msg.Code {
 | 
				
			||||||
	case StatusMsg:
 | 
						case StatusMsg:
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received StatusMsg from peer %v", p.id)
 | 
							glog.V(logger.Debug).Infof("<=== StatusMsg from peer %v", p.id)
 | 
				
			||||||
		// Status messages should never arrive after the handshake
 | 
							// Status messages should never arrive after the handshake
 | 
				
			||||||
		return errResp(ErrExtraStatusMsg, "uncontrolled status message")
 | 
							return errResp(ErrExtraStatusMsg, "uncontrolled status message")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Block header query, collect the requested headers and reply
 | 
						// Block header query, collect the requested headers and reply
 | 
				
			||||||
	case AnnounceMsg:
 | 
						case AnnounceMsg:
 | 
				
			||||||
 | 
							glog.V(logger.Debug).Infoln("<=== AnnounceMsg from peer %v:", p.id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		var req announceData
 | 
							var req announceData
 | 
				
			||||||
		if err := msg.Decode(&req); err != nil {
 | 
							if err := msg.Decode(&req); err != nil {
 | 
				
			||||||
			return errResp(ErrDecode, "%v: %v", msg, err)
 | 
								return errResp(ErrDecode, "%v: %v", msg, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		//fmt.Println("RECEIVED", req.Number, req.Hash, req.Td, req.ReorgDepth)
 | 
							glog.V(logger.Detail).Infoln("AnnounceMsg:", req.Number, req.Hash, req.Td, req.ReorgDepth)
 | 
				
			||||||
		pm.fetcher.notify(p, &req)
 | 
							pm.fetcher.notify(p, &req)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	case GetBlockHeadersMsg:
 | 
						case GetBlockHeadersMsg:
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received GetBlockHeadersMsg from peer %v", p.id)
 | 
							glog.V(logger.Debug).Infof("<=== GetBlockHeadersMsg from peer %v", p.id)
 | 
				
			||||||
		// Decode the complex header query
 | 
							// Decode the complex header query
 | 
				
			||||||
		var req struct {
 | 
							var req struct {
 | 
				
			||||||
			ReqID uint64
 | 
								ReqID uint64
 | 
				
			||||||
@@ -540,7 +540,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
			return errResp(ErrUnexpectedResponse, "")
 | 
								return errResp(ErrUnexpectedResponse, "")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received BlockHeadersMsg from peer %v", p.id)
 | 
							glog.V(logger.Debug).Infof("<=== BlockHeadersMsg from peer %v", p.id)
 | 
				
			||||||
		// A batch of headers arrived to one of our previous requests
 | 
							// A batch of headers arrived to one of our previous requests
 | 
				
			||||||
		var resp struct {
 | 
							var resp struct {
 | 
				
			||||||
			ReqID, BV uint64
 | 
								ReqID, BV uint64
 | 
				
			||||||
@@ -560,7 +560,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	case GetBlockBodiesMsg:
 | 
						case GetBlockBodiesMsg:
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received GetBlockBodiesMsg from peer %v", p.id)
 | 
							glog.V(logger.Debug).Infof("<===  GetBlockBodiesMsg from peer %v", p.id)
 | 
				
			||||||
		// Decode the retrieval message
 | 
							// Decode the retrieval message
 | 
				
			||||||
		var req struct {
 | 
							var req struct {
 | 
				
			||||||
			ReqID  uint64
 | 
								ReqID  uint64
 | 
				
			||||||
@@ -597,7 +597,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
			return errResp(ErrUnexpectedResponse, "")
 | 
								return errResp(ErrUnexpectedResponse, "")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received BlockBodiesMsg from peer %v", p.id)
 | 
							glog.V(logger.Debug).Infof("<===  BlockBodiesMsg from peer %v", p.id)
 | 
				
			||||||
		// A batch of block bodies arrived to one of our previous requests
 | 
							// A batch of block bodies arrived to one of our previous requests
 | 
				
			||||||
		var resp struct {
 | 
							var resp struct {
 | 
				
			||||||
			ReqID, BV uint64
 | 
								ReqID, BV uint64
 | 
				
			||||||
@@ -614,7 +614,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	case GetCodeMsg:
 | 
						case GetCodeMsg:
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received GetCodeMsg from peer %v", p.id)
 | 
							glog.V(logger.Debug).Infof("<===  GetCodeMsg from peer %v", p.id)
 | 
				
			||||||
		// Decode the retrieval message
 | 
							// Decode the retrieval message
 | 
				
			||||||
		var req struct {
 | 
							var req struct {
 | 
				
			||||||
			ReqID uint64
 | 
								ReqID uint64
 | 
				
			||||||
@@ -658,7 +658,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
			return errResp(ErrUnexpectedResponse, "")
 | 
								return errResp(ErrUnexpectedResponse, "")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received CodeMsg from peer %v", p.id)
 | 
							glog.V(logger.Debug).Infof("<=== CodeMsg from peer %v", p.id)
 | 
				
			||||||
		// A batch of node state data arrived to one of our previous requests
 | 
							// A batch of node state data arrived to one of our previous requests
 | 
				
			||||||
		var resp struct {
 | 
							var resp struct {
 | 
				
			||||||
			ReqID, BV uint64
 | 
								ReqID, BV uint64
 | 
				
			||||||
@@ -675,7 +675,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	case GetReceiptsMsg:
 | 
						case GetReceiptsMsg:
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received GetReceiptsMsg from peer %v", p.id)
 | 
							glog.V(logger.Debug).Infof("<===  GetReceiptsMsg from peer %v", p.id)
 | 
				
			||||||
		// Decode the retrieval message
 | 
							// Decode the retrieval message
 | 
				
			||||||
		var req struct {
 | 
							var req struct {
 | 
				
			||||||
			ReqID  uint64
 | 
								ReqID  uint64
 | 
				
			||||||
@@ -721,7 +721,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
			return errResp(ErrUnexpectedResponse, "")
 | 
								return errResp(ErrUnexpectedResponse, "")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received ReceiptsMsg from peer %v", p.id)
 | 
							glog.V(logger.Debug).Infof("<=== ReceiptsMsg from peer %v", p.id)
 | 
				
			||||||
		// A batch of receipts arrived to one of our previous requests
 | 
							// A batch of receipts arrived to one of our previous requests
 | 
				
			||||||
		var resp struct {
 | 
							var resp struct {
 | 
				
			||||||
			ReqID, BV uint64
 | 
								ReqID, BV uint64
 | 
				
			||||||
@@ -738,7 +738,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	case GetProofsMsg:
 | 
						case GetProofsMsg:
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received GetProofsMsg from peer %v", p.id)
 | 
							glog.V(logger.Debug).Infof("<=== GetProofsMsg from peer %v", p.id)
 | 
				
			||||||
		// Decode the retrieval message
 | 
							// Decode the retrieval message
 | 
				
			||||||
		var req struct {
 | 
							var req struct {
 | 
				
			||||||
			ReqID uint64
 | 
								ReqID uint64
 | 
				
			||||||
@@ -788,7 +788,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
			return errResp(ErrUnexpectedResponse, "")
 | 
								return errResp(ErrUnexpectedResponse, "")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received ProofsMsg from peer %v", p.id)
 | 
							glog.V(logger.Debug).Infof("<=== ProofsMsg from peer %v", p.id)
 | 
				
			||||||
		// A batch of merkle proofs arrived to one of our previous requests
 | 
							// A batch of merkle proofs arrived to one of our previous requests
 | 
				
			||||||
		var resp struct {
 | 
							var resp struct {
 | 
				
			||||||
			ReqID, BV uint64
 | 
								ReqID, BV uint64
 | 
				
			||||||
@@ -805,7 +805,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	case GetHeaderProofsMsg:
 | 
						case GetHeaderProofsMsg:
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received GetHeaderProofsMsg from peer %v", p.id)
 | 
							glog.V(logger.Debug).Infof("<=== GetHeaderProofsMsg from peer %v", p.id)
 | 
				
			||||||
		// Decode the retrieval message
 | 
							// Decode the retrieval message
 | 
				
			||||||
		var req struct {
 | 
							var req struct {
 | 
				
			||||||
			ReqID uint64
 | 
								ReqID uint64
 | 
				
			||||||
@@ -849,7 +849,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
			return errResp(ErrUnexpectedResponse, "")
 | 
								return errResp(ErrUnexpectedResponse, "")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received HeaderProofsMsg from peer %v", p.id)
 | 
							glog.V(logger.Debug).Infof("<=== HeaderProofsMsg from peer %v", p.id)
 | 
				
			||||||
		var resp struct {
 | 
							var resp struct {
 | 
				
			||||||
			ReqID, BV uint64
 | 
								ReqID, BV uint64
 | 
				
			||||||
			Data      []ChtResp
 | 
								Data      []ChtResp
 | 
				
			||||||
@@ -882,7 +882,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 | 
				
			|||||||
		pm.server.fcCostStats.update(msg.Code, uint64(reqCnt), rcost)
 | 
							pm.server.fcCostStats.update(msg.Code, uint64(reqCnt), rcost)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		glog.V(logger.Debug).Infof("LES: received unknown message with code %d from peer %v", msg.Code, p.id)
 | 
							glog.V(logger.Debug).Infof("<=== unknown message with code %d from peer %v", msg.Code, p.id)
 | 
				
			||||||
		return errResp(ErrInvalidMsgCode, "%v", msg.Code)
 | 
							return errResp(ErrInvalidMsgCode, "%v", msg.Code)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,6 @@ package les
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/binary"
 | 
						"encoding/binary"
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"math"
 | 
						"math"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
@@ -31,6 +30,8 @@ import (
 | 
				
			|||||||
	"github.com/ethereum/go-ethereum/ethdb"
 | 
						"github.com/ethereum/go-ethereum/ethdb"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/les/flowcontrol"
 | 
						"github.com/ethereum/go-ethereum/les/flowcontrol"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/light"
 | 
						"github.com/ethereum/go-ethereum/light"
 | 
				
			||||||
 | 
						"github.com/ethereum/go-ethereum/logger"
 | 
				
			||||||
 | 
						"github.com/ethereum/go-ethereum/logger/glog"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/p2p"
 | 
						"github.com/ethereum/go-ethereum/p2p"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/rlp"
 | 
						"github.com/ethereum/go-ethereum/rlp"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/trie"
 | 
						"github.com/ethereum/go-ethereum/trie"
 | 
				
			||||||
@@ -288,7 +289,9 @@ func (pm *ProtocolManager) blockLoop() {
 | 
				
			|||||||
						}
 | 
											}
 | 
				
			||||||
						lastHead = header
 | 
											lastHead = header
 | 
				
			||||||
						lastBroadcastTd = td
 | 
											lastBroadcastTd = td
 | 
				
			||||||
						//fmt.Println("BROADCAST", number, hash, td, reorg)
 | 
					
 | 
				
			||||||
 | 
											glog.V(logger.Debug).Infoln("===> ", number, hash, td, reorg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						announce := announceData{Hash: hash, Number: number, Td: td, ReorgDepth: reorg}
 | 
											announce := announceData{Hash: hash, Number: number, Td: td, ReorgDepth: reorg}
 | 
				
			||||||
						for _, p := range peers {
 | 
											for _, p := range peers {
 | 
				
			||||||
							select {
 | 
												select {
 | 
				
			||||||
@@ -391,7 +394,9 @@ func makeCht(db ethdb.Database) bool {
 | 
				
			|||||||
		lastChtNum = 0
 | 
							lastChtNum = 0
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		lastChtNum++
 | 
							lastChtNum++
 | 
				
			||||||
		fmt.Printf("CHT %d %064x\n", lastChtNum, root)
 | 
					
 | 
				
			||||||
 | 
							glog.V(logger.Info).Infoln("CHT %d %064x\n", lastChtNum, root)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		storeChtRoot(db, lastChtNum, root)
 | 
							storeChtRoot(db, lastChtNum, root)
 | 
				
			||||||
		var data [8]byte
 | 
							var data [8]byte
 | 
				
			||||||
		binary.BigEndian.PutUint64(data[:], lastChtNum)
 | 
							binary.BigEndian.PutUint64(data[:], lastChtNum)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user