From d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 22 Feb 2017 14:10:07 +0200 Subject: all: blidly swap out glog to our log15, logs need rework --- miner/agent.go | 6 +++--- miner/miner.go | 9 ++++----- miner/remote_agent.go | 8 ++++---- miner/unconfirmed.go | 12 ++++++------ miner/worker.go | 38 ++++++++++++++++++-------------------- 5 files changed, 35 insertions(+), 38 deletions(-) (limited to 'miner') diff --git a/miner/agent.go b/miner/agent.go index 697e3971b..21300b5b9 100644 --- a/miner/agent.go +++ b/miner/agent.go @@ -17,14 +17,14 @@ package miner import ( + "fmt" "sync" "sync/atomic" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/pow" ) @@ -108,7 +108,7 @@ done: } func (self *CpuAgent) mine(work *Work, stop <-chan struct{}) { - glog.V(logger.Debug).Infof("(re)started agent[%d]. mining...\n", self.index) + log.Debug(fmt.Sprintf("(re)started agent[%d]. mining...\n", self.index)) // Mine nonce, mixDigest := self.pow.Search(work.Block, stop, self.index) diff --git a/miner/miner.go b/miner/miner.go index 83059f4b1..33d77e174 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -30,8 +30,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/params" "github.com/ethereum/go-ethereum/pow" ) @@ -87,7 +86,7 @@ out: if self.Mining() { self.Stop() atomic.StoreInt32(&self.shouldStart, 1) - glog.V(logger.Info).Infoln("Mining operation aborted due to sync operation") + log.Info(fmt.Sprint("Mining operation aborted due to sync operation")) } case downloader.DoneEvent, downloader.FailedEvent: shouldStart := atomic.LoadInt32(&self.shouldStart) == 1 @@ -124,7 +123,7 @@ func (self *Miner) Start(coinbase common.Address, threads int) { self.threads = threads if atomic.LoadInt32(&self.canStart) == 0 { - glog.V(logger.Info).Infoln("Can not start mining operation due to network sync (starts when finished)") + log.Info(fmt.Sprint("Can not start mining operation due to network sync (starts when finished)")) return } atomic.StoreInt32(&self.mining, 1) @@ -133,7 +132,7 @@ func (self *Miner) Start(coinbase common.Address, threads int) { self.worker.register(NewCpuAgent(i, self.pow)) } - glog.V(logger.Info).Infof("Starting mining operation (CPU=%d TOT=%d)\n", threads, len(self.worker.agents)) + log.Info(fmt.Sprintf("Starting mining operation (CPU=%d TOT=%d)\n", threads, len(self.worker.agents))) self.worker.start() self.worker.commitNewWork() } diff --git a/miner/remote_agent.go b/miner/remote_agent.go index 23277bac8..ec9d2c199 100644 --- a/miner/remote_agent.go +++ b/miner/remote_agent.go @@ -18,6 +18,7 @@ package miner import ( "errors" + "fmt" "math/big" "sync" "sync/atomic" @@ -26,8 +27,7 @@ import ( "github.com/ethereum/ethash" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/pow" ) @@ -140,13 +140,13 @@ func (a *RemoteAgent) SubmitWork(nonce types.BlockNonce, mixDigest, hash common. // Make sure the work submitted is present work := a.work[hash] if work == nil { - glog.V(logger.Info).Infof("Work was submitted for %x but no pending work found", hash) + log.Info(fmt.Sprintf("Work was submitted for %x but no pending work found", hash)) return false } // Make sure the PoW solutions is indeed valid block := work.Block.WithMiningResult(nonce, mixDigest) if !a.pow.Verify(block) { - glog.V(logger.Warn).Infof("Invalid PoW submitted for %x", hash) + log.Warn(fmt.Sprintf("Invalid PoW submitted for %x", hash)) return false } // Solutions seems to be valid, return to the miner and notify acceptance diff --git a/miner/unconfirmed.go b/miner/unconfirmed.go index 86a30de35..bb7d0ff26 100644 --- a/miner/unconfirmed.go +++ b/miner/unconfirmed.go @@ -18,12 +18,12 @@ package miner import ( "container/ring" + "fmt" "sync" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" ) // headerRetriever is used by the unconfirmed block set to verify whether a previously @@ -80,7 +80,7 @@ func (set *unconfirmedBlocks) Insert(index uint64, hash common.Hash) { set.blocks.Move(-1).Link(item) } // Display a log for the user to notify of a new mined block unconfirmed - glog.V(logger.Info).Infof("🔨 mined potential block #%d [%x…], waiting for %d blocks to confirm", index, hash.Bytes()[:4], set.depth) + log.Info(fmt.Sprintf("🔨 mined potential block #%d [%x…], waiting for %d blocks to confirm", index, hash.Bytes()[:4], set.depth)) } // Shift drops all unconfirmed blocks from the set which exceed the unconfirmed sets depth @@ -100,11 +100,11 @@ func (set *unconfirmedBlocks) Shift(height uint64) { header := set.chain.GetHeaderByNumber(next.index) switch { case header == nil: - glog.V(logger.Warn).Infof("failed to retrieve header of mined block #%d [%x…]", next.index, next.hash.Bytes()[:4]) + log.Warn(fmt.Sprintf("failed to retrieve header of mined block #%d [%x…]", next.index, next.hash.Bytes()[:4])) case header.Hash() == next.hash: - glog.V(logger.Info).Infof("🔗 mined block #%d [%x…] reached canonical chain", next.index, next.hash.Bytes()[:4]) + log.Info(fmt.Sprintf("🔗 mined block #%d [%x…] reached canonical chain", next.index, next.hash.Bytes()[:4])) default: - glog.V(logger.Info).Infof("⑂ mined block #%d [%x…] became a side fork", next.index, next.hash.Bytes()[:4]) + log.Info(fmt.Sprintf("⑂ mined block #%d [%x…] became a side fork", next.index, next.hash.Bytes()[:4])) } // Drop the block out of the ring if set.blocks.Value == set.blocks.Next().Value { diff --git a/miner/worker.go b/miner/worker.go index ef64c8fc9..037924257 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -32,8 +32,7 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "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/params" "github.com/ethereum/go-ethereum/pow" "gopkg.in/fatih/set.v0" @@ -278,7 +277,7 @@ func (self *worker) wait() { if self.fullValidation { if _, err := self.chain.InsertChain(types.Blocks{block}); err != nil { - glog.V(logger.Error).Infoln("mining err", err) + log.Error(fmt.Sprint("mining err", err)) continue } go self.mux.Post(core.NewMinedBlockEvent{Block: block}) @@ -286,19 +285,19 @@ func (self *worker) wait() { work.state.Commit(self.config.IsEIP158(block.Number())) parent := self.chain.GetBlock(block.ParentHash(), block.NumberU64()-1) if parent == nil { - glog.V(logger.Error).Infoln("Invalid block found during mining") + log.Error(fmt.Sprint("Invalid block found during mining")) continue } auxValidator := self.eth.BlockChain().AuxValidator() if err := core.ValidateHeader(self.config, auxValidator, block.Header(), parent.Header(), true, false); err != nil && err != core.BlockFutureErr { - glog.V(logger.Error).Infoln("Invalid header on mined block:", err) + log.Error(fmt.Sprint("Invalid header on mined block:", err)) continue } stat, err := self.chain.WriteBlock(block) if err != nil { - glog.V(logger.Error).Infoln("error writing block to chain", err) + log.Error(fmt.Sprint("error writing block to chain", err)) continue } @@ -334,7 +333,7 @@ func (self *worker) wait() { self.mux.Post(logs) } if err := core.WriteBlockReceipts(self.chainDb, block.Hash(), block.NumberU64(), receipts); err != nil { - glog.V(logger.Warn).Infoln("error writing block receipts:", err) + log.Warn(fmt.Sprint("error writing block receipts:", err)) } }(block, work.state.Logs(), work.receipts) } @@ -427,7 +426,7 @@ func (self *worker) commitNewWork() { // this will ensure we're not going off too far in the future if now := time.Now().Unix(); tstamp > now+4 { wait := time.Duration(tstamp-now) * time.Second - glog.V(logger.Info).Infoln("We are too far in the future. Waiting for", wait) + log.Info(fmt.Sprint("We are too far in the future. Waiting for", wait)) time.Sleep(wait) } @@ -458,7 +457,7 @@ func (self *worker) commitNewWork() { // Could potentially happen if starting to mine in an odd state. err := self.makeCurrent(parent, header) if err != nil { - glog.V(logger.Info).Infoln("Could not create new env for mining, retrying on next block.") + log.Info(fmt.Sprint("Could not create new env for mining, retrying on next block.")) return } // Create the current work task and check any fork transitions needed @@ -469,7 +468,7 @@ func (self *worker) commitNewWork() { pending, err := self.eth.TxPool().Pending() if err != nil { - glog.Errorf("Could not fetch pending transactions: %v", err) + log.Error(fmt.Sprintf("Could not fetch pending transactions: %v", err)) return } @@ -489,13 +488,12 @@ func (self *worker) commitNewWork() { break } if err := self.commitUncle(work, uncle.Header()); err != nil { - if glog.V(logger.Ridiculousness) { - glog.V(logger.Detail).Infof("Bad uncle found and will be removed (%x)\n", hash[:4]) - glog.V(logger.Detail).Infoln(uncle) - } + log.Trace(fmt.Sprintf("Bad uncle found and will be removed (%x)\n", hash[:4])) + log.Trace(fmt.Sprint(uncle)) + badUncles = append(badUncles, hash) } else { - glog.V(logger.Debug).Infof("committing %x as uncle\n", hash[:4]) + log.Debug(fmt.Sprintf("committing %x as uncle\n", hash[:4])) uncles = append(uncles, uncle.Header()) } } @@ -514,7 +512,7 @@ func (self *worker) commitNewWork() { // We only care about logging if we're actually mining. if atomic.LoadInt32(&self.mining) == 1 { - glog.V(logger.Info).Infof("commit new work on block %v with %d txs & %d uncles. Took %v\n", work.Block.Number(), work.tcount, len(uncles), time.Since(tstart)) + log.Info(fmt.Sprintf("commit new work on block %v with %d txs & %d uncles. Took %v\n", work.Block.Number(), work.tcount, len(uncles), time.Since(tstart))) self.unconfirmed.Shift(work.Block.NumberU64() - 1) } self.push(work) @@ -554,7 +552,7 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB // Check whether the tx is replay protected. If we're not in the EIP155 hf // phase, start ignoring the sender until we do. if tx.Protected() && !env.config.IsEIP155(env.header.Number) { - glog.V(logger.Detail).Infof("Transaction (%x) is replay protected, but we haven't yet hardforked. Transaction will be ignored until we hardfork.\n", tx.Hash()) + log.Trace(fmt.Sprintf("Transaction (%x) is replay protected, but we haven't yet hardforked. Transaction will be ignored until we hardfork.\n", tx.Hash())) txs.Pop() continue @@ -563,7 +561,7 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB // Ignore any transactions (and accounts subsequently) with low gas limits if tx.GasPrice().Cmp(gasPrice) < 0 && !env.ownedAccounts.Has(from) { // Pop the current low-priced transaction without shifting in the next from the account - glog.V(logger.Info).Infof("Transaction (%x) below gas price (tx=%v ask=%v). All sequential txs from this address(%x) will be ignored\n", tx.Hash().Bytes()[:4], common.CurrencyToString(tx.GasPrice()), common.CurrencyToString(gasPrice), from[:4]) + log.Info(fmt.Sprintf("Transaction (%x) below gas price (tx=%v ask=%v). All sequential txs from this address(%x) will be ignored\n", tx.Hash().Bytes()[:4], common.CurrencyToString(tx.GasPrice()), common.CurrencyToString(gasPrice), from[:4])) env.lowGasTxs = append(env.lowGasTxs, tx) txs.Pop() @@ -577,12 +575,12 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB switch { case core.IsGasLimitErr(err): // Pop the current out-of-gas transaction without shifting in the next from the account - glog.V(logger.Detail).Infof("Gas limit reached for (%x) in this block. Continue to try smaller txs\n", from[:4]) + log.Trace(fmt.Sprintf("Gas limit reached for (%x) in this block. Continue to try smaller txs\n", from[:4])) txs.Pop() case err != nil: // Pop the current failed transaction without shifting in the next from the account - glog.V(logger.Detail).Infof("Transaction (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err) + log.Trace(fmt.Sprintf("Transaction (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err)) env.failedTxs = append(env.failedTxs, tx) txs.Pop() -- cgit v1.2.3