aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2014-06-26 23:37:56 +0800
committerzelig <viktor.tron@gmail.com>2014-06-26 23:37:56 +0800
commitda38faa8f7c0f2a6620b54e46fc38a201845e104 (patch)
tree2656f980c91f9f93d98215867f75c9253e330019
parent098136b68198083a47408ec5c04cd0c8f9fdcc87 (diff)
parent0ed19d9f2024744ba93d0e34db6939766b3cfed5 (diff)
downloadgo-tangerine-da38faa8f7c0f2a6620b54e46fc38a201845e104.tar.gz
go-tangerine-da38faa8f7c0f2a6620b54e46fc38a201845e104.tar.zst
go-tangerine-da38faa8f7c0f2a6620b54e46fc38a201845e104.zip
merge upstream; fix port in use warning; new logger API
-rw-r--r--ethchain/asm.go4
-rw-r--r--ethchain/block_chain.go11
-rw-r--r--ethchain/vm.go31
-rw-r--r--ethereum.go2
-rw-r--r--ethutil/script.go1
-rw-r--r--ethutil/trie.go2
6 files changed, 24 insertions, 27 deletions
diff --git a/ethchain/asm.go b/ethchain/asm.go
index 277326ff9..09d6af56f 100644
--- a/ethchain/asm.go
+++ b/ethchain/asm.go
@@ -18,7 +18,7 @@ func Disassemble(script []byte) (asm []string) {
// Get the opcode (it must be an opcode!)
op := OpCode(val)
- asm = append(asm, fmt.Sprintf("%v", op))
+ asm = append(asm, fmt.Sprintf("%04v: %v", pc, op))
switch op {
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
@@ -28,7 +28,7 @@ func Disassemble(script []byte) (asm []string) {
if len(data) == 0 {
data = []byte{0}
}
- asm = append(asm, fmt.Sprintf("0x%x", data))
+ asm = append(asm, fmt.Sprintf("%04v: 0x%x", pc, data))
pc.Add(pc, big.NewInt(a-1))
}
diff --git a/ethchain/block_chain.go b/ethchain/block_chain.go
index f964e0e3a..05b2564cf 100644
--- a/ethchain/block_chain.go
+++ b/ethchain/block_chain.go
@@ -176,18 +176,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 {
@@ -233,6 +227,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 {
+ chainlogger.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 4c1821f56..20d355674 100644
--- a/ethchain/vm.go
+++ b/ethchain/vm.go
@@ -102,22 +102,21 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
vmlogger.Debugf("(~) %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
@@ -128,7 +127,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 28d1c0437..8caa75cbd 100644
--- a/ethereum.go
+++ b/ethereum.go
@@ -342,7 +342,7 @@ func (s *Ethereum) Start(seed bool) {
// Bind to addr and port
ln, err := net.Listen("tcp", ":"+s.Port)
if err != nil {
- ethlogger.Warnln("Connection listening disabled. Acting as client")
+ ethlogger.Warnf("Port %s in use. Connection listening disabled. Acting as client", s.Port)
s.listening = false
} else {
s.listening = true
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)