diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-04 18:40:11 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-04 18:40:11 +0800 |
commit | a0e44e3281fcef0913b172ed4cdb5283a8d4a46b (patch) | |
tree | e10b9ce906119e3810a15df66f433da678a2764e /core | |
parent | 60e097a5f4c10e9e869bd2b4b2814b766b409e18 (diff) | |
download | dexon-a0e44e3281fcef0913b172ed4cdb5283a8d4a46b.tar.gz dexon-a0e44e3281fcef0913b172ed4cdb5283a8d4a46b.tar.zst dexon-a0e44e3281fcef0913b172ed4cdb5283a8d4a46b.zip |
basic glog
Diffstat (limited to 'core')
-rw-r--r-- | core/block_processor.go | 24 | ||||
-rw-r--r-- | core/chain_manager.go | 10 | ||||
-rw-r--r-- | core/state/state_object.go | 19 | ||||
-rw-r--r-- | core/state/statedb.go | 4 | ||||
-rw-r--r-- | core/vm/common.go | 6 | ||||
-rw-r--r-- | core/vm/vm.go | 11 |
6 files changed, 37 insertions, 37 deletions
diff --git a/core/block_processor.go b/core/block_processor.go index 0a98f3e32..b3e18a70a 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -165,15 +165,9 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big // Create a new state based on the parent's root (e.g., create copy) state := state.New(parent.Root(), sm.db) - // track (possible) uncle block - var uncle bool // Block validation if err = sm.ValidateHeader(block.Header(), parent.Header()); err != nil { - if err != BlockEqualTSErr { - return - } - err = nil - uncle = true + return } // There can be at most two uncles @@ -231,23 +225,14 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big // Sync the current block's state to the database state.Sync() - if !uncle { - // Remove transactions from the pool - sm.txpool.RemoveSet(block.Transactions()) - } + // Remove transactions from the pool + sm.txpool.RemoveSet(block.Transactions()) // This puts transactions in a extra db for rpc for i, tx := range block.Transactions() { putTx(sm.extraDb, tx, block, uint64(i)) } - if uncle { - chainlogger.Infof("found possible uncle block #%d (%x...)\n", header.Number, block.Hash().Bytes()[0:4]) - return td, nil, BlockEqualTSErr - } else { - chainlogger.Infof("processed block #%d (%d TXs %d UNCs) (%x...)\n", header.Number, len(block.Transactions()), len(block.Uncles()), block.Hash().Bytes()[0:4]) - } - return td, state.Logs(), nil } @@ -272,7 +257,8 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error { return fmt.Errorf("GasLimit check failed for block %v (%v > %v)", block.GasLimit, a, b) } - if int64(block.Time) > time.Now().Unix() { + // Allow future blocks up to 4 seconds + if int64(block.Time)+4 > time.Now().Unix() { return BlockFutureErr } diff --git a/core/chain_manager.go b/core/chain_manager.go index bf5ba9b40..b9a08b13d 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -12,6 +12,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/params" "github.com/ethereum/go-ethereum/rlp" ) @@ -494,6 +495,10 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error { queue[i] = ChainEvent{block, logs} queueEvent.canonicalCount++ + + if glog.V(logger.Debug) { + glog.Infof("inserted block #%d (%d TXs %d UNCs) (%x...)\n", block.Number(), len(block.Transactions()), len(block.Uncles()), block.Hash().Bytes()[0:4]) + } } else { queue[i] = ChainSideEvent{block, logs} queueEvent.sideCount++ @@ -503,6 +508,11 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error { } + if len(chain) > 0 && glog.V(logger.Info) { + start, end := chain[0], chain[len(chain)-1] + glog.Infof("imported %d blocks [%x / %x] #%v\n", len(chain), start.Hash().Bytes()[:4], end.Hash().Bytes()[:4], end.Number()) + } + go self.eventMux.Post(queueEvent) return nil diff --git a/core/state/state_object.go b/core/state/state_object.go index a7c20722c..e44bf2cd6 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -7,6 +7,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" ) @@ -121,7 +123,10 @@ func NewStateObjectFromBytes(address common.Address, data []byte, db common.Data func (self *StateObject) MarkForDeletion() { self.remove = true self.dirty = true - statelogger.Debugf("%x: #%d %v X\n", self.Address(), self.nonce, self.balance) + + if glog.V(logger.Debug) { + glog.Infof("%x: #%d %v X\n", self.Address(), self.nonce, self.balance) + } } func (c *StateObject) getAddr(addr common.Hash) *common.Value { @@ -185,13 +190,17 @@ func (c *StateObject) GetInstr(pc *big.Int) *common.Value { func (c *StateObject) AddBalance(amount *big.Int) { c.SetBalance(new(big.Int).Add(c.balance, amount)) - statelogger.Debugf("%x: #%d %v (+ %v)\n", c.Address(), c.nonce, c.balance, amount) + if glog.V(logger.Debug) { + glog.Infof("%x: #%d %v (+ %v)\n", c.Address(), c.nonce, c.balance, amount) + } } func (c *StateObject) SubBalance(amount *big.Int) { c.SetBalance(new(big.Int).Sub(c.balance, amount)) - statelogger.Debugf("%x: #%d %v (- %v)\n", c.Address(), c.nonce, c.balance, amount) + if glog.V(logger.Debug) { + glog.Infof("%x: #%d %v (- %v)\n", c.Address(), c.nonce, c.balance, amount) + } } func (c *StateObject) SetBalance(amount *big.Int) { @@ -225,7 +234,9 @@ func (c *StateObject) ConvertGas(gas, price *big.Int) error { func (self *StateObject) SetGasPool(gasLimit *big.Int) { self.gasPool = new(big.Int).Set(gasLimit) - statelogger.Debugf("%x: gas (+ %v)", self.Address(), self.gasPool) + if glog.V(logger.Debug) { + glog.Infof("%x: gas (+ %v)", self.Address(), self.gasPool) + } } func (self *StateObject) BuyGas(gas, price *big.Int) error { diff --git a/core/state/statedb.go b/core/state/statedb.go index 33e8c20e5..e027533aa 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -6,12 +6,10 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/trie" - "github.com/golang/glog" ) -var statelogger = logger.NewLogger("STATE") - // StateDBs within the ethereum protocol are used to store anything // within the merkle trie. StateDBs take care of caching and storing // nested states. It's the general query interface to retrieve: diff --git a/core/vm/common.go b/core/vm/common.go index 0a93c3dd9..7b8b7dc4d 100644 --- a/core/vm/common.go +++ b/core/vm/common.go @@ -5,11 +5,9 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger/glog" ) -var vmlogger = logger.NewLogger("VM") - // Global Debug flag indicating Debug VM (full logging) var Debug bool @@ -41,7 +39,7 @@ func NewVm(env Environment) VirtualMachine { case JitVmTy: return NewJitVm(env) default: - vmlogger.Infoln("unsupported vm type %d", env.VmType()) + glog.V(0).Infoln("unsupported vm type %d", env.VmType()) fallthrough case StdVmTy: return New(env) diff --git a/core/vm/vm.go b/core/vm/vm.go index 6222ef8c2..118f60076 100644 --- a/core/vm/vm.go +++ b/core/vm/vm.go @@ -7,6 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/params" ) @@ -885,9 +886,7 @@ func (self *Vm) RunPrecompiled(p *PrecompiledAccount, callData []byte, context * func (self *Vm) Printf(format string, v ...interface{}) VirtualMachine { if self.debug { - if self.logTy == LogTyPretty { - self.logStr += fmt.Sprintf(format, v...) - } + self.logStr += fmt.Sprintf(format, v...) } return self @@ -895,10 +894,8 @@ func (self *Vm) Printf(format string, v ...interface{}) VirtualMachine { func (self *Vm) Endl() VirtualMachine { if self.debug { - if self.logTy == LogTyPretty { - vmlogger.Infoln(self.logStr) - self.logStr = "" - } + glog.V(0).Infoln(self.logStr) + self.logStr = "" } return self |