diff options
author | obscuren <geffobscura@gmail.com> | 2015-06-17 19:27:51 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-06-17 19:27:51 +0800 |
commit | aa699a1283c93740bba15f94c774d92ea6fe1980 (patch) | |
tree | 08e04161d8552e8516f449440067c76728fb9c19 /core | |
parent | aaddc99c35f1fcc9b5d7198dd6571dfa43718ae8 (diff) | |
download | dexon-aa699a1283c93740bba15f94c774d92ea6fe1980.tar dexon-aa699a1283c93740bba15f94c774d92ea6fe1980.tar.gz dexon-aa699a1283c93740bba15f94c774d92ea6fe1980.tar.bz2 dexon-aa699a1283c93740bba15f94c774d92ea6fe1980.tar.lz dexon-aa699a1283c93740bba15f94c774d92ea6fe1980.tar.xz dexon-aa699a1283c93740bba15f94c774d92ea6fe1980.tar.zst dexon-aa699a1283c93740bba15f94c774d92ea6fe1980.zip |
core/state: removed state from state object
Diffstat (limited to 'core')
-rw-r--r-- | core/state/dump.go | 6 | ||||
-rw-r--r-- | core/state/state_object.go | 33 | ||||
-rw-r--r-- | core/state/statedb.go | 12 |
3 files changed, 20 insertions, 31 deletions
diff --git a/core/state/dump.go b/core/state/dump.go index 70ea21691..f6f2f9029 100644 --- a/core/state/dump.go +++ b/core/state/dump.go @@ -34,7 +34,7 @@ func (self *StateDB) RawDump() World { account := Account{Balance: stateObject.balance.String(), Nonce: stateObject.nonce, Root: common.Bytes2Hex(stateObject.Root()), CodeHash: common.Bytes2Hex(stateObject.codeHash)} account.Storage = make(map[string]string) - storageIt := stateObject.State.trie.Iterator() + storageIt := stateObject.trie.Iterator() for storageIt.Next() { account.Storage[common.Bytes2Hex(self.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(storageIt.Value) } @@ -54,8 +54,8 @@ func (self *StateDB) Dump() []byte { // Debug stuff func (self *StateObject) CreateOutputForDiff() { - fmt.Printf("%x %x %x %x\n", self.Address(), self.State.Root(), self.balance.Bytes(), self.nonce) - it := self.State.trie.Iterator() + fmt.Printf("%x %x %x %x\n", self.Address(), self.Root(), self.balance.Bytes(), self.nonce) + it := self.trie.Iterator() for it.Next() { fmt.Printf("%x %x\n", it.Key, it.Value) } diff --git a/core/state/state_object.go b/core/state/state_object.go index 1deb9bf02..2e4fe3269 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -40,9 +40,8 @@ func (self Storage) Copy() Storage { type StateObject struct { // State database for storing state changes - db common.Database - // The state object - State *StateDB + db common.Database + trie *trie.SecureTrie // Address belonging to this account address common.Address @@ -75,7 +74,6 @@ type StateObject struct { func (self *StateObject) Reset() { self.storage = make(Storage) - self.State.Reset() } func NewStateObject(address common.Address, db common.Database) *StateObject { @@ -83,7 +81,7 @@ func NewStateObject(address common.Address, db common.Database) *StateObject { //address := common.ToAddress(addr) object := &StateObject{db: db, address: address, balance: new(big.Int), gasPool: new(big.Int), dirty: true} - object.State = New(common.Hash{}, db) //New(trie.New(common.Config.Db, "")) + object.trie = trie.NewSecure((common.Hash{}).Bytes(), db) object.storage = make(Storage) object.gasPool = new(big.Int) object.prepaid = new(big.Int) @@ -110,7 +108,7 @@ func NewStateObjectFromBytes(address common.Address, data []byte, db common.Data object.nonce = extobject.Nonce object.balance = extobject.Balance object.codeHash = extobject.CodeHash - object.State = New(extobject.Root, db) + object.trie = trie.NewSecure(extobject.Root[:], db) object.storage = make(map[string]common.Hash) object.gasPool = new(big.Int) object.prepaid = new(big.Int) @@ -130,7 +128,7 @@ func (self *StateObject) MarkForDeletion() { func (c *StateObject) getAddr(addr common.Hash) common.Hash { var ret []byte - rlp.DecodeBytes(c.State.trie.Get(addr[:]), &ret) + rlp.DecodeBytes(c.trie.Get(addr[:]), &ret) return common.BytesToHash(ret) } @@ -140,7 +138,7 @@ func (c *StateObject) setAddr(addr []byte, value common.Hash) { // if RLPing failed we better panic and not fail silently. This would be considered a consensus issue panic(err) } - c.State.trie.Update(addr, v) + c.trie.Update(addr, v) } func (self *StateObject) Storage() Storage { @@ -165,10 +163,11 @@ func (self *StateObject) SetState(k, value common.Hash) { self.dirty = true } -func (self *StateObject) Sync() { +// Update updates the current cached storage to the trie +func (self *StateObject) Update() { for key, value := range self.storage { if (value == common.Hash{}) { - self.State.trie.Delete([]byte(key)) + self.trie.Delete([]byte(key)) continue } @@ -261,9 +260,7 @@ func (self *StateObject) Copy() *StateObject { stateObject.balance.Set(self.balance) stateObject.codeHash = common.CopyBytes(self.codeHash) stateObject.nonce = self.nonce - if self.State != nil { - stateObject.State = self.State.Copy() - } + stateObject.trie = self.trie stateObject.code = common.CopyBytes(self.code) stateObject.initCode = common.CopyBytes(self.initCode) stateObject.storage = self.storage.Copy() @@ -301,11 +298,11 @@ func (c *StateObject) Init() Code { } func (self *StateObject) Trie() *trie.SecureTrie { - return self.State.trie + return self.trie } func (self *StateObject) Root() []byte { - return self.Trie().Root() + return self.trie.Root() } func (self *StateObject) Code() []byte { @@ -337,10 +334,10 @@ func (self *StateObject) EachStorage(cb func(key, value []byte)) { cb([]byte(h), v.Bytes()) } - it := self.State.trie.Iterator() + it := self.trie.Iterator() for it.Next() { // ignore cached values - key := self.State.trie.GetKey(it.Key) + key := self.trie.GetKey(it.Key) if _, ok := self.storage[string(key)]; !ok { cb(key, it.Value) } @@ -364,7 +361,7 @@ func (c *StateObject) RlpDecode(data []byte) { decoder := common.NewValueFromBytes(data) c.nonce = decoder.Get(0).Uint() c.balance = decoder.Get(1).BigInt() - c.State = New(common.BytesToHash(decoder.Get(2).Bytes()), c.db) //New(trie.New(common.Config.Db, decoder.Get(2).Interface())) + c.trie = trie.NewSecure(decoder.Get(2).Bytes(), c.db) c.storage = make(map[string]common.Hash) c.gasPool = new(big.Int) diff --git a/core/state/statedb.go b/core/state/statedb.go index 1c75ee4db..134c4b3c7 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -296,10 +296,6 @@ func (s *StateDB) Reset() { // Reset all nested states for _, stateObject := range s.stateObjects { - if stateObject.State == nil { - continue - } - stateObject.Reset() } @@ -310,11 +306,7 @@ func (s *StateDB) Reset() { func (s *StateDB) Sync() { // Sync all nested states for _, stateObject := range s.stateObjects { - if stateObject.State == nil { - continue - } - - stateObject.State.Sync() + stateObject.trie.Commit() } s.trie.Commit() @@ -339,7 +331,7 @@ func (self *StateDB) Update() { if stateObject.remove { self.DeleteStateObject(stateObject) } else { - stateObject.Sync() + stateObject.Update() self.UpdateStateObject(stateObject) } |