aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-06-17 19:27:51 +0800
committerobscuren <geffobscura@gmail.com>2015-06-17 19:27:51 +0800
commitaa699a1283c93740bba15f94c774d92ea6fe1980 (patch)
tree08e04161d8552e8516f449440067c76728fb9c19 /core
parentaaddc99c35f1fcc9b5d7198dd6571dfa43718ae8 (diff)
downloaddexon-aa699a1283c93740bba15f94c774d92ea6fe1980.tar.gz
dexon-aa699a1283c93740bba15f94c774d92ea6fe1980.tar.zst
dexon-aa699a1283c93740bba15f94c774d92ea6fe1980.zip
core/state: removed state from state object
Diffstat (limited to 'core')
-rw-r--r--core/state/dump.go6
-rw-r--r--core/state/state_object.go33
-rw-r--r--core/state/statedb.go12
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)
}
ass='deletions'>-0/+52 * - Update to 0.97.0wen2018-03-172-4/+4 * - Update to 5.3.2wen2018-03-172-4/+4 * Fix WWWsunpoet2018-03-171-1/+1 * Fix WWWsunpoet2018-03-171-1/+1 * Fix WWWsunpoet2018-03-171-1/+1 * Fix WWWsunpoet2018-03-171-1/+1 * Fix WWWsunpoet2018-03-171-1/+1 * Update WWWsunpoet2018-03-171-1/+1 * Update WWWsunpoet2018-03-171-1/+1 * Update WWWsunpoet2018-03-171-1/+1 * Update WWWsunpoet2018-03-171-1/+1 * Update WWWsunpoet2018-03-171-1/+1 * Update to 3.8.1sunpoet2018-03-173-18/+7 * Update to 3.0.2sunpoet2018-03-172-4/+4 * Update to 1.3.1sunpoet2018-03-172-4/+4 * Update to 3.0.2sunpoet2018-03-172-4/+4 * Update to 1.3.3sunpoet2018-03-172-4/+4 * Update to 1.6.2sunpoet2018-03-172-9/+6 * Update to 1.8.3sunpoet2018-03-173-5/+6 * Add LICENSEsunpoet2018-03-172-3/+8 * Convert to options dependency helpersunpoet2018-03-172-24/+20 * Add py-idna_ssl 1.0.1sunpoet2018-03-174-0/+35 * Add p5-Progress-Any 0.211sunpoet2018-03-175-0/+46 * Update to the 20180315 snapshot of GCC 7.3.1.gerald2018-03-172-5/+4 * Update to Wine 3.4. This includes the following changes:gerald2018-03-173-5/+57 * Update to the 20180314 snapshot of GCC 6.4.1.gerald2018-03-172-5/+4 * - Add LICENSEamdmi32018-03-172-4/+5 * net/prtunnel: Update URL, the previous gives 404vd2018-03-171-1/+1 * Skip ENOMEM check for printf when building with qemu, this makesantoine2018-03-171-0/+4 * Skip ENOMEM check for printf when building with qemu, this makesantoine2018-03-172-0/+8 * Update to 7.3.0matthew2018-03-173-4/+11 * Attempt to fix on HEAD.bar2018-03-172-0/+22 * - Unbreak patchvsevolod2018-03-171-49/+1 * Update to the 20180311 snapshot of GCC 8.gerald2018-03-172-5/+4 * - Add LICENSEamdmi32018-03-171-0/+5 * Update net/nats-streaming-server to version 0.9.0.olgeni2018-03-172-4/+4 * irc/xchat: Deprecatetobik2018-03-171-0/+3 * - Remove redundant regression-test target, the port already supports 'make test'amdmi32018-03-171-5/+0 * www/palemoon: Disable official brandingtobik2018-03-171-7/+1 * print/lilypond: Unbreakyuri2018-03-172-8/+19 * Connect editors/libreoffice-hsblwhsu2018-03-171-0/+1 * Attempt to fix on HEAD.bar2018-03-172-2/+22 * New ports: The TeX Gyre (TG) Math Fonts (4 new ports)yuri2018-03-1713-0/+140 * - Update LibreOffice to 6.0.2 [1]lwhsu2018-03-17246-1103/+608 * - fix API for pg-1.0.0dinoex2018-03-173-0/+95 * graphics/py-pillow: Update to 5.0.0koobs2018-03-172-9/+9 * Re-added port: textproc/ibus-table: Table-based input method framework for IB...yuri2018-03-176-1/+96 * Add LICENSEsunpoet2018-03-173-6/+12 * Update to 3.36.0sunpoet2018-03-173-23/+27 * Update to 3.20.0sunpoet2018-03-173-14/+14 * Update to 0.61.0sunpoet2018-03-172-4/+4 * Update to 6.4.1sunpoet2018-03-172-4/+4 * Update to 2018.3sunpoet2018-03-172-4/+4 * Update to 11.8.0sunpoet2018-03-172-4/+4 * devel/jenkins-lts: update to 2.107.1swills2018-03-172-4/+4 * Upgrade dnsdbq to version 1.0.0:truckman2018-03-172-6/+6 * emulators/rpcs3: update to 0.0.5.83jbeich2018-03-172-5/+5 * No reason to try removing /usr as it is in the base mtreebdrewery2018-03-17