diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-22 20:10:07 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-02-23 18:16:44 +0800 |
commit | d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851 (patch) | |
tree | 17c93170551d3eeabe2935de1765f157007f0dc2 /eth/handler.go | |
parent | 47af53f9aaf9aa7b12cd976eb150ccf3d64da6fd (diff) | |
download | go-tangerine-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.gz go-tangerine-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.zst go-tangerine-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.zip |
all: blidly swap out glog to our log15, logs need rework
Diffstat (limited to 'eth/handler.go')
-rw-r--r-- | eth/handler.go | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/eth/handler.go b/eth/handler.go index 0e7eed352..bcb83ed90 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -33,8 +33,7 @@ import ( "github.com/ethereum/go-ethereum/eth/fetcher" "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/params" @@ -116,7 +115,7 @@ func NewProtocolManager(config *params.ChainConfig, fastSync bool, networkId int } // Figure out whether to allow fast sync or not if fastSync && blockchain.CurrentBlock().NumberU64() > 0 { - glog.V(logger.Info).Infof("blockchain not empty, fast sync disabled") + log.Info(fmt.Sprintf("blockchain not empty, fast sync disabled")) fastSync = false } if fastSync { @@ -179,7 +178,7 @@ func NewProtocolManager(config *params.ChainConfig, fastSync bool, networkId int manager.fetcher = fetcher.New(blockchain.GetBlockByHash, validator, manager.BroadcastBlock, heighter, inserter, manager.removePeer) if blockchain.Genesis().Hash().Hex() == defaultGenesisHash && networkId == 1 { - glog.V(logger.Debug).Infoln("Bad Block Reporting is enabled") + log.Debug(fmt.Sprint("Bad Block Reporting is enabled")) manager.badBlockReportingEnabled = true } @@ -200,12 +199,12 @@ func (pm *ProtocolManager) removePeer(id string) { if peer == nil { return } - 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 pm.downloader.UnregisterPeer(id) if err := pm.peers.Unregister(id); err != nil { - glog.V(logger.Error).Infoln("Removal failed:", err) + log.Error(fmt.Sprint("Removal failed:", err)) } // Hard disconnect at the networking layer if peer != nil { @@ -227,7 +226,7 @@ func (pm *ProtocolManager) Start() { } func (pm *ProtocolManager) Stop() { - glog.V(logger.Info).Infoln("Stopping ethereum protocol handler...") + log.Info(fmt.Sprint("Stopping ethereum protocol handler...")) pm.txSub.Unsubscribe() // quits txBroadcastLoop pm.minedBlockSub.Unsubscribe() // quits blockBroadcastLoop @@ -248,7 +247,7 @@ func (pm *ProtocolManager) Stop() { // Wait for all peer handler goroutines and the loops to come down. pm.wg.Wait() - glog.V(logger.Info).Infoln("Ethereum protocol handler stopped") + log.Info(fmt.Sprint("Ethereum protocol handler stopped")) } func (pm *ProtocolManager) newPeer(pv int, p *p2p.Peer, rw p2p.MsgReadWriter) *peer { @@ -262,21 +261,21 @@ func (pm *ProtocolManager) handle(p *peer) error { return p2p.DiscTooManyPeers } - 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 Ethereum handshake td, head, genesis := pm.blockchain.Status() if err := p.Handshake(pm.networkId, td, head, genesis); 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 pm.removePeer(p.id) @@ -297,7 +296,7 @@ func (pm *ProtocolManager) handle(p *peer) error { } // Start a timer to disconnect if the peer doesn't reply in time p.forkDrop = time.AfterFunc(daoChallengeTimeout, func() { - glog.V(logger.Debug).Infof("%v: timed out DAO fork-check, dropping", p) + log.Debug(fmt.Sprintf("%v: timed out DAO fork-check, dropping", p)) pm.removePeer(p.id) }) // Make sure it's cleaned up if the peer dies off @@ -311,7 +310,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 } } @@ -387,7 +386,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { ) if next <= current { infos, _ := json.MarshalIndent(p.Peer.Info(), "", " ") - glog.V(logger.Warn).Infof("%v: GetBlockHeaders skip overflow attack (current %v, skip %v, next %v)\nMalicious peer infos: %s", p, current, query.Skip, next, infos) + log.Warn(fmt.Sprintf("%v: GetBlockHeaders skip overflow attack (current %v, skip %v, next %v)\nMalicious peer infos: %s", p, current, query.Skip, next, infos)) unknown = true } else { if header := pm.blockchain.GetHeaderByNumber(next); header != nil { @@ -435,7 +434,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { } // If we're seemingly on the same chain, disable the drop timer if verifyDAO { - glog.V(logger.Debug).Infof("%v: seems to be on the same side of the DAO fork", p) + log.Debug(fmt.Sprintf("%v: seems to be on the same side of the DAO fork", p)) p.forkDrop.Stop() p.forkDrop = nil return nil @@ -452,10 +451,10 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { // Validate the header and either drop the peer or continue if err := core.ValidateDAOHeaderExtraData(pm.chainconfig, headers[0]); err != nil { - glog.V(logger.Debug).Infof("%v: verified to be on the other side of the DAO fork, dropping", p) + log.Debug(fmt.Sprintf("%v: verified to be on the other side of the DAO fork, dropping", p)) return err } - glog.V(logger.Debug).Infof("%v: verified to be on the same side of the DAO fork", p) + log.Debug(fmt.Sprintf("%v: verified to be on the same side of the DAO fork", p)) return nil } // Irrelevant of the fork checks, send the header to the fetcher just in case @@ -464,7 +463,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { if len(headers) > 0 || !filter { err := pm.downloader.DeliverHeaders(p.id, headers) if err != nil { - glog.V(logger.Debug).Infoln(err) + log.Debug(fmt.Sprint(err)) } } @@ -517,7 +516,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { if len(trasactions) > 0 || len(uncles) > 0 || !filter { err := pm.downloader.DeliverBodies(p.id, trasactions, uncles) if err != nil { - glog.V(logger.Debug).Infoln(err) + log.Debug(fmt.Sprint(err)) } } @@ -556,7 +555,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { } // Deliver all to the downloader if err := pm.downloader.DeliverNodeData(p.id, data); err != nil { - glog.V(logger.Debug).Infof("failed to deliver node state data: %v", err) + log.Debug(fmt.Sprintf("failed to deliver node state data: %v", err)) } case p.version >= eth63 && msg.Code == GetReceiptsMsg: @@ -587,7 +586,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) @@ -603,7 +602,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { } // Deliver all to the downloader if err := pm.downloader.DeliverReceipts(p.id, receipts); err != nil { - glog.V(logger.Debug).Infof("failed to deliver receipts: %v", err) + log.Debug(fmt.Sprintf("failed to deliver receipts: %v", err)) } case msg.Code == NewBlockHashesMsg: @@ -696,7 +695,7 @@ func (pm *ProtocolManager) BroadcastBlock(block *types.Block, propagate bool) { if parent := pm.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1); parent != nil { td = new(big.Int).Add(block.Difficulty(), pm.blockchain.GetTd(block.ParentHash(), block.NumberU64()-1)) } else { - glog.V(logger.Error).Infof("propagating dangling block #%d [%x]", block.NumberU64(), hash[:4]) + log.Error(fmt.Sprintf("propagating dangling block #%d [%x]", block.NumberU64(), hash[:4])) return } // Send the block to a subset of our peers @@ -704,14 +703,14 @@ func (pm *ProtocolManager) BroadcastBlock(block *types.Block, propagate bool) { for _, peer := range transfer { peer.SendNewBlock(block, td) } - glog.V(logger.Detail).Infof("propagated block %x to %d peers in %v", hash[:4], len(transfer), time.Since(block.ReceivedAt)) + log.Trace(fmt.Sprintf("propagated block %x to %d peers in %v", hash[:4], len(transfer), time.Since(block.ReceivedAt))) } // Otherwise if the block is indeed in out own chain, announce it if pm.blockchain.HasBlock(hash) { for _, peer := range peers { peer.SendNewBlockHashes([]common.Hash{hash}, []uint64{block.NumberU64()}) } - glog.V(logger.Detail).Infof("announced block %x to %d peers in %v", hash[:4], len(peers), time.Since(block.ReceivedAt)) + log.Trace(fmt.Sprintf("announced block %x to %d peers in %v", hash[:4], len(peers), time.Since(block.ReceivedAt))) } } @@ -724,7 +723,7 @@ func (pm *ProtocolManager) BroadcastTx(hash common.Hash, tx *types.Transaction) for _, peer := range peers { peer.SendTransactions(types.Transactions{tx}) } - glog.V(logger.Detail).Infoln("broadcast tx to", len(peers), "peers") + log.Trace(fmt.Sprint("broadcast tx to", len(peers), "peers")) } // Mined broadcast loop |