aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2014-07-01 22:03:02 +0800
committerzelig <viktor.tron@gmail.com>2014-07-01 22:03:02 +0800
commit89630d2826300d119f2cdc9f8af6c94926f478a2 (patch)
treeaa2addd061e2d2a8f3cdc0821260409f31ac3b09 /ethchain
parent12972b4b65a303dc3f9e135b0e2d97f8b7a661e2 (diff)
parent550407b0ec78b7026737d1abe28127da8c0c9063 (diff)
downloadgo-tangerine-89630d2826300d119f2cdc9f8af6c94926f478a2.tar
go-tangerine-89630d2826300d119f2cdc9f8af6c94926f478a2.tar.gz
go-tangerine-89630d2826300d119f2cdc9f8af6c94926f478a2.tar.bz2
go-tangerine-89630d2826300d119f2cdc9f8af6c94926f478a2.tar.lz
go-tangerine-89630d2826300d119f2cdc9f8af6c94926f478a2.tar.xz
go-tangerine-89630d2826300d119f2cdc9f8af6c94926f478a2.tar.zst
go-tangerine-89630d2826300d119f2cdc9f8af6c94926f478a2.zip
merge upstream
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/block.go2
-rw-r--r--ethchain/block_chain.go2
-rw-r--r--ethchain/dagger.go1
-rw-r--r--ethchain/state.go83
-rw-r--r--ethchain/state_manager.go10
-rw-r--r--ethchain/state_object.go5
-rw-r--r--ethchain/state_test.go4
-rw-r--r--ethchain/state_transition.go50
-rw-r--r--ethchain/vm.go29
-rw-r--r--ethchain/vm_test.go8
10 files changed, 93 insertions, 101 deletions
diff --git a/ethchain/block.go b/ethchain/block.go
index ed5b754f8..a0f9ecd86 100644
--- a/ethchain/block.go
+++ b/ethchain/block.go
@@ -168,7 +168,7 @@ func (block *Block) CalcGasLimit(parent *Block) *big.Int {
result := new(big.Int).Add(previous, curInt)
result.Div(result, big.NewInt(1024))
- min := ethutil.BigPow(10, 4)
+ min := big.NewInt(125000)
return ethutil.BigMax(min, result)
/*
diff --git a/ethchain/block_chain.go b/ethchain/block_chain.go
index 7a481ed7c..df735d679 100644
--- a/ethchain/block_chain.go
+++ b/ethchain/block_chain.go
@@ -271,7 +271,7 @@ func AddTestNetFunds(block *Block) {
for _, addr := range []string{
"51ba59315b3a95761d0863b05ccc7a7f54703d99",
"e4157b34ea9615cfbde6b4fda419828124b70c78",
- "1e12515ce3e0f817a4ddef9ca55788a1d66bd2df",
+ "b9c015918bdaba24b4ff057a92a3873d6eb201be",
"6c386a4b26f73c802f34673f7248bb118f97424a",
"cd2a3d9f938e13cd947ec05abc7fe734df8dd826",
"2ef47100e0787b915105fd5e3f4ff6752079d5cb",
diff --git a/ethchain/dagger.go b/ethchain/dagger.go
index 46b1081e9..4dda21ff5 100644
--- a/ethchain/dagger.go
+++ b/ethchain/dagger.go
@@ -32,6 +32,7 @@ func (pow *EasyPow) Search(block *Block, reactChan chan ethutil.React) []byte {
for {
select {
case <-reactChan:
+ powlogger.Infoln("Breaking from mining")
return nil
default:
i++
diff --git a/ethchain/state.go b/ethchain/state.go
index dc2d3c73b..8b6c2efb8 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -127,7 +127,7 @@ func (self *State) GetOrNewStateObject(addr []byte) *StateObject {
}
func (self *State) NewStateObject(addr []byte) *StateObject {
- statelogger.Infof("(+) %x\n", addr)
+ //statelogger.Infof("(+) %x\n", addr)
stateObject := NewStateObject(addr)
self.stateObjects[string(addr)] = stateObject
@@ -206,84 +206,3 @@ func (m *Manifest) AddStorageChange(stateObject *StateObject, storageAddr []byte
m.storageChanges[string(stateObject.Address())][string(storageAddr)] = storage
}
-
-/*
-
-// Resets the trie and all siblings
-func (s *State) Reset() {
- s.trie.Undo()
-
- // Reset all nested states
- for _, state := range s.states {
- state.Reset()
- }
-}
-
-// Syncs the trie and all siblings
-func (s *State) Sync() {
- // Sync all nested states
- for _, state := range s.states {
- state.Sync()
- }
-
- s.trie.Sync()
-}
-func (s *State) GetStateObject(addr []byte) *StateObject {
- data := s.trie.Get(string(addr))
- if data == "" {
- return nil
- }
-
- stateObject := NewStateObjectFromBytes(addr, []byte(data))
-
- // Check if there's a cached state for this contract
- cachedStateObject := s.states[string(addr)]
- if cachedStateObject != nil {
- //fmt.Printf("get cached #%d %x addr: %x\n", cachedStateObject.trie.Cache().Len(), cachedStateObject.Root(), addr[0:4])
- stateObject.state = cachedStateObject
- }
-
- return stateObject
-}
-
-// Updates any given state object
-func (s *State) UpdateStateObject(object *StateObject) {
- addr := object.Address()
-
- if object.state != nil && s.states[string(addr)] == nil {
- s.states[string(addr)] = object.state
- }
-
- ethutil.Config.Db.Put(ethutil.Sha3Bin(object.Script()), object.Script())
-
- s.trie.Update(string(addr), string(object.RlpEncode()))
-
- s.manifest.AddObjectChange(object)
-}
-
-func (s *State) GetAccount(addr []byte) (account *StateObject) {
- data := s.trie.Get(string(addr))
- if data == "" {
- account = NewAccount(addr, big.NewInt(0))
- } else {
- account = NewStateObjectFromBytes(addr, []byte(data))
- }
-
- // Check if there's a cached state for this contract
- cachedStateObject := s.states[string(addr)]
- if cachedStateObject != nil {
- account.state = cachedStateObject
- }
-
- return
-}
-
-func (s *State) Copy() *State {
- state := NewState(s.trie.Copy())
- for k, subState := range s.states {
- state.states[k] = subState.Copy()
- }
-
- return state
-}
-*/
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index f199e20ec..dea82cae3 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -3,6 +3,7 @@ package ethchain
import (
"bytes"
"container/list"
+ "fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethutil"
@@ -125,6 +126,8 @@ done:
break done
default:
statelogger.Infoln(err)
+ err = nil
+ //return nil, nil, nil, err
}
}
@@ -202,7 +205,7 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
}
if !block.State().Cmp(state) {
- statelogger.Errorf("Invalid merkle root.\nrec: %x\nis: %x", block.State().trie.Root, state.trie.Root)
+ err = fmt.Errorf("Invalid merkle root.\nrec: %x\nis: %x", block.State().trie.Root, state.trie.Root)
return
}
@@ -237,7 +240,10 @@ func (sm *StateManager) ApplyDiff(state *State, parent, block *Block) (receipts
coinbase.SetGasPool(block.CalcGasLimit(parent))
// Process the transactions on to current block
- receipts, _, _, _ = sm.ProcessTransactions(coinbase, state, block, parent, block.Transactions())
+ receipts, _, _, err = sm.ProcessTransactions(coinbase, state, block, parent, block.Transactions())
+ if err != nil {
+ return nil, err
+ }
return receipts, nil
}
diff --git a/ethchain/state_object.go b/ethchain/state_object.go
index e55540153..7c9430af2 100644
--- a/ethchain/state_object.go
+++ b/ethchain/state_object.go
@@ -50,7 +50,10 @@ func MakeContract(tx *Transaction, state *State) *StateObject {
}
func NewStateObject(addr []byte) *StateObject {
- return &StateObject{address: addr, Amount: new(big.Int), gasPool: new(big.Int)}
+ object := &StateObject{address: addr, Amount: new(big.Int), gasPool: new(big.Int)}
+ object.state = NewState(ethutil.NewTrie(ethutil.Config.Db, ""))
+
+ return object
}
func NewContract(address []byte, Amount *big.Int, root []byte) *StateObject {
diff --git a/ethchain/state_test.go b/ethchain/state_test.go
index 503bdddb4..95be0f373 100644
--- a/ethchain/state_test.go
+++ b/ethchain/state_test.go
@@ -16,12 +16,12 @@ func TestSnapshot(t *testing.T) {
state.UpdateStateObject(stateObject)
stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(42))
- snapshot := state.Snapshot()
+ snapshot := state.Copy()
stateObject = state.GetStateObject([]byte("aa"))
stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(43))
- state.Revert(snapshot)
+ state.Set(snapshot)
stateObject = state.GetStateObject([]byte("aa"))
if !stateObject.GetStorage(ethutil.Big("0")).Cmp(ethutil.NewValue(42)) {
diff --git a/ethchain/state_transition.go b/ethchain/state_transition.go
index f84c3486b..94c3de3d9 100644
--- a/ethchain/state_transition.go
+++ b/ethchain/state_transition.go
@@ -1,7 +1,9 @@
package ethchain
import (
+ "bytes"
"fmt"
+ "github.com/ethereum/eth-go/ethutil"
"math/big"
)
@@ -224,15 +226,11 @@ func (self *StateTransition) transferValue(sender, receiver *StateObject) error
return fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", self.value, sender.Amount)
}
- //if self.value.Cmp(ethutil.Big0) > 0 {
// Subtract the amount from the senders account
sender.SubAmount(self.value)
// Add the amount to receivers account which should conclude this transaction
receiver.AddAmount(self.value)
- //statelogger.Debugf("%x => %x (%v)\n", sender.Address()[:4], receiver.Address()[:4], self.value)
- //}
-
return nil
}
@@ -255,8 +253,50 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by
Value: self.value,
})
vm.Verbose = true
- ret, _, err = closure.Call(vm, self.data, nil)
+
+ ret, err, deepErr = Call(vm, closure, self.data)
+
+ return
+}
+
+func Call(vm *Vm, closure *Closure, data []byte) (ret []byte, err error, deepErr bool) {
+ ret, _, err = closure.Call(vm, data, nil)
deepErr = vm.err != nil
+ Paranoia := ethutil.Config.Paranoia
+ if Paranoia {
+ var (
+ context = closure.object
+ trie = context.state.trie
+ trie2 = ethutil.NewTrie(ethutil.Config.Db, "")
+ )
+
+ trie.NewIterator().Each(func(key string, v *ethutil.Value) {
+ trie2.Update(key, v.Str())
+ })
+
+ a := ethutil.NewValue(trie2.Root).Bytes()
+ b := ethutil.NewValue(context.state.trie.Root).Bytes()
+ if bytes.Compare(a, b) != 0 {
+ // TODO FIXME ASAP
+ context.state.trie = trie2
+ /*
+ statelogger.Debugf("(o): %x\n", trie.Root)
+ trie.NewIterator().Each(func(key string, v *ethutil.Value) {
+ v.Decode()
+ statelogger.Debugf("%x : %x\n", key, v.Str())
+ })
+
+ statelogger.Debugf("(c): %x\n", trie2.Root)
+ trie2.NewIterator().Each(func(key string, v *ethutil.Value) {
+ v.Decode()
+ statelogger.Debugf("%x : %x\n", key, v.Str())
+ })
+ */
+
+ //return nil, fmt.Errorf("PARANOIA: Different state object roots during copy"), false
+ }
+ }
+
return
}
diff --git a/ethchain/vm.go b/ethchain/vm.go
index 66b5a9182..c5ccb3420 100644
--- a/ethchain/vm.go
+++ b/ethchain/vm.go
@@ -347,6 +347,29 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
} else {
stack.Push(ethutil.BigFalse)
}
+
+ case SLT:
+ require(2)
+ x, y := stack.Popn()
+ vm.Printf(" %v < %v", y, x)
+ // x < y
+ if y.Cmp(x) < 0 {
+ stack.Push(ethutil.BigTrue)
+ } else {
+ stack.Push(ethutil.BigFalse)
+ }
+ case SGT:
+ require(2)
+ x, y := stack.Popn()
+ vm.Printf(" %v > %v", y, x)
+
+ // x > y
+ if y.Cmp(x) > 0 {
+ stack.Push(ethutil.BigTrue)
+ } else {
+ stack.Push(ethutil.BigFalse)
+ }
+
case EQ:
require(2)
x, y := stack.Popn()
@@ -661,7 +684,8 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
// Create a new callable closure
closure := NewClosure(closure, stateObject, stateObject.script, vm.state, gas, closure.Price)
// Executer the closure and get the return value (if any)
- ret, _, err := closure.Call(vm, args, hook)
+ //ret, _, err := closure.Call(vm, args, hook)
+ ret, err, _ := Call(vm, closure, args)
if err != nil {
stack.Push(ethutil.BigFalse)
@@ -700,7 +724,8 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
return closure.Return(nil), nil
default:
- vmlogger.Debugf("Invalid opcode %x\n", op)
+ vmlogger.Debugf("(pc) %-3v Invalid opcode %x\n", pc, op)
+ fmt.Println(Code(closure.Script))
return closure.Return(nil), fmt.Errorf("Invalid opcode %x", op)
}
diff --git a/ethchain/vm_test.go b/ethchain/vm_test.go
index c569d89ae..c8023cd79 100644
--- a/ethchain/vm_test.go
+++ b/ethchain/vm_test.go
@@ -5,9 +5,7 @@ import (
"fmt"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
- "github.com/obscuren/mutan"
"math/big"
- "strings"
"testing"
)
@@ -17,7 +15,7 @@ func TestRun4(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
state := NewState(ethutil.NewTrie(db, ""))
- callerScript, err := mutan.Compile(strings.NewReader(`
+ callerScript, err := ethutil.Compile(`
this.store[this.origin()] = 10**20
hello := "world"
@@ -31,7 +29,7 @@ func TestRun4(t *testing.T) {
this.store[to] = this.store[to] + value
}
}
- `), false)
+ `)
if err != nil {
fmt.Println(err)
}
@@ -55,7 +53,7 @@ func TestRun4(t *testing.T) {
vm := NewVm(state, nil, RuntimeVars{
Origin: account.Address(),
- BlockNumber: 1,
+ BlockNumber: big.NewInt(1),
PrevHash: ethutil.FromHex("5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"),
Coinbase: ethutil.FromHex("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"),
Time: 1,