Skip to content

Commit

Permalink
Updated logging
Browse files Browse the repository at this point in the history
  • Loading branch information
obscuren committed Apr 4, 2015
1 parent 5dc5e66 commit 053d555
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
26 changes: 18 additions & 8 deletions core/chain_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ func (self *ChainManager) Export(w io.Writer) error {
self.mu.RLock()
defer self.mu.RUnlock()
glog.V(logger.Info).Infof("exporting %v blocks...\n", self.currentBlock.Header().Number)

for block := self.currentBlock; block != nil; block = self.GetBlock(block.Header().ParentHash) {
if err := block.EncodeRLP(w); err != nil {
return err
Expand Down Expand Up @@ -360,7 +361,7 @@ func (self *ChainManager) GetBlock(hash common.Hash) *types.Block {
}
var block types.StorageBlock
if err := rlp.Decode(bytes.NewReader(data), &block); err != nil {
chainlogger.Errorf("invalid block RLP for hash %x: %v", hash, err)
glog.V(logger.Error).Infof("invalid block RLP for hash %x: %v", hash, err)
return nil
}
return (*types.Block)(&block)
Expand Down Expand Up @@ -448,8 +449,11 @@ func (self *ChainManager) procFutureBlocks() {

func (self *ChainManager) InsertChain(chain types.Blocks) error {
// A queued approach to delivering events. This is generally faster than direct delivery and requires much less mutex acquiring.
var queue = make([]interface{}, len(chain))
var queueEvent = queueEvent{queue: queue}
var (
queue = make([]interface{}, len(chain))
queueEvent = queueEvent{queue: queue}
stats struct{ delayed, processed int }
)
for i, block := range chain {
if block == nil {
continue
Expand All @@ -467,18 +471,22 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
// future block for future use
if err == BlockFutureErr {
self.futureBlocks.Push(block)
stats.delayed++
continue
}

if IsParentErr(err) && self.futureBlocks.Has(block.ParentHash()) {
self.futureBlocks.Push(block)
stats.delayed++
continue
}

h := block.Header()
chainlogger.Errorf("INVALID block #%v (%x)\n", h.Number, h.Hash().Bytes()[:4])
chainlogger.Errorln(err)
chainlogger.Debugln(block)

glog.V(logger.Error).Infof("INVALID block #%v (%x)\n", h.Number, h.Hash().Bytes()[:4])
glog.V(logger.Error).Infoln(err)
glog.V(logger.Debug).Infoln(block)

return err
}
block.Td = td
Expand Down Expand Up @@ -530,13 +538,15 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
}
self.mu.Unlock()

stats.processed++

self.futureBlocks.Delete(block.Hash())

}

if len(chain) > 0 && glog.V(logger.Info) {
if (stats.delayed > 0 || stats.processed > 0) && bool(glog.V(logger.Info)) {
start, end := chain[0], chain[len(chain)-1]
glog.Infof("imported %d block(s) #%v [%x / %x]\n", len(chain), end.Number(), start.Hash().Bytes()[:4], end.Hash().Bytes()[:4])
glog.Infof("imported %d block(s) %d delayed. #%v [%x / %x]\n", stats.processed, stats.delayed, end.Number(), start.Hash().Bytes()[:4], end.Hash().Bytes()[:4])
}

go self.eventMux.Post(queueEvent)
Expand Down
3 changes: 2 additions & 1 deletion logger/verbosity.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package logger

const (
Error = iota + 2
Error = iota + 1
Warn
Info
Core
Debug
Expand Down
4 changes: 3 additions & 1 deletion miner/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"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/pow"
)

Expand Down Expand Up @@ -75,7 +77,7 @@ done:
}

func (self *CpuMiner) mine(block *types.Block) {
minerlogger.Debugf("(re)started agent[%d]. mining...\n", self.index)
glog.V(logger.Debug).Infof("(re)started agent[%d]. mining...\n", self.index)

// Reset the channel
self.chMu.Lock()
Expand Down
3 changes: 0 additions & 3 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import (
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/pow"
)

var minerlogger = logger.NewLogger("MINER")

type Miner struct {
worker *worker

Expand Down
24 changes: 15 additions & 9 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/pow"
"gopkg.in/fatih/set.v0"
)
Expand Down Expand Up @@ -144,7 +145,9 @@ out:
}
break out
case <-timer.C:
minerlogger.Infoln("Hash rate:", self.HashRate(), "Khash")
if glog.V(logger.Info) {
glog.Infoln("Hash rate:", self.HashRate(), "Khash")
}

// XXX In case all mined a possible uncle
if atomic.LoadInt64(&self.atWork) == 0 {
Expand All @@ -171,7 +174,7 @@ func (self *worker) wait() {
}
self.mux.Post(core.NewMinedBlockEvent{block})

minerlogger.Infof("🔨 Mined block #%v", block.Number())
glog.V(logger.Info).Infof("🔨 Mined block #%v", block.Number())

jsonlogger.LogJson(&logger.EthMinerNewBlock{
BlockHash: block.Hash().Hex(),
Expand Down Expand Up @@ -238,10 +241,13 @@ gasLimit:
from, _ := tx.From()
self.chain.TxState().RemoveNonce(from, tx.Nonce())
remove = append(remove, tx)
minerlogger.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err)
minerlogger.Infoln(tx)

if glog.V(logger.Info) {
glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err)
}
glog.V(logger.Debug).Infoln(tx)
case state.IsGasLimitErr(err):
minerlogger.Infof("Gas limit reached for block. %d TXs included in this block\n", i)
glog.V(logger.Info).Infof("Gas limit reached for block. %d TXs included in this block\n", i)
// Break on gas limit
break gasLimit
default:
Expand All @@ -260,15 +266,15 @@ gasLimit:
}

if err := self.commitUncle(uncle.Header()); err != nil {
minerlogger.Infof("Bad uncle found and will be removed (%x)\n", hash[:4])
minerlogger.Debugln(uncle)
glog.V(logger.Info).Infof("Bad uncle found and will be removed (%x)\n", hash[:4])
glog.V(logger.Debug).Infoln(uncle)
badUncles = append(badUncles, hash)
} else {
minerlogger.Infof("commiting %x as uncle\n", hash[:4])
glog.V(logger.Info).Infof("commiting %x as uncle\n", hash[:4])
uncles = append(uncles, uncle.Header())
}
}
minerlogger.Infof("commit new work on block %v with %d txs & %d uncles\n", self.current.block.Number(), tcount, len(uncles))
glog.V(logger.Info).Infof("commit new work on block %v with %d txs & %d uncles\n", self.current.block.Number(), tcount, len(uncles))
for _, hash := range badUncles {
delete(self.possibleUncles, hash)
}
Expand Down

0 comments on commit 053d555

Please sign in to comment.