diff options
Diffstat (limited to 'les')
-rw-r--r-- | les/backend.go | 5 | ||||
-rw-r--r-- | les/fetcher.go | 38 | ||||
-rw-r--r-- | les/handler.go | 71 | ||||
-rw-r--r-- | les/odr.go | 8 | ||||
-rw-r--r-- | les/odr_requests.go | 76 | ||||
-rw-r--r-- | les/peer.go | 19 | ||||
-rw-r--r-- | les/server.go | 8 | ||||
-rw-r--r-- | les/serverpool.go | 20 |
8 files changed, 121 insertions, 124 deletions
diff --git a/les/backend.go b/les/backend.go index 21ee08498..94563c29f 100644 --- a/les/backend.go +++ b/les/backend.go @@ -36,8 +36,7 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/light" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/params" @@ -188,7 +187,7 @@ func (s *LightEthereum) Protocols() []p2p.Protocol { // Start implements node.Service, starting all internal goroutines needed by the // Ethereum protocol implementation. func (s *LightEthereum) Start(srvr *p2p.Server) error { - glog.V(logger.Info).Infof("WARNING: light client mode is an experimental feature") + log.Info(fmt.Sprintf("WARNING: light client mode is an experimental feature")) s.netRPCService = ethapi.NewPublicNetAPI(srvr, s.netVersionId) s.protocolManager.Start(srvr) return nil diff --git a/les/fetcher.go b/les/fetcher.go index de706de5e..dcaea87e8 100644 --- a/les/fetcher.go +++ b/les/fetcher.go @@ -18,6 +18,7 @@ package les import ( + "fmt" "math/big" "sync" "time" @@ -27,8 +28,7 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/light" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" ) const ( @@ -174,7 +174,7 @@ func (f *lightFetcher) syncLoop() { f.reqMu.Unlock() if ok { f.pm.serverPool.adjustResponseTime(req.peer.poolEntry, time.Duration(mclock.Now()-req.sent), true) - glog.V(logger.Debug).Infof("hard timeout by peer %v", req.peer.id) + log.Debug(fmt.Sprintf("hard timeout by peer %v", req.peer.id)) go f.pm.removePeer(req.peer.id) } case resp := <-f.deliverChn: @@ -192,13 +192,13 @@ func (f *lightFetcher) syncLoop() { } f.lock.Lock() if !ok || !(f.syncing || f.processResponse(req, resp)) { - glog.V(logger.Debug).Infof("failed processing response by peer %v", resp.peer.id) + log.Debug(fmt.Sprintf("failed processing response by peer %v", resp.peer.id)) go f.pm.removePeer(resp.peer.id) } f.lock.Unlock() case p := <-f.syncDone: f.lock.Lock() - glog.V(logger.Debug).Infof("done synchronising with peer %v", p.id) + log.Debug(fmt.Sprintf("done synchronising with peer %v", p.id)) f.checkSyncedHeaders(p) f.syncing = false f.lock.Unlock() @@ -239,17 +239,17 @@ func (f *lightFetcher) removePeer(p *peer) { func (f *lightFetcher) announce(p *peer, head *announceData) { f.lock.Lock() defer f.lock.Unlock() - glog.V(logger.Debug).Infof("received announce from peer %v #%d %016x reorg: %d", p.id, head.Number, head.Hash[:8], head.ReorgDepth) + log.Debug(fmt.Sprintf("received announce from peer %v #%d %016x reorg: %d", p.id, head.Number, head.Hash[:8], head.ReorgDepth)) fp := f.peers[p] if fp == nil { - glog.V(logger.Debug).Infof("announce: unknown peer") + log.Debug(fmt.Sprintf("announce: unknown peer")) return } if fp.lastAnnounced != nil && head.Td.Cmp(fp.lastAnnounced.td) <= 0 { // announced tds should be strictly monotonic - glog.V(logger.Debug).Infof("non-monotonic Td from peer %v", p.id) + log.Debug(fmt.Sprintf("non-monotonic Td from peer %v", p.id)) go f.pm.removePeer(p.id) return } @@ -355,14 +355,14 @@ func (f *lightFetcher) peerHasBlock(p *peer, hash common.Hash, number uint64) bo func (f *lightFetcher) request(p *peer, reqID uint64, n *fetcherTreeNode, amount uint64) (uint64, bool) { fp := f.peers[p] if fp == nil { - glog.V(logger.Debug).Infof("request: unknown peer") + log.Debug(fmt.Sprintf("request: unknown peer")) p.fcServer.DeassignRequest(reqID) return 0, false } if fp.bestConfirmed == nil || fp.root == nil || !f.checkKnownNode(p, fp.root) { f.syncing = true go func() { - glog.V(logger.Debug).Infof("synchronising with peer %v", p.id) + log.Debug(fmt.Sprintf("synchronising with peer %v", p.id)) f.pm.synchronise(p) f.syncDone <- p }() @@ -457,7 +457,7 @@ func (f *lightFetcher) deliverHeaders(peer *peer, reqID uint64, headers []*types // processResponse processes header download request responses, returns true if successful func (f *lightFetcher) processResponse(req fetchRequest, resp fetchResponse) bool { if uint64(len(resp.headers)) != req.amount || resp.headers[0].Hash() != req.hash { - glog.V(logger.Debug).Infof("response mismatch %v %016x != %v %016x", len(resp.headers), resp.headers[0].Hash().Bytes()[:8], req.amount, req.hash[:8]) + log.Debug(fmt.Sprintf("response mismatch %v %016x != %v %016x", len(resp.headers), resp.headers[0].Hash().Bytes()[:8], req.amount, req.hash[:8])) return false } headers := make([]*types.Header, req.amount) @@ -468,14 +468,14 @@ func (f *lightFetcher) processResponse(req fetchRequest, resp fetchResponse) boo if err == core.BlockFutureErr { return true } - glog.V(logger.Debug).Infof("InsertHeaderChain error: %v", err) + log.Debug(fmt.Sprintf("InsertHeaderChain error: %v", err)) return false } tds := make([]*big.Int, len(headers)) for i, header := range headers { td := f.chain.GetTd(header.Hash(), header.Number.Uint64()) if td == nil { - glog.V(logger.Debug).Infof("TD not found for header %v of %v", i+1, len(headers)) + log.Debug(fmt.Sprintf("TD not found for header %v of %v", i+1, len(headers))) return false } tds[i] = td @@ -490,7 +490,7 @@ func (f *lightFetcher) newHeaders(headers []*types.Header, tds []*big.Int) { var maxTd *big.Int for p, fp := range f.peers { if !f.checkAnnouncedHeaders(fp, headers, tds) { - glog.V(logger.Debug).Infof("announce inconsistency by peer %v", p.id) + log.Debug(fmt.Sprintf("announce inconsistency by peer %v", p.id)) go f.pm.removePeer(p.id) } if fp.confirmedTd != nil && (maxTd == nil || maxTd.Cmp(fp.confirmedTd) > 0) { @@ -576,7 +576,7 @@ func (f *lightFetcher) checkAnnouncedHeaders(fp *fetcherPeerInfo, headers []*typ func (f *lightFetcher) checkSyncedHeaders(p *peer) { fp := f.peers[p] if fp == nil { - glog.V(logger.Debug).Infof("checkSyncedHeaders: unknown peer") + log.Debug(fmt.Sprintf("checkSyncedHeaders: unknown peer")) return } n := fp.lastAnnounced @@ -589,7 +589,7 @@ func (f *lightFetcher) checkSyncedHeaders(p *peer) { } // now n is the latest downloaded header after syncing if n == nil { - glog.V(logger.Debug).Infof("synchronisation failed with peer %v", p.id) + log.Debug(fmt.Sprintf("synchronisation failed with peer %v", p.id)) go f.pm.removePeer(p.id) } else { header := f.chain.GetHeader(n.hash, n.number) @@ -610,12 +610,12 @@ func (f *lightFetcher) checkKnownNode(p *peer, n *fetcherTreeNode) bool { fp := f.peers[p] if fp == nil { - glog.V(logger.Debug).Infof("checkKnownNode: unknown peer") + log.Debug(fmt.Sprintf("checkKnownNode: unknown peer")) return false } header := f.chain.GetHeader(n.hash, n.number) if !f.checkAnnouncedHeaders(fp, []*types.Header{header}, []*big.Int{td}) { - glog.V(logger.Debug).Infof("announce inconsistency by peer %v", p.id) + log.Debug(fmt.Sprintf("announce inconsistency by peer %v", p.id)) go f.pm.removePeer(p.id) } if fp.confirmedTd != nil { @@ -700,7 +700,7 @@ func (f *lightFetcher) checkUpdateStats(p *peer, newEntry *updateStatsEntry) { now := mclock.Now() fp := f.peers[p] if fp == nil { - glog.V(logger.Debug).Infof("checkUpdateStats: unknown peer") + log.Debug(fmt.Sprintf("checkUpdateStats: unknown peer")) return } if newEntry != nil && fp.firstUpdateStats == nil { diff --git a/les/handler.go b/les/handler.go index 42a45845d..0d85d4839 100644 --- a/les/handler.go +++ b/les/handler.go @@ -34,8 +34,7 @@ import ( "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/discv5" @@ -199,7 +198,7 @@ func NewProtocolManager(chainConfig *params.ChainConfig, lightSync bool, network } if lightSync { - glog.V(logger.Debug).Infof("LES: create downloader") + log.Debug(fmt.Sprintf("LES: create downloader")) manager.downloader = downloader.New(downloader.LightSync, chainDb, manager.eventMux, blockchain.HasHeader, nil, blockchain.GetHeaderByHash, nil, blockchain.CurrentHeader, nil, nil, nil, blockchain.GetTdByHash, blockchain.InsertHeaderChain, nil, nil, blockchain.Rollback, removePeer) @@ -230,12 +229,12 @@ func (pm *ProtocolManager) removePeer(id string) { if err == errNotRegistered { return } - glog.V(logger.Error).Infoln("Removal failed:", err) + log.Error(fmt.Sprint("Removal failed:", err)) } - glog.V(logger.Debug).Infoln("Removing peer", id) + log.Debug(fmt.Sprint("Removing peer", id)) // Unregister the peer from the downloader and Ethereum peer set - glog.V(logger.Debug).Infof("LES: unregister peer %v", id) + log.Debug(fmt.Sprintf("LES: unregister peer %v", id)) if pm.lightSync { pm.downloader.UnregisterPeer(id) if pm.txrelay != nil { @@ -268,9 +267,9 @@ func (pm *ProtocolManager) Start(srvr *p2p.Server) { } else { if topicDisc != nil { go func() { - glog.V(logger.Info).Infoln("Starting registering topic", string(lesTopic)) + log.Info(fmt.Sprint("Starting registering topic", string(lesTopic))) topicDisc.RegisterTopic(lesTopic, pm.quitSync) - glog.V(logger.Info).Infoln("Stopped registering topic", string(lesTopic)) + log.Info(fmt.Sprint("Stopped registering topic", string(lesTopic))) }() } go func() { @@ -283,7 +282,7 @@ func (pm *ProtocolManager) Start(srvr *p2p.Server) { func (pm *ProtocolManager) Stop() { // Showing a log message. During download / process this could actually // take between 5 to 10 seconds and therefor feedback is required. - glog.V(logger.Info).Infoln("Stopping light ethereum protocol handler...") + log.Info(fmt.Sprint("Stopping light ethereum protocol handler...")) // Quit the sync loop. // After this send has completed, no new peers will be accepted. @@ -300,7 +299,7 @@ func (pm *ProtocolManager) Stop() { // Wait for any process action pm.wg.Wait() - glog.V(logger.Info).Infoln("Light ethereum protocol handler stopped") + log.Info(fmt.Sprint("Light ethereum protocol handler stopped")) } func (pm *ProtocolManager) newPeer(pv, nv int, p *p2p.Peer, rw p2p.MsgReadWriter) *peer { @@ -310,22 +309,22 @@ func (pm *ProtocolManager) newPeer(pv, nv int, p *p2p.Peer, rw p2p.MsgReadWriter // handle is the callback invoked to manage the life cycle of a les peer. When // this function terminates, the peer is disconnected. func (pm *ProtocolManager) handle(p *peer) error { - glog.V(logger.Debug).Infof("%v: peer connected [%s]", p, p.Name()) + log.Debug(fmt.Sprintf("%v: peer connected [%s]", p, p.Name())) // Execute the LES handshake td, head, genesis := pm.blockchain.Status() headNum := core.GetBlockNumber(pm.chainDb, head) if err := p.Handshake(td, head, headNum, genesis, pm.server); err != nil { - glog.V(logger.Debug).Infof("%v: handshake failed: %v", p, err) + log.Debug(fmt.Sprintf("%v: handshake failed: %v", p, err)) return err } if rw, ok := p.rw.(*meteredMsgReadWriter); ok { rw.Init(p.version) } // Register the peer locally - glog.V(logger.Detail).Infof("%v: adding peer", p) + log.Trace(fmt.Sprintf("%v: adding peer", p)) if err := pm.peers.Register(p); err != nil { - glog.V(logger.Error).Infof("%v: addition failed: %v", p, err) + log.Error(fmt.Sprintf("%v: addition failed: %v", p, err)) return err } defer func() { @@ -336,7 +335,7 @@ func (pm *ProtocolManager) handle(p *peer) error { }() // Register the peer in the downloader. If the downloader considers it banned, we disconnect - glog.V(logger.Debug).Infof("LES: register peer %v", p.id) + log.Debug(fmt.Sprintf("LES: register peer %v", p.id)) if pm.lightSync { requestHeadersByHash := func(origin common.Hash, amount int, skip int, reverse bool) error { reqID := getNextReqID() @@ -390,7 +389,7 @@ func (pm *ProtocolManager) handle(p *peer) error { // main loop. handle incoming messages. for { if err := pm.handleMsg(p); err != nil { - glog.V(logger.Debug).Infof("%v: message handling failed: %v", p, err) + log.Debug(fmt.Sprintf("%v: message handling failed: %v", p, err)) return err } } @@ -407,7 +406,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { return err } - glog.V(logger.Debug).Infoln("msg:", msg.Code, msg.Size) + log.Debug(fmt.Sprint("msg:", msg.Code, msg.Size)) costs := p.fcCosts[msg.Code] reject := func(reqCnt, maxCnt uint64) bool { @@ -420,7 +419,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { cost = pm.server.defParams.BufLimit } if cost > bufValue { - glog.V(logger.Error).Infof("Request from %v came %v too early", p.id, time.Duration((cost-bufValue)*1000000/pm.server.defParams.MinRecharge)) + log.Error(fmt.Sprintf("Request from %v came %v too early", p.id, time.Duration((cost-bufValue)*1000000/pm.server.defParams.MinRecharge))) return true } return false @@ -436,25 +435,25 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { // Handle the message depending on its contents switch msg.Code { case StatusMsg: - glog.V(logger.Debug).Infof("<=== StatusMsg from peer %v", p.id) + log.Debug(fmt.Sprintf("<=== StatusMsg from peer %v", p.id)) // Status messages should never arrive after the handshake return errResp(ErrExtraStatusMsg, "uncontrolled status message") // Block header query, collect the requested headers and reply case AnnounceMsg: - glog.V(logger.Debug).Infoln("<=== AnnounceMsg from peer %v:", p.id) + log.Debug(fmt.Sprint("<=== AnnounceMsg from peer %v:", p.id)) var req announceData if err := msg.Decode(&req); err != nil { return errResp(ErrDecode, "%v: %v", msg, err) } - glog.V(logger.Detail).Infoln("AnnounceMsg:", req.Number, req.Hash, req.Td, req.ReorgDepth) + log.Trace(fmt.Sprint("AnnounceMsg:", req.Number, req.Hash, req.Td, req.ReorgDepth)) if pm.fetcher != nil { pm.fetcher.announce(p, &req) } case GetBlockHeadersMsg: - glog.V(logger.Debug).Infof("<=== GetBlockHeadersMsg from peer %v", p.id) + log.Debug(fmt.Sprintf("<=== GetBlockHeadersMsg from peer %v", p.id)) // Decode the complex header query var req struct { ReqID uint64 @@ -539,7 +538,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { return errResp(ErrUnexpectedResponse, "") } - glog.V(logger.Debug).Infof("<=== BlockHeadersMsg from peer %v", p.id) + log.Debug(fmt.Sprintf("<=== BlockHeadersMsg from peer %v", p.id)) // A batch of headers arrived to one of our previous requests var resp struct { ReqID, BV uint64 @@ -554,12 +553,12 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { } else { err := pm.downloader.DeliverHeaders(p.id, resp.Headers) if err != nil { - glog.V(logger.Debug).Infoln(err) + log.Debug(fmt.Sprint(err)) } } case GetBlockBodiesMsg: - glog.V(logger.Debug).Infof("<=== GetBlockBodiesMsg from peer %v", p.id) + log.Debug(fmt.Sprintf("<=== GetBlockBodiesMsg from peer %v", p.id)) // Decode the retrieval message var req struct { ReqID uint64 @@ -596,7 +595,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { return errResp(ErrUnexpectedResponse, "") } - glog.V(logger.Debug).Infof("<=== BlockBodiesMsg from peer %v", p.id) + log.Debug(fmt.Sprintf("<=== BlockBodiesMsg from peer %v", p.id)) // A batch of block bodies arrived to one of our previous requests var resp struct { ReqID, BV uint64 @@ -613,7 +612,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { } case GetCodeMsg: - glog.V(logger.Debug).Infof("<=== GetCodeMsg from peer %v", p.id) + log.Debug(fmt.Sprintf("<=== GetCodeMsg from peer %v", p.id)) // Decode the retrieval message var req struct { ReqID uint64 @@ -657,7 +656,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { return errResp(ErrUnexpectedResponse, "") } - glog.V(logger.Debug).Infof("<=== CodeMsg from peer %v", p.id) + log.Debug(fmt.Sprintf("<=== CodeMsg from peer %v", p.id)) // A batch of node state data arrived to one of our previous requests var resp struct { ReqID, BV uint64 @@ -674,7 +673,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { } case GetReceiptsMsg: - glog.V(logger.Debug).Infof("<=== GetReceiptsMsg from peer %v", p.id) + log.Debug(fmt.Sprintf("<=== GetReceiptsMsg from peer %v", p.id)) // Decode the retrieval message var req struct { ReqID uint64 @@ -705,7 +704,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { } // If known, encode and queue for response packet if encoded, err := rlp.EncodeToBytes(results); err != nil { - glog.V(logger.Error).Infof("failed to encode receipt: %v", err) + log.Error(fmt.Sprintf("failed to encode receipt: %v", err)) } else { receipts = append(receipts, encoded) bytes += len(encoded) @@ -720,7 +719,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { return errResp(ErrUnexpectedResponse, "") } - glog.V(logger.Debug).Infof("<=== ReceiptsMsg from peer %v", p.id) + log.Debug(fmt.Sprintf("<=== ReceiptsMsg from peer %v", p.id)) // A batch of receipts arrived to one of our previous requests var resp struct { ReqID, BV uint64 @@ -737,7 +736,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { } case GetProofsMsg: - glog.V(logger.Debug).Infof("<=== GetProofsMsg from peer %v", p.id) + log.Debug(fmt.Sprintf("<=== GetProofsMsg from peer %v", p.id)) // Decode the retrieval message var req struct { ReqID uint64 @@ -787,7 +786,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { return errResp(ErrUnexpectedResponse, "") } - glog.V(logger.Debug).Infof("<=== ProofsMsg from peer %v", p.id) + log.Debug(fmt.Sprintf("<=== ProofsMsg from peer %v", p.id)) // A batch of merkle proofs arrived to one of our previous requests var resp struct { ReqID, BV uint64 @@ -804,7 +803,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { } case GetHeaderProofsMsg: - glog.V(logger.Debug).Infof("<=== GetHeaderProofsMsg from peer %v", p.id) + log.Debug(fmt.Sprintf("<=== GetHeaderProofsMsg from peer %v", p.id)) // Decode the retrieval message var req struct { ReqID uint64 @@ -848,7 +847,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { return errResp(ErrUnexpectedResponse, "") } - glog.V(logger.Debug).Infof("<=== HeaderProofsMsg from peer %v", p.id) + log.Debug(fmt.Sprintf("<=== HeaderProofsMsg from peer %v", p.id)) var resp struct { ReqID, BV uint64 Data []ChtResp @@ -885,7 +884,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { pm.server.fcCostStats.update(msg.Code, uint64(reqCnt), rcost) default: - glog.V(logger.Debug).Infof("<=== unknown message with code %d from peer %v", msg.Code, p.id) + log.Debug(fmt.Sprintf("<=== unknown message with code %d from peer %v", msg.Code, p.id)) return errResp(ErrInvalidMsgCode, "%v", msg.Code) } diff --git a/les/odr.go b/les/odr.go index 88c7d85a5..78c7c1af4 100644 --- a/les/odr.go +++ b/les/odr.go @@ -19,14 +19,14 @@ package les import ( "crypto/rand" "encoding/binary" + "fmt" "sync" "time" "github.com/ethereum/go-ethereum/common/mclock" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/light" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "golang.org/x/net/context" ) @@ -151,7 +151,7 @@ func (self *LesOdr) requestPeer(req *sentReq, peer *peer, delivered, timeout cha select { case <-delivered: case <-time.After(hardRequestTimeout): - glog.V(logger.Debug).Infof("ODR hard request timeout from peer %v", peer.id) + log.Debug(fmt.Sprintf("ODR hard request timeout from peer %v", peer.id)) go self.removePeer(peer.id) case <-self.stop: return @@ -237,7 +237,7 @@ func (self *LesOdr) Retrieve(ctx context.Context, req light.OdrRequest) (err err // retrieved from network, store in db req.StoreResult(self.db) } else { - glog.V(logger.Debug).Infof("networkRequest err = %v", err) + log.Debug(fmt.Sprintf("networkRequest err = %v", err)) } return } diff --git a/les/odr_requests.go b/les/odr_requests.go index 2987eb297..5321a68cb 100644 --- a/les/odr_requests.go +++ b/les/odr_requests.go @@ -21,6 +21,7 @@ package les import ( "bytes" "encoding/binary" + "fmt" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" @@ -28,8 +29,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/light" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" ) @@ -74,7 +74,7 @@ func (self *BlockRequest) CanSend(peer *peer) bool { // Request sends an ODR request to the LES network (implementation of LesOdrRequest) func (self *BlockRequest) Request(reqID uint64, peer *peer) error { - glog.V(logger.Debug).Infof("ODR: requesting body of block %08x from peer %v", self.Hash[:4], peer.id) + log.Debug(fmt.Sprintf("ODR: requesting body of block %08x from peer %v", self.Hash[:4], peer.id)) return peer.RequestBodies(reqID, self.GetCost(peer), []common.Hash{self.Hash}) } @@ -82,39 +82,39 @@ func (self *BlockRequest) Request(reqID uint64, peer *peer) error { // returns true and stores results in memory if the message was a valid reply // to the request (implementation of LesOdrRequest) func (self *BlockRequest) Valid(db ethdb.Database, msg *Msg) bool { - glog.V(logger.Debug).Infof("ODR: validating body of block %08x", self.Hash[:4]) + log.Debug(fmt.Sprintf("ODR: validating body of block %08x", self.Hash[:4])) if msg.MsgType != MsgBlockBodies { - glog.V(logger.Debug).Infof("ODR: invalid message type") + log.Debug(fmt.Sprintf("ODR: invalid message type")) return false } bodies := msg.Obj.([]*types.Body) if len(bodies) != 1 { - glog.V(logger.Debug).Infof("ODR: invalid number of entries: %d", len(bodies)) + log.Debug(fmt.Sprintf("ODR: invalid number of entries: %d", len(bodies))) return false } body := bodies[0] header := core.GetHeader(db, self.Hash, self.Number) if header == nil { - glog.V(logger.Debug).Infof("ODR: header not found for block %08x", self.Hash[:4]) + log.Debug(fmt.Sprintf("ODR: header not found for block %08x", self.Hash[:4])) return false } txHash := types.DeriveSha(types.Transactions(body.Transactions)) if header.TxHash != txHash { - glog.V(logger.Debug).Infof("ODR: header.TxHash %08x does not match received txHash %08x", header.TxHash[:4], txHash[:4]) + log.Debug(fmt.Sprintf("ODR: header.TxHash %08x does not match received txHash %08x", header.TxHash[:4], txHash[:4])) return false } uncleHash := types.CalcUncleHash(body.Uncles) if header.UncleHash != uncleHash { - glog.V(logger.Debug).Infof("ODR: header.UncleHash %08x does not match received uncleHash %08x", header.UncleHash[:4], uncleHash[:4]) + log.Debug(fmt.Sprintf("ODR: header.UncleHash %08x does not match received uncleHash %08x", header.UncleHash[:4], uncleHash[:4])) return false } data, err := rlp.EncodeToBytes(body) if err != nil { - glog.V(logger.Debug).Infof("ODR: body RLP encode error: %v", err) + log.Debug(fmt.Sprintf("ODR: body RLP encode error: %v", err)) return false } self.Rlp = data - glog.V(logger.Debug).Infof("ODR: validation successful") + log.Debug(fmt.Sprintf("ODR: validation successful")) return true } @@ -134,7 +134,7 @@ func (self *ReceiptsRequest) CanSend(peer *peer) bool { // Request sends an ODR request to the LES network (implementation of LesOdrRequest) func (self *ReceiptsRequest) Request(reqID uint64, peer *peer) error { - glog.V(logger.Debug).Infof("ODR: requesting receipts for block %08x from peer %v", self.Hash[:4], peer.id) + log.Debug(fmt.Sprintf("ODR: requesting receipts for block %08x from peer %v", self.Hash[:4], peer.id)) return peer.RequestReceipts(reqID, self.GetCost(peer), []common.Hash{self.Hash}) } @@ -142,28 +142,28 @@ func (self *ReceiptsRequest) Request(reqID uint64, peer *peer) error { // returns true and stores results in memory if the message was a valid reply // to the request (implementation of LesOdrRequest) func (self *ReceiptsRequest) Valid(db ethdb.Database, msg *Msg) bool { - glog.V(logger.Debug).Infof("ODR: validating receipts for block %08x", self.Hash[:4]) + log.Debug(fmt.Sprintf("ODR: validating receipts for block %08x", self.Hash[:4])) if msg.MsgType != MsgReceipts { - glog.V(logger.Debug).Infof("ODR: invalid message type") + log.Debug(fmt.Sprintf("ODR: invalid message type")) return false } receipts := msg.Obj.([]types.Receipts) if len(receipts) != 1 { - glog.V(logger.Debug).Infof("ODR: invalid number of entries: %d", len(receipts)) + log.Debug(fmt.Sprintf("ODR: invalid number of entries: %d", len(receipts))) return false } hash := types.DeriveSha(receipts[0]) header := core.GetHeader(db, self.Hash, self.Number) if header == nil { - glog.V(logger.Debug).Infof("ODR: header not found for block %08x", self.Hash[:4]) + log.Debug(fmt.Sprintf("ODR: header not found for block %08x", self.Hash[:4])) return false } if !bytes.Equal(header.ReceiptHash[:], hash[:]) { - glog.V(logger.Debug).Infof("ODR: header receipts hash %08x does not match calculated RLP hash %08x", header.ReceiptHash[:4], hash[:4]) + log.Debug(fmt.Sprintf("ODR: header receipts hash %08x does not match calculated RLP hash %08x", header.ReceiptHash[:4], hash[:4])) return false } self.Receipts = receipts[0] - glog.V(logger.Debug).Infof("ODR: validation successful") + log.Debug(fmt.Sprintf("ODR: validation successful")) return true } @@ -189,7 +189,7 @@ func (self *TrieRequest) CanSend(peer *peer) bool { // Request sends an ODR request to the LES network (implementation of LesOdrRequest) func (self *TrieRequest) Request(reqID uint64, peer *peer) error { - glog.V(logger.Debug).Infof("ODR: requesting trie root %08x key %08x from peer %v", self.Id.Root[:4], self.Key[:4], peer.id) + log.Debug(fmt.Sprintf("ODR: requesting trie root %08x key %08x from peer %v", self.Id.Root[:4], self.Key[:4], peer.id)) req := &ProofReq{ BHash: self.Id.BlockHash, AccKey: self.Id.AccKey, @@ -202,24 +202,24 @@ func (self *TrieRequest) Request(reqID uint64, peer *peer) error { // returns true and stores results in memory if the message was a valid reply // to the request (implementation of LesOdrRequest) func (self *TrieRequest) Valid(db ethdb.Database, msg *Msg) bool { - glog.V(logger.Debug).Infof("ODR: validating trie root %08x key %08x", self.Id.Root[:4], self.Key[:4]) + log.Debug(fmt.Sprintf("ODR: validating trie root %08x key %08x", self.Id.Root[:4], self.Key[:4])) if msg.MsgType != MsgProofs { - glog.V(logger.Debug).Infof("ODR: invalid message type") + log.Debug(fmt.Sprintf("ODR: invalid message type")) return false } proofs := msg.Obj.([][]rlp.RawValue) if len(proofs) != 1 { - glog.V(logger.Debug).Infof("ODR: invalid number of entries: %d", len(proofs)) + log.Debug(fmt.Sprintf("ODR: invalid number of entries: %d", len(proofs))) return false } _, err := trie.VerifyProof(self.Id.Root, self.Key, proofs[0]) if err != nil { - glog.V(logger.Debug).Infof("ODR: merkle proof verification error: %v", err) + log.Debug(fmt.Sprintf("ODR: merkle proof verification error: %v", err)) return false } self.Proof = proofs[0] - glog.V(logger.Debug).Infof("ODR: validation successful") + log.Debug(fmt.Sprintf("ODR: validation successful")) return true } @@ -244,7 +244,7 @@ func (self *CodeRequest) CanSend(peer *peer) bool { // Request sends an ODR request to the LES network (implementation of LesOdrRequest) func (self *CodeRequest) Request(reqID uint64, peer *peer) error { - glog.V(logger.Debug).Infof("ODR: requesting node data for hash %08x from peer %v", self.Hash[:4], peer.id) + log.Debug(fmt.Sprintf("ODR: requesting node data for hash %08x from peer %v", self.Hash[:4], peer.id)) req := &CodeReq{ BHash: self.Id.BlockHash, AccKey: self.Id.AccKey, @@ -256,23 +256,23 @@ func (self *CodeRequest) Request(reqID uint64, peer *peer) error { // returns true and stores results in memory if the message was a valid reply // to the request (implementation of LesOdrRequest) func (self *CodeRequest) Valid(db ethdb.Database, msg *Msg) bool { - glog.V(logger.Debug).Infof("ODR: validating node data for hash %08x", self.Hash[:4]) + log.Debug(fmt.Sprintf("ODR: validating node data for hash %08x", self.Hash[:4])) if msg.MsgType != MsgCode { - glog.V(logger.Debug).Infof("ODR: invalid message type") + log.Debug(fmt.Sprintf("ODR: invalid message type")) return false } reply := msg.Obj.([][]byte) if len(reply) != 1 { - glog.V(logger.Debug).Infof("ODR: invalid number of entries: %d", len(reply)) + log.Debug(fmt.Sprintf("ODR: invalid number of entries: %d", len(reply))) return false } data := reply[0] if hash := crypto.Keccak256Hash(data); self.Hash != hash { - glog.V(logger.Debug).Infof("ODR: requested hash %08x does not match received data hash %08x", self.Hash[:4], hash[:4]) + log.Debug(fmt.Sprintf("ODR: requested hash %08x does not match received data hash %08x", self.Hash[:4], hash[:4])) return false } self.Data = data - glog.V(logger.Debug).Infof("ODR: validation successful") + log.Debug(fmt.Sprintf("ODR: validation successful")) return true } @@ -304,7 +304,7 @@ func (self *ChtRequest) CanSend(peer *peer) bool { // Request sends an ODR request to the LES network (implementation of LesOdrRequest) func (self *ChtRequest) Request(reqID uint64, peer *peer) error { - glog.V(logger.Debug).Infof("ODR: requesting CHT #%d block #%d from peer %v", self.ChtNum, self.BlockNum, peer.id) + log.Debug(fmt.Sprintf("ODR: requesting CHT #%d block #%d from peer %v", self.ChtNum, self.BlockNum, peer.id)) req := &ChtReq{ ChtNum: self.ChtNum, BlockNum: self.BlockNum, @@ -316,15 +316,15 @@ func (self *ChtRequest) Request(reqID uint64, peer *peer) error { // returns true and stores results in memory if the message was a valid reply // to the request (implementation of LesOdrRequest) func (self *ChtRequest) Valid(db ethdb.Database, msg *Msg) bool { - glog.V(logger.Debug).Infof("ODR: validating CHT #%d block #%d", self.ChtNum, self.BlockNum) + log.Debug(fmt.Sprintf("ODR: validating CHT #%d block #%d", self.ChtNum, self.BlockNum)) if msg.MsgType != MsgHeaderProofs { - glog.V(logger.Debug).Infof("ODR: invalid message type") + log.Debug(fmt.Sprintf("ODR: invalid message type")) return false } proofs := msg.Obj.([]ChtResp) if len(proofs) != 1 { - glog.V(logger.Debug).Infof("ODR: invalid number of entries: %d", len(proofs)) + log.Debug(fmt.Sprintf("ODR: invalid number of entries: %d", len(proofs))) return false } proof := proofs[0] @@ -332,22 +332,22 @@ func (self *ChtRequest) Valid(db ethdb.Database, msg *Msg) bool { binary.BigEndian.PutUint64(encNumber[:], self.BlockNum) value, err := trie.VerifyProof(self.ChtRoot, encNumber[:], proof.Proof) if err != nil { - glog.V(logger.Debug).Infof("ODR: CHT merkle proof verification error: %v", err) + log.Debug(fmt.Sprintf("ODR: CHT merkle proof verification error: %v", err)) return false } var node light.ChtNode if err := rlp.DecodeBytes(value, &node); err != nil { - glog.V(logger.Debug).Infof("ODR: error decoding CHT node: %v", err) + log.Debug(fmt.Sprintf("ODR: error decoding CHT node: %v", err)) return false } if node.Hash != proof.Header.Hash() { - glog.V(logger.Debug).Infof("ODR: CHT header hash does not match") + log.Debug(fmt.Sprintf("ODR: CHT header hash does not match")) return false } self.Proof = proof.Proof self.Header = proof.Header self.Td = node.Td - glog.V(logger.Debug).Infof("ODR: validation successful") + log.Debug(fmt.Sprintf("ODR: validation successful")) return true } diff --git a/les/peer.go b/les/peer.go index d5008ded1..fc3591c78 100644 --- a/les/peer.go +++ b/les/peer.go @@ -27,8 +27,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/les/flowcontrol" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/rlp" ) @@ -196,51 +195,51 @@ func (p *peer) SendHeaderProofs(reqID, bv uint64, proofs []ChtResp) error { // RequestHeadersByHash fetches a batch of blocks' headers corresponding to the // specified header query, based on the hash of an origin block. func (p *peer) RequestHeadersByHash(reqID, cost uint64, origin common.Hash, amount int, skip int, reverse bool) error { - glog.V(logger.Debug).Infof("%v fetching %d headers from %x, skipping %d (reverse = %v)", p, amount, origin[:4], skip, reverse) + log.Debug(fmt.Sprintf("%v fetching %d headers from %x, skipping %d (reverse = %v)", p, amount, origin[:4], skip, reverse)) return sendRequest(p.rw, GetBlockHeadersMsg, reqID, cost, &getBlockHeadersData{Origin: hashOrNumber{Hash: origin}, Amount: uint64(amount), Skip: uint64(skip), Reverse: reverse}) } // RequestHeadersByNumber fetches a batch of blocks' headers corresponding to the // specified header query, based on the number of an origin block. func (p *peer) RequestHeadersByNumber(reqID, cost, origin uint64, amount int, skip int, reverse bool) error { - glog.V(logger.Debug).Infof("%v fetching %d headers from #%d, skipping %d (reverse = %v)", p, amount, origin, skip, reverse) + log.Debug(fmt.Sprintf("%v fetching %d headers from #%d, skipping %d (reverse = %v)", p, amount, origin, skip, reverse)) return sendRequest(p.rw, GetBlockHeadersMsg, reqID, cost, &getBlockHeadersData{Origin: hashOrNumber{Number: origin}, Amount: uint64(amount), Skip: uint64(skip), Reverse: reverse}) } // RequestBodies fetches a batch of blocks' bodies corresponding to the hashes // specified. func (p *peer) RequestBodies(reqID, cost uint64, hashes []common.Hash) error { - glog.V(logger.Debug).Infof("%v fetching %d block bodies", p, len(hashes)) + log.Debug(fmt.Sprintf("%v fetching %d block bodies", p, len(hashes))) return sendRequest(p.rw, GetBlockBodiesMsg, reqID, cost, hashes) } // RequestCode fetches a batch of arbitrary data from a node's known state // data, corresponding to the specified hashes. func (p *peer) RequestCode(reqID, cost uint64, reqs []*CodeReq) error { - glog.V(logger.Debug).Infof("%v fetching %v state data", p, len(reqs)) + log.Debug(fmt.Sprintf("%v fetching %v state data", p, len(reqs))) return sendRequest(p.rw, GetCodeMsg, reqID, cost, reqs) } // RequestReceipts fetches a batch of transaction receipts from a remote node. func (p *peer) RequestReceipts(reqID, cost uint64, hashes []common.Hash) error { - glog.V(logger.Debug).Infof("%v fetching %v receipts", p, len(hashes)) + log.Debug(fmt.Sprintf("%v fetching %v receipts", p, len(hashes))) return sendRequest(p.rw, GetReceiptsMsg, reqID, cost, hashes) } // RequestProofs fetches a batch of merkle proofs from a remote node. func (p *peer) RequestProofs(reqID, cost uint64, reqs []*ProofReq) error { - glog.V(logger.Debug).Infof("%v fetching %v proofs", p, len(reqs)) + log.Debug(fmt.Sprintf("%v fetching %v proofs", p, len(reqs))) return sendRequest(p.rw, GetProofsMsg, reqID, cost, reqs) } // RequestHeaderProofs fetches a batch of header merkle proofs from a remote node. func (p *peer) RequestHeaderProofs(reqID, cost uint64, reqs []*ChtReq) error { - glog.V(logger.Debug).Infof("%v fetching %v header proofs", p, len(reqs)) + log.Debug(fmt.Sprintf("%v fetching %v header proofs", p, len(reqs))) return sendRequest(p.rw, GetHeaderProofsMsg, reqID, cost, reqs) } func (p *peer) SendTxs(cost uint64, txs types.Transactions) error { - glog.V(logger.Debug).Infof("%v relaying %v txs", p, len(txs)) + log.Debug(fmt.Sprintf("%v relaying %v txs", p, len(txs))) reqID := getNextReqID() p.fcServer.MustAssignRequest(reqID) p.fcServer.SendRequest(reqID, cost) diff --git a/les/server.go b/les/server.go index c4c6fcab5..b04c9c4ca 100644 --- a/les/server.go +++ b/les/server.go @@ -19,6 +19,7 @@ package les import ( "encoding/binary" + "fmt" "math" "sync" "time" @@ -30,8 +31,7 @@ import ( "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/les/flowcontrol" "github.com/ethereum/go-ethereum/light" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" @@ -292,7 +292,7 @@ func (pm *ProtocolManager) blockLoop() { lastHead = header lastBroadcastTd = td - glog.V(logger.Debug).Infoln("===> ", number, hash, td, reorg) + log.Debug(fmt.Sprint("===> ", number, hash, td, reorg)) announce := announceData{Hash: hash, Number: number, Td: td, ReorgDepth: reorg} for _, p := range peers { @@ -396,7 +396,7 @@ func makeCht(db ethdb.Database) bool { } else { lastChtNum++ - glog.V(logger.Detail).Infof("cht: %d %064x", lastChtNum, root) + log.Trace(fmt.Sprintf("cht: %d %064x", lastChtNum, root)) storeChtRoot(db, lastChtNum, root) var data [8]byte diff --git a/les/serverpool.go b/les/serverpool.go index 9735a718e..95a8242b3 100644 --- a/les/serverpool.go +++ b/les/serverpool.go @@ -18,6 +18,7 @@ package les import ( + "fmt" "io" "math" "math/rand" @@ -28,8 +29,7 @@ import ( "github.com/ethereum/go-ethereum/common/mclock" "github.com/ethereum/go-ethereum/ethdb" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/discv5" @@ -162,7 +162,7 @@ func (pool *serverPool) connect(p *peer, ip net.IP, port uint16) *poolEntry { if entry == nil { entry = pool.findOrNewNode(p.ID(), ip, port) } - glog.V(logger.Debug).Infof("connecting to %v, state: %v", p.id, entry.state) + log.Debug(fmt.Sprintf("connecting to %v, state: %v", p.id, entry.state)) if entry.state == psConnected || entry.state == psRegistered { return nil } @@ -184,7 +184,7 @@ func (pool *serverPool) connect(p *peer, ip net.IP, port uint16) *poolEntry { // registered should be called after a successful handshake func (pool *serverPool) registered(entry *poolEntry) { - glog.V(logger.Debug).Infof("registered %v", entry.id.String()) + log.Debug(fmt.Sprintf("registered %v", entry.id.String())) pool.lock.Lock() defer pool.lock.Unlock() @@ -202,7 +202,7 @@ func (pool *serverPool) registered(entry *poolEntry) { // can be updated optionally (not updated if no registration happened, in this case // only connection statistics are updated, just like in case of timeout) func (pool *serverPool) disconnect(entry *poolEntry) { - glog.V(logger.Debug).Infof("disconnected %v", entry.id.String()) + log.Debug(fmt.Sprintf("disconnected %v", entry.id.String())) pool.lock.Lock() defer pool.lock.Unlock() @@ -418,7 +418,7 @@ func (pool *serverPool) findOrNewNode(id discover.NodeID, ip net.IP, port uint16 now := mclock.Now() entry := pool.entries[id] if entry == nil { - glog.V(logger.Debug).Infof("discovered %v", id.String()) + log.Debug(fmt.Sprintf("discovered %v", id.String())) entry = &poolEntry{ id: id, addr: make(map[string]*poolEntryAddress), @@ -459,11 +459,11 @@ func (pool *serverPool) loadNodes() { var list []*poolEntry err = rlp.DecodeBytes(enc, &list) if err != nil { - glog.V(logger.Debug).Infof("node list decode error: %v", err) + log.Debug(fmt.Sprintf("node list decode error: %v", err)) return } for _, e := range list { - glog.V(logger.Debug).Infof("loaded server stats %016x fails: %v connStats: %v / %v delayStats: %v / %v responseStats: %v / %v timeoutStats: %v / %v", e.id[0:8], e.lastConnected.fails, e.connectStats.avg, e.connectStats.weight, time.Duration(e.delayStats.avg), e.delayStats.weight, time.Duration(e.responseStats.avg), e.responseStats.weight, e.timeoutStats.avg, e.timeoutStats.weight) + log.Debug(fmt.Sprintf("loaded server stats %016x fails: %v connStats: %v / %v delayStats: %v / %v responseStats: %v / %v timeoutStats: %v / %v", e.id[0:8], e.lastConnected.fails, e.connectStats.avg, e.connectStats.weight, time.Duration(e.delayStats.avg), e.delayStats.weight, time.Duration(e.responseStats.avg), e.responseStats.weight, e.timeoutStats.avg, e.timeoutStats.weight)) pool.entries[e.id] = e pool.knownQueue.setLatest(e) pool.knownSelect.update((*knownEntry)(e)) @@ -568,7 +568,7 @@ func (pool *serverPool) dial(entry *poolEntry, knownSelected bool) { pool.newSelected++ } addr := entry.addrSelect.choose().(*poolEntryAddress) - glog.V(logger.Debug).Infof("dialing %v out of %v, known: %v", entry.id.String()+"@"+addr.strKey(), len(entry.addr), knownSelected) + log.Debug(fmt.Sprintf("dialing %v out of %v, known: %v", entry.id.String()+"@"+addr.strKey(), len(entry.addr), knownSelected)) entry.dialed = addr go func() { pool.server.AddPeer(discover.NewNode(entry.id, addr.ip, addr.port, addr.port)) @@ -589,7 +589,7 @@ func (pool *serverPool) checkDialTimeout(entry *poolEntry) { if entry.state != psDialed { return } - glog.V(logger.Debug).Infof("timeout %v", entry.id.String()+"@"+entry.dialed.strKey()) + log.Debug(fmt.Sprintf("timeout %v", entry.id.String()+"@"+entry.dialed.strKey())) entry.state = psNotConnected if entry.knownSelected { pool.knownSelected-- |