aboutsummaryrefslogtreecommitdiffstats
path: root/ethstate
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-09-15 21:42:12 +0800
committerobscuren <geffobscura@gmail.com>2014-09-15 21:42:12 +0800
commit33a0dec8a157b9687ca6038f4deb011f3f1f7bdc (patch)
tree197b792e06dc3952df93957a39fdf6e44582ac96 /ethstate
parent2f614900e82036e3e8f6f6a714efc43e09aca830 (diff)
downloaddexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar.gz
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar.bz2
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar.lz
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar.xz
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar.zst
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.zip
Improved catching up and refactored
Diffstat (limited to 'ethstate')
-rw-r--r--ethstate/dump.go2
-rw-r--r--ethstate/state.go5
-rw-r--r--ethstate/state_object.go15
3 files changed, 14 insertions, 8 deletions
diff --git a/ethstate/dump.go b/ethstate/dump.go
index be60a05fc..cdd4228b8 100644
--- a/ethstate/dump.go
+++ b/ethstate/dump.go
@@ -28,7 +28,7 @@ func (self *State) Dump() []byte {
self.Trie.NewIterator().Each(func(key string, value *ethutil.Value) {
stateObject := NewStateObjectFromBytes([]byte(key), value.Bytes())
- account := Account{Balance: stateObject.Balance.String(), Nonce: stateObject.Nonce, CodeHash: ethutil.Bytes2Hex(stateObject.CodeHash)}
+ account := Account{Balance: stateObject.Balance.String(), Nonce: stateObject.Nonce, CodeHash: ethutil.Bytes2Hex(stateObject.codeHash)}
account.Storage = make(map[string]string)
stateObject.EachStorage(func(key string, value *ethutil.Value) {
diff --git a/ethstate/state.go b/ethstate/state.go
index 42bbf021b..0e87659fc 100644
--- a/ethstate/state.go
+++ b/ethstate/state.go
@@ -3,7 +3,6 @@ package ethstate
import (
"math/big"
- "github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
@@ -66,7 +65,9 @@ func (self *State) GetCode(addr []byte) []byte {
func (self *State) UpdateStateObject(stateObject *StateObject) {
addr := stateObject.Address()
- ethutil.Config.Db.Put(ethcrypto.Sha3Bin(stateObject.Code), stateObject.Code)
+ if len(stateObject.CodeHash()) > 0 {
+ ethutil.Config.Db.Put(stateObject.CodeHash(), stateObject.Code)
+ }
self.Trie.Update(string(addr), string(stateObject.RlpEncode()))
}
diff --git a/ethstate/state_object.go b/ethstate/state_object.go
index 6fc0696a8..be083e80a 100644
--- a/ethstate/state_object.go
+++ b/ethstate/state_object.go
@@ -32,7 +32,7 @@ type StateObject struct {
address []byte
// Shared attributes
Balance *big.Int
- CodeHash []byte
+ codeHash []byte
Nonce uint64
// Contract related attributes
State *State
@@ -236,7 +236,7 @@ func (self *StateObject) RefundGas(gas, price *big.Int) {
func (self *StateObject) Copy() *StateObject {
stateObject := NewStateObject(self.Address())
stateObject.Balance.Set(self.Balance)
- stateObject.CodeHash = ethutil.CopyBytes(self.CodeHash)
+ stateObject.codeHash = ethutil.CopyBytes(self.codeHash)
stateObject.Nonce = self.Nonce
if self.State != nil {
stateObject.State = self.State.Copy()
@@ -297,12 +297,17 @@ func (c *StateObject) RlpEncode() []byte {
} else {
root = ""
}
+
+ return ethutil.Encode([]interface{}{c.Nonce, c.Balance, root, c.CodeHash()})
+}
+
+func (c *StateObject) CodeHash() ethutil.Bytes {
var codeHash []byte
if len(c.Code) > 0 {
codeHash = ethcrypto.Sha3Bin(c.Code)
}
- return ethutil.Encode([]interface{}{c.Nonce, c.Balance, root, codeHash})
+ return codeHash
}
func (c *StateObject) RlpDecode(data []byte) {
@@ -314,9 +319,9 @@ func (c *StateObject) RlpDecode(data []byte) {
c.storage = make(map[string]*ethutil.Value)
c.gasPool = new(big.Int)
- c.CodeHash = decoder.Get(3).Bytes()
+ c.codeHash = decoder.Get(3).Bytes()
- c.Code, _ = ethutil.Config.Db.Get(c.CodeHash)
+ c.Code, _ = ethutil.Config.Db.Get(c.codeHash)
}
// Storage change object. Used by the manifest for notifying changes to