aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-21 07:12:39 +0800
committerobscuren <geffobscura@gmail.com>2014-05-21 07:12:39 +0800
commit734b2e4cf7a2e6ed3ab0815b795730c62e235a6b (patch)
treeb86a624e21eedc4eceb695a88a1ff3bb81e17848
parent5ceb1620e93e1999c6f72e6164c7c65af63244ec (diff)
parent3c35ba7c31423da644c5fb73030af4673cff90ec (diff)
downloadgo-tangerine-734b2e4cf7a2e6ed3ab0815b795730c62e235a6b.tar.gz
go-tangerine-734b2e4cf7a2e6ed3ab0815b795730c62e235a6b.tar.zst
go-tangerine-734b2e4cf7a2e6ed3ab0815b795730c62e235a6b.zip
Merge branch 'hotfix/4' into develop
-rw-r--r--ethchain/state.go10
-rw-r--r--ethchain/state_object.go1
-rw-r--r--ethchain/vm.go6
-rw-r--r--ethpub/pub.go2
-rw-r--r--ethutil/trie.go4
5 files changed, 12 insertions, 11 deletions
diff --git a/ethchain/state.go b/ethchain/state.go
index db715f1cb..6ec6916f4 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -60,6 +60,7 @@ func (s *State) GetStateObject(addr []byte) *StateObject {
// 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
}
@@ -70,8 +71,9 @@ func (s *State) GetStateObject(addr []byte) *StateObject {
func (s *State) UpdateStateObject(object *StateObject) {
addr := object.Address()
- if object.state != nil {
+ if object.state != nil && s.states[string(addr)] == nil {
s.states[string(addr)] = object.state
+ //fmt.Printf("update cached #%d %x addr: %x\n", object.state.trie.Cache().Len(), object.state.Root(), addr[0:4])
}
ethutil.Config.Db.Put(ethutil.Sha3Bin(object.Script()), object.Script())
@@ -81,12 +83,6 @@ func (s *State) UpdateStateObject(object *StateObject) {
s.manifest.AddObjectChange(object)
}
-func (s *State) SetStateObject(stateObject *StateObject) {
- s.states[string(stateObject.address)] = stateObject.state
-
- s.UpdateStateObject(stateObject)
-}
-
func (s *State) GetAccount(addr []byte) (account *StateObject) {
data := s.trie.Get(string(addr))
if data == "" {
diff --git a/ethchain/state_object.go b/ethchain/state_object.go
index cb6211ea6..8e059f334 100644
--- a/ethchain/state_object.go
+++ b/ethchain/state_object.go
@@ -78,6 +78,7 @@ func (c *StateObject) SetAddr(addr []byte, value interface{}) {
func (c *StateObject) SetStorage(num *big.Int, val *ethutil.Value) {
addr := ethutil.BigToBytes(num, 256)
+ //fmt.Println("storing", val.BigInt(), "@", num)
c.SetAddr(addr, val)
}
diff --git a/ethchain/vm.go b/ethchain/vm.go
index 9be38fcc1..d8254998e 100644
--- a/ethchain/vm.go
+++ b/ethchain/vm.go
@@ -450,7 +450,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
} else {
stack.Push(ethutil.BigD(addr))
- vm.state.SetStateObject(contract)
+ vm.state.UpdateStateObject(contract)
}
case oCALL:
require(7)
@@ -499,7 +499,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
stack.Push(ethutil.BigTrue)
}
- vm.state.SetStateObject(contract)
+ vm.state.UpdateStateObject(contract)
mem.Set(retOffset.Int64(), retSize.Int64(), ret)
} else {
@@ -517,7 +517,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
receiver := vm.state.GetAccount(stack.Pop().Bytes())
receiver.AddAmount(closure.object.Amount)
- vm.state.SetStateObject(receiver)
+ vm.state.UpdateStateObject(receiver)
closure.object.state.Purge()
diff --git a/ethpub/pub.go b/ethpub/pub.go
index fb1018d47..ec187e276 100644
--- a/ethpub/pub.go
+++ b/ethpub/pub.go
@@ -162,7 +162,7 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in
acc := lib.stateManager.TransState().GetStateObject(keyPair.Address())
tx.Nonce = acc.Nonce
acc.Nonce += 1
- lib.stateManager.TransState().SetStateObject(acc)
+ lib.stateManager.TransState().UpdateStateObject(acc)
tx.Sign(keyPair.PrivateKey)
lib.txPool.QueueTransaction(tx)
diff --git a/ethutil/trie.go b/ethutil/trie.go
index 1c7bd478d..c993e4d8f 100644
--- a/ethutil/trie.go
+++ b/ethutil/trie.go
@@ -6,6 +6,10 @@ import (
"sync"
)
+func (s *Cache) Len() int {
+ return len(s.nodes)
+}
+
// TODO
// A StateObject is an object that has a state root
// This is goig to be the object for the second level caching (the caching of object which have a state such as contracts)