diff options
author | obscuren <geffobscura@gmail.com> | 2014-06-26 17:26:42 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-06-26 17:26:42 +0800 |
commit | 0ed19d9f2024744ba93d0e34db6939766b3cfed5 (patch) | |
tree | 76f36ff8ed0a21bcb9976e6d9919401990061b60 | |
parent | 39cb34850a573ea9b2ea73eb624139684502bc79 (diff) | |
download | go-tangerine-0ed19d9f2024744ba93d0e34db6939766b3cfed5.tar go-tangerine-0ed19d9f2024744ba93d0e34db6939766b3cfed5.tar.gz go-tangerine-0ed19d9f2024744ba93d0e34db6939766b3cfed5.tar.bz2 go-tangerine-0ed19d9f2024744ba93d0e34db6939766b3cfed5.tar.lz go-tangerine-0ed19d9f2024744ba93d0e34db6939766b3cfed5.tar.xz go-tangerine-0ed19d9f2024744ba93d0e34db6939766b3cfed5.tar.zst go-tangerine-0ed19d9f2024744ba93d0e34db6939766b3cfed5.zip |
Logging, variable rearrangement
-rw-r--r-- | ethchain/block_chain.go | 11 | ||||
-rw-r--r-- | ethchain/vm.go | 31 | ||||
-rw-r--r-- | ethereum.go | 4 | ||||
-rw-r--r-- | ethutil/script.go | 1 | ||||
-rw-r--r-- | ethutil/trie.go | 2 |
5 files changed, 23 insertions, 26 deletions
diff --git a/ethchain/block_chain.go b/ethchain/block_chain.go index 19b5248d7..286a158ba 100644 --- a/ethchain/block_chain.go +++ b/ethchain/block_chain.go @@ -174,18 +174,12 @@ func (bc *BlockChain) ResetTillBlockHash(hash []byte) error { bc.LastBlockHash = bc.genesisBlock.Hash() bc.LastBlockNumber = 1 } else { - // TODO: Somehow this doesn't really give the right numbers, double check. - // TODO: Change logs into debug lines returnTo = bc.GetBlock(hash) bc.CurrentBlock = returnTo bc.LastBlockHash = returnTo.Hash() - //info := bc.BlockInfo(returnTo) bc.LastBlockNumber = returnTo.Number.Uint64() } - // XXX Why are we resetting? This is the block chain, it has nothing to do with states - //bc.Ethereum.StateManager().PrepareDefault(returnTo) - // Manually reset the last sync block err := ethutil.Config.Db.Delete(lastBlock.Hash()) if err != nil { @@ -231,6 +225,11 @@ func (bc *BlockChain) GetChainFromHash(hash []byte, max uint64) []interface{} { for i := uint64(0); bytes.Compare(currentHash, hash) != 0 && num >= parentNumber && i < count; i++ { // Get the block of the chain block := bc.GetBlock(currentHash) + if block == nil { + ethutil.Config.Log.Debugf("Unexpected error during GetChainFromHash: Unable to find %x\n", currentHash) + break + } + currentHash = block.PrevHash chain = append(chain, block.Value().Val) diff --git a/ethchain/vm.go b/ethchain/vm.go index 4c6c5e24d..199eaae50 100644 --- a/ethchain/vm.go +++ b/ethchain/vm.go @@ -99,22 +99,21 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro ethutil.Config.Log.Debugf("[VM] (~) %x gas: %v (d) %x\n", closure.object.Address(), closure.Gas, closure.Args) - // Memory for the current closure - mem := &Memory{} - // New stack (should this be shared?) - stack := NewStack() - require := func(m int) { - if stack.Len() < m { - isRequireError = true - panic(fmt.Sprintf("stack err = %d, req = %d", stack.Len(), m)) + var ( + op OpCode + + mem = &Memory{} + stack = NewStack() + pc = big.NewInt(0) + step = 0 + prevStep = 0 + require = func(m int) { + if stack.Len() < m { + isRequireError = true + panic(fmt.Sprintf("%04v (%v) stack err size = %d, required = %d", pc, op, stack.Len(), m)) + } } - } - - // Program counter - pc := big.NewInt(0) - // Current step count - step := 0 - prevStep := 0 + ) for { prevStep = step @@ -125,7 +124,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro // Get the memory location of pc val := closure.Get(pc) // Get the opcode (it must be an opcode!) - op := OpCode(val.Uint()) + op = OpCode(val.Uint()) gas := new(big.Int) addStepGasUsage := func(amount *big.Int) { diff --git a/ethereum.go b/ethereum.go index a6cb78b1f..6345f8864 100644 --- a/ethereum.go +++ b/ethereum.go @@ -340,7 +340,7 @@ func (s *Ethereum) Start(seed bool) { // Bind to addr and port ln, err := net.Listen("tcp", ":"+s.Port) if err != nil { - log.Println("Connection listening disabled. Acting as client") + ethutil.Config.Log.Infof("port=%s in use. Connection listening disabled.") s.listening = false } else { s.listening = true @@ -395,7 +395,7 @@ func (s *Ethereum) Seed() { peers = append(peers, peer) } } else { - ethutil.Config.Log.Debugln("[SERV} Couldn't resolve :", target) + ethutil.Config.Log.Debugln("[SERV] Couldn't resolve :", target) } } // Connect to Peer list diff --git a/ethutil/script.go b/ethutil/script.go index 235498df2..af4ca6a38 100644 --- a/ethutil/script.go +++ b/ethutil/script.go @@ -22,7 +22,6 @@ func Compile(script string) (ret []byte, err error) { } else { compiler := mutan.NewCompiler(backend.NewEthereumBackend()) byteCode, errors := compiler.Compile(strings.NewReader(script)) - //byteCode, errors := mutan.Compile(strings.NewReader(script), false) if len(errors) > 0 { var errs string for _, er := range errors { diff --git a/ethutil/trie.go b/ethutil/trie.go index 18d0a5f0a..0c1a6d260 100644 --- a/ethutil/trie.go +++ b/ethutil/trie.go @@ -47,7 +47,7 @@ func (cache *Cache) Put(v interface{}) interface{} { value := NewValue(v) enc := value.Encode() - if len(enc) >= 32 { + if len(enc) < 32 { sha := Sha3Bin(enc) cache.nodes[string(sha)] = NewNode(sha, value, true) |