aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-17 17:21:18 +0800
committerobscuren <geffobscura@gmail.com>2014-07-17 17:21:18 +0800
commited3424ff75b396360990725afc124326dea4ab45 (patch)
tree1d1bc85f1133d5138e3c23bfdadadce54d1354ec /ethchain
parent14c4f06100d9f06592097c4ee588d0f83f6b17bd (diff)
downloaddexon-ed3424ff75b396360990725afc124326dea4ab45.tar.gz
dexon-ed3424ff75b396360990725afc124326dea4ab45.tar.zst
dexon-ed3424ff75b396360990725afc124326dea4ab45.zip
Trie fixes
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/state.go4
-rw-r--r--ethchain/state_manager.go1
-rw-r--r--ethchain/state_object.go41
-rw-r--r--ethchain/vm.go2
4 files changed, 37 insertions, 11 deletions
diff --git a/ethchain/state.go b/ethchain/state.go
index 66c298b3c..6b849296a 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -76,6 +76,8 @@ func (self *State) DeleteStateObject(stateObject *StateObject) {
// Retrieve a state object given my the address. Nil if not found
func (self *State) GetStateObject(addr []byte) *StateObject {
+ addr = ethutil.Address(addr)
+
stateObject := self.stateObjects[string(addr)]
if stateObject != nil {
return stateObject
@@ -204,6 +206,8 @@ func (self *State) Update() {
// FIXME trie delete is broken
valid, t2 := ethtrie.ParanoiaCheck(self.trie)
if !valid {
+ statelogger.Infof("Warn: PARANOIA: Different state root during copy %x vs %x\n", self.trie.Root, t2.Root)
+
self.trie = t2
}
}
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index 80362fa77..a0568c4cd 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -121,6 +121,7 @@ done:
for i, tx := range txs {
txGas := new(big.Int).Set(tx.Gas)
st := NewStateTransition(coinbase, tx, state, block)
+ //fmt.Printf("#%d\n", i+1)
err = st.TransitionState()
if err != nil {
switch {
diff --git a/ethchain/state_object.go b/ethchain/state_object.go
index 889496e91..cf37586fc 100644
--- a/ethchain/state_object.go
+++ b/ethchain/state_object.go
@@ -75,7 +75,7 @@ func MakeContract(tx *Transaction, state *State) *StateObject {
func NewStateObject(addr []byte) *StateObject {
// This to ensure that it has 20 bytes (and not 0 bytes), thus left or right pad doesn't matter.
- address := ethutil.LeftPadBytes(addr, 20)
+ address := ethutil.Address(addr)
object := &StateObject{address: address, Amount: new(big.Int), gasPool: new(big.Int)}
object.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, ""))
@@ -92,13 +92,6 @@ func NewContract(address []byte, Amount *big.Int, root []byte) *StateObject {
return contract
}
-// Returns a newly created account
-func NewAccount(address []byte, amount *big.Int) *StateObject {
- account := &StateObject{address: address, Amount: amount, Nonce: 0}
-
- return account
-}
-
func NewStateObjectFromBytes(address, data []byte) *StateObject {
object := &StateObject{address: address}
object.RlpDecode(data)
@@ -139,17 +132,37 @@ func (self *StateObject) getStorage(k []byte) *ethutil.Value {
}
return value
+
+ //return self.GetAddr(key)
}
func (self *StateObject) setStorage(k []byte, value *ethutil.Value) {
key := ethutil.LeftPadBytes(k, 32)
- //fmt.Printf("%x %v\n", key, value)
self.storage[string(key)] = value.Copy()
+
+ /*
+ if value.BigInt().Cmp(ethutil.Big0) == 0 {
+ self.state.trie.Delete(string(key))
+ return
+ }
+
+ self.SetAddr(key, value)
+ */
}
func (self *StateObject) Sync() {
+ /*
+ fmt.Println("############# BEFORE ################")
+ self.state.EachStorage(func(key string, value *ethutil.Value) {
+ fmt.Printf("%x %x %x\n", self.Address(), []byte(key), value.Bytes())
+ })
+ fmt.Printf("%x @:%x\n", self.Address(), self.state.Root())
+ fmt.Println("#####################################")
+ */
for key, value := range self.storage {
- if value.BigInt().Cmp(ethutil.Big0) == 0 {
+ if value.Len() == 0 { // value.BigInt().Cmp(ethutil.Big0) == 0 {
+ //data := self.getStorage([]byte(key))
+ //fmt.Printf("deleting %x %x 0x%x\n", self.Address(), []byte(key), data)
self.state.trie.Delete(string(key))
continue
}
@@ -163,6 +176,14 @@ func (self *StateObject) Sync() {
self.state.trie = t2
}
+
+ /*
+ fmt.Println("############# AFTER ################")
+ self.state.EachStorage(func(key string, value *ethutil.Value) {
+ fmt.Printf("%x %x %x\n", self.Address(), []byte(key), value.Bytes())
+ })
+ */
+ //fmt.Printf("%x @:%x\n", self.Address(), self.state.Root())
}
func (c *StateObject) GetInstr(pc *big.Int) *ethutil.Value {
diff --git a/ethchain/vm.go b/ethchain/vm.go
index 3a956ee83..58d1bee89 100644
--- a/ethchain/vm.go
+++ b/ethchain/vm.go
@@ -195,7 +195,7 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
val := closure.GetStorage(x)
if val.BigInt().Cmp(ethutil.Big0) == 0 && len(y.Bytes()) > 0 {
mult = ethutil.Big2
- } else if !val.IsEmpty() && len(y.Bytes()) == 0 {
+ } else if val.BigInt().Cmp(ethutil.Big0) != 0 && len(y.Bytes()) == 0 {
mult = ethutil.Big0
} else {
mult = ethutil.Big1