mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-22 19:40:36 +00:00
Updated logging
This commit is contained in:
parent
5dc5e66986
commit
053d5552ab
@ -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
|
||||
@ -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)
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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)
|
||||
|
@ -1,7 +1,8 @@
|
||||
package logger
|
||||
|
||||
const (
|
||||
Error = iota + 2
|
||||
Error = iota + 1
|
||||
Warn
|
||||
Info
|
||||
Core
|
||||
Debug
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
@ -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()
|
||||
|
@ -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
|
||||
|
||||
|
@ -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"
|
||||
)
|
||||
@ -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 {
|
||||
@ -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(),
|
||||
@ -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:
|
||||
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user