From 42d43147cac99469eb3f445342fe9e1ebeb5222e Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 22 Aug 2014 10:58:49 +0200 Subject: Changed log statements --- ethstate/state.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethstate') diff --git a/ethstate/state.go b/ethstate/state.go index cf060e795..2f7f00a32 100644 --- a/ethstate/state.go +++ b/ethstate/state.go @@ -103,7 +103,7 @@ func (self *State) GetOrNewStateObject(addr []byte) *StateObject { func (self *State) NewStateObject(addr []byte) *StateObject { addr = ethutil.Address(addr) - statelogger.Infof("(+) %x\n", addr) + statelogger.Debugf("(+) %x\n", addr) stateObject := NewStateObject(addr) self.stateObjects[string(addr)] = stateObject -- cgit v1.2.3 From 3f904bf3acb5779f68834ebca95825ea1990f85b Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 25 Aug 2014 11:29:42 +0200 Subject: Implemented POST --- ethstate/state_object.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ethstate') diff --git a/ethstate/state_object.go b/ethstate/state_object.go index 67d09edd8..bf4e92583 100644 --- a/ethstate/state_object.go +++ b/ethstate/state_object.go @@ -245,6 +245,7 @@ func (self *StateObject) Copy() *StateObject { stateObject.InitCode = ethutil.CopyBytes(self.InitCode) stateObject.storage = self.storage.Copy() stateObject.gasPool.Set(self.gasPool) + stateObject.remove = self.remove return stateObject } @@ -271,6 +272,11 @@ func (c *StateObject) Init() Code { return c.InitCode } +// To satisfy ClosureRef +func (self *StateObject) Object() *StateObject { + return self +} + // Debug stuff func (self *StateObject) CreateOutputForDiff() { fmt.Printf("%x %x %x %x\n", self.Address(), self.State.Root(), self.Balance.Bytes(), self.Nonce) -- cgit v1.2.3 From d91357d00ca080c63d81570504e5c45fb15e3841 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 8 Sep 2014 00:50:04 +0200 Subject: Added GetCode method --- ethstate/state.go | 9 +++++++++ ethstate/state_object.go | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'ethstate') diff --git a/ethstate/state.go b/ethstate/state.go index 2f7f00a32..42bbf021b 100644 --- a/ethstate/state.go +++ b/ethstate/state.go @@ -49,6 +49,15 @@ func (self *State) GetNonce(addr []byte) uint64 { return 0 } +func (self *State) GetCode(addr []byte) []byte { + stateObject := self.GetStateObject(addr) + if stateObject != nil { + return stateObject.Code + } + + return nil +} + // // Setting, updating & deleting state object methods // diff --git a/ethstate/state_object.go b/ethstate/state_object.go index bf4e92583..6fc0696a8 100644 --- a/ethstate/state_object.go +++ b/ethstate/state_object.go @@ -297,8 +297,12 @@ func (c *StateObject) RlpEncode() []byte { } else { root = "" } + var codeHash []byte + if len(c.Code) > 0 { + codeHash = ethcrypto.Sha3Bin(c.Code) + } - return ethutil.Encode([]interface{}{c.Nonce, c.Balance, root, ethcrypto.Sha3Bin(c.Code)}) + return ethutil.Encode([]interface{}{c.Nonce, c.Balance, root, codeHash}) } func (c *StateObject) RlpDecode(data []byte) { -- cgit v1.2.3 From 33a0dec8a157b9687ca6038f4deb011f3f1f7bdc Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 15 Sep 2014 15:42:12 +0200 Subject: Improved catching up and refactored --- ethstate/dump.go | 2 +- ethstate/state.go | 5 +++-- ethstate/state_object.go | 15 ++++++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) (limited to 'ethstate') 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 -- cgit v1.2.3